[goffice] Draw background and outline for data labels. [#592]
- From: Jean Bréfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Draw background and outline for data labels. [#592]
- Date: Sat, 28 Aug 2021 09:30:52 +0000 (UTC)
commit 65b03b6424ee4ffdbfd3dedfeaa04e9c6fae2384
Author: Jean Brefort <jean brefort normalesup org>
Date: Sat Aug 28 11:30:32 2021 +0200
Draw background and outline for data labels. [#592]
ChangeLog | 7 +++++++
NEWS | 1 +
goffice/graph/gog-renderer.c | 49 ++++++++++++++++++++++++++++++++------------
plugins/plot_xy/gog-xy.c | 2 +-
4 files changed, 45 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a37a4fefb..a44239d87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-08-28 Jean Brefort <jean brefort normalesup org>
+
+ reviewed by: <delete if not using a buddy>
+
+ * goffice/graph/gog-renderer.c (gog_renderer_draw_data_label):
+ * plugins/plot_xy/gog-xy.c (gog_xy_view_render):
+
2021-06-11 Jean Brefort <jean brefort normalesup org>
* plugins/plot_xy/gog-xy.c (gog_xy_view_render): do not clip markers. #584.
diff --git a/NEWS b/NEWS
index eb020a5a1..a5ee0f8a2 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ goffice 0.10.51:
Jean:
* Do not clip markers in scatter plots. [#584]
+ * Draw background and outline for data labels. [#592]
--------------------------------------------------------------------------
goffice 0.10.50:
diff --git a/goffice/graph/gog-renderer.c b/goffice/graph/gog-renderer.c
index fecc03e81..9237f1eba 100644
--- a/goffice/graph/gog-renderer.c
+++ b/goffice/graph/gog-renderer.c
@@ -1136,7 +1136,9 @@ gog_renderer_draw_data_label (GogRenderer *rend, GogSeriesLabelElt const *elt,
GOStyle const *style;
int iw, ih;
PangoAttrList *attrs;
- PangoRectangle rect;
+ PangoRectangle rect, ir, lr;
+ GogViewAllocation rectangle;
+ double w;
g_return_if_fail (elt != NULL && elt->str != NULL);
g_return_if_fail (GOG_IS_RENDERER (rend));
@@ -1157,11 +1159,8 @@ gog_renderer_draw_data_label (GogRenderer *rend, GogSeriesLabelElt const *elt,
if (attrs)
pango_layout_set_attributes (layout, attrs);
pango_cairo_context_set_resolution (context, 72.0);
- /*now get the real size */
- pango_layout_get_size (layout, &iw, &ih);
if (elt->legend_pos >= 0) {
/* we need to add enough room to draw the legend entry */
- PangoRectangle rect;
PangoAttribute *attr;
rect.x = rect.y = 0;
pango_layout_get_size (layout, &iw, &ih);
@@ -1172,8 +1171,11 @@ gog_renderer_draw_data_label (GogRenderer *rend, GogSeriesLabelElt const *elt,
attr->end_index = elt->legend_pos + 1;
pango_attr_list_insert (attrs, attr);
pango_layout_set_attributes (layout, attrs);
- pango_layout_get_size (layout, &iw, &ih);
}
+ /*now get the real size */
+ pango_layout_get_extents (layout, &ir, &lr);
+ iw = lr.width;
+ ih = lr.height;
pango_attr_list_unref (attrs);
obr.w = rend->scale * ((double) iw + (double) PANGO_SCALE / 2.0)
@@ -1185,22 +1187,24 @@ gog_renderer_draw_data_label (GogRenderer *rend, GogSeriesLabelElt const *elt,
obr.y = pos->y;
go_geometry_OBR_to_AABR (&obr, &aabr);
+ w = ((style->interesting_fields | GO_STYLE_LINE) && (style->line.width > 0.))?
+ gog_renderer_line_size (rend, style->line.width): 1.;
switch (anchor) {
case GO_ANCHOR_NW: case GO_ANCHOR_W: case GO_ANCHOR_SW:
- obr.x += aabr.w / 2.0;
+ obr.x += aabr.w / 2.0 + w;
break;
case GO_ANCHOR_NE : case GO_ANCHOR_SE : case GO_ANCHOR_E :
- obr.x -= aabr.w / 2.0;
+ obr.x -= aabr.w / 2.0 + w;
break;
default : break;
}
switch (anchor) {
case GO_ANCHOR_NW: case GO_ANCHOR_N: case GO_ANCHOR_NE:
- obr.y += aabr.h / 2.0;
+ obr.y += aabr.h / 2.0 + w;
break;
case GO_ANCHOR_SE : case GO_ANCHOR_S : case GO_ANCHOR_SW :
- obr.y -= aabr.h / 2.0;
+ obr.y -= aabr.h / 2.0 + w;
break;
default : break;
}
@@ -1212,10 +1216,27 @@ gog_renderer_draw_data_label (GogRenderer *rend, GogSeriesLabelElt const *elt,
obr.y - (obr.w / 2.0) * sin (obr.alpha) -
(obr.h / 2.0) * cos (obr.alpha));
cairo_rotate (cairo, obr.alpha);
- /* now draw the legen entry if needed */
+
+ /* draw outline and background if needed */
+ gog_renderer_push_style (rend, style);
+ if (style->interesting_fields & (GO_STYLE_FILL | GO_STYLE_LINE)) {
+ GOPath *path = go_path_new ();
+ double dx = ((double) ir.width / PANGO_SCALE + 2.) * rend->scale,
+ dy = ((double) ir.height / PANGO_SCALE + 2.) * rend->scale,
+ x0 = (double) ir.x / PANGO_SCALE - 1.,
+ y0 = (double) ir.y / PANGO_SCALE - 1.;
+ go_path_move_to (path, x0 - w / 2., y0 - w / 2.);
+ go_path_line_to (path, x0 + dx + w / 2., y0 - w / 2.);
+ go_path_line_to (path, x0 + dx + w / 2., y0 + dy + w / 2.);
+ go_path_line_to (path, x0 - w / 2., y0 + dy + w / 2.);
+ go_path_close (path);
+ cairo_set_line_join (cairo, CAIRO_LINE_JOIN_MITER); /* probably not the right place */
+ gog_renderer_draw_shape (rend, path);
+ go_path_free (path);
+ }
+ /* now draw the legend entry if needed */
if (elt->legend_pos >= 0 && legend_style != NULL) {
GOStyle *style = go_style_dup (legend_style);
- GogViewAllocation rectangle;
double x, y,w, h;
pango_layout_index_to_pos (layout, elt->legend_pos, &rect);
x = (double) rect.x / PANGO_SCALE * rend->scale;
@@ -1251,7 +1272,6 @@ gog_renderer_draw_data_label (GogRenderer *rend, GogSeriesLabelElt const *elt,
rectangle.y = y;
rectangle.w = w;
rectangle.h = h;
-
gog_renderer_push_style (rend, style);
gog_renderer_draw_rectangle (rend, &rectangle);
} else if (style->interesting_fields & GO_STYLE_MARKER) {
/* markers only */
@@ -1259,13 +1279,16 @@ gog_renderer_draw_data_label (GogRenderer *rend, GogSeriesLabelElt const *elt,
go_marker_set_size (style->marker.mark, h);
gog_renderer_push_style (rend, style);
gog_renderer_draw_marker (rend, x + w / 2., y + h / 2.);
- }
+ } else
+ gog_renderer_push_style (rend, style); // just to be sure
gog_renderer_pop_style (rend);
g_object_unref (style);
}
cairo_scale (cairo, rend->scale, rend->scale);
+ cairo_set_source_rgba (cairo, GO_COLOR_TO_CAIRO (style->font.color));
pango_cairo_show_layout (cairo, layout);
cairo_restore (cairo);
+ gog_renderer_pop_style (rend);
g_object_unref (layout);
}
diff --git a/plugins/plot_xy/gog-xy.c b/plugins/plot_xy/gog-xy.c
index 581c7768c..e74f12def 100644
--- a/plugins/plot_xy/gog-xy.c
+++ b/plugins/plot_xy/gog-xy.c
@@ -1594,7 +1594,7 @@ gog_xy_view_render (GogView *view, GogViewAllocation const *bbox)
anchor = GO_ANCHOR_CENTER;
break;
case GOG_SERIES_LABELS_TOP:
- alloc.y -= cur_offset * gog_renderer_get_scale (view->renderer);;
+ alloc.y -= cur_offset * gog_renderer_get_scale (view->renderer);
anchor = GO_ANCHOR_SOUTH;
break;
case GOG_SERIES_LABELS_BOTTOM:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]