[gtk/small-text-fixes: 20/20] gtk-demo: Improve the font rendering demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/small-text-fixes: 20/20] gtk-demo: Improve the font rendering demo
- Date: Fri, 3 Sep 2021 04:23:59 +0000 (UTC)
commit 8cd64d149e90a49a051608ea0f698da81223729e
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Sep 3 00:19:17 2021 -0400
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.
demos/gtk-demo/fontrendering.c | 11 +++++++++++
demos/gtk-demo/fontrendering.ui | 9 +++++++++
2 files changed, 20 insertions(+)
---
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
@@ -98,6 +98,15 @@
</layout>
</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>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]