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