[gtk/better-font-rendering-demo: 2/6] gtk-demo: Font rendering - improve the grid
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/better-font-rendering-demo: 2/6] gtk-demo: Font rendering - improve the grid
- Date: Sun, 5 Sep 2021 03:06:08 +0000 (UTC)
commit 7c3fbdecf2420c57fec62627d1ff1f472a071a8b
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Sep 4 20:28:59 2021 -0400
gtk-demo: Font rendering - improve the grid
Allow changing the character shown in the grid.
demos/gtk-demo/fontrendering.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/demos/gtk-demo/fontrendering.c b/demos/gtk-demo/fontrendering.c
index e95a78f7e7..749d067663 100644
--- a/demos/gtk-demo/fontrendering.c
+++ b/demos/gtk-demo/fontrendering.c
@@ -167,10 +167,26 @@ update_image (void)
PangoLayoutRun *run;
PangoGlyphInfo *g;
int i, j;
+ GString *str;
+ gunichar ch;
+
+ if (*text == '\0')
+ text = " ";
+
+ ch = g_utf8_get_char (text);
+
+ str = g_string_new ("");
+
+ for (i = 0; i < 4; i++)
+ {
+ g_string_append_unichar (str, ch);
+ g_string_append_unichar (str, 0x200c);
+ }
layout = pango_layout_new (context);
pango_layout_set_font_description (layout, desc);
- pango_layout_set_text (layout, "aaaa", -1);
+ pango_layout_set_text (layout, str->str, -1);
+ g_string_free (str, TRUE);
pango_layout_get_extents (layout, &ink, &logical);
pango_extents_to_pixels (&logical, NULL);
@@ -185,7 +201,7 @@ update_image (void)
cairo_set_source_rgb (cr, 0, 0, 0);
for (i = 0; i < 4; i++)
{
- g = &(run->glyphs->glyphs[i]);
+ g = &(run->glyphs->glyphs[2*i]);
g->geometry.width = PANGO_UNITS_ROUND (g->geometry.width * 3 / 2);
}
@@ -193,7 +209,7 @@ update_image (void)
{
for (i = 0; i < 4; i++)
{
- g = &(run->glyphs->glyphs[i]);
+ g = &(run->glyphs->glyphs[2*i]);
g->geometry.x_offset = i * (PANGO_SCALE / 4);
g->geometry.y_offset = j * (PANGO_SCALE / 4);
}
@@ -212,7 +228,6 @@ update_image (void)
cairo_surface_destroy (surface);
}
-
gtk_picture_set_pixbuf (GTK_PICTURE (image), pixbuf2);
g_object_unref (pixbuf2);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]