[gtk+/wip/matthiasc/font-variations] Fix the demo a bit
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/font-variations] Fix the demo a bit
- Date: Fri, 15 Sep 2017 12:37:53 +0000 (UTC)
commit ebe7facd30fe376a953e99a8eb88f581fd91ca26
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Sep 15 07:56:49 2017 -0400
Fix the demo a bit
We need to generate the values using a fixed format with
a decimal point. So, use g_ascii_dtostr.
And we were inadvertendly duplicating the varations part of the font
description string. To avoid that, we need to strip out the variations
part from the font description before adding our own.
demos/gtk-demo/font_features.c | 16 +++++++++++++---
1 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/demos/gtk-demo/font_features.c b/demos/gtk-demo/font_features.c
index f609786..4fd8ce9 100644
--- a/demos/gtk-demo/font_features.c
+++ b/demos/gtk-demo/font_features.c
@@ -59,11 +59,20 @@ update_display (void)
GtkTreeModel *model;
GtkTreeIter iter;
const char *lang;
+ PangoFontDescription *desc;
+ char *tmp;
text = gtk_entry_get_text (GTK_ENTRY (entry));
- s = g_string_new ("");
- g_string_append (s , gtk_font_chooser_get_font (GTK_FONT_CHOOSER (font)));
+ desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (font));
+ pango_font_description_unset_fields (desc, PANGO_FONT_MASK_VARIATIONS);
+ tmp = pango_font_description_to_string (desc);
+
+ s = g_string_new (tmp);
+
+ g_free (tmp);
+ pango_font_description_free (desc);
+
add_font_variations (s);
font_desc = g_string_free (s, FALSE);
@@ -456,6 +465,7 @@ add_font_variations (GString *s)
{
GHashTableIter iter;
Axis *axis;
+ char buf[G_ASCII_DTOSTR_BUF_SIZE];
char *sep = " @";
g_hash_table_iter_init (&iter, axes);
@@ -468,7 +478,7 @@ add_font_variations (GString *s)
tag[4] = '\0';
value = gtk_adjustment_get_value (axis->adjustment);
- g_string_append_printf (s, "%s%s=%g", sep, tag, value);
+ g_string_append_printf (s, "%s%s=%s", sep, tag, g_ascii_dtostr (buf, sizeof (buf), value));
sep = ",";
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]