1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-19 01:10:57 -08:00

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.
This commit is contained in:
Lars Ingebrigtsen 2021-08-11 22:07:13 +02:00
parent bdec9daf57
commit 81fd380dea

View file

@ -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. */