From 8c3b00eda317f2e28acf075edb98c6bd5ee44a1a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 4 Jan 2009 02:11:19 +0000 Subject: [PATCH] =?utf8?q?Bug=20168085=20=E2=80=93=20numeric=20styles=20in?= =?utf8?q?=20pango=5Ffont=5Fdescription=5Fto=5Fstring()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2009-01-03 Behdad Esfahbod Bug 168085 – numeric styles in pango_font_description_to_string() * pango/fonts.c (parse_int), (find_field), (find_field_any), (append_field), (pango_font_description_to_string): Print-out, and parse, numeric styles correctly. Things like "DejaVu Sans weight=100" parse correctly now. svn path=/trunk/; revision=2781 --- ChangeLog | 9 +++++++++ pango/fonts.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index cdac78d..a275b4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2009-01-03 Behdad Esfahbod + Bug 168085 – numeric styles in pango_font_description_to_string() + + * pango/fonts.c (parse_int), (find_field), (find_field_any), + (append_field), (pango_font_description_to_string): + Print-out, and parse, numeric styles correctly. Things like + "DejaVu Sans weight=100" parse correctly now. + +2009-01-03 Behdad Esfahbod + Bug 529591 – Code related to malayalam is misplaced. Patch from Rahul Bhalerao diff --git a/pango/fonts.c b/pango/fonts.c index ada299f..e1a10a5 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -920,9 +920,38 @@ field_matches (const gchar *s1, } static gboolean -find_field (const FieldMap *map, int n_elements, const char *str, int len, int *val) +parse_int (const char *word, + size_t wordlen, + int *out) +{ + char *end; + long val = strtol (word, &end, 10); + int i = val; + + if (end != word && (end == word + wordlen) && val >= 0 && val == i) + { + if (out) + *out = i; + + return TRUE; + } + + return FALSE; +} + +static gboolean +find_field (const char *what, const FieldMap *map, int n_elements, const char *str, int len, int *val) { int i; + gboolean had_prefix = FALSE; + + i = strlen (what); + if (len > i && 0 == strncmp (what, str, i) && str[i] == '=') + { + str += i + 1; + len -= i + 1; + had_prefix = TRUE; + } for (i=0; iNAME : NULL)) \ { \ if (desc) \ @@ -954,10 +986,10 @@ find_field_any (const char *str, int len, PangoFontDescription *desc) } \ } G_STMT_END - FIELD (style, PANGO_FONT_MASK_STYLE); - FIELD (variant, PANGO_FONT_MASK_VARIANT); FIELD (weight, PANGO_FONT_MASK_WEIGHT); + FIELD (style, PANGO_FONT_MASK_STYLE); FIELD (stretch, PANGO_FONT_MASK_STRETCH); + FIELD (variant, PANGO_FONT_MASK_VARIANT); FIELD (gravity, PANGO_FONT_MASK_GRAVITY); #undef FIELD @@ -1115,7 +1147,7 @@ pango_font_description_from_string (const char *str) } static void -append_field (GString *str, const FieldMap *map, int n_elements, int val) +append_field (GString *str, const char *what, const FieldMap *map, int n_elements, int val) { int i; for (i=0; ilen > 0 || str->str[str->len -1] != ' ')) g_string_append_c (str, ' '); - g_string_append_printf (str, "%d", val); + g_string_append_printf (str, "%s=%d", what, val); } /** @@ -1181,12 +1213,17 @@ pango_font_description_to_string (const PangoFontDescription *desc) g_string_append_c (result, ','); } - append_field (result, weight_map, G_N_ELEMENTS (weight_map), desc->weight); - append_field (result, style_map, G_N_ELEMENTS (style_map), desc->style); - append_field (result, stretch_map, G_N_ELEMENTS (stretch_map), desc->stretch); - append_field (result, variant_map, G_N_ELEMENTS (variant_map), desc->variant); +#define FIELD(NAME, MASK) \ + append_field (result, G_STRINGIFY (NAME), NAME##_map, G_N_ELEMENTS (NAME##_map), desc->NAME) + + FIELD (weight, PANGO_FONT_MASK_WEIGHT); + FIELD (style, PANGO_FONT_MASK_STYLE); + FIELD (stretch, PANGO_FONT_MASK_STRETCH); + FIELD (variant, PANGO_FONT_MASK_VARIANT); if (desc->mask & PANGO_FONT_MASK_GRAVITY) - append_field (result, gravity_map, G_N_ELEMENTS (gravity_map), desc->gravity); + FIELD (gravity, PANGO_FONT_MASK_GRAVITY); + +#undef FIELD if (result->len == 0) g_string_append (result, "Normal"); -- 2.7.4