[goffice] Use markup for discrete axis tip labels.



commit 4f9a1b48a37628f5faadf63969852a01d3a24bac
Author: Jean Brefort <jean brefort normalesup org>
Date:   Fri Aug 5 15:24:44 2011 +0200

    Use markup for discrete axis tip labels.

 ChangeLog                   |   10 ++++++++++
 goffice/data/go-data-impl.h |    4 ++--
 goffice/data/go-data.c      |    4 ++--
 goffice/data/go-data.h      |    2 +-
 goffice/graph/gog-axis.c    |   13 ++++++++++++-
 goffice/utils/go-string.c   |   19 +++++++++++--------
 6 files changed, 38 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3f41d04..65a9cb1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-08-05  Jean Brefort  <jean brefort normalesup org>
+
+	* goffice/data/go-data-impl.h: sanitize the get_murkup API.
+	* goffice/data/go-data.c (_data_scalar_get_markup):
+	* goffice/data/go-data.h: ditto.
+	* goffice/graph/gog-axis.c (gog_axis_ticks_set_markup),
+	(map_discrete_calc_ticks): use markup for discrete axes tip labels.
+	* goffice/utils/go-string.c (replace_rich_base_with_plain),
+	(go_string_new_rich), (go_string_unref):
+
 2011-08-04  Jean Brefort  <jean brefort normalesup org>
 
 	* goffice/canvas/goc-group.c (goc_group_update_bounds),
diff --git a/goffice/data/go-data-impl.h b/goffice/data/go-data-impl.h
index 3d90369..f6b6a90 100644
--- a/goffice/data/go-data-impl.h
+++ b/goffice/data/go-data-impl.h
@@ -92,7 +92,7 @@ typedef struct {
 	void	 (*load_values) (GODataVector *vec);
 	double	 (*get_value)   (GODataVector *vec, unsigned i);
 	char	*(*get_str)	(GODataVector *vec, unsigned i);
-	PangoAttrList const *(*get_markup) (GODataVector *data, unsigned i);
+	PangoAttrList *(*get_markup) (GODataVector *data, unsigned i);
 } GODataVectorClass;
 
 #define	GO_DATA_MATRIX_SIZE_CACHED GO_DATA_SIZE_CACHED
@@ -112,7 +112,7 @@ typedef struct {
 	void	 (*load_values) (GODataMatrix *vec);
 	double	 (*get_value)   (GODataMatrix *mat, unsigned i, unsigned j);
 	char	*(*get_str)	(GODataMatrix *mat, unsigned i, unsigned j);
-	PangoAttrList const *(*get_markup) (GODataMatrix *mat, unsigned i, unsigned j);
+	PangoAttrList *(*get_markup) (GODataMatrix *mat, unsigned i, unsigned j);
 } GODataMatrixClass;
 
 G_END_DECLS
diff --git a/goffice/data/go-data.c b/goffice/data/go-data.c
index 6505e62..0885e8b 100644
--- a/goffice/data/go-data.c
+++ b/goffice/data/go-data.c
@@ -602,7 +602,7 @@ _data_scalar_get_string (GOData *data, unsigned int *coordinates)
 static PangoAttrList *
 _data_scalar_get_markup (GOData *data, unsigned int *coordinates)
 {
-	return pango_attr_list_copy (go_data_scalar_get_markup ((GODataScalar *) data));
+	return pango_attr_list_copy ((PangoAttrList *) go_data_scalar_get_markup ((GODataScalar *) data));
 }
 
 static void
@@ -638,7 +638,7 @@ go_data_scalar_get_str (GODataScalar *scalar)
 	return (*klass->get_str) (scalar);
 }
 
