summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-09-03 00:19:17 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-09-03 11:29:44 -0400
commitf3ccf62463019ef0ec0e79f304056895a47d4f4e (patch)
tree7d1094da309e98997094a928ea5809ae4d0690ae
parent44fea33c5d927cca8c48a40f14ed4f43d9ff5ff4 (diff)
downloadgtk+-f3ccf62463019ef0ec0e79f304056895a47d4f4e.tar.gz
gtk-demo: Improve the font rendering demo
Add a toggle for antialiasing, and make the metrics hinting turn on rounding of positions, to match what we do with settings now.
-rw-r--r--demos/gtk-demo/fontrendering.c11
-rw-r--r--demos/gtk-demo/fontrendering.ui9
2 files changed, 20 insertions, 0 deletions
diff --git a/demos/gtk-demo/fontrendering.c b/demos/gtk-demo/fontrendering.c
index 005f3637c6..e95a78f7e7 100644
--- a/demos/gtk-demo/fontrendering.c
+++ b/demos/gtk-demo/fontrendering.c
@@ -10,6 +10,7 @@ static GtkWidget *font_button = NULL;
static GtkWidget *entry = NULL;
static GtkWidget *image = NULL;
static GtkWidget *hinting = NULL;
+static GtkWidget *anti_alias = NULL;
static GtkWidget *hint_metrics = NULL;
static GtkWidget *up_button = NULL;
static GtkWidget *down_button = NULL;
@@ -37,6 +38,7 @@ update_image (void)
cairo_font_options_t *fopt;
cairo_hint_style_t hintstyle;
cairo_hint_metrics_t hintmetrics;
+ cairo_antialias_t antialias;
if (!context)
context = gtk_widget_create_pango_context (image);
@@ -65,6 +67,13 @@ update_image (void)
hintmetrics = CAIRO_HINT_METRICS_OFF;
cairo_font_options_set_hint_metrics (fopt, hintmetrics);
+ if (gtk_check_button_get_active (GTK_CHECK_BUTTON (anti_alias)))
+ antialias = CAIRO_ANTIALIAS_GRAY;
+ else
+ antialias = CAIRO_ANTIALIAS_NONE;
+ cairo_font_options_set_antialias (fopt, antialias);
+
+ pango_context_set_round_glyph_positions (context, hintmetrics == CAIRO_HINT_METRICS_ON);
pango_cairo_context_set_font_options (context, fopt);
cairo_font_options_destroy (fopt);
pango_context_changed (context);
@@ -252,6 +261,7 @@ do_fontrendering (GtkWidget *do_widget)
entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry"));
image = GTK_WIDGET (gtk_builder_get_object (builder, "image"));
hinting = GTK_WIDGET (gtk_builder_get_object (builder, "hinting"));
+ anti_alias = GTK_WIDGET (gtk_builder_get_object (builder, "antialias"));
hint_metrics = GTK_WIDGET (gtk_builder_get_object (builder, "hint_metrics"));
text_radio = GTK_WIDGET (gtk_builder_get_object (builder, "text_radio"));
show_grid = GTK_WIDGET (gtk_builder_get_object (builder, "show_grid"));
@@ -262,6 +272,7 @@ do_fontrendering (GtkWidget *do_widget)
g_signal_connect (entry, "notify::text", G_CALLBACK (update_image), NULL);
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 (anti_alias, "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 (show_grid, "notify::active", G_CALLBACK (update_image), NULL);
diff --git a/demos/gtk-demo/fontrendering.ui b/demos/gtk-demo/fontrendering.ui
index 363f6f5e3d..fc7a9fed4a 100644
--- a/demos/gtk-demo/fontrendering.ui
+++ b/demos/gtk-demo/fontrendering.ui
@@ -99,6 +99,15 @@
</object>
</child>
<child>
+ <object class="GtkCheckButton" id="antialias">
+ <property name="label">Antialias</property>
+ <layout>
+ <property name="column">3</property>
+ <property name="row">1</property>
+ </layout>
+ </object>
+ </child>
+ <child>
<object class="GtkComboBoxText" id="hinting">
<property name="active">0</property>
<property name="valign">center</property>