diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2021-08-11 22:07:13 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-08-11 22:07:13 +0200 |
commit | 81fd380dea4d4e66d2a93b708caa0e2a9c79de4a (patch) | |
tree | fb7da687a3adc52a1f3bbd8930f3171a3ef448b3 /src | |
parent | bdec9daf57a72dc48a70ae1600b3f331531c229b (diff) | |
download | emacs-81fd380dea4d4e66d2a93b708caa0e2a9c79de4a.tar.gz |
Allow using XLFD font names with dashes in the family name
* src/font.c (font_parse_xlfd_1): Rename from font_parse_xlfd to
allow calling twice from a wrapper (bug#35816).
(font_parse_xlfd): Wrapper function -- first try to parse in the
normal way, and then try to guess that the hyphenated bits are in
the family name.
Diffstat (limited to 'src')
-rw-r--r-- | src/font.c | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/font.c b/src/font.c index 7c1d1ff89b1..e043ef8d01b 100644 --- a/src/font.c +++ b/src/font.c @@ -1029,8 +1029,8 @@ font_expand_wildcards (Lisp_Object *field, int n) X font backend driver, it is a font-entity. In that case, NAME is a fully specified XLFD. */ -int -font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font) +static int +font_parse_xlfd_1 (char *name, ptrdiff_t len, Lisp_Object font, int segments) { int i, j, n; char *f[XLFD_LAST_INDEX + 1]; @@ -1040,17 +1040,27 @@ font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font) if (len > 255 || !len) /* Maximum XLFD name length is 255. */ return -1; + /* Accept "*-.." as a fully specified XLFD. */ if (name[0] == '*' && (len == 1 || name[1] == '-')) i = 1, f[XLFD_FOUNDRY_INDEX] = name; else i = 0; + + /* Split into segments. */ for (p = name + i; *p; p++) if (*p == '-') { - f[i++] = p + 1; - if (i == XLFD_LAST_INDEX) - break; + /* If we have too many segments, then gather them up into the + FAMILY part of the name. This allows using fonts with + dashes in the FAMILY bit. */ + if (segments > XLFD_LAST_INDEX && i == XLFD_WEIGHT_INDEX) + segments--; + else { + f[i++] = p + 1; + if (i == XLFD_LAST_INDEX) + break; + } } f[i] = name + len; @@ -1215,6 +1225,28 @@ font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font) return 0; } +int +font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font) +{ + int found = font_parse_xlfd_1 (name, len, font, -1); + if (found > -1) + return found; + + int segments = 0; + /* Count how many segments we have. */ + for (char *p = name; *p; p++) + if (*p == '-') + segments++; + + /* If we have a surplus of segments, then we try to parse again, in + case there's a font with dashes in the family name. */ + if (segments > XLFD_LAST_INDEX) + return font_parse_xlfd_1 (name, len, font, segments); + else + return -1; +} + + /* Store XLFD name of FONT (font-spec or font-entity) in NAME (NBYTES length), and return the name length. If FONT_SIZE_INDEX of FONT is 0, use PIXEL_SIZE instead. */ |