-PangoAttrList *
+PangoAttrList const *
 go_data_scalar_get_markup (GODataScalar *scalar)
 {
 	GODataScalarClass const *klass = GO_DATA_SCALAR_GET_CLASS (scalar);
diff --git a/goffice/data/go-data.h b/goffice/data/go-data.h
index ff28ee7..58e82f6 100644
--- a/goffice/data/go-data.h
+++ b/goffice/data/go-data.h
@@ -76,7 +76,7 @@ GType go_data_scalar_get_type (void);
 
 double      go_data_scalar_get_value  (GODataScalar *val);
 char const *go_data_scalar_get_str    (GODataScalar *val);
-PangoAttrList *go_data_scalar_get_markup    (GODataScalar *val);
+PangoAttrList const *go_data_scalar_get_markup    (GODataScalar *val);
 
 /*************************************************************************/
 
diff --git a/goffice/graph/gog-axis.c b/goffice/graph/gog-axis.c
index b9016e7..be61241 100644
--- a/goffice/graph/gog-axis.c
+++ b/goffice/graph/gog-axis.c
@@ -121,6 +121,13 @@ gog_axis_ticks_set_text (GogAxisTick *ticks, char const *str)
 	ticks->str = go_string_new (str);
 }
 
+static void
+gog_axis_ticks_set_markup (GogAxisTick *ticks, char const *str, PangoAttrList *l)
+{
+	go_string_unref (ticks->str);
+	ticks->str = go_string_new_rich (str, -1, TRUE, l, NULL);
+}
+
 static GogAxisTick *
 create_invalid_axis_ticks (double min, double max)
 {
@@ -382,8 +389,12 @@ map_discrete_calc_ticks (GogAxis *axis)
 		ticks[j].str = NULL;
 		if (axis->labels != NULL) {
 			if (index < (int) go_data_get_vector_size (axis->labels) && index >= 0) {
+				PangoAttrList *l = go_data_get_vector_markup (axis->labels, index);
 				label = go_data_get_vector_string (axis->labels, index);
-				gog_axis_ticks_set_text(&ticks[j], label);
+				if (l != NULL)
+					gog_axis_ticks_set_markup (&ticks[j], label, l);
+				else
+					gog_axis_ticks_set_text (&ticks[j], label);
 				g_free (label);
 			}
 		} else {
diff --git a/goffice/utils/go-string.c b/goffice/utils/go-string.c
index 1783810..8322f99 100644
--- a/goffice/utils/go-string.c
+++ b/goffice/utils/go-string.c
@@ -82,12 +82,17 @@ replace_rich_base_with_plain (GOStringRichImpl *rich)
 	if ((rich->base.flags & GO_STRING_IS_SHARED)) {
 		GSList *shares = g_hash_table_lookup (go_strings_shared, res->base.str);
 		unsigned n = g_slist_length (shares);
-		g_assert (rich->base.ref_count > n);
+		g_assert (rich->base.ref_count >= n);
+		if (n == 0)
+			res->flags &= ~GO_STRING_IS_SHARED;
 		rich->base.flags &= ~GO_STRING_IS_SHARED;
 		rich->base.ref_count -= n;
+		if (rich->base.ref_count == 0) {
+			rich->base.ref_count = 1;
+			rich->base.base.str = g_strdup (rich->base.base.str); /* don't free the string */
+			go_string_unref ((GOString *) rich);
+		}
 		res->ref_count += n;
-		/* ignore result, assignment is just to make the compiler shutup */
-		shares = g_slist_insert (shares, res, 1);
 	} else
 		g_hash_table_insert (go_strings_shared, (gpointer) res->base.str,
 			g_slist_prepend (NULL, rich));
@@ -236,10 +241,7 @@ go_string_new_rich (char const *str,
 		g_hash_table_insert (go_strings_base, rich, rich);
 	} else {
 		go_string_ref (&base->base);
-		if (str != rich->base.base.str) { /* watch for people doing something stupid */
-			if (!copy) g_free ((char *)str);
-			rich->base.base.str = base->base.str;
-		}
+		rich->base.base.str = base->base.str;
 		rich->base.flags |= GO_STRING_IS_DEPENDENT;
 		if ((base->flags & GO_STRING_IS_SHARED)) {
 			GSList *shares = g_hash_table_lookup (go_strings_shared, rich->base.base.str);
@@ -298,7 +300,8 @@ go_string_unref (GOString *gstr)
 			g_hash_table_remove (go_strings_base, gstr);
 			g_free ((gpointer)gstr->str);
 		}
-		g_slice_free1 (sizeof (GOStringImpl), gstr);
+		g_slice_free1 ((impl->flags & GO_STRING_IS_RICH?
+		        		sizeof (GOStringRichImpl): sizeof (GOStringImpl)), gstr);
 	}
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]