From 5c6bc9117934a13465a6db3d94a1b1803f26a930 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Wed, 2 Mar 2005 23:22:57 +0000 Subject: For family names that add in numbers add a , to distinguish them from 2005-03-02 Owen Taylor * pango/fonts.c (pango_font_description_from_string_: For family names that add in numbers add a , to distinguish them from family+size (#166540, debugging/testing by Manish Singh) --- pango/fonts.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'pango/fonts.c') diff --git a/pango/fonts.c b/pango/fonts.c index b0b73f16..eefe07b9 100644 --- a/pango/fonts.c +++ b/pango/fonts.c @@ -859,6 +859,25 @@ getword (const char *str, const char *last, size_t *wordlen) return result; } +static gboolean +parse_size (const char *word, + size_t wordlen, + int *pango_size) +{ + char *end; + double size = g_ascii_strtod (word, &end); + + if (end - word == wordlen) /* word is a valid float */ + { + if (pango_size) + *pango_size = (int)(size * PANGO_SCALE + 0.5); + + return TRUE; + } + + return FALSE; +} + /** * pango_font_description_from_string: * @str: string representation of a font description. @@ -912,13 +931,10 @@ pango_font_description_from_string (const char *str) */ if (wordlen != 0) { - char *end; - double size = g_ascii_strtod (p, &end); - if (end - p == wordlen) /* word is a valid float */ + if (parse_size (p, wordlen, &desc->size)) { - desc->size = (int)(size * PANGO_SCALE + 0.5); desc->mask |= PANGO_FONT_MASK_SIZE; - last = p; + last = p; } } @@ -1006,9 +1022,20 @@ pango_font_description_to_string (const PangoFontDescription *desc) size_t wordlen; g_string_append (result, desc->family_name); - + + /* We need to add a trailing comma if the family name ends + * in a keyword like "Bold", or if the family name ends in + * a number and no keywords will be added. + */ p = getword (desc->family_name, desc->family_name + strlen(desc->family_name), &wordlen); - if (wordlen != 0 && find_field_any (p, wordlen, NULL)) + if (wordlen != 0 && + (find_field_any (p, wordlen, NULL) || + (parse_size (p, wordlen, NULL) && + desc->weight == PANGO_WEIGHT_NORMAL && + desc->style == PANGO_STYLE_NORMAL && + desc->stretch == PANGO_STRETCH_NORMAL && + desc->variant == PANGO_VARIANT_NORMAL && + (desc->mask & PANGO_FONT_MASK_SIZE) == 0))) g_string_append_c (result, ','); } -- cgit v1.2.1