[goffice] Add support for rich text labels in charts.
- From: Jean BrÃfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Add support for rich text labels in charts.
- Date: Wed, 3 Aug 2011 14:21:40 +0000 (UTC)
commit 5457e47ee4b9af197e0c397392289936023de842
Author: Jean Brefort <jean brefort normalesup org>
Date: Wed Aug 3 16:25:40 2011 +0200
Add support for rich text labels in charts.
ChangeLog | 12 ++++++++++++
goffice/canvas/goc-polygon.c | 2 +-
goffice/graph/gog-label.c | 40 ++++++++++++++++++++++++++++++++++++----
goffice/graph/gog-label.h | 2 ++
goffice/graph/gog-renderer.c | 18 +++++++++++++++++-
goffice/graph/gog-renderer.h | 2 ++
6 files changed, 70 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 65b2722..dbce4a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2011-08-03 Jean Brefort <jean brefort normalesup org>
+ * goffice/canvas/goc-polygon.c (goc_polygon_set_property): make it
+ compile again.
+ * goffice/graph/gog-label.c (gog_text_get_markup),
+ (gog_label_get_markup), (gog_label_class_init),
+ (gog_text_view_render): add support for rich text labels.
+ * goffice/graph/gog-label.h: ditto.
+ * goffice/graph/gog-renderer.c (gog_renderer_get_text_AABR),
+ (gog_renderer_get_gostring_AABR): ditto.
+ * goffice/graph/gog-renderer.h: ditto.
+
+2011-08-03 Jean Brefort <jean brefort normalesup org>
+
* goffice/canvas/goc-polygon.c (goc_polygon_finalize),
(goc_polygon_set_property), (goc_polygon_get_property),
(goc_polygon_prepare_path): replaced private structures by public data.
diff --git a/goffice/canvas/goc-polygon.c b/goffice/canvas/goc-polygon.c
index 37b53a2..7c8ac08 100644
--- a/goffice/canvas/goc-polygon.c
+++ b/goffice/canvas/goc-polygon.c
@@ -69,7 +69,7 @@ goc_polygon_set_property (GObject *gobject, guint param_id,
} else
polygon->points = NULL;
/* reset sizes */
- g_free (priv->sizes);
+ g_free (polygon->sizes);
polygon->sizes = NULL;
polygon->nb_sizes = 0;
break;
diff --git a/goffice/graph/gog-label.c b/goffice/graph/gog-label.c
index 805e874..ba85966 100644
--- a/goffice/graph/gog-label.c
+++ b/goffice/graph/gog-label.c
@@ -143,6 +143,21 @@ gog_text_get_str (GogText *text)
return NULL;
}
+PangoAttrList *
+gog_text_get_markup (GogText *text)
+{
+ GogTextClass *klass;
+
+ g_return_val_if_fail (GOG_IS_TEXT (text), NULL);
+
+ klass = GOG_TEXT_GET_CLASS (text);
+
+ if (klass->get_markup != NULL)
+ return (*klass->get_markup) (text);
+
+ return NULL;
+}
+
GSF_CLASS_ABSTRACT (GogText, gog_text,
gog_text_class_init, gog_text_init,
GOG_TYPE_OUTLINED_OBJECT);
@@ -201,6 +216,19 @@ gog_label_get_str (GogText *text)
return NULL;
}
+static PangoAttrList *
+gog_label_get_markup (GogText *text)
+{
+ GogLabel *label = GOG_LABEL (text);
+
+ g_return_val_if_fail (GOG_IS_LABEL (label), NULL);
+
+ if (label->text.data != NULL)
+ return go_data_get_scalar_markup (label->text.data);
+
+ return NULL;
+}
+
static void
gog_label_finalize (GObject *obj)
{
@@ -221,6 +249,7 @@ gog_label_class_init (GogLabelClass *klass)
label_parent_klass = g_type_class_peek_parent (klass);
gobject_klass->finalize = gog_label_finalize;
got_klass->get_str = gog_label_get_str;
+ got_klass->get_markup = gog_label_get_markup;
}
static void
@@ -460,6 +489,9 @@ gog_text_view_render (GogView *view, GogViewAllocation const *bbox)
gog_renderer_push_style (view->renderer, style);
if (str != NULL) {
+ GOString *gostr = go_string_new_rich (str, -1, FALSE,
+ gog_label_get_markup (text),
+ NULL);
double outline = gog_renderer_line_size (view->renderer,
goo->base.style->line.width);
if (style->fill.type != GO_STYLE_FILL_NONE || outline > 0.) {
@@ -467,15 +499,15 @@ gog_text_view_render (GogView *view, GogViewAllocation const *bbox)
GOGeometryAABR aabr;
double pad_x = gog_renderer_pt2r_x (view->renderer, goo->padding_pts);
double pad_y = gog_renderer_pt2r_y (view->renderer, goo->padding_pts);
-
- gog_renderer_get_text_AABR (view->renderer, str, FALSE, &aabr);
+ gog_renderer_get_gostring_AABR (view->renderer, gostr, &aabr);
rect = view->allocation;
rect.w = aabr.w + 2. * outline + pad_x;
rect.h = aabr.h + 2. * outline + pad_y;
gog_renderer_draw_rectangle (view->renderer, &rect);
}
- gog_renderer_draw_text (view->renderer, str,
- &view->residual, GO_ANCHOR_NW, FALSE);
+ gog_renderer_draw_gostring (view->renderer, gostr,
+ &view->residual, GO_ANCHOR_NW);
+ go_string_unref (gostr);
g_free (str);
}
gog_renderer_pop_style (view->renderer);
diff --git a/goffice/graph/gog-label.h b/goffice/graph/gog-label.h
index c63a5a2..63378b7 100644
--- a/goffice/graph/gog-label.h
+++ b/goffice/graph/gog-label.h
@@ -36,6 +36,7 @@ typedef struct {
GogOutlinedObjectClass base;
char *(*get_str) (GogText *text);
+ PangoAttrList *(*get_markup) (GogText *text);
} GogTextClass;
#define GOG_TYPE_TEXT (gog_text_get_type ())
@@ -45,6 +46,7 @@ typedef struct {
GType gog_text_get_type (void);
char *gog_text_get_str (GogText *text);
+PangoAttrList *gog_text_get_markup (GogText *text);
#define GOG_TYPE_LABEL (gog_label_get_type ())
#define GOG_LABEL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOG_TYPE_LABEL, GogLabel))
diff --git a/goffice/graph/gog-renderer.c b/goffice/graph/gog-renderer.c
index 5bd6c41..3eebd9a 100644
--- a/goffice/graph/gog-renderer.c
+++ b/goffice/graph/gog-renderer.c
@@ -992,7 +992,7 @@ gog_renderer_get_text_OBR (GogRenderer *rend, char const *text,
* gog_renderer_get_text_AABR :
* @rend: #GogRenderer
* @text: the string to draw
- * @use_markup: wether to use pango markup
+ * @use_markup: whether to use pango markup
* @aabr: #GOGeometryAABR to store the Axis Aligned Bounding Rectangle of @text.
**/
void
@@ -1005,6 +1005,22 @@ gog_renderer_get_text_AABR (GogRenderer *rend, char const *text,
go_geometry_OBR_to_AABR (&obr, aabr);
}
+/**
+ * gog_renderer_get_gostring_AABR :
+ * @rend: #GogRenderer
+ * @string: the string to draw
+ * @aabr: #GOGeometryAABR to store the Axis Aligned Bounding Rectangle of @text.
+ **/
+void
+gog_renderer_get_gostring_AABR (GogRenderer *rend, GOString *str,
+ GOGeometryAABR *aabr)
+{
+ GOGeometryOBR obr;
+
+ gog_renderer_get_gostring_OBR (rend, str, &obr);
+ go_geometry_OBR_to_AABR (&obr, aabr);
+}
+
static void
_free_marker_data (GogRenderer *rend)
{
diff --git a/goffice/graph/gog-renderer.h b/goffice/graph/gog-renderer.h
index 12414df..9dfd1e7 100644
--- a/goffice/graph/gog-renderer.h
+++ b/goffice/graph/gog-renderer.h
@@ -99,6 +99,8 @@ void gog_renderer_get_gostring_OBR (GogRenderer *rend, GOString *str,
GOGeometryOBR *obr);
void gog_renderer_get_text_OBR (GogRenderer *rend, char const *text,
gboolean use_markup, GOGeometryOBR *obr);
+void gog_renderer_get_gostring_AABR (GogRenderer *rend, GOString *str,
+ GOGeometryAABR *aabr);
void gog_renderer_get_text_AABR (GogRenderer *rend, char const *text,
gboolean use_markup, GOGeometryAABR *aabr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]