aboutsummaryrefslogtreecommitdiffstats
path: root/src/font.c
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-08-11 22:07:13 +0200
committerLars Ingebrigtsen2021-08-11 22:07:13 +0200
commit81fd380dea4d4e66d2a93b708caa0e2a9c79de4a (patch)
treefb7da687a3adc52a1f3bbd8930f3171a3ef448b3 /src/font.c
parentbdec9daf57a72dc48a70ae1600b3f331531c229b (diff)
downloademacs-81fd380dea4d4e66d2a93b708caa0e2a9c79de4a.tar.gz
emacs-81fd380dea4d4e66d2a93b708caa0e2a9c79de4a.zip
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/font.c')
-rw-r--r--src/font.c42
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)
1029 X font backend driver, it is a font-entity. In that case, NAME is 1029 X font backend driver, it is a font-entity. In that case, NAME is
1030 a fully specified XLFD. */ 1030 a fully specified XLFD. */
1031 1031
1032int 1032static int
1033font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font) 1033font_parse_xlfd_1 (char *name, ptrdiff_t len, Lisp_Object font, int segments)
1034{ 1034{
1035 int i, j, n; 1035 int i, j, n;
1036 char *f[XLFD_LAST_INDEX + 1]; 1036 char *f[XLFD_LAST_INDEX + 1];
@@ -1040,17 +1040,27 @@ font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font)
1040 if (len > 255 || !len) 1040 if (len > 255 || !len)
1041 /* Maximum XLFD name length is 255. */ 1041 /* Maximum XLFD name length is 255. */
1042 return -1; 1042 return -1;
1043
1043 /* Accept "*-.." as a fully specified XLFD. */ 1044 /* Accept "*-.." as a fully specified XLFD. */
1044 if (name[0] == '*' && (len == 1 || name[1] == '-')) 1045 if (name[0] == '*' && (len == 1 || name[1] == '-'))
1045 i = 1, f[XLFD_FOUNDRY_INDEX] = name; 1046 i = 1, f[XLFD_FOUNDRY_INDEX] = name;
1046 else 1047 else
1047 i = 0; 1048 i = 0;
1049
1050 /* Split into segments. */
1048 for (p = name + i; *p; p++) 1051 for (p = name + i; *p; p++)
1049 if (*p == '-') 1052 if (*p == '-')
1050 { 1053 {
1051 f[i++] = p + 1; 1054 /* If we have too many segments, then gather them up into the
1052 if (i == XLFD_LAST_INDEX) 1055 FAMILY part of the name. This allows using fonts with
1053 break; 1056 dashes in the FAMILY bit. */
1057 if (segments > XLFD_LAST_INDEX && i == XLFD_WEIGHT_INDEX)
1058 segments--;
1059 else {
1060 f[i++] = p + 1;
1061 if (i == XLFD_LAST_INDEX)
1062 break;
1063 }
1054 } 1064 }
1055 f[i] = name + len; 1065 f[i] = name + len;
1056 1066
@@ -1215,6 +1225,28 @@ font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font)
1215 return 0; 1225 return 0;
1216} 1226}
1217 1227
1228int
1229font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font)
1230{
1231 int found = font_parse_xlfd_1 (name, len, font, -1);
1232 if (found > -1)
1233 return found;
1234
1235 int segments = 0;
1236 /* Count how many segments we have. */
1237 for (char *p = name; *p; p++)
1238 if (*p == '-')
1239 segments++;
1240
1241 /* If we have a surplus of segments, then we try to parse again, in
1242 case there's a font with dashes in the family name. */
1243 if (segments > XLFD_LAST_INDEX)
1244 return font_parse_xlfd_1 (name, len, font, segments);
1245 else
1246 return -1;
1247}
1248
1249
1218/* Store XLFD name of FONT (font-spec or font-entity) in NAME (NBYTES 1250/* Store XLFD name of FONT (font-spec or font-entity) in NAME (NBYTES
1219 length), and return the name length. If FONT_SIZE_INDEX of FONT is 1251 length), and return the name length. If FONT_SIZE_INDEX of FONT is
1220 0, use PIXEL_SIZE instead. */ 1252 0, use PIXEL_SIZE instead. */