[gtk/dotted-lines] Implement dashed and dotted underlines
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/dotted-lines] Implement dashed and dotted underlines
- Date: Wed, 31 Mar 2021 03:33:31 +0000 (UTC)
commit c890348ad9f48e56297860a06e1181d49436f5f8
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Mar 30 23:31:37 2021 -0400
Implement dashed and dotted underlines
This is implementing new support in Pango for
rendering dashed and dotted lines. This is currently
not very optimized - it is just emitting the a
rounded clip for each dot.
gtk/gskpango.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 106 insertions(+)
---
diff --git a/gtk/gskpango.c b/gtk/gskpango.c
index cfe868cb7a..ffaf0987a9 100644
--- a/gtk/gskpango.c
+++ b/gtk/gskpango.c
@@ -127,6 +127,106 @@ gsk_pango_renderer_draw_rectangle (PangoRenderer *renderer,
(double)height / PANGO_SCALE));
}
+static void
+gsk_pango_renderer_draw_line (PangoRenderer *renderer,
+ PangoRenderPart part,
+ PangoRenderLineStyle style,
+ int x,
+ int y,
+ int width,
+ int height)
+{
+ GskPangoRenderer *crenderer = (GskPangoRenderer *) (renderer);
+ GdkRGBA rgba;
+ double xx, yy, ww, hh;
+
+ xx = (double)x / PANGO_SCALE;
+ yy = (double)y / PANGO_SCALE;
+ ww = (double)width / PANGO_SCALE;
+ hh = (double)height / PANGO_SCALE;
+
+ get_color (crenderer, part, &rgba);
+ switch (style)
+ {
+ case PANGO_RENDER_LINE_SOLID:
+ gtk_snapshot_append_color (crenderer->snapshot,
+ &rgba,
+ &GRAPHENE_RECT_INIT (xx, yy, ww, hh));
+ break;
+
+ case PANGO_RENDER_LINE_DOTTED:
+ {
+#if 0
+ GskRoundedRect dot;
+ double d = MIN (ww, hh);
+ graphene_rect_t bounds = GRAPHENE_RECT_INIT (xx, yy, d, d);
+ graphene_size_t rr = GRAPHENE_SIZE_INIT (d/2, d/2);
+ GdkRGBA transparent = { 0.f, 0.f, 0.f, 0.f };
+
+ gsk_rounded_rect_init (&dot, &bounds, &rr, &rr, &rr, &rr);
+
+ gtk_snapshot_push_repeat (crenderer->snapshot,
+ &GRAPHENE_RECT_INIT (xx, yy, ww, hh),
+ NULL);
+
+ gtk_snapshot_push_rounded_clip (crenderer->snapshot, &dot);
+ gtk_snapshot_append_color (crenderer->snapshot, &rgba, &bounds);
+ gtk_snapshot_pop (crenderer->snapshot);
+ gtk_snapshot_append_color (crenderer->snapshot, &transparent, &GRAPHENE_RECT_INIT (xx + d, yy, 0.5 *
d, d));
+ gtk_snapshot_pop (crenderer->snapshot);
+#else
+ double d = MIN (ww, hh);
+ double xend = xx + ww;
+
+ gtk_snapshot_push_clip (crenderer->snapshot,
+ &GRAPHENE_RECT_INIT (xx, yy, ww, hh));
+
+ while (xx <= xend)
+ {
+ GskRoundedRect dot;
+ graphene_rect_t bounds = GRAPHENE_RECT_INIT (xx, yy, d, d);
+ graphene_size_t rr = GRAPHENE_SIZE_INIT (d/2, d/2);
+
+ gsk_rounded_rect_init (&dot, &bounds, &rr, &rr, &rr, &rr);
+ gtk_snapshot_push_rounded_clip (crenderer->snapshot, &dot);
+ gtk_snapshot_append_color (crenderer->snapshot, &rgba, &bounds);
+ gtk_snapshot_pop (crenderer->snapshot);
+ xx += 1.5 * d;
+ }
+
+ gtk_snapshot_pop (crenderer->snapshot);
+#endif
+ }
+ break;
+
+ case PANGO_RENDER_LINE_DASHED:
+ {
+ GskColorStop stops[4];
+ GdkRGBA transparent = { 0.f, 0.f, 0.f, 0.f };
+
+ stops[0].offset = 0;
+ stops[0].color = rgba;
+ stops[1].offset = 0.66;
+ stops[1].color = rgba;
+ stops[2].offset = 0.66;
+ stops[2].color = transparent;
+ stops[3].offset = 1;
+ stops[3].color = transparent;
+
+ gtk_snapshot_append_repeating_linear_gradient (
+ crenderer->snapshot,
+ &GRAPHENE_RECT_INIT (xx, yy, ww, hh),
+ &GRAPHENE_POINT_INIT (xx, yy),
+ &GRAPHENE_POINT_INIT (xx + 9 * MIN (ww, hh), yy),
+ stops, 4);
+ }
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+}
+
static void
gsk_pango_renderer_draw_trapezoid (PangoRenderer *renderer,
PangoRenderPart part,
@@ -409,6 +509,11 @@ gsk_pango_renderer_prepare_run (PangoRenderer *renderer,
}
else
text_renderer_set_rgba (crenderer, PANGO_RENDER_PART_UNDERLINE, fg_rgba);
+
+ if (appearance->overline_rgba)
+ text_renderer_set_rgba (crenderer, PANGO_RENDER_PART_OVERLINE, appearance->overline_rgba);
+ else
+ text_renderer_set_rgba (crenderer, PANGO_RENDER_PART_OVERLINE, fg_rgba);
}
static void
@@ -426,6 +531,7 @@ gsk_pango_renderer_class_init (GskPangoRendererClass *klass)
renderer_class->draw_trapezoid = gsk_pango_renderer_draw_trapezoid;
renderer_class->draw_error_underline = gsk_pango_renderer_draw_error_underline;
renderer_class->draw_shape = gsk_pango_renderer_draw_shape;
+ renderer_class->draw_line = gsk_pango_renderer_draw_line;
renderer_class->prepare_run = gsk_pango_renderer_prepare_run;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]