[goffice] Add support for rich text in legends.
- From: Jean BrÃfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Add support for rich text in legends.
- Date: Fri, 5 Aug 2011 19:13:33 +0000 (UTC)
commit 679a8ea5d3ceb0447cb524333376e000b201d47a
Author: Jean Brefort <jean brefort normalesup org>
Date: Fri Aug 5 21:17:56 2011 +0200
Add support for rich text in legends.
ChangeLog | 11 +++++++++++
goffice/graph/goffice-graph.h | 2 +-
goffice/graph/gog-legend.c | 22 +++++++++++++++++-----
goffice/graph/gog-plot.c | 17 ++++++++++++-----
goffice/utils/go-string.c | 1 -
plugins/plot_surface/gog-contour.c | 8 ++++----
6 files changed, 45 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index eda275d..ceff0d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-08-05 Jean Brefort <jean brefort normalesup org>
+
+ * goffice/graph/goffice-graph.h: add support for rich text in legends.
+ * goffice/graph/gog-legend.c (cb_size_elements), (cb_swatch_scale),
+ (cb_render_elements): ditto.
+ * goffice/graph/gog-plot.c (gog_plot_foreach_elem): ditto.
+ * goffice/utils/go-string.c (replace_rich_base_with_plain): don't leak
+ a string.
+ * plugins/plot_surface/gog-contour.c
+ (gog_contour_plot_foreach_elem): add support for rich text in legends.
+
2011-08-05 Andreas J. Guelzow <aguelzow pyrshep ca>
* goffice/utils/go-format.c
diff --git a/goffice/graph/goffice-graph.h b/goffice/graph/goffice-graph.h
index 2d3a10f..9ad07fb 100644
--- a/goffice/graph/goffice-graph.h
+++ b/goffice/graph/goffice-graph.h
@@ -88,7 +88,7 @@ typedef struct {
} GogViewPadding;
typedef void (*GogEnumFunc) (unsigned i, gpointer style,
- char const *name, gpointer data);
+ char const *name, PangoAttrList *l, gpointer data);
typedef enum {
GOG_AXIS_UNKNOWN = -1,
diff --git a/goffice/graph/gog-legend.c b/goffice/graph/gog-legend.c
index 5050882..adbdef1 100644
--- a/goffice/graph/gog-legend.c
+++ b/goffice/graph/gog-legend.c
@@ -272,12 +272,17 @@ static GogViewClass *lview_parent_klass;
static void
cb_size_elements (unsigned i, GOStyle const *style,
- char const *name, GogLegendView *glv)
+ char const *name, PangoAttrList *l, GogLegendView *glv)
{
GogView *view = GOG_VIEW (glv);
GOGeometryAABR aabr;
- gog_renderer_get_text_AABR (view->renderer, name, FALSE, &aabr);
+ if (l) {
+ GOString *str = go_string_new_rich (name, -1, TRUE, l, NULL);
+ gog_renderer_get_gostring_AABR (view->renderer, str, &aabr);
+ go_string_unref (str);
+ } else
+ gog_renderer_get_text_AABR (view->renderer, name, FALSE, &aabr);
if (glv->element_width < aabr.w)
glv->element_width = aabr.w;
@@ -383,7 +388,7 @@ typedef struct {
static void
cb_swatch_scale (unsigned i, GOStyle const *style, char const *name,
- SwatchScaleClosure *data)
+ PangoAttrList *l, SwatchScaleClosure *data)
{
GOStyleLine const *line = NULL;
double size;
@@ -417,6 +422,8 @@ cb_swatch_scale (unsigned i, GOStyle const *style, char const *name,
scale = 0;
if (data->line_scale > scale)
data->line_scale = scale;
+ if (l)
+ pango_attr_list_unref (l);
}
typedef struct {
@@ -433,7 +440,7 @@ typedef struct {
static void
cb_render_elements (unsigned index, GOStyle const *base_style, char const *name,
- RenderClosure *data)
+ PangoAttrList *l, RenderClosure *data)
{
GogView const *view = data->view;
GogLegendView *glv = GOG_LEGEND_VIEW (view);
@@ -511,7 +518,12 @@ cb_render_elements (unsigned index, GOStyle const *base_style, char const *name,
pos.x = data->x + glv->label_offset;
pos.y = data->y + glv->element_height / 2.0;
pos.w = pos.h = -1;
- gog_renderer_draw_text (renderer, name, &pos, GO_ANCHOR_W, FALSE);
+ if (l) {
+ GOString *str = go_string_new_rich (name, -1, TRUE, l, NULL);
+ gog_renderer_draw_gostring (view->renderer, str, &pos, GO_ANCHOR_W);
+ go_string_unref (str);
+ } else
+ gog_renderer_draw_text (renderer, name, &pos, GO_ANCHOR_W, FALSE);
if (style != base_style && style != NULL)
g_object_unref (style);
diff --git a/goffice/graph/gog-plot.c b/goffice/graph/gog-plot.c
index 3b05d75..59f2b94 100644
--- a/goffice/graph/gog-plot.c
+++ b/goffice/graph/gog-plot.c
@@ -583,6 +583,7 @@ gog_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
GogTheme *theme = gog_object_get_theme (GOG_OBJECT (plot));
GogPlotClass *klass = GOG_PLOT_GET_CLASS (plot);
GList *overrides;
+ PangoAttrList *pl;
g_return_if_fail (GOG_IS_PLOT (plot));
if (!plot->cardinality_valid)
@@ -607,8 +608,11 @@ gog_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
for (; ptr != NULL ; ptr = ptr->next) {
if (!only_visible || gog_series_has_legend (ptr->data)) {
+ GOData *dat = gog_dataset_get_dim (GOG_DATASET (ptr->data), -1);
func (i, go_styled_object_get_style (ptr->data),
- gog_object_get_name (ptr->data), data);
+ gog_object_get_name (ptr->data),
+ (dat? go_data_get_scalar_markup (dat): NULL),
+ data);
i++;
}
/* now add the trend lines if any */
@@ -617,7 +621,7 @@ gog_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
if (GOG_IS_TREND_LINE (children->data) &&
gog_trend_line_has_legend (GOG_TREND_LINE (children->data))) {
func (i, go_styled_object_get_style (children->data),
- gog_object_get_name (children->data), data);
+ gog_object_get_name (children->data), NULL, data);
i++;
}
children = children->next;
@@ -647,13 +651,16 @@ gog_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
gog_theme_fillin_style (theme, tmp_style, GOG_OBJECT (series),
plot->index_num + i, tmp_style->interesting_fields);
- if (labels != NULL)
+ if (labels != NULL) {
label = (i < num_labels) ? go_data_get_vector_string (labels, i) : g_strdup ("");
- else
+ pl = (i < num_labels)? go_data_get_vector_markup (labels, i): NULL;
+ } else {
label = NULL;
+ pl = NULL;
+ }
if (label == NULL)
label = g_strdup_printf ("%d", i);
- (func) (i, tmp_style, label, data);
+ (func) (i, tmp_style, label, pl, data);
g_free (label);
}
g_object_unref (style);
diff --git a/goffice/utils/go-string.c b/goffice/utils/go-string.c
index 2960f4c..fc3e007 100644
--- a/goffice/utils/go-string.c
+++ b/goffice/utils/go-string.c
@@ -88,7 +88,6 @@ replace_rich_base_with_plain (GOStringRichImpl *rich)
res->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);
} else {
shares = g_slist_prepend (shares, rich);
diff --git a/plugins/plot_surface/gog-contour.c b/plugins/plot_surface/gog-contour.c
index 1ccc824..2f5861c 100644
--- a/plugins/plot_surface/gog-contour.c
+++ b/plugins/plot_surface/gog-contour.c
@@ -182,14 +182,14 @@ gog_contour_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
style->fill.pattern.back = color[i];
label = g_strdup_printf ("[%g%s %g%c", limits[j - i - 1], separator,
limits[j - i], (limits[i - j] > minimum)? '[':']');
- (func) (i, style, label, data);
+ (func) (i, style, label, NULL, data);
g_free (label);
}
if (limits[i - j] > minimum) {
gog_theme_fillin_style (theme, style, GOG_OBJECT (plot->series->data), i, style->interesting_fields);
label = g_strdup_printf ("[%g%s %g]", minimum, separator,
limits[i - j]);
- (func) (i, style, label, data);
+ (func) (i, style, label, NULL, data);
g_free (label);
}
} else {
@@ -197,7 +197,7 @@ gog_contour_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
style->fill.pattern.back = color[0];
label = g_strdup_printf ("[%g%s %g]", minimum, separator,
limits[0]);
- (func) (0, style, label, data);
+ (func) (0, style, label, NULL, data);
g_free (label);
i = 1;
j++;
@@ -207,7 +207,7 @@ gog_contour_plot_foreach_elem (GogPlot *plot, gboolean only_visible,
style->fill.pattern.back = color[i];
label = g_strdup_printf ("[%g%s %g%c", limits[i], separator,
limits[i + 1], (i == j - 1)? ']':'[');
- (func) (i, style, label, data);
+ (func) (i, style, label, NULL, data);
g_free (label);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]