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];
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;
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. */