[goffice] trim label. [#657670]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] trim label. [#657670]
- Date: Wed, 31 Aug 2011 03:20:49 +0000 (UTC)
commit 6939536aa66f70b7e91097d4a1e5881748ace4d3
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Tue Aug 30 21:20:15 2011 -0600
trim label. [#657670]
2011-08-30 Andreas J. Guelzow <aguelzow pyrshep ca>
* goffice/graph/gog-axis.c (axis_format_value): trim label. [#657670]
* goffice/utils/go-string.c (find_shape_attr): new
(go_string_trim): new
* goffice/utils/go-string.h (go_string_trim): new
ChangeLog | 7 +++++
goffice/graph/gog-axis.c | 10 ++++---
goffice/utils/go-string.c | 65 +++++++++++++++++++++++++++++++++++++++++++++
goffice/utils/go-string.h | 1 +
4 files changed, 79 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 477209a..e792078 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-08-30 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * goffice/graph/gog-axis.c (axis_format_value): trim label. [#657670]
+ * goffice/utils/go-string.c (find_shape_attr): new
+ (go_string_trim): new
+ * goffice/utils/go-string.h (go_string_trim): new
+
2011-08-30 Jean Brefort <jean brefort normalesup org>
* goffice/canvas/goc-graph.c (goc_graph_do_tooltip),
diff --git a/goffice/graph/gog-axis.c b/goffice/graph/gog-axis.c
index 1506d0b..bf67b80 100644
--- a/goffice/graph/gog-axis.c
+++ b/goffice/graph/gog-axis.c
@@ -185,13 +185,15 @@ axis_format_value (GogAxis *axis, double val, GOString **str)
-1, date_conv, TRUE);
if (err)
*str = go_string_new ("#####");
- else
+ else {
*str = go_string_new_rich
(g_strdup (pango_layout_get_text (layout)),
- -1,
- FALSE,
- pango_attr_list_ref (pango_layout_get_attributes (layout)),
+ -1, FALSE,
+ pango_attr_list_ref
+ (pango_layout_get_attributes (layout)),
NULL);
+ *str = go_string_trim (*str, TRUE);
+ }
g_object_unref (layout);
}
diff --git a/goffice/utils/go-string.c b/goffice/utils/go-string.c
index fc3e007..3d781b0 100644
--- a/goffice/utils/go-string.c
+++ b/goffice/utils/go-string.c
@@ -651,3 +651,68 @@ go_string_equal_rich (gconstpointer gstr_a, gconstpointer gstr_b)
return go_string_equal (gstr_a, gstr_b);
}
+
+static gboolean
+find_shape_attr (PangoAttribute *attribute, G_GNUC_UNUSED gpointer data)
+{
+ return (attribute->klass->type == PANGO_ATTR_SHAPE);
+}
+
+/**
+ * go_string_trim
+ **/
+GOString *
+go_string_trim (GOString *gstr, gboolean internal)
+{
+ /*TODO: handle phonetics */
+ GOStringImpl *impl = (GOStringImpl *)gstr;
+ char *text = NULL;
+ char const *ctext;
+ PangoAttrList *attrs;
+ char const *t;
+ int cnt, len;
+
+ if ((impl->flags & GO_STRING_IS_RICH) == 0)
+ return gstr;
+
+ attrs = go_string_get_markup (gstr);
+ t = ctext = text = g_strdup (gstr->str);
+ if (attrs != NULL)
+ attrs = pango_attr_list_copy (attrs);
+ while (*t != 0 && *t == ' ')
+ t++;
+ cnt = t - text;
+ if (cnt > 0) {
+ len = strlen (t);
+ memmove (text, t, len + 1);
+ go_pango_attr_list_erase (attrs, 0, cnt);
+ } else
+ len = strlen(ctext);
+ t = ctext + len - 1;
+ while (t > ctext && *t == ' ')
+ t--;
+ cnt = ((t - ctext) + 1);
+ if (len > cnt) {
+ text[cnt] = '\0';
+ go_pango_attr_list_erase (attrs, cnt, len - cnt);
+ }
+
+ if (internal) {
+ PangoAttrList *at = pango_attr_list_filter (attrs, find_shape_attr, NULL);
+ char *tt = text;
+ if (at) pango_attr_list_unref (at);
+ while (NULL != (tt = strchr (tt, ' '))) {
+ if (tt[1] == ' ') {
+ go_pango_attr_list_erase (attrs, tt - text, 1);
+ memmove (tt + 1, tt + 2, strlen(tt + 2) + 1);
+ continue;
+ }
+ tt++;
+ }
+ }
+
+ go_string_unref (gstr);
+
+ return go_string_new_rich (text, -1, FALSE, attrs, NULL);
+}
+
diff --git a/goffice/utils/go-string.h b/goffice/utils/go-string.h
index 3d1dcd0..8391d08 100644
--- a/goffice/utils/go-string.h
+++ b/goffice/utils/go-string.h
@@ -63,6 +63,7 @@ int go_string_cmp_ignorecase (gconstpointer gstr_a, gconstpointer gstr_b);
gboolean go_string_equal (gconstpointer gstr_a, gconstpointer gstr_b);
gboolean go_string_equal_ignorecase (gconstpointer gstr_a, gconstpointer gstr_b);
gboolean go_string_equal_rich (gconstpointer gstr_a, gconstpointer gstr_b);
+GOString *go_string_trim (GOString *gstr, gboolean internal);
GOString *go_string_ERROR (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]