[gtk/font-rendering-demo-3] Add a grid example
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/font-rendering-demo-3] Add a grid example
- Date: Sat, 28 Jul 2018 03:06:39 +0000 (UTC)
commit 3759fda75faa5bb80db6ef590b72638012447393
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Jul 27 23:03:50 2018 -0400
Add a grid example
This shows (theoretically) all 16 phases of the letter a,
if we had subpixel positioning already.
demos/gtk-demo/fontrendering.c | 84 ++++++++++++++++++++++++++++++++---------
demos/gtk-demo/fontrendering.ui | 32 +++++++++++++++-
2 files changed, 98 insertions(+), 18 deletions(-)
---
diff --git a/demos/gtk-demo/fontrendering.c b/demos/gtk-demo/fontrendering.c
index 146bcf1c45..e54f2cb163 100644
--- a/demos/gtk-demo/fontrendering.c
+++ b/demos/gtk-demo/fontrendering.c
@@ -13,10 +13,11 @@ static GtkWidget *hinting = NULL;
static GtkWidget *hint_metrics = NULL;
static GtkWidget *up_button = NULL;
static GtkWidget *down_button = NULL;
+static GtkWidget *text_radio = NULL;
static PangoContext *context;
-static int scale = 1;
+static int scale = 10;
static GdkPixbuf *pb;
@@ -72,25 +73,74 @@ update_image (void)
pango_cairo_context_set_font_options (context, fopt);
cairo_font_options_destroy (fopt);
- layout = pango_layout_new (context);
- pango_layout_set_text (layout, text, -1);
- pango_layout_set_font_description (layout, desc);
- pango_layout_get_extents (layout, &ink, &logical);
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_radio)))
+ {
+ layout = pango_layout_new (context);
+ pango_layout_set_font_description (layout, desc);
+ pango_layout_set_text (layout, text, -1);
+ pango_layout_get_extents (layout, &ink, &logical);
- pango_extents_to_pixels (&logical, NULL);
+ pango_extents_to_pixels (&logical, NULL);
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, logical.width, logical.height);
- cr = cairo_create (surface);
- cairo_set_source_rgb (cr, 1, 1, 1);
- cairo_paint (cr);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, logical.width, logical.height);
+ cr = cairo_create (surface);
+ cairo_set_source_rgb (cr, 1, 1, 1);
+ cairo_paint (cr);
- cairo_set_source_rgb (cr, 0, 0, 0);
- pango_cairo_show_layout (cr, layout);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ pango_cairo_show_layout (cr, layout);
- cairo_destroy (cr);
+ cairo_destroy (cr);
+ g_object_unref (layout);
+ }
+ else
+ {
+ PangoLayoutIter *iter;
+ PangoGlyphItem *run;
+ PangoGlyphInfo *g;
+ int i, j;
+
+ layout = pango_layout_new (context);
+ pango_layout_set_font_description (layout, desc);
+ pango_layout_set_text (layout, "aaaa", -1);
+ pango_layout_get_extents (layout, &ink, &logical);
+ pango_extents_to_pixels (&logical, NULL);
+
+ iter = pango_layout_get_iter (layout);
+ run = pango_layout_iter_get_run (iter);
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, logical.width * 3 / 2, 4*logical.height);
+ cr = cairo_create (surface);
+ cairo_set_source_rgb (cr, 1, 1, 1);
+ cairo_paint (cr);
+
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ for (i = 0; i < 4; i++)
+ {
+ g = &(run->glyphs->glyphs[i]);
+ g->geometry.width = PANGO_UNITS_ROUND (g->geometry.width * 3 / 2);
+ }
+
+ for (j = 0; j < 4; j++)
+ {
+ for (i = 0; i < 4; i++)
+ {
+ g = &(run->glyphs->glyphs[i]);
+ g->geometry.x_offset = i * (PANGO_SCALE / 4);
+ g->geometry.y_offset = j * (PANGO_SCALE / 4);
+ }
+
+ cairo_move_to (cr, 0, j * logical.height);
+ pango_cairo_show_layout (cr, layout);
+ }
+
+ cairo_destroy (cr);
+ pango_layout_iter_free (iter);
+ g_object_unref (layout);
+ }
- pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, logical.width, logical.height);
- pixbuf2 = gdk_pixbuf_scale_simple (pixbuf, logical.width * scale, logical.height * scale,
GDK_INTERP_NEAREST);
+ pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface));
+ pixbuf2 = gdk_pixbuf_scale_simple (pixbuf, gdk_pixbuf_get_width (pixbuf) * scale, gdk_pixbuf_get_height
(pixbuf) * scale, GDK_INTERP_NEAREST);
g_set_object (&pb, pixbuf2);
@@ -101,8 +151,6 @@ update_image (void)
cairo_surface_destroy (surface);
pango_font_description_free (desc);
-
-
}
static void
@@ -172,6 +220,7 @@ do_fontrendering (GtkWidget *do_widget)
image = GTK_WIDGET (gtk_builder_get_object (builder, "image"));
hinting = GTK_WIDGET (gtk_builder_get_object (builder, "hinting"));
hint_metrics = GTK_WIDGET (gtk_builder_get_object (builder, "hint_metrics"));
+ text_radio = GTK_WIDGET (gtk_builder_get_object (builder, "text_radio"));
g_signal_connect (up_button, "clicked", G_CALLBACK (scale_up), NULL);
g_signal_connect (down_button, "clicked", G_CALLBACK (scale_down), NULL);
@@ -179,6 +228,7 @@ do_fontrendering (GtkWidget *do_widget)
g_signal_connect (font_button, "notify::font-desc", G_CALLBACK (update_image), NULL);
g_signal_connect (hinting, "notify::active", G_CALLBACK (update_image), NULL);
g_signal_connect (hint_metrics, "notify::active", G_CALLBACK (update_image), NULL);
+ g_signal_connect (text_radio, "notify::active", G_CALLBACK (update_image), NULL);
g_signal_connect (image, "draw", G_CALLBACK (draw), NULL);
diff --git a/demos/gtk-demo/fontrendering.ui b/demos/gtk-demo/fontrendering.ui
index 205b2ff01a..e5092ea1d7 100644
--- a/demos/gtk-demo/fontrendering.ui
+++ b/demos/gtk-demo/fontrendering.ui
@@ -152,12 +152,42 @@
<property name="top-attach">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <property name="orientation">horizontal</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <style><class name="linked"/></style>
+ <child>
+ <object class="GtkRadioButton" id="text_radio">
+ <property name="visible">1</property>
+ <property name="draw-indicator">0</property>
+ <property name="label">Text</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="grid_radio">
+ <property name="visible">1</property>
+ <property name="draw-indicator">0</property>
+ <property name="label">Grid</property>
+ <property name="group">text_radio</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">3</property>
+ <property name="width">7</property>
+ </packing>
+ </child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">1</property>
<property name="hscrollbar-policy">automatic</property>
<property name="vscrollbar-policy">automatic</property>
<property name="propagate-natural-height">1</property>
+ <property name="shadow-type">in</property>
<property name="hexpand">1</property>
<property name="vexpand">1</property>
<child>
@@ -170,7 +200,7 @@
</object>
<packing>
<property name="left-attach">0</property>
- <property name="top-attach">3</property>
+ <property name="top-attach">4</property>
<property name="width">7</property>
</packing>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]