summaryrefslogtreecommitdiff
path: root/pango/pangocairo-render.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-07-07 15:45:14 -0400
committerMatthias Clasen <mclasen@redhat.com>2019-07-25 00:50:40 -0400
commit49cd1c08f86ee29761190268071779959c36009b (patch)
treeace6d1c1dc75a37032d595076064b6ba3596a22c /pango/pangocairo-render.c
parentc7a2b41a22b78bd74956c02f2960859fbe0c9112 (diff)
downloadpango-49cd1c08f86ee29761190268071779959c36009b.tar.gz
cairo: Render visible space differently
Instead of a [SPC] hex box, just render a centered dot, as is commonly used to indicate space. Also render synthetic glyphs for tabs and newlines. This makes single-paragraph mode prettier.
Diffstat (limited to 'pango/pangocairo-render.c')
-rw-r--r--pango/pangocairo-render.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/pango/pangocairo-render.c b/pango/pangocairo-render.c
index 01d6c2ab..f4c57a87 100644
--- a/pango/pangocairo-render.c
+++ b/pango/pangocairo-render.c
@@ -394,6 +394,82 @@ _pango_cairo_renderer_draw_unknown_glyph (PangoCairoRenderer *crenderer,
rows = hbi->rows;
cols = 1;
}
+ else if (ch == 0x2423 ||
+ g_unichar_type (ch) == G_UNICODE_SPACE_SEPARATOR)
+ {
+ /* We never want to show a hex box or other drawing for
+ * space. If we want space to be visible, we replace 0x20
+ * by 0x2423 (visible space).
+ *
+ * Since we don't want to rely on glyph availability,
+ * we render a centered dot ourselves.
+ */
+ double x = cx + 0.5 *((double)gi->geometry.width / PANGO_SCALE);
+ double y = cy + hbi->box_descent - 0.5 * hbi->box_height;
+
+ cairo_new_sub_path (crenderer->cr);
+ cairo_arc (crenderer->cr, x, y, 1.5 * hbi->line_width, 0, 2 * G_PI);
+ cairo_close_path (crenderer->cr);
+ cairo_fill (crenderer->cr);
+ goto done;
+ }
+ else if (ch == '\t')
+ {
+ /* Since we don't want to rely on glyph availability,
+ * we render an arrow like ↦ ourselves.
+ */
+ double y = cy + hbi->box_descent - 0.5 * hbi->box_height;
+ double width = (double)gi->geometry.width / PANGO_SCALE;
+ double offset = 0.2 * width;
+ double x = cx + offset;
+ double al = width - 2 * offset; /* arrow length */
+ double tl = MIN (hbi->digit_width, 0.75 * al); /* tip length */
+ double tw2 = 2.5 * hbi->line_width; /* tip width / 2 */
+ double lw2 = 0.5 * hbi->line_width; /* line width / 2 */
+
+ cairo_move_to (crenderer->cr, x - lw2, y - tw2);
+ cairo_line_to (crenderer->cr, x + lw2, y - tw2);
+ cairo_line_to (crenderer->cr, x + lw2, y - lw2);
+ cairo_line_to (crenderer->cr, x + al - tl, y - lw2);
+ cairo_line_to (crenderer->cr, x + al - tl, y - tw2);
+ cairo_line_to (crenderer->cr, x + al, y);
+ cairo_line_to (crenderer->cr, x + al - tl, y + tw2);
+ cairo_line_to (crenderer->cr, x + al - tl, y + lw2);
+ cairo_line_to (crenderer->cr, x + lw2, y + lw2);
+ cairo_line_to (crenderer->cr, x + lw2, y + tw2);
+ cairo_line_to (crenderer->cr, x - lw2, y + tw2);
+ cairo_close_path (crenderer->cr);
+ cairo_fill (crenderer->cr);
+ goto done;
+ }
+ else if (ch == '\n' || ch == 0x2028 || ch == 0x2029)
+ {
+ /* Since we don't want to rely on glyph availability,
+ * we render an arrow like ↵ ourselves.
+ */
+ double width = (double)gi->geometry.width / PANGO_SCALE;
+ double offset = 0.2 * width;
+ double al = width - 2 * offset; /* arrow length */
+ double tl = MIN (hbi->digit_width, 0.75 * al); /* tip length */
+ double ah = al - 0.5 * tl; /* arrow height */
+ double tw2 = 2.5 * hbi->line_width; /* tip width / 2 */
+ double x = cx + offset;
+ double y = cy - (hbi->box_height - al) / 2;
+ double lw2 = 0.5 * hbi->line_width; /* line width / 2 */
+
+ cairo_move_to (crenderer->cr, x, y);
+ cairo_line_to (crenderer->cr, x + tl, y - tw2);
+ cairo_line_to (crenderer->cr, x + tl, y - lw2);
+ cairo_line_to (crenderer->cr, x + al - lw2, y - lw2);
+ cairo_line_to (crenderer->cr, x + al - lw2, y - ah);
+ cairo_line_to (crenderer->cr, x + al + lw2, y - ah);
+ cairo_line_to (crenderer->cr, x + al + lw2, y + lw2);
+ cairo_line_to (crenderer->cr, x + tl, y + lw2);
+ cairo_line_to (crenderer->cr, x + tl, y + tw2);
+ cairo_close_path (crenderer->cr);
+ cairo_fill (crenderer->cr);
+ goto done;
+ }
else if ((name = pango_get_ignorable_size (ch, &rows, &cols)))
{
/* Nothing else to do, we render 'default ignorable' chars
@@ -402,6 +478,7 @@ _pango_cairo_renderer_draw_unknown_glyph (PangoCairoRenderer *crenderer,
}
else
{
+ /* Everything else gets a traditional hex box. */
rows = hbi->rows;
cols = (ch > 0xffff ? 6 : 4) / rows;
g_snprintf (buf, sizeof(buf), (ch > 0xffff) ? "%06X" : "%04X", ch);