From 3ef8c1b49e06347a04ec6cbdc7bd5f0432ca583d Mon Sep 17 00:00:00 2001 From: Jason Rumney Date: Mon, 16 Jun 2008 09:11:05 +0000 Subject: [PATCH] Fix crashing bug in use of bold fonts from x-select-font on W32. * w32font.c (w32_to_fc_weight): New function. (w32font_full_name, logfont_to_fcname): Use it. * font.h (font_style_symbolic_from_value): Remove. * font.c (font_style_symbolic_from_value): Remove. (font_style_symbolic): Revert to pre 2008-06-13 version. --- src/ChangeLog | 10 ++++++++++ src/font.c | 15 +++------------ src/font.h | 4 ---- src/w32font.c | 46 +++++++++++++++++++++++----------------------- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 2eeb98135eb..3ccbdc87439 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2008-06-16 Jason Rumney + + * font.h (font_style_symbolic_from_value): Remove. + + * font.c (font_style_symbolic_from_value): Remove. + (font_style_symbolic): Revert to pre 2008-06-13 version. + + * w32font.c (w32_to_fc_weight): New function. + (w32font_full_name, logfont_to_fcname): Use it. + 2008-06-16 Kenichi Handa * font.c (font_check_object): Delete it. diff --git a/src/font.c b/src/font.c index 60c0b4fdcf6..4d2f486181f 100644 --- a/src/font.c +++ b/src/font.c @@ -357,11 +357,12 @@ font_style_to_value (prop, val, noerror) } Lisp_Object -font_style_symbolic_from_value (prop, val, for_face) +font_style_symbolic (font, prop, for_face) + Lisp_Object font; enum font_property_index prop; - Lisp_Object val; int for_face; { + Lisp_Object val = AREF (font, prop); Lisp_Object table, elt; int i; @@ -375,16 +376,6 @@ font_style_symbolic_from_value (prop, val, for_face) return (for_face ? AREF (elt, 1) : AREF (elt, (i & 0xF) + 1)); } -Lisp_Object -font_style_symbolic (font, prop, for_face) - Lisp_Object font; - enum font_property_index prop; - int for_face; -{ - Lisp_Object val = AREF (font, prop); - return font_style_symbolic_from_value (prop, val, for_face); -} - extern Lisp_Object Vface_alternative_font_family_alist; extern Lisp_Object find_font_encoding P_ ((Lisp_Object)); diff --git a/src/font.h b/src/font.h index cc14365508c..522343255e7 100644 --- a/src/font.h +++ b/src/font.h @@ -776,10 +776,6 @@ extern int font_style_to_value P_ ((enum font_property_index prop, extern Lisp_Object font_style_symbolic P_ ((Lisp_Object font, enum font_property_index prop, int for_face)); -extern Lisp_Object font_style_symbolic_from_value - P_ ((enum font_property_index prop, - Lisp_Object val, - int for_face)); extern int font_match_p P_ ((Lisp_Object spec, Lisp_Object entity)); extern Lisp_Object font_list_entities P_ ((Lisp_Object frame, diff --git a/src/w32font.c b/src/w32font.c index 862bdabec96..9e4bb494e70 100644 --- a/src/w32font.c +++ b/src/w32font.c @@ -1487,6 +1487,19 @@ w32_encode_weight (n) return 0; } +/* Convert a Windows font weight into one of the weights supported + by fontconfig (see font.c:font_parse_fcname). */ +static Lisp_Object +w32_to_fc_weight (n) + int n; +{ + if (n >= FW_EXTRABOLD) return intern ("black"); + if (n >= FW_BOLD) return intern ("bold"); + if (n >= FW_SEMIBOLD) return intern ("demibold"); + if (n >= FW_NORMAL) return intern ("medium"); + return intern ("light"); +} + /* Fill in all the available details of LOGFONT from FONT_SPEC. */ static void fill_in_logfont (f, logfont, font_spec) @@ -1869,8 +1882,8 @@ w32font_full_name (font, font_obj, pixel_size, name, nbytes) if (font->lfWeight && font->lfWeight != FW_NORMAL) { - weight = FONT_WEIGHT_SYMBOLIC (font_obj); - len += 8 + SBYTES (SYMBOL_NAME (weight)); /* :weight=NAME */ + weight = w32_to_fc_weight (font->lfWeight); + len += 1 + SBYTES (SYMBOL_NAME (weight)); /* :WEIGHT */ } antialiasing = lispy_antialias_type (font->lfQuality); @@ -1900,12 +1913,12 @@ w32font_full_name (font, font_obj, pixel_size, name, nbytes) p += sprintf (p, ":pixelsize=%d", height); } + if (SYMBOLP (weight) && ! NILP (weight)) + p += sprintf (p, ":%s", SDATA (SYMBOL_NAME (weight))); + if (font->lfItalic) p += sprintf (p, ":italic"); - if (SYMBOLP (weight) && ! NILP (weight)) - p += sprintf (p, ":weight=%s", SDATA (SYMBOL_NAME (weight))); - if (SYMBOLP (antialiasing) && ! NILP (antialiasing)) p += sprintf (p, ":antialias=%s", SDATA (SYMBOL_NAME (antialiasing))); @@ -1940,19 +1953,8 @@ static int logfont_to_fcname(font, pointsize, fcname, size) len += 7; /* :italic */ if (font->lfWeight && font->lfWeight != FW_NORMAL) { - int fc_weight = w32_decode_weight (font->lfWeight); - weight = font_style_symbolic_from_value (FONT_WEIGHT_INDEX, - make_number (fc_weight), 0); - len += 8; /* :weight= */ - if (SYMBOLP (weight)) - len += SBYTES (SYMBOL_NAME (weight)); - else - { - weight = make_number (fc_weight); - len++; - while (fc_weight /= 10) - len++; - } + weight = w32_to_fc_weight (font->lfWeight); + len += SBYTES (SYMBOL_NAME (weight)) + 1; } if (len > size) @@ -1962,14 +1964,12 @@ static int logfont_to_fcname(font, pointsize, fcname, size) if (pointsize % 10) p += sprintf (p, ".%d", pointsize % 10); + if (SYMBOLP (weight) && !NILP (weight)) + p += sprintf (p, ":%s", SDATA (SYMBOL_NAME (weight))); + if (font->lfItalic) p += sprintf (p, ":italic"); - if (SYMBOLP (weight) && !NILP (weight)) - p += sprintf (p, "weight=%s", SDATA (SYMBOL_NAME (weight))); - else if (INTEGERP (weight)) - p += sprintf (p, "weight=%d", XINT (weight)); - return (p - fcname); } -- 2.39.2