Commit | Line | Data |
---|---|---|
c2f5bfd6 | 1 | /* ftfont.c -- FreeType font driver. |
77ad4cfe GM |
2 | Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc. |
3 | Copyright (C) 2006, 2007, 2008 | |
c2f5bfd6 KH |
4 | National Institute of Advanced Industrial Science and Technology (AIST) |
5 | Registration Number H13PRO009 | |
6 | ||
7 | This file is part of GNU Emacs. | |
8 | ||
9ec0b715 | 9 | GNU Emacs is free software: you can redistribute it and/or modify |
c2f5bfd6 | 10 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
11 | the Free Software Foundation, either version 3 of the License, or |
12 | (at your option) any later version. | |
c2f5bfd6 KH |
13 | |
14 | GNU Emacs is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 20 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
c2f5bfd6 KH |
21 | |
22 | #include <config.h> | |
23 | #include <stdio.h> | |
24 | ||
c2f5bfd6 KH |
25 | #include <fontconfig/fontconfig.h> |
26 | #include <fontconfig/fcfreetype.h> | |
27 | ||
28 | #include "lisp.h" | |
29 | #include "dispextern.h" | |
30 | #include "frame.h" | |
31 | #include "blockinput.h" | |
32 | #include "character.h" | |
33 | #include "charset.h" | |
34 | #include "coding.h" | |
35 | #include "fontset.h" | |
36 | #include "font.h" | |
de023c40 | 37 | #include "ftfont.h" |
c2f5bfd6 | 38 | |
c2801c99 | 39 | /* Symbolic type of this font-driver. */ |
c2f5bfd6 KH |
40 | Lisp_Object Qfreetype; |
41 | ||
706b6995 KH |
42 | /* Fontconfig's generic families and their aliases. */ |
43 | static Lisp_Object Qmonospace, Qsans_serif, Qserif, Qmono, Qsans, Qsans__serif; | |
44 | ||
2a46904e | 45 | /* Flag to tell if FcInit is already called or not. */ |
c2f5bfd6 | 46 | static int fc_initialized; |
c2801c99 KH |
47 | |
48 | /* Handle to a FreeType library instance. */ | |
c2f5bfd6 KH |
49 | static FT_Library ft_library; |
50 | ||
c2801c99 | 51 | /* Cache for FreeType fonts. */ |
c2f5bfd6 KH |
52 | static Lisp_Object freetype_font_cache; |
53 | ||
e302a291 | 54 | /* Cache for FT_Face and FcCharSet. */ |
21988a08 | 55 | static Lisp_Object ft_face_cache; |
c2f5bfd6 KH |
56 | |
57 | /* The actual structure for FreeType font that can be casted to struct | |
58 | font. */ | |
59 | ||
60 | struct ftfont_info | |
61 | { | |
62 | struct font font; | |
de023c40 | 63 | #ifdef HAVE_LIBOTF |
e302a291 KH |
64 | /* The following three members must be here in this order to be |
65 | compatible with struct xftfont_info (in xftfont.c). */ | |
de023c40 KH |
66 | int maybe_otf; /* Flag to tell if this may be OTF or not. */ |
67 | OTF *otf; | |
68 | #endif /* HAVE_LIBOTF */ | |
e302a291 KH |
69 | FT_Size ft_size; |
70 | int index; | |
c2f5bfd6 KH |
71 | }; |
72 | ||
e302a291 | 73 | static Lisp_Object ftfont_pattern_entity P_ ((FcPattern *, Lisp_Object)); |
21988a08 | 74 | |
7d7ad10e KH |
75 | static Lisp_Object ftfont_resolve_generic_family P_ ((Lisp_Object, |
76 | FcPattern *)); | |
e302a291 KH |
77 | static Lisp_Object ftfont_lookup_cache P_ ((Lisp_Object, int)); |
78 | ||
7d7ad10e | 79 | Lisp_Object ftfont_font_format P_ ((FcPattern *, Lisp_Object)); |
706b6995 KH |
80 | |
81 | #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM)) | |
82 | ||
21988a08 | 83 | static struct |
c2f5bfd6 | 84 | { |
e302a291 | 85 | /* registry name */ |
21988a08 KH |
86 | char *name; |
87 | /* characters to distinguish the charset from the others */ | |
88 | int uniquifier[6]; | |
7d7ad10e KH |
89 | /* additional constraint by language */ |
90 | char *lang; | |
21988a08 KH |
91 | /* set on demand */ |
92 | FcCharSet *fc_charset; | |
93 | } fc_charset_table[] = | |
e302a291 KH |
94 | { { "iso8859-1", { 0x00A0, 0x00A1, 0x00B4, 0x00BC, 0x00D0 } }, |
95 | { "iso8859-2", { 0x00A0, 0x010E }}, | |
96 | { "iso8859-3", { 0x00A0, 0x0108 }}, | |
97 | { "iso8859-4", { 0x00A0, 0x00AF, 0x0128, 0x0156, 0x02C7 }}, | |
98 | { "iso8859-5", { 0x00A0, 0x0401 }}, | |
99 | { "iso8859-6", { 0x00A0, 0x060C }}, | |
100 | { "iso8859-7", { 0x00A0, 0x0384 }}, | |
101 | { "iso8859-8", { 0x00A0, 0x05D0 }}, | |
102 | { "iso8859-9", { 0x00A0, 0x00A1, 0x00BC, 0x011E }}, | |
103 | { "iso8859-10", { 0x00A0, 0x00D0, 0x0128, 0x2015 }}, | |
104 | { "iso8859-11", { 0x00A0, 0x0E01 }}, | |
105 | { "iso8859-13", { 0x00A0, 0x201C }}, | |
106 | { "iso8859-14", { 0x00A0, 0x0174 }}, | |
107 | { "iso8859-15", { 0x00A0, 0x00A1, 0x00D0, 0x0152 }}, | |
108 | { "iso8859-16", { 0x00A0, 0x0218}}, | |
109 | { "gb2312.1980-0", { 0x4E13 }, "zh-cn"}, | |
110 | { "big5-0", { 0xF6B1 }, "zh-tw" }, | |
111 | { "jisx0208.1983-0", { 0x4E55 }, "ja"}, | |
112 | { "ksc5601.1985-0", { 0xAC00 }, "ko"}, | |
113 | { "cns11643.1992-1", { 0xFE32 }, "zh-tw"}, | |
114 | { "cns11643.1992-2", { 0x4E33, 0x7934 }}, | |
115 | { "cns11643.1992-3", { 0x201A9 }}, | |
116 | { "cns11643.1992-4", { 0x20057 }}, | |
117 | { "cns11643.1992-5", { 0x20000 }}, | |
118 | { "cns11643.1992-6", { 0x20003 }}, | |
119 | { "cns11643.1992-7", { 0x20055 }}, | |
120 | { "gbk-0", { 0x4E06 }, "zh-cn"}, | |
121 | { "jisx0212.1990-0", { 0x4E44 }}, | |
122 | { "jisx0213.2000-1", { 0xFA10 }, "ja"}, | |
123 | { "jisx0213.2000-2", { 0xFA49 }}, | |
124 | { "jisx0213.2004-1", { 0x20B9F }}, | |
125 | { "viscii1.1-1", { 0x1EA0, 0x1EAE, 0x1ED2 }, "vi"}, | |
126 | { "tis620.2529-1", { 0x0E01 }, "th"}, | |
7d7ad10e KH |
127 | { "windows-1251", { 0x0401, 0x0490 }, "ru"}, |
128 | { "koi8-r", { 0x0401, 0x2219 }, "ru"}, | |
e302a291 | 129 | { "mulelao-1", { 0x0E81 }, "lo"}, |
21988a08 KH |
130 | { NULL } |
131 | }; | |
c2f5bfd6 | 132 | |
42984a74 KH |
133 | extern Lisp_Object Qc, Qm, Qp, Qd; |
134 | ||
706b6995 | 135 | static Lisp_Object |
e302a291 | 136 | ftfont_pattern_entity (p, extra) |
c2801c99 | 137 | FcPattern *p; |
e302a291 | 138 | Lisp_Object extra; |
c2801c99 KH |
139 | { |
140 | Lisp_Object entity; | |
21988a08 | 141 | char *file, *str; |
e302a291 | 142 | int index; |
c2801c99 KH |
143 | int numeric; |
144 | double dbl; | |
42984a74 | 145 | FcBool b; |
c2801c99 | 146 | |
21988a08 | 147 | if (FcPatternGetString (p, FC_FILE, 0, (FcChar8 **) &file) != FcResultMatch) |
c2801c99 | 148 | return Qnil; |
e302a291 KH |
149 | if (FcPatternGetInteger (p, FC_INDEX, 0, &index) != FcResultMatch) |
150 | return Qnil; | |
c2801c99 | 151 | |
42984a74 | 152 | entity = font_make_entity (); |
c2801c99 KH |
153 | |
154 | ASET (entity, FONT_TYPE_INDEX, Qfreetype); | |
e302a291 | 155 | ASET (entity, FONT_REGISTRY_INDEX, Qiso10646_1); |
c2801c99 | 156 | |
21988a08 | 157 | if (FcPatternGetString (p, FC_FOUNDRY, 0, (FcChar8 **) &str) == FcResultMatch) |
a1a94102 | 158 | ASET (entity, FONT_FOUNDRY_INDEX, font_intern_prop (str, strlen (str), 1)); |
21988a08 | 159 | if (FcPatternGetString (p, FC_FAMILY, 0, (FcChar8 **) &str) == FcResultMatch) |
a1a94102 | 160 | ASET (entity, FONT_FAMILY_INDEX, font_intern_prop (str, strlen (str), 1)); |
c2801c99 | 161 | if (FcPatternGetInteger (p, FC_WEIGHT, 0, &numeric) == FcResultMatch) |
f63d54dc | 162 | { |
42984a74 KH |
163 | if (numeric >= FC_WEIGHT_REGULAR && numeric < FC_WEIGHT_MEDIUM) |
164 | numeric = FC_WEIGHT_MEDIUM; | |
165 | FONT_SET_STYLE (entity, FONT_WEIGHT_INDEX, make_number (numeric)); | |
f63d54dc | 166 | } |
c2801c99 | 167 | if (FcPatternGetInteger (p, FC_SLANT, 0, &numeric) == FcResultMatch) |
42984a74 KH |
168 | { |
169 | numeric += 100; | |
170 | FONT_SET_STYLE (entity, FONT_SLANT_INDEX, make_number (numeric)); | |
171 | } | |
c2801c99 | 172 | if (FcPatternGetInteger (p, FC_WIDTH, 0, &numeric) == FcResultMatch) |
42984a74 KH |
173 | { |
174 | FONT_SET_STYLE (entity, FONT_WIDTH_INDEX, make_number (numeric)); | |
175 | } | |
c2801c99 KH |
176 | if (FcPatternGetDouble (p, FC_PIXEL_SIZE, 0, &dbl) == FcResultMatch) |
177 | ASET (entity, FONT_SIZE_INDEX, make_number (dbl)); | |
178 | else | |
179 | ASET (entity, FONT_SIZE_INDEX, make_number (0)); | |
42984a74 KH |
180 | if (FcPatternGetInteger (p, FC_SPACING, 0, &numeric) == FcResultMatch) |
181 | ASET (entity, FONT_SPACING_INDEX, make_number (numeric)); | |
182 | if (FcPatternGetDouble (p, FC_DPI, 0, &dbl) == FcResultMatch) | |
183 | { | |
184 | int dpi = dbl; | |
185 | ASET (entity, FONT_DPI_INDEX, make_number (dpi)); | |
186 | } | |
187 | if (FcPatternGetBool (p, FC_SCALABLE, 0, &b) == FcResultMatch | |
188 | && b == FcTrue) | |
189 | ASET (entity, FONT_AVGWIDTH_INDEX, make_number (0)); | |
c2801c99 | 190 | |
4ffe34a4 | 191 | ASET (entity, FONT_EXTRA_INDEX, Fcopy_sequence (extra)); |
21988a08 KH |
192 | font_put_extra (entity, QCfont_entity, |
193 | Fcons (make_unibyte_string ((char *) file, | |
194 | strlen ((char *) file)), | |
e302a291 | 195 | make_number (index))); |
c2801c99 KH |
196 | return entity; |
197 | } | |
198 | ||
42984a74 | 199 | |
706b6995 KH |
200 | static Lisp_Object ftfont_generic_family_list; |
201 | ||
202 | static Lisp_Object | |
7d7ad10e | 203 | ftfont_resolve_generic_family (family, pattern) |
42984a74 | 204 | Lisp_Object family; |
7d7ad10e | 205 | FcPattern *pattern; |
706b6995 | 206 | { |
318548be | 207 | Lisp_Object slot; |
7d7ad10e | 208 | FcPattern *match; |
318548be | 209 | FcResult result; |
706b6995 | 210 | |
318548be | 211 | family = Fintern (Fdowncase (SYMBOL_NAME (family)), Qnil); |
706b6995 KH |
212 | if (EQ (family, Qmono)) |
213 | family = Qmonospace; | |
214 | else if (EQ (family, Qsans) || EQ (family, Qsans__serif)) | |
215 | family = Qsans_serif; | |
216 | slot = assq_no_quit (family, ftfont_generic_family_list); | |
217 | if (! CONSP (slot)) | |
42984a74 | 218 | return Qnil; |
318548be KH |
219 | if (! EQ (XCDR (slot), Qt)) |
220 | return XCDR (slot); | |
7d7ad10e | 221 | pattern = FcPatternDuplicate (pattern); |
42984a74 KH |
222 | if (! pattern) |
223 | goto err; | |
bb658864 | 224 | FcPatternDel (pattern, FC_FOUNDRY); |
7d7ad10e KH |
225 | FcPatternDel (pattern, FC_FAMILY); |
226 | FcPatternAddString (pattern, FC_FAMILY, SYMBOL_FcChar8 (family)); | |
42984a74 | 227 | FcConfigSubstitute (NULL, pattern, FcMatchPattern); |
318548be KH |
228 | FcDefaultSubstitute (pattern); |
229 | match = FcFontMatch (NULL, pattern, &result); | |
230 | if (match) | |
706b6995 | 231 | { |
318548be KH |
232 | FcChar8 *fam; |
233 | ||
234 | if (FcPatternGetString (match, FC_FAMILY, 0, &fam) == FcResultMatch) | |
235 | family = intern ((char *) fam); | |
706b6995 | 236 | } |
318548be KH |
237 | else |
238 | family = Qnil; | |
239 | XSETCDR (slot, family); | |
42984a74 | 240 | err: |
318548be | 241 | if (match) FcPatternDestroy (match); |
42984a74 | 242 | if (pattern) FcPatternDestroy (pattern); |
318548be | 243 | return family; |
706b6995 KH |
244 | } |
245 | ||
e302a291 KH |
246 | struct ftfont_cache_data |
247 | { | |
248 | FT_Face ft_face; | |
249 | FcCharSet *fc_charset; | |
250 | }; | |
251 | ||
252 | static Lisp_Object | |
253 | ftfont_lookup_cache (key, for_face) | |
254 | Lisp_Object key; | |
255 | int for_face; | |
21988a08 KH |
256 | { |
257 | Lisp_Object cache, val; | |
e302a291 | 258 | struct ftfont_cache_data *cache_data; |
21988a08 | 259 | |
e302a291 | 260 | cache = assoc_no_quit (key, ft_face_cache); |
21988a08 KH |
261 | if (NILP (cache)) |
262 | { | |
e302a291 KH |
263 | cache_data = xmalloc (sizeof (struct ftfont_cache_data)); |
264 | cache_data->ft_face = NULL; | |
265 | cache_data->fc_charset = NULL; | |
21988a08 | 266 | val = make_save_value (NULL, 0); |
e302a291 KH |
267 | XSAVE_VALUE (val)->integer = 0; |
268 | XSAVE_VALUE (val)->pointer = cache_data; | |
269 | cache = Fcons (key, val); | |
21988a08 KH |
270 | ft_face_cache = Fcons (cache, ft_face_cache); |
271 | } | |
272 | else | |
21988a08 | 273 | { |
e302a291 KH |
274 | val = XCDR (cache); |
275 | cache_data = XSAVE_VALUE (val)->pointer; | |
276 | } | |
277 | if (for_face ? ! cache_data->ft_face : ! cache_data->fc_charset) | |
278 | { | |
279 | char *filename = (char *) SDATA (XCAR (key)); | |
280 | int index = XINT (XCDR (key)); | |
21988a08 | 281 | |
e302a291 KH |
282 | if (for_face) |
283 | { | |
284 | if (! ft_library | |
285 | && FT_Init_FreeType (&ft_library) != 0) | |
286 | return Qnil; | |
287 | if (FT_New_Face (ft_library, filename, index, &cache_data->ft_face) | |
288 | != 0) | |
289 | return Qnil; | |
290 | } | |
291 | else | |
292 | { | |
293 | FcPattern *pat; | |
294 | FcFontSet *fontset; | |
295 | FcObjectSet *objset; | |
296 | FcCharSet *charset; | |
297 | ||
298 | pat = FcPatternBuild (0, FC_FILE, FcTypeString, (FcChar8 *) filename, | |
299 | FC_INDEX, FcTypeInteger, index, NULL); | |
300 | objset = FcObjectSetBuild (FC_CHARSET, NULL); | |
301 | fontset = FcFontList (NULL, pat, objset); | |
302 | xassert (fontset && fontset->nfont > 0); | |
303 | if (FcPatternGetCharSet (fontset->fonts[0], FC_CHARSET, 0, &charset) | |
304 | == FcResultMatch) | |
305 | cache_data->fc_charset = FcCharSetCopy (charset); | |
306 | else | |
307 | cache_data->fc_charset = FcCharSetCreate (); | |
308 | FcFontSetDestroy (fontset); | |
309 | FcObjectSetDestroy (objset); | |
310 | FcPatternDestroy (pat); | |
311 | } | |
21988a08 KH |
312 | } |
313 | return cache; | |
314 | } | |
315 | ||
e302a291 KH |
316 | FcCharSet * |
317 | ftfont_get_fc_charset (entity) | |
318 | Lisp_Object entity; | |
319 | { | |
320 | Lisp_Object val, cache; | |
321 | struct ftfont_cache_data *cache_data; | |
322 | ||
323 | val = assq_no_quit (QCfont_entity, AREF (entity, FONT_EXTRA_INDEX)); | |
324 | xassert (CONSP (val)); | |
325 | val = XCDR (val); | |
326 | cache = ftfont_lookup_cache (val, 0); | |
327 | val = XCDR (cache); | |
328 | cache_data = XSAVE_VALUE (val)->pointer; | |
329 | return cache_data->fc_charset; | |
330 | } | |
331 | ||
332 | #ifdef HAVE_LIBOTF | |
333 | static OTF * | |
334 | ftfont_get_otf (ftfont_info) | |
335 | struct ftfont_info *ftfont_info; | |
336 | { | |
337 | OTF *otf; | |
338 | ||
339 | if (ftfont_info->otf) | |
340 | return ftfont_info->otf; | |
341 | if (! ftfont_info->maybe_otf) | |
342 | return NULL; | |
343 | otf = OTF_open_ft_face (ftfont_info->ft_size->face); | |
344 | if (! otf || OTF_get_table (otf, "head") < 0) | |
345 | { | |
346 | if (otf) | |
347 | OTF_close (otf); | |
348 | ftfont_info->maybe_otf = 0; | |
349 | return NULL; | |
350 | } | |
351 | ftfont_info->otf = otf; | |
352 | return otf; | |
353 | } | |
354 | #endif /* HAVE_LIBOTF */ | |
355 | ||
77175228 | 356 | static Lisp_Object ftfont_get_cache P_ ((FRAME_PTR)); |
c2f5bfd6 | 357 | static Lisp_Object ftfont_list P_ ((Lisp_Object, Lisp_Object)); |
8daf5667 | 358 | static Lisp_Object ftfont_match P_ ((Lisp_Object, Lisp_Object)); |
c2f5bfd6 | 359 | static Lisp_Object ftfont_list_family P_ ((Lisp_Object)); |
42984a74 | 360 | static Lisp_Object ftfont_open P_ ((FRAME_PTR, Lisp_Object, int)); |
c2f5bfd6 KH |
361 | static void ftfont_close P_ ((FRAME_PTR, struct font *)); |
362 | static int ftfont_has_char P_ ((Lisp_Object, int)); | |
363 | static unsigned ftfont_encode_char P_ ((struct font *, int)); | |
364 | static int ftfont_text_extents P_ ((struct font *, unsigned *, int, | |
365 | struct font_metrics *)); | |
366 | static int ftfont_get_bitmap P_ ((struct font *, unsigned, | |
367 | struct font_bitmap *, int)); | |
368 | static int ftfont_anchor_point P_ ((struct font *, unsigned, int, | |
369 | int *, int *)); | |
e302a291 | 370 | static Lisp_Object ftfont_otf_capability P_ ((struct font *)); |
de023c40 | 371 | static Lisp_Object ftfont_shape P_ ((Lisp_Object)); |
c2f5bfd6 KH |
372 | |
373 | struct font_driver ftfont_driver = | |
374 | { | |
09a56ce4 | 375 | 0, /* Qfreetype */ |
42984a74 | 376 | 0, /* case insensitive */ |
c2f5bfd6 | 377 | ftfont_get_cache, |
c2f5bfd6 | 378 | ftfont_list, |
8daf5667 | 379 | ftfont_match, |
c2f5bfd6 | 380 | ftfont_list_family, |
42984a74 | 381 | NULL, |
c2f5bfd6 KH |
382 | ftfont_open, |
383 | ftfont_close, | |
384 | /* We can't draw a text without device dependent functions. */ | |
385 | NULL, | |
386 | NULL, | |
387 | ftfont_has_char, | |
388 | ftfont_encode_char, | |
389 | ftfont_text_extents, | |
390 | /* We can't draw a text without device dependent functions. */ | |
391 | NULL, | |
392 | ftfont_get_bitmap, | |
393 | NULL, | |
394 | NULL, | |
395 | NULL, | |
396 | ftfont_anchor_point, | |
e302a291 KH |
397 | #ifdef HAVE_LIBOTF |
398 | ftfont_otf_capability, | |
399 | #else /* not HAVE_LIBOTF */ | |
c2f5bfd6 | 400 | NULL, |
e302a291 | 401 | #endif /* not HAVE_LIBOTF */ |
c2f5bfd6 | 402 | NULL, |
de023c40 KH |
403 | NULL, |
404 | NULL, | |
637ac44c | 405 | #if defined (HAVE_M17N_FLT) && defined (HAVE_LIBOTF) |
de023c40 | 406 | ftfont_shape |
637ac44c | 407 | #else /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */ |
c2f5bfd6 | 408 | NULL |
637ac44c | 409 | #endif /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */ |
c2f5bfd6 KH |
410 | }; |
411 | ||
c2f5bfd6 KH |
412 | extern Lisp_Object QCname; |
413 | ||
414 | static Lisp_Object | |
77175228 KH |
415 | ftfont_get_cache (f) |
416 | FRAME_PTR f; | |
c2f5bfd6 | 417 | { |
c2f5bfd6 KH |
418 | return freetype_font_cache; |
419 | } | |
420 | ||
21988a08 KH |
421 | static int |
422 | ftfont_get_charset (registry) | |
423 | Lisp_Object registry; | |
424 | { | |
e302a291 KH |
425 | char *str = (char *) SDATA (SYMBOL_NAME (registry)); |
426 | char *re = alloca (SBYTES (SYMBOL_NAME (registry)) * 2 + 1); | |
427 | Lisp_Object regexp; | |
21988a08 KH |
428 | int i, j; |
429 | ||
e302a291 KH |
430 | for (i = j = 0; i < SBYTES (SYMBOL_NAME (registry)); i++, j++) |
431 | { | |
432 | if (str[i] == '.') | |
433 | re[j++] = '\\'; | |
434 | else if (str[i] == '*') | |
435 | re[j++] = '.'; | |
436 | re[j] = str[i]; | |
437 | if (re[j] == '?') | |
438 | re[j] = '.'; | |
439 | } | |
440 | re[j] = '\0'; | |
441 | regexp = make_unibyte_string (re, j); | |
21988a08 | 442 | for (i = 0; fc_charset_table[i].name; i++) |
e302a291 | 443 | if (fast_c_string_match_ignore_case (regexp, fc_charset_table[i].name) >= 0) |
21988a08 KH |
444 | break; |
445 | if (! fc_charset_table[i].name) | |
446 | return -1; | |
447 | if (! fc_charset_table[i].fc_charset) | |
448 | { | |
449 | FcCharSet *charset = FcCharSetCreate (); | |
450 | int *uniquifier = fc_charset_table[i].uniquifier; | |
451 | ||
452 | if (! charset) | |
453 | return -1; | |
454 | for (j = 0; uniquifier[j]; j++) | |
455 | if (! FcCharSetAddChar (charset, uniquifier[j])) | |
456 | { | |
457 | FcCharSetDestroy (charset); | |
458 | return -1; | |
459 | } | |
2a46904e | 460 | fc_charset_table[i].fc_charset = charset; |
21988a08 KH |
461 | } |
462 | return i; | |
463 | } | |
464 | ||
cc63eaf9 KH |
465 | struct OpenTypeSpec |
466 | { | |
16963817 KH |
467 | Lisp_Object script; |
468 | unsigned int script_tag, langsys_tag; | |
cc63eaf9 KH |
469 | int nfeatures[2]; |
470 | unsigned int *features[2]; | |
471 | }; | |
472 | ||
7eb5d3d7 | 473 | #define OTF_SYM_TAG(SYM, TAG) \ |
cc63eaf9 | 474 | do { \ |
7eb5d3d7 KH |
475 | unsigned char *p = SDATA (SYMBOL_NAME (SYM)); \ |
476 | TAG = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; \ | |
cc63eaf9 KH |
477 | } while (0) |
478 | ||
7eb5d3d7 | 479 | #define OTF_TAG_STR(TAG, P) \ |
cc63eaf9 | 480 | do { \ |
7eb5d3d7 KH |
481 | (P)[0] = (char) (TAG >> 24); \ |
482 | (P)[1] = (char) ((TAG >> 16) & 0xFF); \ | |
483 | (P)[2] = (char) ((TAG >> 8) & 0xFF); \ | |
484 | (P)[3] = (char) (TAG & 0xFF); \ | |
16963817 | 485 | (P)[4] = '\0'; \ |
cc63eaf9 KH |
486 | } while (0) |
487 | ||
e302a291 KH |
488 | #define OTF_TAG_SYM(SYM, TAG) \ |
489 | do { \ | |
490 | char str[5]; \ | |
491 | \ | |
492 | OTF_TAG_STR (TAG, str); \ | |
493 | (SYM) = font_intern_prop (str, 4, 1); \ | |
494 | } while (0) | |
495 | ||
496 | ||
cc63eaf9 KH |
497 | static struct OpenTypeSpec * |
498 | ftfont_get_open_type_spec (Lisp_Object otf_spec) | |
499 | { | |
500 | struct OpenTypeSpec *spec = malloc (sizeof (struct OpenTypeSpec)); | |
501 | Lisp_Object val; | |
502 | int i, j, negative; | |
503 | ||
504 | if (! spec) | |
505 | return NULL; | |
16963817 | 506 | spec->script = XCAR (otf_spec); |
43f4f91c | 507 | if (! NILP (spec->script)) |
16963817 KH |
508 | { |
509 | OTF_SYM_TAG (spec->script, spec->script_tag); | |
510 | val = assq_no_quit (spec->script, Votf_script_alist); | |
511 | if (CONSP (val) && SYMBOLP (XCDR (val))) | |
512 | spec->script = XCDR (val); | |
513 | else | |
514 | spec->script = Qnil; | |
515 | } | |
cc63eaf9 | 516 | else |
16963817 | 517 | spec->script_tag = 0x44464C54; /* "DFLT" */ |
cc63eaf9 KH |
518 | otf_spec = XCDR (otf_spec); |
519 | val = XCAR (otf_spec); | |
520 | if (! NILP (val)) | |
16963817 | 521 | OTF_SYM_TAG (val, spec->langsys_tag); |
cc63eaf9 | 522 | else |
16963817 | 523 | spec->langsys_tag = 0; |
cc63eaf9 KH |
524 | spec->nfeatures[0] = spec->nfeatures[1] = 0; |
525 | for (i = 0; i < 2; i++) | |
526 | { | |
527 | Lisp_Object len; | |
528 | ||
2a46904e | 529 | otf_spec = XCDR (otf_spec); |
cc63eaf9 KH |
530 | if (NILP (otf_spec)) |
531 | break; | |
532 | val = XCAR (otf_spec); | |
533 | if (NILP (val)) | |
534 | continue; | |
535 | len = Flength (val); | |
536 | spec->features[i] = malloc (sizeof (int) * XINT (len)); | |
537 | if (! spec->features[i]) | |
538 | { | |
539 | if (i > 0 && spec->features[0]) | |
540 | free (spec->features[0]); | |
541 | free (spec); | |
542 | return NULL; | |
543 | } | |
544 | for (j = 0, negative = 0; CONSP (val); val = XCDR (val)) | |
545 | { | |
546 | if (NILP (XCAR (val))) | |
547 | negative = 1; | |
548 | else | |
549 | { | |
550 | unsigned int tag; | |
551 | ||
552 | OTF_SYM_TAG (XCAR (val), tag); | |
553 | spec->features[i][j++] = negative ? tag & 0x80000000 : tag; | |
554 | } | |
555 | } | |
556 | spec->nfeatures[i] = j; | |
557 | } | |
558 | return spec; | |
559 | } | |
560 | ||
e302a291 | 561 | static FcPattern *ftfont_spec_pattern P_ ((Lisp_Object, char *, |
21988a08 KH |
562 | struct OpenTypeSpec **)); |
563 | ||
42984a74 | 564 | static FcPattern * |
e302a291 | 565 | ftfont_spec_pattern (spec, otlayout, otspec) |
42984a74 KH |
566 | Lisp_Object spec; |
567 | char *otlayout; | |
568 | struct OpenTypeSpec **otspec; | |
c2f5bfd6 | 569 | { |
21988a08 | 570 | Lisp_Object tmp, extra; |
c2f5bfd6 KH |
571 | FcPattern *pattern = NULL; |
572 | FcCharSet *charset = NULL; | |
573 | FcLangSet *langset = NULL; | |
42984a74 KH |
574 | int n; |
575 | int dpi = -1; | |
bc9a2afe | 576 | int scalable = -1; |
42984a74 | 577 | Lisp_Object script = Qnil; |
21988a08 | 578 | Lisp_Object registry; |
e302a291 | 579 | int fc_charset_idx; |
c2f5bfd6 | 580 | |
63565713 | 581 | if (! NILP (AREF (spec, FONT_ADSTYLE_INDEX)) |
42984a74 KH |
582 | && SBYTES (SYMBOL_NAME (AREF (spec, FONT_ADSTYLE_INDEX))) > 0) |
583 | /* Fontconfig doesn't support adstyle property. */ | |
584 | return NULL; | |
585 | if ((n = FONT_SLANT_NUMERIC (spec)) >= 0 | |
586 | && n < 100) | |
63565713 | 587 | /* Fontconfig doesn't support reverse-italic/obligue. */ |
42984a74 KH |
588 | return NULL; |
589 | ||
590 | if (INTEGERP (AREF (spec, FONT_DPI_INDEX))) | |
591 | dpi = XINT (AREF (spec, FONT_DPI_INDEX)); | |
42984a74 KH |
592 | if (INTEGERP (AREF (spec, FONT_AVGWIDTH_INDEX)) |
593 | && XINT (AREF (spec, FONT_AVGWIDTH_INDEX)) == 0) | |
594 | scalable = 1; | |
63565713 | 595 | |
21988a08 KH |
596 | registry = AREF (spec, FONT_REGISTRY_INDEX); |
597 | if (NILP (registry) | |
770835fd | 598 | || EQ (registry, Qascii_0) |
21988a08 KH |
599 | || EQ (registry, Qiso10646_1) |
600 | || EQ (registry, Qunicode_bmp) | |
601 | || EQ (registry, Qunicode_sip)) | |
e302a291 | 602 | fc_charset_idx = -1; |
21988a08 | 603 | else |
c2f5bfd6 | 604 | { |
7d7ad10e KH |
605 | FcChar8 *lang; |
606 | ||
e302a291 KH |
607 | fc_charset_idx = ftfont_get_charset (registry); |
608 | if (fc_charset_idx < 0) | |
42984a74 | 609 | return NULL; |
e302a291 KH |
610 | charset = fc_charset_table[fc_charset_idx].fc_charset; |
611 | lang = (FcChar8 *) fc_charset_table[fc_charset_idx].lang; | |
7d7ad10e KH |
612 | if (lang) |
613 | { | |
614 | langset = FcLangSetCreate (); | |
615 | if (! langset) | |
616 | goto err; | |
617 | FcLangSetAdd (langset, lang); | |
618 | } | |
c2f5bfd6 KH |
619 | } |
620 | ||
cc63eaf9 | 621 | otlayout[0] = '\0'; |
8daf5667 KH |
622 | for (extra = AREF (spec, FONT_EXTRA_INDEX); |
623 | CONSP (extra); extra = XCDR (extra)) | |
c2f5bfd6 | 624 | { |
8daf5667 KH |
625 | Lisp_Object key, val; |
626 | ||
42984a74 KH |
627 | key = XCAR (XCAR (extra)), val = XCDR (XCAR (extra)); |
628 | if (EQ (key, QCdpi)) | |
629 | dpi = XINT (val); | |
42984a74 | 630 | else if (EQ (key, QClang)) |
c2f5bfd6 | 631 | { |
7d7ad10e KH |
632 | if (! langset) |
633 | langset = FcLangSetCreate (); | |
c2f5bfd6 KH |
634 | if (! langset) |
635 | goto err; | |
8daf5667 | 636 | if (SYMBOLP (val)) |
c2f5bfd6 | 637 | { |
8daf5667 | 638 | if (! FcLangSetAdd (langset, SYMBOL_FcChar8 (val))) |
c2f5bfd6 KH |
639 | goto err; |
640 | } | |
641 | else | |
8daf5667 KH |
642 | for (; CONSP (val); val = XCDR (val)) |
643 | if (SYMBOLP (XCAR (val)) | |
644 | && ! FcLangSetAdd (langset, SYMBOL_FcChar8 (XCAR (val)))) | |
645 | goto err; | |
c2f5bfd6 | 646 | } |
42984a74 KH |
647 | else if (EQ (key, QCotf)) |
648 | { | |
649 | *otspec = ftfont_get_open_type_spec (val); | |
650 | if (! *otspec) | |
651 | return NULL; | |
652 | strcat (otlayout, "otlayout:"); | |
653 | OTF_TAG_STR ((*otspec)->script_tag, otlayout + 9); | |
654 | script = (*otspec)->script; | |
655 | } | |
8daf5667 KH |
656 | else if (EQ (key, QCscript)) |
657 | script = val; | |
8daf5667 KH |
658 | else if (EQ (key, QCscalable)) |
659 | scalable = ! NILP (val); | |
660 | } | |
c2f5bfd6 | 661 | |
8daf5667 KH |
662 | if (! NILP (script) && ! charset) |
663 | { | |
664 | Lisp_Object chars = assq_no_quit (script, Vscript_representative_chars); | |
665 | ||
666 | if (CONSP (chars)) | |
667 | { | |
668 | charset = FcCharSetCreate (); | |
669 | if (! charset) | |
670 | goto err; | |
671 | for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars)) | |
672 | if (CHARACTERP (XCAR (chars)) | |
673 | && ! FcCharSetAddChar (charset, XUINT (XCAR (chars)))) | |
674 | goto err; | |
c2f5bfd6 KH |
675 | } |
676 | } | |
677 | ||
4ffe34a4 | 678 | pattern = FcPatternCreate (); |
706b6995 KH |
679 | if (! pattern) |
680 | goto err; | |
706b6995 | 681 | tmp = AREF (spec, FONT_FOUNDRY_INDEX); |
42984a74 | 682 | if (! NILP (tmp) |
706b6995 KH |
683 | && ! FcPatternAddString (pattern, FC_FOUNDRY, SYMBOL_FcChar8 (tmp))) |
684 | goto err; | |
318548be KH |
685 | tmp = AREF (spec, FONT_FAMILY_INDEX); |
686 | if (! NILP (tmp) | |
687 | && ! FcPatternAddString (pattern, FC_FAMILY, SYMBOL_FcChar8 (tmp))) | |
688 | goto err; | |
c2f5bfd6 KH |
689 | if (charset |
690 | && ! FcPatternAddCharSet (pattern, FC_CHARSET, charset)) | |
691 | goto err; | |
692 | if (langset | |
693 | && ! FcPatternAddLangSet (pattern, FC_LANG, langset)) | |
694 | goto err; | |
bc9a2afe KH |
695 | if (dpi >= 0 |
696 | && ! FcPatternAddDouble (pattern, FC_DPI, dpi)) | |
697 | goto err; | |
bc9a2afe | 698 | if (scalable >= 0 |
25a5d05b | 699 | && ! FcPatternAddBool (pattern, FC_SCALABLE, scalable ? FcTrue : FcFalse)) |
bc9a2afe | 700 | goto err; |
7d7ad10e | 701 | |
42984a74 | 702 | goto finish; |
c2f5bfd6 | 703 | |
42984a74 KH |
704 | err: |
705 | /* We come here because of unexpected error in fontconfig API call | |
706 | (usually insufficient memory). */ | |
707 | if (pattern) | |
708 | { | |
709 | FcPatternDestroy (pattern); | |
710 | pattern = NULL; | |
711 | } | |
712 | if (*otspec) | |
713 | { | |
714 | if ((*otspec)->nfeatures[0] > 0) | |
715 | free ((*otspec)->features[0]); | |
716 | if ((*otspec)->nfeatures[1] > 0) | |
717 | free ((*otspec)->features[1]); | |
718 | free (*otspec); | |
719 | *otspec = NULL; | |
720 | } | |
721 | ||
722 | finish: | |
42984a74 | 723 | if (langset) FcLangSetDestroy (langset); |
e302a291 | 724 | if (charset && fc_charset_idx < 0) FcCharSetDestroy (charset); |
42984a74 KH |
725 | return pattern; |
726 | } | |
727 | ||
728 | static Lisp_Object | |
729 | ftfont_list (frame, spec) | |
730 | Lisp_Object frame, spec; | |
731 | { | |
e302a291 | 732 | Lisp_Object val = Qnil, family; |
42984a74 KH |
733 | int i; |
734 | FcPattern *pattern; | |
735 | FcFontSet *fontset = NULL; | |
736 | FcObjectSet *objset = NULL; | |
42984a74 KH |
737 | char otlayout[15]; /* For "otlayout:XXXX" */ |
738 | struct OpenTypeSpec *otspec = NULL; | |
5d376f74 | 739 | int spacing = -1; |
2a46904e | 740 | |
42984a74 KH |
741 | if (! fc_initialized) |
742 | { | |
743 | FcInit (); | |
744 | fc_initialized = 1; | |
745 | } | |
746 | ||
e302a291 | 747 | pattern = ftfont_spec_pattern (spec, otlayout, &otspec); |
42984a74 KH |
748 | if (! pattern) |
749 | return Qnil; | |
5d376f74 KH |
750 | if (INTEGERP (AREF (spec, FONT_SPACING_INDEX))) |
751 | spacing = XINT (AREF (spec, FONT_SPACING_INDEX)); | |
318548be KH |
752 | family = AREF (spec, FONT_FAMILY_INDEX); |
753 | if (! NILP (family)) | |
754 | { | |
755 | Lisp_Object resolved; | |
756 | ||
7d7ad10e | 757 | resolved = ftfont_resolve_generic_family (family, pattern); |
318548be KH |
758 | if (! NILP (resolved)) |
759 | { | |
760 | FcPatternDel (pattern, FC_FAMILY); | |
761 | if (! FcPatternAddString (pattern, FC_FAMILY, | |
762 | SYMBOL_FcChar8 (resolved))) | |
763 | goto err; | |
764 | } | |
765 | } | |
766 | ||
706b6995 | 767 | objset = FcObjectSetBuild (FC_FOUNDRY, FC_FAMILY, FC_WEIGHT, FC_SLANT, |
42984a74 | 768 | FC_WIDTH, FC_PIXEL_SIZE, FC_SPACING, FC_SCALABLE, |
e302a291 | 769 | FC_FILE, FC_INDEX, |
42984a74 KH |
770 | #ifdef FC_CAPABILITY |
771 | FC_CAPABILITY, | |
772 | #endif /* FC_CAPABILITY */ | |
4ffe34a4 KH |
773 | #ifdef FC_FONTFORMAT |
774 | FC_FONTFORMAT, | |
775 | #endif | |
e907d979 | 776 | NULL); |
706b6995 KH |
777 | if (! objset) |
778 | goto err; | |
42984a74 | 779 | |
318548be KH |
780 | fontset = FcFontList (NULL, pattern, objset); |
781 | if (! fontset) | |
782 | goto err; | |
770835fd KH |
783 | #if 0 |
784 | /* Need fix because this finds any fonts. */ | |
785 | if (fontset->nfont == 0 && ! NILP (family)) | |
786 | { | |
787 | /* Try maching with configuration. For instance, the | |
788 | configuration may specify "Nimbus Mono L" as an alias of | |
789 | "Courier". */ | |
790 | FcPattern *pat = FcPatternBuild (0, FC_FAMILY, FcTypeString, | |
791 | SYMBOL_FcChar8 (family), NULL); | |
792 | FcChar8 *fam; | |
793 | ||
794 | if (FcConfigSubstitute (NULL, pat, FcMatchPattern) == FcTrue) | |
795 | { | |
796 | for (i = 0; | |
797 | FcPatternGetString (pat, FC_FAMILY, i, &fam) == FcResultMatch; | |
798 | i++) | |
799 | { | |
800 | FcPatternDel (pattern, FC_FAMILY); | |
801 | FcPatternAddString (pattern, FC_FAMILY, fam); | |
802 | FcFontSetDestroy (fontset); | |
803 | fontset = FcFontList (NULL, pattern, objset); | |
804 | if (fontset->nfont > 0) | |
805 | break; | |
806 | } | |
807 | } | |
808 | } | |
809 | #endif | |
318548be | 810 | for (i = 0; i < fontset->nfont; i++) |
bc5f6c42 | 811 | { |
318548be | 812 | Lisp_Object entity; |
f63d54dc | 813 | |
5d376f74 KH |
814 | if (spacing >= 0) |
815 | { | |
816 | int this; | |
817 | ||
818 | if ((FcPatternGetInteger (fontset->fonts[i], FC_SPACING, 0, &this) | |
819 | == FcResultMatch) | |
820 | && spacing != this) | |
821 | continue; | |
822 | } | |
823 | ||
bc5f6c42 | 824 | #ifdef FC_CAPABILITY |
318548be KH |
825 | if (otlayout[0]) |
826 | { | |
827 | FcChar8 *this; | |
a85f724a | 828 | |
318548be KH |
829 | if (FcPatternGetString (fontset->fonts[i], FC_CAPABILITY, 0, |
830 | &this) != FcResultMatch | |
831 | || ! strstr ((char *) this, otlayout)) | |
832 | continue; | |
833 | } | |
bc5f6c42 | 834 | #endif /* FC_CAPABILITY */ |
cc63eaf9 | 835 | #ifdef HAVE_LIBOTF |
318548be KH |
836 | if (otspec) |
837 | { | |
838 | FcChar8 *file; | |
839 | OTF *otf; | |
840 | ||
841 | if (FcPatternGetString (fontset->fonts[i], FC_FILE, 0, &file) | |
842 | != FcResultMatch) | |
843 | continue; | |
844 | otf = OTF_open ((char *) file); | |
845 | if (! otf) | |
846 | continue; | |
847 | if (OTF_check_features (otf, 1, | |
848 | otspec->script_tag, otspec->langsys_tag, | |
849 | otspec->features[0], | |
850 | otspec->nfeatures[0]) != 1 | |
851 | || OTF_check_features (otf, 0, | |
852 | otspec->script_tag, otspec->langsys_tag, | |
853 | otspec->features[1], | |
854 | otspec->nfeatures[1]) != 1) | |
855 | continue; | |
c2f5bfd6 | 856 | } |
318548be | 857 | #endif /* HAVE_LIBOTF */ |
e302a291 KH |
858 | entity = ftfont_pattern_entity (fontset->fonts[i], |
859 | AREF (spec, FONT_EXTRA_INDEX)); | |
318548be KH |
860 | if (! NILP (entity)) |
861 | val = Fcons (entity, val); | |
c2f5bfd6 | 862 | } |
318548be | 863 | font_add_log ("ftfont-list", spec, val); |
c2f5bfd6 KH |
864 | goto finish; |
865 | ||
866 | err: | |
867 | /* We come here because of unexpected error in fontconfig API call | |
706b6995 | 868 | (usually insufficient memory). */ |
c2f5bfd6 KH |
869 | val = Qnil; |
870 | ||
871 | finish: | |
c2f5bfd6 KH |
872 | if (objset) FcObjectSetDestroy (objset); |
873 | if (fontset) FcFontSetDestroy (fontset); | |
c2f5bfd6 | 874 | if (pattern) FcPatternDestroy (pattern); |
c2f5bfd6 KH |
875 | return val; |
876 | } | |
877 | ||
8daf5667 KH |
878 | static Lisp_Object |
879 | ftfont_match (frame, spec) | |
880 | Lisp_Object frame, spec; | |
881 | { | |
21988a08 | 882 | Lisp_Object entity; |
42984a74 | 883 | FcPattern *pattern, *match = NULL; |
8daf5667 | 884 | FcResult result; |
42984a74 KH |
885 | char otlayout[15]; /* For "otlayout:XXXX" */ |
886 | struct OpenTypeSpec *otspec = NULL; | |
8daf5667 KH |
887 | |
888 | if (! fc_initialized) | |
889 | { | |
890 | FcInit (); | |
891 | fc_initialized = 1; | |
892 | } | |
893 | ||
e302a291 | 894 | pattern = ftfont_spec_pattern (spec, otlayout, &otspec); |
42984a74 | 895 | if (! pattern) |
8daf5667 KH |
896 | return Qnil; |
897 | ||
42984a74 | 898 | if (INTEGERP (AREF (spec, FONT_SIZE_INDEX))) |
8daf5667 | 899 | { |
42984a74 | 900 | FcValue value; |
55082642 | 901 | |
42984a74 KH |
902 | value.type = FcTypeDouble; |
903 | value.u.d = XINT (AREF (spec, FONT_SIZE_INDEX)); | |
904 | FcPatternAdd (pattern, FC_PIXEL_SIZE, value, FcFalse); | |
905 | } | |
906 | if (FcConfigSubstitute (NULL, pattern, FcMatchPattern) == FcTrue) | |
907 | { | |
908 | FcDefaultSubstitute (pattern); | |
909 | match = FcFontMatch (NULL, pattern, &result); | |
910 | if (match) | |
8daf5667 | 911 | { |
e302a291 | 912 | entity = ftfont_pattern_entity (match, AREF (spec, FONT_EXTRA_INDEX)); |
42984a74 KH |
913 | FcPatternDestroy (match); |
914 | if (! NILP (AREF (spec, FONT_FAMILY_INDEX)) | |
915 | && NILP (assq_no_quit (AREF (spec, FONT_FAMILY_INDEX), | |
916 | ftfont_generic_family_list)) | |
917 | && NILP (Fstring_equal (AREF (spec, FONT_FAMILY_INDEX), | |
918 | AREF (entity, FONT_FAMILY_INDEX)))) | |
919 | entity = Qnil; | |
8daf5667 | 920 | } |
8daf5667 | 921 | } |
42984a74 | 922 | FcPatternDestroy (pattern); |
8daf5667 | 923 | |
318548be | 924 | font_add_log ("ftfont-match", spec, entity); |
8daf5667 KH |
925 | return entity; |
926 | } | |
927 | ||
c2f5bfd6 KH |
928 | static Lisp_Object |
929 | ftfont_list_family (frame) | |
930 | Lisp_Object frame; | |
931 | { | |
932 | Lisp_Object list; | |
933 | FcPattern *pattern = NULL; | |
934 | FcFontSet *fontset = NULL; | |
935 | FcObjectSet *objset = NULL; | |
936 | int i; | |
937 | ||
938 | if (! fc_initialized) | |
939 | { | |
940 | FcInit (); | |
941 | fc_initialized = 1; | |
942 | } | |
943 | ||
944 | pattern = FcPatternCreate (); | |
945 | if (! pattern) | |
946 | goto finish; | |
706b6995 | 947 | objset = FcObjectSetBuild (FC_FAMILY, NULL); |
c2f5bfd6 KH |
948 | if (! objset) |
949 | goto finish; | |
950 | fontset = FcFontList (NULL, pattern, objset); | |
951 | if (! fontset) | |
952 | goto finish; | |
953 | ||
954 | list = Qnil; | |
955 | for (i = 0; i < fontset->nfont; i++) | |
956 | { | |
957 | FcPattern *pat = fontset->fonts[i]; | |
958 | FcChar8 *str; | |
959 | ||
960 | if (FcPatternGetString (pat, FC_FAMILY, 0, &str) == FcResultMatch) | |
42984a74 | 961 | list = Fcons (intern ((char *) str), list); |
c2f5bfd6 KH |
962 | } |
963 | ||
964 | finish: | |
965 | if (objset) FcObjectSetDestroy (objset); | |
966 | if (fontset) FcFontSetDestroy (fontset); | |
967 | if (pattern) FcPatternDestroy (pattern); | |
968 | ||
969 | return list; | |
970 | } | |
971 | ||
972 | ||
42984a74 | 973 | static Lisp_Object |
c2f5bfd6 KH |
974 | ftfont_open (f, entity, pixel_size) |
975 | FRAME_PTR f; | |
976 | Lisp_Object entity; | |
977 | int pixel_size; | |
978 | { | |
979 | struct ftfont_info *ftfont_info; | |
980 | struct font *font; | |
e302a291 | 981 | struct ftfont_cache_data *cache_data; |
c2f5bfd6 KH |
982 | FT_Face ft_face; |
983 | FT_Size ft_size; | |
984 | FT_UInt size; | |
e302a291 | 985 | Lisp_Object val, filename, index, cache, font_object; |
21988a08 | 986 | int scalable; |
c2f5bfd6 | 987 | int spacing; |
42984a74 KH |
988 | char name[256]; |
989 | int i, len; | |
990 | int upEM; | |
c2f5bfd6 | 991 | |
42984a74 KH |
992 | val = assq_no_quit (QCfont_entity, AREF (entity, FONT_EXTRA_INDEX)); |
993 | if (! CONSP (val)) | |
994 | return Qnil; | |
995 | val = XCDR (val); | |
e302a291 | 996 | cache = ftfont_lookup_cache (val, 1); |
21988a08 KH |
997 | if (NILP (cache)) |
998 | return Qnil; | |
e302a291 KH |
999 | filename = XCAR (val); |
1000 | index = XCDR (val); | |
21988a08 | 1001 | val = XCDR (cache); |
e302a291 KH |
1002 | cache_data = XSAVE_VALUE (XCDR (cache))->pointer; |
1003 | ft_face = cache_data->ft_face; | |
21988a08 | 1004 | if (XSAVE_VALUE (val)->integer > 0) |
c2f5bfd6 | 1005 | { |
21988a08 | 1006 | /* FT_Face in this cache is already used by the different size. */ |
c2f5bfd6 | 1007 | if (FT_New_Size (ft_face, &ft_size) != 0) |
42984a74 | 1008 | return Qnil; |
c2f5bfd6 KH |
1009 | if (FT_Activate_Size (ft_size) != 0) |
1010 | { | |
1011 | FT_Done_Size (ft_size); | |
42984a74 | 1012 | return Qnil; |
c2f5bfd6 | 1013 | } |
21988a08 KH |
1014 | } |
1015 | XSAVE_VALUE (val)->integer++; | |
c2f5bfd6 KH |
1016 | size = XINT (AREF (entity, FONT_SIZE_INDEX)); |
1017 | if (size == 0) | |
1018 | size = pixel_size; | |
1019 | if (FT_Set_Pixel_Sizes (ft_face, size, size) != 0) | |
1020 | { | |
1021 | if (XSAVE_VALUE (val)->integer == 0) | |
1022 | FT_Done_Face (ft_face); | |
42984a74 | 1023 | return Qnil; |
c2f5bfd6 KH |
1024 | } |
1025 | ||
e302a291 | 1026 | font_object = font_make_object (VECSIZE (struct ftfont_info), entity, size); |
42984a74 | 1027 | ASET (font_object, FONT_TYPE_INDEX, Qfreetype); |
42984a74 KH |
1028 | len = font_unparse_xlfd (entity, size, name, 256); |
1029 | if (len > 0) | |
1030 | ASET (font_object, FONT_NAME_INDEX, make_unibyte_string (name, len)); | |
1031 | len = font_unparse_fcname (entity, size, name, 256); | |
1032 | if (len > 0) | |
1033 | ASET (font_object, FONT_FULLNAME_INDEX, make_unibyte_string (name, len)); | |
1034 | else | |
1035 | ASET (font_object, FONT_FULLNAME_INDEX, | |
1036 | AREF (font_object, FONT_NAME_INDEX)); | |
21988a08 | 1037 | ASET (font_object, FONT_FILE_INDEX, filename); |
7d7ad10e | 1038 | ASET (font_object, FONT_FORMAT_INDEX, ftfont_font_format (NULL, filename)); |
42984a74 KH |
1039 | font = XFONT_OBJECT (font_object); |
1040 | ftfont_info = (struct ftfont_info *) font; | |
21988a08 | 1041 | ftfont_info->ft_size = ft_face->size; |
e302a291 | 1042 | ftfont_info->index = XINT (index); |
0d674a05 | 1043 | #ifdef HAVE_LIBOTF |
de023c40 KH |
1044 | ftfont_info->maybe_otf = ft_face->face_flags & FT_FACE_FLAG_SFNT; |
1045 | ftfont_info->otf = NULL; | |
0d674a05 | 1046 | #endif /* HAVE_LIBOTF */ |
c2f5bfd6 KH |
1047 | font->pixel_size = size; |
1048 | font->driver = &ftfont_driver; | |
42984a74 | 1049 | font->encoding_charset = font->repertory_charset = -1; |
c9c0c429 | 1050 | |
42984a74 | 1051 | upEM = ft_face->units_per_EM; |
21988a08 KH |
1052 | scalable = (INTEGERP (AREF (entity, FONT_AVGWIDTH_INDEX)) |
1053 | && XINT (AREF (entity, FONT_AVGWIDTH_INDEX)) == 0); | |
42984a74 KH |
1054 | if (scalable) |
1055 | { | |
1056 | font->ascent = ft_face->ascender * size / upEM; | |
1057 | font->descent = - ft_face->descender * size / upEM; | |
1058 | font->height = ft_face->height * size / upEM; | |
1059 | } | |
1060 | else | |
1061 | { | |
1062 | font->ascent = ft_face->size->metrics.ascender >> 6; | |
1063 | font->descent = - ft_face->size->metrics.descender >> 6; | |
1064 | font->height = ft_face->size->metrics.height >> 6; | |
c9c0c429 | 1065 | } |
21988a08 KH |
1066 | if (INTEGERP (AREF (entity, FONT_SPACING_INDEX))) |
1067 | spacing = XINT (AREF (entity, FONT_SPACING_INDEX)); | |
1068 | else | |
c9c0c429 KH |
1069 | spacing = FC_PROPORTIONAL; |
1070 | if (spacing != FC_PROPORTIONAL) | |
42984a74 KH |
1071 | font->min_width = font->average_width = font->space_width |
1072 | = (scalable ? ft_face->max_advance_width * size / upEM | |
1073 | : ft_face->size->metrics.max_advance >> 6); | |
c2f5bfd6 KH |
1074 | else |
1075 | { | |
42984a74 | 1076 | int n; |
c2f5bfd6 | 1077 | |
42984a74 KH |
1078 | font->min_width = font->average_width = font->space_width = 0; |
1079 | for (i = 32, n = 0; i < 127; i++) | |
1080 | if (FT_Load_Char (ft_face, i, FT_LOAD_DEFAULT) != 0) | |
1081 | { | |
1082 | int this_width = ft_face->glyph->metrics.horiAdvance >> 6; | |
1083 | ||
1084 | if (this_width > 0 | |
1085 | && (! font->min_width || font->min_width > this_width)) | |
1086 | font->min_width = this_width; | |
1087 | if (i == 32) | |
1088 | font->space_width = this_width; | |
1089 | font->average_width += this_width; | |
1090 | n++; | |
1091 | } | |
1092 | if (n > 0) | |
1093 | font->average_width /= n; | |
c2f5bfd6 KH |
1094 | } |
1095 | ||
42984a74 KH |
1096 | font->baseline_offset = 0; |
1097 | font->relative_compose = 0; | |
1098 | font->default_ascent = 0; | |
1099 | font->vertical_centering = 0; | |
1100 | if (scalable) | |
1101 | { | |
1102 | font->underline_position = -ft_face->underline_position * size / upEM; | |
1103 | font->underline_thickness = -ft_face->underline_thickness * size / upEM; | |
1104 | } | |
1105 | else | |
1106 | { | |
1107 | font->underline_position = -1; | |
1108 | font->underline_thickness = 0; | |
1109 | } | |
c2f5bfd6 | 1110 | |
42984a74 | 1111 | return font_object; |
c2f5bfd6 KH |
1112 | } |
1113 | ||
1114 | static void | |
1115 | ftfont_close (f, font) | |
1116 | FRAME_PTR f; | |
1117 | struct font *font; | |
1118 | { | |
1119 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
21988a08 | 1120 | Lisp_Object val, cache; |
c2f5bfd6 | 1121 | |
e302a291 KH |
1122 | val = Fcons (font->props[FONT_FILE_INDEX], make_number (ftfont_info->index)); |
1123 | cache = ftfont_lookup_cache (val, 1); | |
1124 | xassert (CONSP (cache)); | |
21988a08 | 1125 | val = XCDR (cache); |
c2f5bfd6 KH |
1126 | (XSAVE_VALUE (val)->integer)--; |
1127 | if (XSAVE_VALUE (val)->integer == 0) | |
de023c40 | 1128 | { |
e302a291 | 1129 | struct ftfont_cache_data *cache_data = XSAVE_VALUE (val)->pointer; |
21988a08 | 1130 | |
e302a291 | 1131 | FT_Done_Face (cache_data->ft_face); |
de023c40 KH |
1132 | #ifdef HAVE_LIBOTF |
1133 | if (ftfont_info->otf) | |
1134 | OTF_close (ftfont_info->otf); | |
1135 | #endif | |
e302a291 | 1136 | cache_data->ft_face = NULL; |
de023c40 | 1137 | } |
c2f5bfd6 KH |
1138 | else |
1139 | FT_Done_Size (ftfont_info->ft_size); | |
c2f5bfd6 KH |
1140 | } |
1141 | ||
2a46904e | 1142 | static int |
c2f5bfd6 KH |
1143 | ftfont_has_char (entity, c) |
1144 | Lisp_Object entity; | |
1145 | int c; | |
1146 | { | |
e302a291 | 1147 | FcCharSet *charset = ftfont_get_fc_charset (entity); |
c2f5bfd6 | 1148 | |
e302a291 | 1149 | return (FcCharSetHasChar (charset, c) == FcTrue); |
c2f5bfd6 KH |
1150 | } |
1151 | ||
1152 | static unsigned | |
1153 | ftfont_encode_char (font, c) | |
1154 | struct font *font; | |
1155 | int c; | |
1156 | { | |
1157 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
1158 | FT_Face ft_face = ftfont_info->ft_size->face; | |
1159 | FT_ULong charcode = c; | |
1160 | FT_UInt code = FT_Get_Char_Index (ft_face, charcode); | |
1161 | ||
4cec6061 | 1162 | return (code > 0 ? code : FONT_INVALID_CODE); |
c2f5bfd6 KH |
1163 | } |
1164 | ||
1165 | static int | |
1166 | ftfont_text_extents (font, code, nglyphs, metrics) | |
1167 | struct font *font; | |
1168 | unsigned *code; | |
1169 | int nglyphs; | |
1170 | struct font_metrics *metrics; | |
1171 | { | |
1172 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
1173 | FT_Face ft_face = ftfont_info->ft_size->face; | |
1174 | int width = 0; | |
e5d05978 | 1175 | int i, first; |
c2f5bfd6 KH |
1176 | |
1177 | if (ftfont_info->ft_size != ft_face->size) | |
1178 | FT_Activate_Size (ftfont_info->ft_size); | |
1179 | if (metrics) | |
1180 | bzero (metrics, sizeof (struct font_metrics)); | |
e5d05978 | 1181 | for (i = 0, first = 1; i < nglyphs; i++) |
c2f5bfd6 KH |
1182 | { |
1183 | if (FT_Load_Glyph (ft_face, code[i], FT_LOAD_DEFAULT) == 0) | |
1184 | { | |
1185 | FT_Glyph_Metrics *m = &ft_face->glyph->metrics; | |
1186 | ||
e5d05978 KH |
1187 | if (first) |
1188 | { | |
1189 | if (metrics) | |
1190 | { | |
1191 | metrics->lbearing = m->horiBearingX >> 6; | |
1192 | metrics->rbearing = (m->horiBearingX + m->width) >> 6; | |
1193 | metrics->ascent = m->horiBearingY >> 6; | |
1194 | metrics->descent = (m->horiBearingY + m->height) >> 6; | |
1195 | } | |
1196 | first = 0; | |
1197 | } | |
c2f5bfd6 KH |
1198 | if (metrics) |
1199 | { | |
1200 | if (metrics->lbearing > width + (m->horiBearingX >> 6)) | |
1201 | metrics->lbearing = width + (m->horiBearingX >> 6); | |
1202 | if (metrics->rbearing | |
1203 | < width + ((m->horiBearingX + m->width) >> 6)) | |
1204 | metrics->rbearing | |
1205 | = width + ((m->horiBearingX + m->width) >> 6); | |
1206 | if (metrics->ascent < (m->horiBearingY >> 6)) | |
1207 | metrics->ascent = m->horiBearingY >> 6; | |
1208 | if (metrics->descent > ((m->horiBearingY + m->height) >> 6)) | |
1209 | metrics->descent = (m->horiBearingY + m->height) >> 6; | |
1210 | } | |
1211 | width += m->horiAdvance >> 6; | |
1212 | } | |
1213 | else | |
1214 | { | |
42984a74 | 1215 | width += font->space_width; |
c2f5bfd6 KH |
1216 | } |
1217 | } | |
1218 | if (metrics) | |
1219 | metrics->width = width; | |
1220 | ||
1221 | return width; | |
1222 | } | |
1223 | ||
1224 | static int | |
1225 | ftfont_get_bitmap (font, code, bitmap, bits_per_pixel) | |
1226 | struct font *font; | |
1227 | unsigned code; | |
1228 | struct font_bitmap *bitmap; | |
1229 | int bits_per_pixel; | |
1230 | { | |
1231 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
1232 | FT_Face ft_face = ftfont_info->ft_size->face; | |
1233 | FT_Int32 load_flags = FT_LOAD_RENDER; | |
1234 | ||
1235 | if (ftfont_info->ft_size != ft_face->size) | |
1236 | FT_Activate_Size (ftfont_info->ft_size); | |
1237 | if (bits_per_pixel == 1) | |
1238 | { | |
1239 | #ifdef FT_LOAD_TARGET_MONO | |
1240 | load_flags |= FT_LOAD_TARGET_MONO; | |
1241 | #else | |
1242 | load_flags |= FT_LOAD_MONOCHROME; | |
1243 | #endif | |
1244 | } | |
1245 | else if (bits_per_pixel != 8) | |
1246 | /* We don't support such a rendering. */ | |
1247 | return -1; | |
1248 | ||
1249 | if (FT_Load_Glyph (ft_face, code, load_flags) != 0) | |
1250 | return -1; | |
b51e5112 KH |
1251 | bitmap->bits_per_pixel |
1252 | = (ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO ? 1 | |
1253 | : ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY ? 8 | |
1254 | : ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD ? 8 | |
1255 | : ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V ? 8 | |
1256 | : -1); | |
1257 | if (bitmap->bits_per_pixel < 0) | |
1258 | /* We don't suport that kind of pixel mode. */ | |
1259 | return -1; | |
c2f5bfd6 KH |
1260 | bitmap->rows = ft_face->glyph->bitmap.rows; |
1261 | bitmap->width = ft_face->glyph->bitmap.width; | |
1262 | bitmap->pitch = ft_face->glyph->bitmap.pitch; | |
1263 | bitmap->buffer = ft_face->glyph->bitmap.buffer; | |
1264 | bitmap->left = ft_face->glyph->bitmap_left; | |
1265 | bitmap->top = ft_face->glyph->bitmap_top; | |
1266 | bitmap->advance = ft_face->glyph->metrics.horiAdvance >> 6; | |
1267 | bitmap->extra = NULL; | |
1268 | ||
1269 | return 0; | |
1270 | } | |
1271 | ||
1272 | static int | |
1273 | ftfont_anchor_point (font, code, index, x, y) | |
1274 | struct font *font; | |
1275 | unsigned code; | |
1276 | int index; | |
1277 | int *x, *y; | |
1278 | { | |
1279 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
1280 | FT_Face ft_face = ftfont_info->ft_size->face; | |
1281 | ||
1282 | if (ftfont_info->ft_size != ft_face->size) | |
1283 | FT_Activate_Size (ftfont_info->ft_size); | |
1284 | if (FT_Load_Glyph (ft_face, code, FT_LOAD_DEFAULT) != 0) | |
1285 | return -1; | |
1286 | if (ft_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE) | |
1287 | return -1; | |
1288 | if (index >= ft_face->glyph->outline.n_points) | |
1289 | return -1; | |
1290 | *x = ft_face->glyph->outline.points[index].x; | |
1291 | *y = ft_face->glyph->outline.points[index].y; | |
1292 | return 0; | |
1293 | } | |
1294 | ||
de023c40 | 1295 | #ifdef HAVE_LIBOTF |
e302a291 KH |
1296 | |
1297 | static Lisp_Object | |
1298 | ftfont_otf_features (gsub_gpos) | |
1299 | OTF_GSUB_GPOS *gsub_gpos; | |
1300 | { | |
1301 | Lisp_Object scripts, langsyses, features, sym; | |
1302 | int i, j, k; | |
1303 | ||
1304 | for (scripts = Qnil, i = gsub_gpos->ScriptList.ScriptCount - 1; i >= 0; i--) | |
1305 | { | |
1306 | OTF_Script *otf_script = gsub_gpos->ScriptList.Script + i; | |
1307 | ||
1308 | for (langsyses = Qnil, j = otf_script->LangSysCount - 1; j >= -1; j--) | |
1309 | { | |
1310 | OTF_LangSys *otf_langsys; | |
1311 | ||
1312 | if (j >= 0) | |
1313 | otf_langsys = otf_script->LangSys + j; | |
1314 | else if (otf_script->DefaultLangSysOffset) | |
1315 | otf_langsys = &otf_script->DefaultLangSys; | |
1316 | else | |
1317 | break; | |
1318 | ||
1319 | for (features = Qnil, k = otf_langsys->FeatureCount - 1; k >= 0; k--) | |
1320 | { | |
1321 | OTF_TAG_SYM (sym, gsub_gpos->FeatureList.Feature[k].FeatureTag); | |
1322 | features = Fcons (sym, features); | |
1323 | } | |
1324 | if (j >= 0) | |
1325 | OTF_TAG_SYM (sym, otf_script->LangSysRecord[j].LangSysTag); | |
1326 | else | |
1327 | sym = Qnil; | |
1328 | langsyses = Fcons (Fcons (sym, features), langsyses); | |
1329 | } | |
1330 | ||
1331 | OTF_TAG_SYM (sym, gsub_gpos->ScriptList.Script[i].ScriptTag); | |
1332 | scripts = Fcons (Fcons (sym, langsyses), scripts); | |
1333 | } | |
1334 | return scripts; | |
1335 | ||
1336 | } | |
1337 | ||
1338 | ||
1339 | static Lisp_Object | |
1340 | ftfont_otf_capability (font) | |
1341 | struct font *font; | |
1342 | { | |
1343 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
1344 | OTF *otf = ftfont_get_otf (ftfont_info); | |
1345 | Lisp_Object gsub_gpos; | |
1346 | ||
1347 | if (! otf) | |
1348 | return Qnil; | |
1349 | gsub_gpos = Fcons (Qnil, Qnil); | |
1350 | if (OTF_get_table (otf, "GSUB") == 0) | |
1351 | XSETCAR (gsub_gpos, ftfont_otf_features (otf->gsub)); | |
1352 | if (OTF_get_table (otf, "GPOS") == 0) | |
1353 | XSETCDR (gsub_gpos, ftfont_otf_features (otf->gpos)); | |
1354 | return gsub_gpos; | |
1355 | } | |
1356 | ||
de023c40 KH |
1357 | #ifdef HAVE_M17N_FLT |
1358 | ||
1359 | struct MFLTFontFT | |
1360 | { | |
1361 | MFLTFont flt_font; | |
1362 | struct font *font; | |
1363 | FT_Face ft_face; | |
1364 | OTF *otf; | |
1365 | }; | |
1366 | ||
1367 | static int | |
1368 | ftfont_get_glyph_id (font, gstring, from, to) | |
1369 | MFLTFont *font; | |
1370 | MFLTGlyphString *gstring; | |
1371 | int from, to; | |
1372 | { | |
1373 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | |
1374 | FT_Face ft_face = flt_font_ft->ft_face; | |
1375 | MFLTGlyph *g; | |
1376 | ||
1377 | for (g = gstring->glyphs + from; from < to; g++, from++) | |
1378 | if (! g->encoded) | |
1379 | { | |
1380 | FT_UInt code = FT_Get_Char_Index (ft_face, g->code); | |
1381 | ||
1382 | g->code = code > 0 ? code : FONT_INVALID_CODE; | |
1383 | g->encoded = 1; | |
1384 | } | |
1385 | return 0; | |
1386 | } | |
1387 | ||
1388 | static int | |
1389 | ftfont_get_metrics (font, gstring, from, to) | |
1390 | MFLTFont *font; | |
1391 | MFLTGlyphString *gstring; | |
1392 | int from, to; | |
1393 | { | |
1394 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | |
1395 | FT_Face ft_face = flt_font_ft->ft_face; | |
1396 | MFLTGlyph *g; | |
1397 | ||
1398 | for (g = gstring->glyphs + from; from < to; g++, from++) | |
1399 | if (! g->measured) | |
1400 | { | |
1401 | if (g->code != FONT_INVALID_CODE) | |
1402 | { | |
1403 | FT_Glyph_Metrics *m; | |
1404 | ||
1405 | if (FT_Load_Glyph (ft_face, g->code, FT_LOAD_DEFAULT) != 0) | |
1406 | abort (); | |
1407 | m = &ft_face->glyph->metrics; | |
1408 | ||
1409 | g->lbearing = m->horiBearingX; | |
1410 | g->rbearing = m->horiBearingX + m->width; | |
1411 | g->ascent = m->horiBearingY; | |
1412 | g->descent = m->height - m->horiBearingY; | |
1413 | g->xadv = m->horiAdvance; | |
1414 | } | |
1415 | else | |
1416 | { | |
1417 | g->lbearing = 0; | |
42984a74 | 1418 | g->rbearing = g->xadv = flt_font_ft->font->space_width << 6; |
de023c40 KH |
1419 | g->ascent = flt_font_ft->font->ascent << 6; |
1420 | g->descent = flt_font_ft->font->descent << 6; | |
1421 | } | |
1422 | g->yadv = 0; | |
1423 | g->measured = 1; | |
1424 | } | |
1425 | return 0; | |
1426 | } | |
1427 | ||
2a46904e | 1428 | static int |
de023c40 KH |
1429 | ftfont_check_otf (MFLTFont *font, MFLTOtfSpec *spec) |
1430 | { | |
1431 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | |
1432 | OTF *otf = flt_font_ft->otf; | |
1433 | OTF_Tag *tags; | |
1434 | int i, n, negative; | |
1435 | ||
1436 | for (i = 0; i < 2; i++) | |
1437 | { | |
1438 | if (! spec->features[i]) | |
1439 | continue; | |
1440 | for (n = 0; spec->features[i][n]; n++); | |
1441 | tags = alloca (sizeof (OTF_Tag) * n); | |
1442 | for (n = 0, negative = 0; spec->features[i][n]; n++) | |
1443 | { | |
1444 | if (spec->features[i][n] == 0xFFFFFFFF) | |
1445 | negative = 1; | |
1446 | else if (negative) | |
1447 | tags[n - 1] = spec->features[i][n] | 0x80000000; | |
1448 | else | |
1449 | tags[n] = spec->features[i][n]; | |
1450 | } | |
1451 | if (n - negative > 0 | |
1452 | && OTF_check_features (otf, i == 0, spec->script, spec->langsys, | |
1453 | tags, n - negative) != 1) | |
1454 | return 0; | |
1455 | } | |
1456 | return 1; | |
1457 | } | |
1458 | ||
1459 | #define DEVICE_DELTA(table, size) \ | |
1460 | (((size) >= (table).StartSize && (size) <= (table).EndSize) \ | |
1461 | ? (table).DeltaValue[(size) - (table).StartSize] << 6 \ | |
1462 | : 0) | |
1463 | ||
1464 | static void | |
1465 | adjust_anchor (FT_Face ft_face, OTF_Anchor *anchor, | |
1466 | unsigned code, int x_ppem, int y_ppem, int *x, int *y) | |
1467 | { | |
1468 | if (anchor->AnchorFormat == 2) | |
1469 | { | |
1470 | FT_Outline *outline; | |
1471 | int ap = anchor->f.f1.AnchorPoint; | |
1472 | ||
1473 | FT_Load_Glyph (ft_face, (FT_UInt) code, FT_LOAD_MONOCHROME); | |
1474 | outline = &ft_face->glyph->outline; | |
1475 | if (ap < outline->n_points) | |
1476 | { | |
1477 | *x = outline->points[ap].x << 6; | |
1478 | *y = outline->points[ap].y << 6; | |
1479 | } | |
1480 | } | |
1481 | else if (anchor->AnchorFormat == 3) | |
1482 | { | |
d90bfd1c KH |
1483 | if (anchor->f.f2.XDeviceTable.offset |
1484 | && anchor->f.f2.XDeviceTable.DeltaValue) | |
de023c40 | 1485 | *x += DEVICE_DELTA (anchor->f.f2.XDeviceTable, x_ppem); |
d90bfd1c KH |
1486 | if (anchor->f.f2.YDeviceTable.offset |
1487 | && anchor->f.f2.YDeviceTable.DeltaValue) | |
de023c40 KH |
1488 | *y += DEVICE_DELTA (anchor->f.f2.YDeviceTable, y_ppem); |
1489 | } | |
1490 | } | |
1491 | ||
1492 | static OTF_GlyphString otf_gstring; | |
1493 | ||
2a46904e | 1494 | static int |
de023c40 KH |
1495 | ftfont_drive_otf (font, spec, in, from, to, out, adjustment) |
1496 | MFLTFont *font; | |
1497 | MFLTOtfSpec *spec; | |
1498 | MFLTGlyphString *in; | |
1499 | int from, to; | |
1500 | MFLTGlyphString *out; | |
1501 | MFLTGlyphAdjustment *adjustment; | |
1502 | { | |
1503 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | |
1504 | FT_Face ft_face = flt_font_ft->ft_face; | |
1505 | OTF *otf = flt_font_ft->otf; | |
1506 | int len = to - from; | |
1507 | int i, j, gidx; | |
1508 | OTF_Glyph *otfg; | |
1509 | char script[5], *langsys = NULL; | |
1510 | char *gsub_features = NULL, *gpos_features = NULL; | |
1511 | ||
1512 | if (len == 0) | |
1513 | return from; | |
1514 | OTF_tag_name (spec->script, script); | |
1515 | if (spec->langsys) | |
1516 | { | |
1517 | langsys = alloca (5); | |
1518 | OTF_tag_name (spec->langsys, langsys); | |
1519 | } | |
1520 | for (i = 0; i < 2; i++) | |
1521 | { | |
1522 | char *p; | |
1523 | ||
1524 | if (spec->features[i] && spec->features[i][1] != 0xFFFFFFFF) | |
1525 | { | |
1526 | for (j = 0; spec->features[i][j]; j++); | |
1527 | if (i == 0) | |
1528 | p = gsub_features = alloca (6 * j); | |
1529 | else | |
1530 | p = gpos_features = alloca (6 * j); | |
1531 | for (j = 0; spec->features[i][j]; j++) | |
1532 | { | |
1533 | if (spec->features[i][j] == 0xFFFFFFFF) | |
1534 | *p++ = '*', *p++ = ','; | |
1535 | else | |
1536 | { | |
1537 | OTF_tag_name (spec->features[i][j], p); | |
1538 | p[4] = ','; | |
1539 | p += 5; | |
1540 | } | |
1541 | } | |
1542 | *--p = '\0'; | |
1543 | } | |
1544 | } | |
1545 | ||
1546 | if (otf_gstring.size == 0) | |
1547 | { | |
1548 | otf_gstring.glyphs = (OTF_Glyph *) malloc (sizeof (OTF_Glyph) * len); | |
1549 | otf_gstring.size = len; | |
1550 | } | |
1551 | else if (otf_gstring.size < len) | |
1552 | { | |
1553 | otf_gstring.glyphs = (OTF_Glyph *) realloc (otf_gstring.glyphs, | |
1554 | sizeof (OTF_Glyph) * len); | |
1555 | otf_gstring.size = len; | |
1556 | } | |
1557 | otf_gstring.used = len; | |
1558 | memset (otf_gstring.glyphs, 0, sizeof (OTF_Glyph) * len); | |
1559 | for (i = 0; i < len; i++) | |
1560 | { | |
1561 | otf_gstring.glyphs[i].c = in->glyphs[from + i].c; | |
1562 | otf_gstring.glyphs[i].glyph_id = in->glyphs[from + i].code; | |
1563 | } | |
1564 | ||
1565 | OTF_drive_gdef (otf, &otf_gstring); | |
1566 | gidx = out->used; | |
1567 | ||
1568 | if (gsub_features) | |
1569 | { | |
1570 | if (OTF_drive_gsub (otf, &otf_gstring, script, langsys, gsub_features) | |
1571 | < 0) | |
1572 | goto simple_copy; | |
1573 | if (out->allocated < out->used + otf_gstring.used) | |
1574 | return -2; | |
7d2fd545 | 1575 | for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used; ) |
de023c40 | 1576 | { |
7d2fd545 KH |
1577 | MFLTGlyph *g; |
1578 | int min_from, max_to; | |
de023c40 KH |
1579 | int j; |
1580 | ||
7d2fd545 | 1581 | g = out->glyphs + out->used; |
de023c40 | 1582 | *g = in->glyphs[from + otfg->f.index.from]; |
de023c40 KH |
1583 | if (g->code != otfg->glyph_id) |
1584 | { | |
7d2fd545 | 1585 | g->c = 0; |
de023c40 KH |
1586 | g->code = otfg->glyph_id; |
1587 | g->measured = 0; | |
1588 | } | |
1589 | out->used++; | |
7d2fd545 KH |
1590 | min_from = g->from; |
1591 | max_to = g->to; | |
1592 | if (otfg->f.index.from < otfg->f.index.to) | |
1593 | { | |
1594 | /* OTFG substitutes multiple glyphs in IN. */ | |
1595 | for (j = from + otfg->f.index.from + 1; | |
1596 | j <= from + otfg->f.index.to; j++) | |
1597 | { | |
1598 | if (min_from > in->glyphs[j].from) | |
1599 | min_from = in->glyphs[j].from; | |
1600 | if (max_to < in->glyphs[j].to) | |
1601 | max_to = in->glyphs[j].to; | |
1602 | } | |
1603 | g->from = min_from; | |
1604 | g->to = max_to; | |
1605 | } | |
1606 | for (i++, otfg++; (i < otf_gstring.used | |
1607 | && otfg->f.index.from == otfg[-1].f.index.from); | |
1608 | i++, otfg++) | |
1609 | { | |
1610 | g = out->glyphs + out->used; | |
1611 | *g = in->glyphs[from + otfg->f.index.to]; | |
1612 | if (g->code != otfg->glyph_id) | |
1613 | { | |
1614 | g->c = 0; | |
1615 | g->code = otfg->glyph_id; | |
1616 | g->measured = 0; | |
1617 | } | |
1618 | out->used++; | |
1619 | } | |
de023c40 KH |
1620 | } |
1621 | } | |
1622 | else | |
1623 | { | |
1624 | if (out->allocated < out->used + len) | |
1625 | return -2; | |
1626 | for (i = 0; i < len; i++) | |
1627 | out->glyphs[out->used++] = in->glyphs[from + i]; | |
1628 | } | |
1629 | ||
1630 | if (gpos_features) | |
1631 | { | |
1632 | MFLTGlyph *base = NULL, *mark = NULL, *g; | |
1633 | int x_ppem, y_ppem, x_scale, y_scale; | |
1634 | ||
1635 | if (OTF_drive_gpos (otf, &otf_gstring, script, langsys, gpos_features) | |
1636 | < 0) | |
1637 | return to; | |
1638 | ||
1639 | x_ppem = ft_face->size->metrics.x_ppem; | |
1640 | y_ppem = ft_face->size->metrics.y_ppem; | |
1641 | x_scale = ft_face->size->metrics.x_scale; | |
1642 | y_scale = ft_face->size->metrics.y_scale; | |
1643 | ||
1644 | for (i = 0, otfg = otf_gstring.glyphs, g = out->glyphs + gidx; | |
1645 | i < otf_gstring.used; i++, otfg++, g++) | |
1646 | { | |
1647 | MFLTGlyph *prev; | |
1648 | ||
1649 | if (! otfg->glyph_id) | |
1650 | continue; | |
1651 | switch (otfg->positioning_type) | |
1652 | { | |
1653 | case 0: | |
1654 | break; | |
1655 | case 1: /* Single */ | |
1656 | case 2: /* Pair */ | |
1657 | { | |
1658 | int format = otfg->f.f1.format; | |
1659 | ||
1660 | if (format & OTF_XPlacement) | |
1661 | adjustment[i].xoff | |
1662 | = otfg->f.f1.value->XPlacement * x_scale / 0x10000; | |
1663 | if (format & OTF_XPlaDevice) | |
1664 | adjustment[i].xoff | |
1665 | += DEVICE_DELTA (otfg->f.f1.value->XPlaDevice, x_ppem); | |
1666 | if (format & OTF_YPlacement) | |
1667 | adjustment[i].yoff | |
1668 | = - (otfg->f.f1.value->YPlacement * y_scale / 0x10000); | |
1669 | if (format & OTF_YPlaDevice) | |
1670 | adjustment[i].yoff | |
1671 | -= DEVICE_DELTA (otfg->f.f1.value->YPlaDevice, y_ppem); | |
1672 | if (format & OTF_XAdvance) | |
1673 | adjustment[i].xadv | |
1674 | += otfg->f.f1.value->XAdvance * x_scale / 0x10000; | |
1675 | if (format & OTF_XAdvDevice) | |
1676 | adjustment[i].xadv | |
1677 | += DEVICE_DELTA (otfg->f.f1.value->XAdvDevice, x_ppem); | |
1678 | if (format & OTF_YAdvance) | |
1679 | adjustment[i].yadv | |
1680 | += otfg->f.f1.value->YAdvance * y_scale / 0x10000; | |
1681 | if (format & OTF_YAdvDevice) | |
1682 | adjustment[i].yadv | |
1683 | += DEVICE_DELTA (otfg->f.f1.value->YAdvDevice, y_ppem); | |
1684 | adjustment[i].set = 1; | |
1685 | } | |
1686 | break; | |
1687 | case 3: /* Cursive */ | |
1688 | /* Not yet supported. */ | |
1689 | break; | |
1690 | case 4: /* Mark-to-Base */ | |
1691 | case 5: /* Mark-to-Ligature */ | |
1692 | if (! base) | |
1693 | break; | |
1694 | prev = base; | |
1695 | goto label_adjust_anchor; | |
1696 | default: /* i.e. case 6 Mark-to-Mark */ | |
1697 | if (! mark) | |
1698 | break; | |
1699 | prev = mark; | |
1700 | ||
1701 | label_adjust_anchor: | |
1702 | { | |
1703 | int base_x, base_y, mark_x, mark_y; | |
1704 | int this_from, this_to; | |
1705 | ||
1706 | base_x = otfg->f.f4.base_anchor->XCoordinate * x_scale / 0x10000; | |
1707 | base_y = otfg->f.f4.base_anchor->YCoordinate * y_scale / 0x10000; | |
1708 | mark_x = otfg->f.f4.mark_anchor->XCoordinate * x_scale / 0x10000; | |
1709 | mark_y = otfg->f.f4.mark_anchor->YCoordinate * y_scale / 0x10000;; | |
1710 | ||
1711 | if (otfg->f.f4.base_anchor->AnchorFormat != 1) | |
1712 | adjust_anchor (ft_face, otfg->f.f4.base_anchor, | |
1713 | prev->code, x_ppem, y_ppem, &base_x, &base_y); | |
1714 | if (otfg->f.f4.mark_anchor->AnchorFormat != 1) | |
1715 | adjust_anchor (ft_face, otfg->f.f4.mark_anchor, g->code, | |
1716 | x_ppem, y_ppem, &mark_x, &mark_y); | |
1717 | adjustment[i].xoff = (base_x - mark_x); | |
1718 | adjustment[i].yoff = - (base_y - mark_y); | |
1719 | adjustment[i].back = (g - prev); | |
1720 | adjustment[i].xadv = 0; | |
1721 | adjustment[i].advance_is_absolute = 1; | |
1722 | adjustment[i].set = 1; | |
1723 | this_from = g->from; | |
1724 | this_to = g->to; | |
1725 | for (j = 0; prev + j < g; j++) | |
1726 | { | |
1727 | if (this_from > prev[j].from) | |
1728 | this_from = prev[j].from; | |
1729 | if (this_to < prev[j].to) | |
1730 | this_to = prev[j].to; | |
1731 | } | |
1732 | for (; prev <= g; prev++) | |
1733 | { | |
1734 | prev->from = this_from; | |
1735 | prev->to = this_to; | |
1736 | } | |
1737 | } | |
1738 | } | |
1739 | if (otfg->GlyphClass == OTF_GlyphClass0) | |
1740 | base = mark = g; | |
1741 | else if (otfg->GlyphClass == OTF_GlyphClassMark) | |
1742 | mark = g; | |
1743 | else | |
1744 | base = g; | |
1745 | } | |
1746 | } | |
1747 | return to; | |
1748 | ||
1749 | simple_copy: | |
1750 | if (out->allocated < out->used + len) | |
1751 | return -2; | |
1752 | font->get_metrics (font, in, from, to); | |
1753 | memcpy (out->glyphs + out->used, in->glyphs + from, | |
1754 | sizeof (MFLTGlyph) * len); | |
1755 | out->used += len; | |
1756 | return to; | |
1757 | } | |
1758 | ||
1759 | static MFLTGlyphString gstring; | |
1760 | ||
1761 | static int m17n_flt_initialized; | |
1762 | ||
1763 | extern Lisp_Object QCfamily; | |
1764 | ||
1765 | Lisp_Object | |
1766 | ftfont_shape_by_flt (lgstring, font, ft_face, otf) | |
1767 | Lisp_Object lgstring; | |
1768 | struct font *font; | |
1769 | FT_Face ft_face; | |
1770 | OTF *otf; | |
1771 | { | |
1772 | EMACS_UINT len = LGSTRING_LENGTH (lgstring); | |
1773 | EMACS_UINT i; | |
1774 | struct MFLTFontFT flt_font_ft; | |
1775 | ||
1776 | if (! m17n_flt_initialized) | |
1777 | { | |
1778 | M17N_INIT (); | |
1779 | m17n_flt_initialized = 1; | |
1780 | } | |
1781 | ||
1782 | for (i = 0; i < len; i++) | |
1783 | if (NILP (LGSTRING_GLYPH (lgstring, i))) | |
1784 | break; | |
1785 | len = i; | |
1786 | ||
1787 | if (gstring.allocated == 0) | |
1788 | { | |
1789 | gstring.allocated = len * 2; | |
1790 | gstring.glyph_size = sizeof (MFLTGlyph); | |
1791 | gstring.glyphs = malloc (sizeof (MFLTGlyph) * gstring.allocated); | |
1792 | } | |
1793 | else if (gstring.allocated < len * 2) | |
1794 | { | |
1795 | gstring.allocated = len * 2; | |
1796 | gstring.glyphs = realloc (gstring.glyphs, | |
1797 | sizeof (MFLTGlyph) * gstring.allocated); | |
1798 | } | |
1799 | for (i = 0; i < len; i++) | |
1800 | gstring.glyphs[i].c = LGLYPH_CHAR (LGSTRING_GLYPH (lgstring, i)); | |
1801 | gstring.used = len; | |
1802 | gstring.r2l = 0; | |
1803 | ||
1804 | { | |
1805 | Lisp_Object family = Ffont_get (LGSTRING_FONT (lgstring), QCfamily); | |
1806 | ||
1807 | if (NILP (family)) | |
1808 | flt_font_ft.flt_font.family = Mnil; | |
1809 | else | |
21988a08 KH |
1810 | flt_font_ft.flt_font.family |
1811 | = msymbol ((char *) SDATA (SYMBOL_NAME (family))); | |
de023c40 KH |
1812 | } |
1813 | flt_font_ft.flt_font.x_ppem = ft_face->size->metrics.x_ppem; | |
1814 | flt_font_ft.flt_font.y_ppem = ft_face->size->metrics.y_ppem; | |
1815 | flt_font_ft.flt_font.get_glyph_id = ftfont_get_glyph_id; | |
1816 | flt_font_ft.flt_font.get_metrics = ftfont_get_metrics; | |
1817 | flt_font_ft.flt_font.check_otf = ftfont_check_otf; | |
1818 | flt_font_ft.flt_font.drive_otf = ftfont_drive_otf; | |
1819 | flt_font_ft.flt_font.internal = NULL; | |
1820 | flt_font_ft.font = font; | |
1821 | flt_font_ft.ft_face = ft_face; | |
1822 | flt_font_ft.otf = otf; | |
1823 | for (i = 0; i < 3; i++) | |
1824 | { | |
1825 | int result = mflt_run (&gstring, 0, len, &flt_font_ft.flt_font, NULL); | |
1826 | if (result != -2) | |
1827 | break; | |
1828 | gstring.allocated += gstring.allocated; | |
1829 | gstring.glyphs = realloc (gstring.glyphs, | |
1830 | sizeof (MFLTGlyph) * gstring.allocated); | |
1831 | } | |
1832 | if (gstring.used > LGSTRING_LENGTH (lgstring)) | |
1833 | return Qnil; | |
1834 | for (i = 0; i < gstring.used; i++) | |
1835 | { | |
1836 | MFLTGlyph *g = gstring.glyphs + i; | |
1837 | ||
1838 | g->from = LGLYPH_FROM (LGSTRING_GLYPH (lgstring, g->from)); | |
1839 | g->to = LGLYPH_TO (LGSTRING_GLYPH (lgstring, g->to)); | |
1840 | } | |
1841 | ||
1842 | for (i = 0; i < gstring.used; i++) | |
1843 | { | |
1844 | Lisp_Object lglyph = LGSTRING_GLYPH (lgstring, i); | |
1845 | MFLTGlyph *g = gstring.glyphs + i; | |
1846 | ||
4cec6061 KH |
1847 | if (NILP (lglyph)) |
1848 | { | |
1849 | lglyph = Fmake_vector (make_number (LGLYPH_SIZE), Qnil); | |
1850 | LGSTRING_SET_GLYPH (lgstring, i, lglyph); | |
1851 | } | |
de023c40 KH |
1852 | LGLYPH_SET_FROM (lglyph, g->from); |
1853 | LGLYPH_SET_TO (lglyph, g->to); | |
1854 | LGLYPH_SET_CHAR (lglyph, g->c); | |
1855 | LGLYPH_SET_CODE (lglyph, g->code); | |
1856 | LGLYPH_SET_WIDTH (lglyph, g->xadv >> 6); | |
1857 | LGLYPH_SET_LBEARING (lglyph, g->lbearing >> 6); | |
1858 | LGLYPH_SET_RBEARING (lglyph, g->rbearing >> 6); | |
1859 | LGLYPH_SET_ASCENT (lglyph, g->ascent >> 6); | |
1860 | LGLYPH_SET_DESCENT (lglyph, g->descent >> 6); | |
1861 | if (g->adjusted) | |
1862 | { | |
1863 | Lisp_Object vec; | |
1864 | ||
1865 | vec = Fmake_vector (make_number (3), Qnil); | |
1866 | ASET (vec, 0, make_number (g->xoff >> 6)); | |
1867 | ASET (vec, 1, make_number (g->yoff >> 6)); | |
1868 | ASET (vec, 2, make_number (g->xadv >> 6)); | |
1869 | LGLYPH_SET_ADJUSTMENT (lglyph, vec); | |
1870 | } | |
1871 | } | |
1872 | return make_number (i); | |
1873 | } | |
1874 | ||
1875 | Lisp_Object | |
1876 | ftfont_shape (lgstring) | |
1877 | Lisp_Object lgstring; | |
1878 | { | |
1879 | struct font *font; | |
1880 | struct ftfont_info *ftfont_info; | |
e302a291 | 1881 | OTF *otf; |
de023c40 KH |
1882 | |
1883 | CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring), font); | |
1884 | ftfont_info = (struct ftfont_info *) font; | |
e302a291 KH |
1885 | otf = ftfont_get_otf (ftfont_info); |
1886 | if (! otf) | |
4cc1c806 | 1887 | return make_number (0); |
e302a291 | 1888 | return ftfont_shape_by_flt (lgstring, font, ftfont_info->ft_size->face, otf); |
de023c40 KH |
1889 | } |
1890 | ||
1891 | #endif /* HAVE_M17N_FLT */ | |
1892 | #endif /* HAVE_LIBOTF */ | |
1893 | ||
0b966021 | 1894 | Lisp_Object |
7d7ad10e | 1895 | ftfont_font_format (FcPattern *pattern, Lisp_Object filename) |
0b966021 | 1896 | { |
e907d979 | 1897 | FcChar8 *str; |
0b966021 | 1898 | |
e907d979 | 1899 | #ifdef FC_FONTFORMAT |
7d7ad10e | 1900 | if (pattern) |
719b3d63 | 1901 | { |
7d7ad10e KH |
1902 | if (FcPatternGetString (pattern, FC_FONTFORMAT, 0, &str) != FcResultMatch) |
1903 | return Qnil; | |
1904 | if (strcmp ((char *) str, "TrueType") == 0) | |
719b3d63 | 1905 | return intern ("truetype"); |
7d7ad10e | 1906 | if (strcmp ((char *) str, "Type 1") == 0) |
719b3d63 | 1907 | return intern ("type1"); |
7d7ad10e | 1908 | if (strcmp ((char *) str, "PCF") == 0) |
719b3d63 | 1909 | return intern ("pcf"); |
7d7ad10e | 1910 | if (strcmp ((char *) str, "BDF") == 0) |
719b3d63 KH |
1911 | return intern ("bdf"); |
1912 | } | |
7d7ad10e KH |
1913 | #endif /* FC_FONTFORMAT */ |
1914 | if (STRINGP (filename)) | |
1915 | { | |
1916 | int len = SBYTES (filename); | |
1917 | ||
1918 | if (len >= 4) | |
1919 | { | |
1920 | str = (FcChar8 *) (SDATA (filename) + len - 4); | |
1921 | if (xstrcasecmp ((char *) str, ".ttf") == 0) | |
1922 | return intern ("truetype"); | |
1923 | if (xstrcasecmp ((char *) str, ".pfb") == 0) | |
1924 | return intern ("type1"); | |
1925 | if (xstrcasecmp ((char *) str, ".pcf") == 0) | |
1926 | return intern ("pcf"); | |
1927 | if (xstrcasecmp ((char *) str, ".bdf") == 0) | |
1928 | return intern ("bdf"); | |
1929 | } | |
1930 | } | |
0b966021 KH |
1931 | return intern ("unknown"); |
1932 | } | |
1933 | ||
c2f5bfd6 KH |
1934 | \f |
1935 | void | |
1936 | syms_of_ftfont () | |
1937 | { | |
706b6995 KH |
1938 | DEFSYM (Qfreetype, "freetype"); |
1939 | DEFSYM (Qmonospace, "monospace"); | |
1940 | DEFSYM (Qsans_serif, "sans-serif"); | |
1941 | DEFSYM (Qserif, "serif"); | |
1942 | DEFSYM (Qmono, "mono"); | |
1943 | DEFSYM (Qsans, "sans"); | |
1944 | DEFSYM (Qsans__serif, "sans serif"); | |
1945 | ||
c2f5bfd6 | 1946 | staticpro (&freetype_font_cache); |
c2801c99 | 1947 | freetype_font_cache = Fcons (Qt, Qnil); |
c2f5bfd6 | 1948 | |
706b6995 KH |
1949 | staticpro (&ftfont_generic_family_list); |
1950 | ftfont_generic_family_list | |
1951 | = Fcons (Fcons (Qmonospace, Qt), | |
1952 | Fcons (Fcons (Qsans_serif, Qt), | |
1953 | Fcons (Fcons (Qsans, Qt), Qnil))); | |
c2f5bfd6 | 1954 | |
21988a08 KH |
1955 | staticpro (&ft_face_cache); |
1956 | ft_face_cache = Qnil; | |
1957 | ||
c2f5bfd6 KH |
1958 | ftfont_driver.type = Qfreetype; |
1959 | register_font_driver (&ftfont_driver, NULL); | |
1960 | } | |
885b7d09 MB |
1961 | |
1962 | /* arch-tag: 7cfa432c-33a6-4988-83d2-a82ed8604aca | |
1963 | (do not change this comment) */ |