diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/xfaces.c | 186 |
1 files changed, 99 insertions, 87 deletions
diff --git a/src/xfaces.c b/src/xfaces.c index 340a87e67ca..277f1908810 100644 --- a/src/xfaces.c +++ b/src/xfaces.c | |||
| @@ -2123,77 +2123,61 @@ face_numeric_swidth (width) | |||
| 2123 | } | 2123 | } |
| 2124 | 2124 | ||
| 2125 | 2125 | ||
| 2126 | /* Return an ASCII font name generated from fontset name NAME and | ||
| 2127 | ASCII font specification ASCII_SPEC. NAME is a string conforming | ||
| 2128 | to XLFD. ASCII_SPEC is a vector: | ||
| 2129 | [FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY]. */ | ||
| 2130 | |||
| 2131 | Lisp_Object | 2126 | Lisp_Object |
| 2132 | generate_ascii_font_name (name, ascii_spec) | 2127 | split_font_name_into_vector (fontname) |
| 2133 | Lisp_Object name, ascii_spec; | 2128 | Lisp_Object fontname; |
| 2134 | { | 2129 | { |
| 2135 | struct font_name font; | 2130 | struct font_name font; |
| 2136 | char *p; | 2131 | Lisp_Object vec; |
| 2132 | int i; | ||
| 2137 | 2133 | ||
| 2138 | font.name = LSTRDUPA (name); | 2134 | font.name = LSTRDUPA (fontname); |
| 2139 | if (! split_font_name (NULL, &font, 0)) | 2135 | if (! split_font_name (NULL, &font, 0)) |
| 2140 | return Qnil; | 2136 | return Qnil; |
| 2137 | vec = Fmake_vector (make_number (XLFD_LAST), Qnil); | ||
| 2138 | for (i = 0; i < XLFD_LAST; i++) | ||
| 2139 | if (font.fields[i][0] != '*') | ||
| 2140 | ASET (vec, i, build_string (font.fields[i])); | ||
| 2141 | return vec; | ||
| 2142 | } | ||
| 2143 | |||
| 2144 | Lisp_Object | ||
| 2145 | build_font_name_from_vector (vec) | ||
| 2146 | Lisp_Object vec; | ||
| 2147 | { | ||
| 2148 | struct font_name font; | ||
| 2149 | Lisp_Object fontname; | ||
| 2150 | char *p; | ||
| 2151 | int i; | ||
| 2141 | 2152 | ||
| 2142 | if (STRINGP (AREF (ascii_spec, FONT_SPEC_FAMILY_INDEX))) | 2153 | for (i = 0; i < XLFD_LAST; i++) |
| 2143 | { | 2154 | { |
| 2144 | p = LSTRDUPA (AREF (ascii_spec, FONT_SPEC_FAMILY_INDEX)); | 2155 | font.fields[i] = (NILP (AREF (vec, i)) |
| 2145 | font.fields[XLFD_FOUNDRY] = p; | 2156 | ? "*" : (char *) XSTRING (AREF (vec, i))->data); |
| 2146 | while (*p != '-') p++; | 2157 | if ((i == XLFD_FAMILY || i == XLFD_REGISTRY) |
| 2147 | if (*p) | 2158 | && (p = strchr (font.fields[i], '-'))) |
| 2148 | { | 2159 | { |
| 2149 | *p++ = 0; | 2160 | char *p1 = STRDUPA (font.fields[i]); |
| 2150 | font.fields[XLFD_FAMILY] = p; | 2161 | |
| 2151 | } | 2162 | p1[p - font.fields[i]] = '\0'; |
| 2152 | else | 2163 | if (i == XLFD_FAMILY) |
| 2153 | { | 2164 | { |
| 2154 | font.fields[XLFD_FAMILY] = font.fields[XLFD_FOUNDRY]; | 2165 | font.fields[XLFD_FOUNDRY] = p1; |
| 2155 | font.fields[XLFD_FOUNDRY] = "*"; | 2166 | font.fields[XLFD_FAMILY] = p + 1; |
| 2167 | } | ||
| 2168 | else | ||
| 2169 | { | ||
| 2170 | font.fields[XLFD_REGISTRY] = p1; | ||
| 2171 | font.fields[XLFD_ENCODING] = p + 1; | ||
| 2172 | break; | ||
| 2173 | } | ||
| 2156 | } | 2174 | } |
| 2157 | } | 2175 | } |
| 2158 | if (STRINGP (AREF (ascii_spec, FONT_SPEC_WEIGHT_INDEX))) | ||
| 2159 | font.fields[XLFD_WEIGHT] | ||
| 2160 | = XSTRING (AREF (ascii_spec, FONT_SPEC_WEIGHT_INDEX))->data; | ||
| 2161 | if (STRINGP (AREF (ascii_spec, FONT_SPEC_SLANT_INDEX))) | ||
| 2162 | font.fields[XLFD_SLANT] | ||
| 2163 | = XSTRING (AREF (ascii_spec, FONT_SPEC_SLANT_INDEX))->data; | ||
| 2164 | if (STRINGP (AREF (ascii_spec, FONT_SPEC_SWIDTH_INDEX))) | ||
| 2165 | font.fields[XLFD_SWIDTH] | ||
| 2166 | = XSTRING (AREF (ascii_spec, FONT_SPEC_SWIDTH_INDEX))->data; | ||
| 2167 | if (STRINGP (AREF (ascii_spec, FONT_SPEC_ADSTYLE_INDEX))) | ||
| 2168 | font.fields[XLFD_ADSTYLE] | ||
| 2169 | = XSTRING (AREF (ascii_spec, FONT_SPEC_ADSTYLE_INDEX))->data; | ||
| 2170 | p = LSTRDUPA (AREF (ascii_spec, FONT_SPEC_REGISTRY_INDEX)); | ||
| 2171 | font.fields[XLFD_REGISTRY] = p; | ||
| 2172 | while (*p != '-') p++; | ||
| 2173 | if (*p) | ||
| 2174 | *p++ = 0; | ||
| 2175 | else | ||
| 2176 | p = "*"; | ||
| 2177 | font.fields[XLFD_ENCODING] = p; | ||
| 2178 | 2176 | ||
| 2179 | p = build_font_name (&font); | 2177 | p = build_font_name (&font); |
| 2180 | name = build_string (p); | 2178 | fontname = build_string (p); |
| 2181 | xfree (p); | 2179 | xfree (p); |
| 2182 | return name; | 2180 | return fontname; |
| 2183 | } | ||
| 2184 | |||
| 2185 | |||
| 2186 | Lisp_Object | ||
| 2187 | font_name_registry (fontname) | ||
| 2188 | Lisp_Object fontname; | ||
| 2189 | { | ||
| 2190 | struct font_name font; | ||
| 2191 | |||
| 2192 | font.name = LSTRDUPA (fontname); | ||
| 2193 | if (! split_font_name (NULL, &font, 0)) | ||
| 2194 | return Qnil; | ||
| 2195 | font.fields[XLFD_ENCODING][-1] = '-'; | ||
| 2196 | return build_string (font.fields[XLFD_REGISTRY]); | ||
| 2197 | } | 2181 | } |
| 2198 | 2182 | ||
| 2199 | #ifdef HAVE_WINDOW_SYSTEM | 2183 | #ifdef HAVE_WINDOW_SYSTEM |
| @@ -2732,8 +2716,9 @@ concat_font_list (fonts1, nfonts1, fonts2, nfonts2) | |||
| 2732 | 2716 | ||
| 2733 | If PATTERN is non-nil, list fonts matching that pattern. | 2717 | If PATTERN is non-nil, list fonts matching that pattern. |
| 2734 | 2718 | ||
| 2735 | If REGISTRY is non-nil, return fonts with that registry and the | 2719 | If REGISTRY is non-nil, it is a list of registry (and encoding) |
| 2736 | alternative registries from Vface_alternative_font_registry_alist. | 2720 | names. Return fonts with those registries and the alternative |
| 2721 | registries from Vface_alternative_font_registry_alist. | ||
| 2737 | 2722 | ||
| 2738 | If REGISTRY is nil return fonts of any registry. | 2723 | If REGISTRY is nil return fonts of any registry. |
| 2739 | 2724 | ||
| @@ -2747,35 +2732,37 @@ font_list (f, pattern, family, registry, fonts) | |||
| 2747 | Lisp_Object pattern, family, registry; | 2732 | Lisp_Object pattern, family, registry; |
| 2748 | struct font_name **fonts; | 2733 | struct font_name **fonts; |
| 2749 | { | 2734 | { |
| 2750 | int nfonts = font_list_1 (f, pattern, family, registry, fonts); | 2735 | int nfonts; |
| 2751 | 2736 | int reg_prio; | |
| 2752 | if (!NILP (registry) | 2737 | int i; |
| 2753 | && CONSP (Vface_alternative_font_registry_alist)) | 2738 | |
| 2739 | if (NILP (registry)) | ||
| 2740 | return font_list_1 (f, pattern, family, registry, fonts); | ||
| 2741 | |||
| 2742 | for (reg_prio = 0, nfonts = 0; CONSP (registry); registry = XCDR (registry)) | ||
| 2754 | { | 2743 | { |
| 2755 | Lisp_Object alter; | 2744 | Lisp_Object elt, alter; |
| 2745 | int nfonts2; | ||
| 2746 | struct font_name *fonts2; | ||
| 2756 | 2747 | ||
| 2757 | alter = Fassoc (registry, Vface_alternative_font_registry_alist); | 2748 | elt = XCAR (registry); |
| 2758 | if (CONSP (alter)) | 2749 | alter = Fassoc (elt, Vface_alternative_font_registry_alist); |
| 2750 | if (NILP (alter)) | ||
| 2751 | alter = Fcons (elt, Qnil); | ||
| 2752 | for (; CONSP (alter); alter = XCDR (alter), reg_prio++) | ||
| 2759 | { | 2753 | { |
| 2760 | int reg_prio, i; | 2754 | nfonts2 = font_list_1 (f, pattern, family, XCAR (alter), &fonts2); |
| 2761 | 2755 | if (nfonts2 > 0) | |
| 2762 | for (alter = XCDR (alter), reg_prio = 1; | 2756 | { |
| 2763 | CONSP (alter); | 2757 | if (reg_prio > 0) |
| 2764 | alter = XCDR (alter), reg_prio++) | ||
| 2765 | if (STRINGP (XCAR (alter))) | ||
| 2766 | { | ||
| 2767 | int nfonts2; | ||
| 2768 | struct font_name *fonts2; | ||
| 2769 | |||
| 2770 | nfonts2 = font_list_1 (f, pattern, family, XCAR (alter), | ||
| 2771 | &fonts2); | ||
| 2772 | for (i = 0; i < nfonts2; i++) | 2758 | for (i = 0; i < nfonts2; i++) |
| 2773 | fonts2[i].registry_priority = reg_prio; | 2759 | fonts2[i].registry_priority = reg_prio; |
| 2774 | *fonts = (nfonts > 0 | 2760 | if (nfonts > 0) |
| 2775 | ? concat_font_list (*fonts, nfonts, fonts2, nfonts2) | 2761 | *fonts = concat_font_list (*fonts, nfonts, fonts2, nfonts2); |
| 2776 | : fonts2); | 2762 | else |
| 2777 | nfonts += nfonts2; | 2763 | *fonts = fonts2; |
| 2778 | } | 2764 | nfonts += nfonts2; |
| 2765 | } | ||
| 2779 | } | 2766 | } |
| 2780 | } | 2767 | } |
| 2781 | 2768 | ||
| @@ -6286,23 +6273,23 @@ choose_face_font (f, attrs, font_spec) | |||
| 6286 | 6273 | ||
| 6287 | /* If we are choosing an ASCII font and a font name is explicitly | 6274 | /* If we are choosing an ASCII font and a font name is explicitly |
| 6288 | specified in ATTRS, return it. */ | 6275 | specified in ATTRS, return it. */ |
| 6289 | #if 0 | ||
| 6290 | if (NILP (font_spec) && STRINGP (attrs[LFACE_FONT_INDEX])) | 6276 | if (NILP (font_spec) && STRINGP (attrs[LFACE_FONT_INDEX])) |
| 6291 | return xstrdup (XSTRING (attrs[LFACE_FONT_INDEX])->data); | 6277 | return xstrdup (XSTRING (attrs[LFACE_FONT_INDEX])->data); |
| 6292 | #endif | ||
| 6293 | 6278 | ||
| 6294 | if (NILP (attrs[LFACE_FAMILY_INDEX])) | 6279 | if (NILP (attrs[LFACE_FAMILY_INDEX])) |
| 6295 | family = Qnil; | 6280 | family = Qnil; |
| 6296 | else | 6281 | else |
| 6297 | family = Fcons (attrs[LFACE_FAMILY_INDEX], Qnil); | 6282 | family = Fcons (attrs[LFACE_FAMILY_INDEX], Qnil); |
| 6298 | 6283 | ||
| 6284 | /* Decide FAMILY, ADSTYLE, and REGISTRY from FONT_SPEC. But, | ||
| 6285 | ADSTYLE is not used in the font selector for the moment. */ | ||
| 6299 | if (VECTORP (font_spec)) | 6286 | if (VECTORP (font_spec)) |
| 6300 | { | 6287 | { |
| 6301 | pattern = Qnil; | 6288 | pattern = Qnil; |
| 6302 | if (STRINGP (AREF (font_spec, FONT_SPEC_FAMILY_INDEX))) | 6289 | if (STRINGP (AREF (font_spec, FONT_SPEC_FAMILY_INDEX))) |
| 6303 | family = Fcons (AREF (font_spec, FONT_SPEC_FAMILY_INDEX), family); | 6290 | family = Fcons (AREF (font_spec, FONT_SPEC_FAMILY_INDEX), family); |
| 6304 | adstyle = AREF (font_spec, FONT_SPEC_ADSTYLE_INDEX); | 6291 | adstyle = AREF (font_spec, FONT_SPEC_ADSTYLE_INDEX); |
| 6305 | registry = AREF (font_spec, FONT_SPEC_REGISTRY_INDEX); | 6292 | registry = Fcons (AREF (font_spec, FONT_SPEC_REGISTRY_INDEX), Qnil); |
| 6306 | } | 6293 | } |
| 6307 | else if (STRINGP (font_spec)) | 6294 | else if (STRINGP (font_spec)) |
| 6308 | { | 6295 | { |
| @@ -6313,9 +6300,34 @@ choose_face_font (f, attrs, font_spec) | |||
| 6313 | } | 6300 | } |
| 6314 | else | 6301 | else |
| 6315 | { | 6302 | { |
| 6303 | /* We are choosing an ASCII font. By default, use the registry | ||
| 6304 | name "iso8859-1". But, if the registry name of the ASCII | ||
| 6305 | font specified in the fontset of ATTRS is not "iso8859-1" | ||
| 6306 | (e.g "iso10646-1"), use also that name with higher | ||
| 6307 | priority. */ | ||
| 6308 | int fontset = face_fontset (attrs); | ||
| 6309 | Lisp_Object ascii; | ||
| 6310 | int len; | ||
| 6311 | struct font_name font; | ||
| 6312 | |||
| 6316 | pattern = Qnil; | 6313 | pattern = Qnil; |
| 6317 | adstyle = Qnil; | 6314 | adstyle = Qnil; |
| 6318 | registry = build_string ("iso8859-1"); | 6315 | registry = Fcons (build_string ("iso8859-1"), Qnil); |
| 6316 | |||
| 6317 | ascii = fontset_ascii (fontset); | ||
| 6318 | len = STRING_BYTES (XSTRING (ascii)); | ||
| 6319 | if (len < 9 | ||
| 6320 | || strcmp (XSTRING (ascii)->data + len - 9, "iso8859-1")) | ||
| 6321 | { | ||
| 6322 | font.name = LSTRDUPA (ascii); | ||
| 6323 | /* Check if the name is in XLFD. */ | ||
| 6324 | if (split_font_name (f, &font, 0)) | ||
| 6325 | { | ||
| 6326 | font.fields[XLFD_ENCODING][-1] = '-'; | ||
| 6327 | registry = Fcons (build_string (font.fields[XLFD_REGISTRY]), | ||
| 6328 | registry); | ||
| 6329 | } | ||
| 6330 | } | ||
| 6319 | } | 6331 | } |
| 6320 | 6332 | ||
| 6321 | /* Get a list of fonts matching that pattern and choose the | 6333 | /* Get a list of fonts matching that pattern and choose the |