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