Commit | Line | Data |
---|---|---|
c2f5bfd6 KH |
1 | /* ftfont.c -- FreeType font driver. |
2 | Copyright (C) 2006 Free Software Foundation, Inc. | |
3 | Copyright (C) 2006 | |
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 2, or (at your option) | |
12 | 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; see the file COPYING. If not, write to | |
21 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
22 | Boston, MA 02110-1301, USA. */ | |
23 | ||
24 | #include <config.h> | |
25 | #include <stdio.h> | |
26 | ||
c2f5bfd6 KH |
27 | #include <fontconfig/fontconfig.h> |
28 | #include <fontconfig/fcfreetype.h> | |
29 | ||
30 | #include "lisp.h" | |
31 | #include "dispextern.h" | |
32 | #include "frame.h" | |
33 | #include "blockinput.h" | |
34 | #include "character.h" | |
35 | #include "charset.h" | |
36 | #include "coding.h" | |
37 | #include "fontset.h" | |
38 | #include "font.h" | |
de023c40 | 39 | #include "ftfont.h" |
c2f5bfd6 | 40 | |
c2801c99 | 41 | /* Symbolic type of this font-driver. */ |
c2f5bfd6 KH |
42 | Lisp_Object Qfreetype; |
43 | ||
706b6995 KH |
44 | /* Fontconfig's generic families and their aliases. */ |
45 | static Lisp_Object Qmonospace, Qsans_serif, Qserif, Qmono, Qsans, Qsans__serif; | |
46 | ||
c2801c99 | 47 | /* Flag to tell if FcInit is areadly called or not. */ |
c2f5bfd6 | 48 | static int fc_initialized; |
c2801c99 KH |
49 | |
50 | /* Handle to a FreeType library instance. */ | |
c2f5bfd6 KH |
51 | static FT_Library ft_library; |
52 | ||
c2801c99 | 53 | /* Cache for FreeType fonts. */ |
c2f5bfd6 KH |
54 | static Lisp_Object freetype_font_cache; |
55 | ||
c2801c99 KH |
56 | /* Fontconfig's charset used for finding fonts of registry |
57 | "iso8859-1". */ | |
c2f5bfd6 KH |
58 | static FcCharSet *cs_iso8859_1; |
59 | ||
60 | /* The actual structure for FreeType font that can be casted to struct | |
61 | font. */ | |
62 | ||
63 | struct ftfont_info | |
64 | { | |
65 | struct font font; | |
66 | FT_Size ft_size; | |
de023c40 KH |
67 | #ifdef HAVE_LIBOTF |
68 | int maybe_otf; /* Flag to tell if this may be OTF or not. */ | |
69 | OTF *otf; | |
70 | #endif /* HAVE_LIBOTF */ | |
c2f5bfd6 KH |
71 | }; |
72 | ||
706b6995 KH |
73 | static int ftfont_build_basic_charsets P_ ((void)); |
74 | static Lisp_Object ftfont_pattern_entity P_ ((FcPattern *, | |
75 | Lisp_Object, Lisp_Object)); | |
76 | static Lisp_Object ftfont_list_generic_family P_ ((Lisp_Object, Lisp_Object, | |
77 | Lisp_Object)); | |
0b966021 | 78 | Lisp_Object ftfont_font_format P_ ((FcPattern *)); |
706b6995 KH |
79 | |
80 | #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM)) | |
81 | ||
c2f5bfd6 KH |
82 | static int |
83 | ftfont_build_basic_charsets () | |
84 | { | |
85 | FcChar32 c; | |
86 | ||
87 | cs_iso8859_1 = FcCharSetCreate (); | |
88 | if (! cs_iso8859_1) | |
89 | return -1; | |
90 | for (c = ' '; c < 127; c++) | |
91 | if (! FcCharSetAddChar (cs_iso8859_1, c)) | |
92 | return -1; | |
260a71fb KH |
93 | #if 0 |
94 | /* This part is currently disabled. Should be fixed later. */ | |
c2f5bfd6 KH |
95 | for (c = 192; c < 256; c++) |
96 | if (! FcCharSetAddChar (cs_iso8859_1, c)) | |
97 | return -1; | |
260a71fb | 98 | #endif |
c2f5bfd6 KH |
99 | return 0; |
100 | } | |
101 | ||
706b6995 KH |
102 | static Lisp_Object |
103 | ftfont_pattern_entity (p, frame, registry) | |
c2801c99 | 104 | FcPattern *p; |
706b6995 | 105 | Lisp_Object frame, registry; |
c2801c99 KH |
106 | { |
107 | Lisp_Object entity; | |
0b966021 | 108 | FcChar8 *file, *fontformat; |
c2801c99 KH |
109 | FcCharSet *charset; |
110 | char *str; | |
111 | int numeric; | |
112 | double dbl; | |
113 | ||
114 | if (FcPatternGetString (p, FC_FILE, 0, &file) != FcResultMatch) | |
115 | return Qnil; | |
f0365b6f | 116 | if (FcPatternGetCharSet (p, FC_CHARSET, 0, &charset) != FcResultMatch) |
c2801c99 | 117 | charset = NULL; |
e907d979 | 118 | #ifdef FC_FONTFORMAT |
0b966021 | 119 | if (FcPatternGetString (p, FC_FONTFORMAT, 0, &fontformat) != FcResultMatch) |
e907d979 | 120 | #endif /* FC_FONTFORMAT */ |
0b966021 | 121 | fontformat = NULL; |
c2801c99 KH |
122 | |
123 | entity = Fmake_vector (make_number (FONT_ENTITY_MAX), null_string); | |
124 | ||
125 | ASET (entity, FONT_TYPE_INDEX, Qfreetype); | |
126 | ASET (entity, FONT_REGISTRY_INDEX, registry); | |
127 | ASET (entity, FONT_FRAME_INDEX, frame); | |
128 | ASET (entity, FONT_OBJLIST_INDEX, Qnil); | |
129 | ||
130 | if (FcPatternGetString (p, FC_FOUNDRY, 0, (FcChar8 **) &str) == FcResultMatch) | |
131 | ASET (entity, FONT_FOUNDRY_INDEX, intern_downcase (str, strlen (str))); | |
132 | if (FcPatternGetString (p, FC_FAMILY, 0, (FcChar8 **) &str) == FcResultMatch) | |
133 | ASET (entity, FONT_FAMILY_INDEX, intern_downcase (str, strlen (str))); | |
134 | if (FcPatternGetInteger (p, FC_WEIGHT, 0, &numeric) == FcResultMatch) | |
f63d54dc KH |
135 | { |
136 | if (numeric == FC_WEIGHT_REGULAR) | |
137 | numeric = 100; | |
138 | ASET (entity, FONT_WEIGHT_INDEX, make_number (numeric)); | |
139 | } | |
c2801c99 KH |
140 | if (FcPatternGetInteger (p, FC_SLANT, 0, &numeric) == FcResultMatch) |
141 | ASET (entity, FONT_SLANT_INDEX, make_number (numeric + 100)); | |
142 | if (FcPatternGetInteger (p, FC_WIDTH, 0, &numeric) == FcResultMatch) | |
143 | ASET (entity, FONT_WIDTH_INDEX, make_number (numeric)); | |
144 | if (FcPatternGetDouble (p, FC_PIXEL_SIZE, 0, &dbl) == FcResultMatch) | |
145 | ASET (entity, FONT_SIZE_INDEX, make_number (dbl)); | |
146 | else | |
147 | ASET (entity, FONT_SIZE_INDEX, make_number (0)); | |
148 | ||
149 | if (FcPatternGetInteger (p, FC_SPACING, 0, &numeric) != FcResultMatch) | |
f0432f81 | 150 | numeric = -1; |
c2801c99 KH |
151 | file = FcStrCopy (file); |
152 | if (! file) | |
153 | return Qnil; | |
154 | ||
155 | p = FcPatternCreate (); | |
156 | if (! p) | |
157 | return Qnil; | |
158 | ||
159 | if (FcPatternAddString (p, FC_FILE, file) == FcFalse | |
0b966021 KH |
160 | || (charset |
161 | && FcPatternAddCharSet (p, FC_CHARSET, charset) == FcFalse) | |
e907d979 | 162 | #ifdef FC_FONTFORMAT |
0b966021 KH |
163 | || (fontformat |
164 | && FcPatternAddString (p, FC_FONTFORMAT, fontformat) == FcFalse) | |
e907d979 | 165 | #endif /* FC_FONTFORMAT */ |
f0432f81 KH |
166 | || (numeric >= 0 |
167 | && FcPatternAddInteger (p, FC_SPACING, numeric) == FcFalse)) | |
c2801c99 KH |
168 | { |
169 | FcPatternDestroy (p); | |
170 | return Qnil; | |
171 | } | |
172 | ASET (entity, FONT_EXTRA_INDEX, make_save_value (p, 0)); | |
173 | return entity; | |
174 | } | |
175 | ||
706b6995 KH |
176 | static Lisp_Object ftfont_generic_family_list; |
177 | ||
178 | static Lisp_Object | |
179 | ftfont_list_generic_family (spec, frame, registry) | |
180 | Lisp_Object spec, frame, registry; | |
181 | { | |
182 | Lisp_Object family = AREF (spec, FONT_FAMILY_INDEX); | |
183 | Lisp_Object slot, list, val; | |
184 | ||
185 | if (EQ (family, Qmono)) | |
186 | family = Qmonospace; | |
187 | else if (EQ (family, Qsans) || EQ (family, Qsans__serif)) | |
188 | family = Qsans_serif; | |
189 | slot = assq_no_quit (family, ftfont_generic_family_list); | |
190 | if (! CONSP (slot)) | |
191 | return null_vector; | |
192 | list = XCDR (slot); | |
193 | if (EQ (list, Qt)) | |
194 | { | |
195 | /* Not yet listed. */ | |
196 | FcObjectSet *objset = NULL; | |
197 | FcPattern *pattern = NULL, *pat = NULL; | |
198 | FcFontSet *fontset = NULL; | |
199 | FcChar8 *fam; | |
200 | int i, j; | |
201 | ||
202 | objset = FcObjectSetBuild (FC_FOUNDRY, FC_FAMILY, FC_WEIGHT, FC_SLANT, | |
203 | FC_WIDTH, FC_PIXEL_SIZE, FC_SPACING, | |
e907d979 KH |
204 | FC_CHARSET, FC_FILE, |
205 | #ifdef FC_FONTFORMAT | |
206 | FC_FONTFORMAT, | |
207 | #endif /* FC_FONTFORMAT */ | |
208 | NULL); | |
706b6995 KH |
209 | if (! objset) |
210 | goto err; | |
211 | pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, | |
212 | SYMBOL_FcChar8 (family), (char *) 0); | |
213 | if (! pattern) | |
214 | goto err; | |
215 | pat = FcPatternCreate (); | |
216 | if (! pat) | |
217 | goto err; | |
218 | FcConfigSubstitute (NULL, pattern, FcMatchPattern); | |
219 | for (i = 0, val = Qnil; | |
220 | FcPatternGetString (pattern, FC_FAMILY, i, &fam) == FcResultMatch; | |
221 | i++) | |
222 | { | |
223 | if (strcmp ((char *) fam, (char *) SYMBOL_FcChar8 (family)) == 0) | |
224 | continue; | |
225 | if (! FcPatternAddString (pat, FC_FAMILY, fam)) | |
226 | goto err; | |
227 | fontset = FcFontList (NULL, pat, objset); | |
228 | if (! fontset) | |
229 | goto err; | |
230 | /* Here we build the list in reverse order so that the last | |
231 | loop in this function build a list in the correct | |
232 | order. */ | |
233 | for (j = 0; j < fontset->nfont; j++) | |
234 | { | |
235 | Lisp_Object entity; | |
236 | ||
237 | entity = ftfont_pattern_entity (fontset->fonts[j], | |
238 | frame, registry); | |
239 | if (! NILP (entity)) | |
240 | val = Fcons (entity, val); | |
241 | } | |
242 | FcFontSetDestroy (fontset); | |
243 | fontset = NULL; | |
244 | FcPatternDel (pat, FC_FAMILY); | |
245 | } | |
246 | list = val; | |
247 | XSETCDR (slot, list); | |
248 | err: | |
249 | if (pat) FcPatternDestroy (pat); | |
250 | if (pattern) FcPatternDestroy (pattern); | |
251 | if (fontset) FcFontSetDestroy (fontset); | |
252 | if (objset) FcObjectSetDestroy (objset); | |
253 | if (EQ (list, Qt)) | |
254 | return Qnil; | |
255 | } | |
256 | ASET (spec, FONT_FAMILY_INDEX, Qnil); | |
257 | for (val = Qnil; CONSP (list); list = XCDR (list)) | |
258 | if (font_match_p (spec, XCAR (list))) | |
259 | val = Fcons (XCAR (list), val); | |
260 | ASET (spec, FONT_FAMILY_INDEX, family); | |
261 | return Fvconcat (1, &val); | |
262 | } | |
263 | ||
c2801c99 | 264 | |
c2f5bfd6 | 265 | static Lisp_Object ftfont_get_cache P_ ((Lisp_Object)); |
c2f5bfd6 | 266 | static Lisp_Object ftfont_list P_ ((Lisp_Object, Lisp_Object)); |
8daf5667 | 267 | static Lisp_Object ftfont_match P_ ((Lisp_Object, Lisp_Object)); |
c2f5bfd6 KH |
268 | static Lisp_Object ftfont_list_family P_ ((Lisp_Object)); |
269 | static void ftfont_free_entity P_ ((Lisp_Object)); | |
270 | static struct font *ftfont_open P_ ((FRAME_PTR, Lisp_Object, int)); | |
271 | static void ftfont_close P_ ((FRAME_PTR, struct font *)); | |
272 | static int ftfont_has_char P_ ((Lisp_Object, int)); | |
273 | static unsigned ftfont_encode_char P_ ((struct font *, int)); | |
274 | static int ftfont_text_extents P_ ((struct font *, unsigned *, int, | |
275 | struct font_metrics *)); | |
276 | static int ftfont_get_bitmap P_ ((struct font *, unsigned, | |
277 | struct font_bitmap *, int)); | |
278 | static int ftfont_anchor_point P_ ((struct font *, unsigned, int, | |
279 | int *, int *)); | |
de023c40 | 280 | static Lisp_Object ftfont_shape P_ ((Lisp_Object)); |
c2f5bfd6 KH |
281 | |
282 | struct font_driver ftfont_driver = | |
283 | { | |
09a56ce4 | 284 | 0, /* Qfreetype */ |
c2f5bfd6 | 285 | ftfont_get_cache, |
c2f5bfd6 | 286 | ftfont_list, |
8daf5667 | 287 | ftfont_match, |
c2f5bfd6 KH |
288 | ftfont_list_family, |
289 | ftfont_free_entity, | |
290 | ftfont_open, | |
291 | ftfont_close, | |
292 | /* We can't draw a text without device dependent functions. */ | |
293 | NULL, | |
294 | NULL, | |
295 | ftfont_has_char, | |
296 | ftfont_encode_char, | |
297 | ftfont_text_extents, | |
298 | /* We can't draw a text without device dependent functions. */ | |
299 | NULL, | |
300 | ftfont_get_bitmap, | |
301 | NULL, | |
302 | NULL, | |
303 | NULL, | |
304 | ftfont_anchor_point, | |
c2f5bfd6 KH |
305 | NULL, |
306 | NULL, | |
de023c40 KH |
307 | NULL, |
308 | NULL, | |
309 | #ifdef HAVE_M17N_FLT | |
310 | ftfont_shape | |
311 | #else /* not HAVE_M17N_FLT */ | |
c2f5bfd6 | 312 | NULL |
de023c40 | 313 | #endif /* not HAVE_M17N_FLT */ |
c2f5bfd6 KH |
314 | }; |
315 | ||
c2f5bfd6 KH |
316 | extern Lisp_Object QCname; |
317 | ||
318 | static Lisp_Object | |
319 | ftfont_get_cache (frame) | |
320 | Lisp_Object frame; | |
321 | { | |
c2f5bfd6 KH |
322 | return freetype_font_cache; |
323 | } | |
324 | ||
c2f5bfd6 KH |
325 | static Lisp_Object |
326 | ftfont_list (frame, spec) | |
327 | Lisp_Object frame, spec; | |
328 | { | |
8daf5667 | 329 | Lisp_Object val, tmp, extra; |
c2f5bfd6 KH |
330 | int i; |
331 | FcPattern *pattern = NULL; | |
332 | FcCharSet *charset = NULL; | |
333 | FcLangSet *langset = NULL; | |
334 | FcFontSet *fontset = NULL; | |
335 | FcObjectSet *objset = NULL; | |
8daf5667 | 336 | Lisp_Object script; |
c2801c99 | 337 | Lisp_Object registry = Qunicode_bmp; |
63565713 | 338 | int weight = 0; |
bc9a2afe KH |
339 | double dpi = -1; |
340 | int spacing = -1; | |
341 | int scalable = -1; | |
a85f724a | 342 | char otf_script[15]; /* For "otlayout\:XXXX" */ |
c2f5bfd6 KH |
343 | |
344 | val = null_vector; | |
345 | ||
346 | if (! fc_initialized) | |
347 | { | |
348 | FcInit (); | |
349 | fc_initialized = 1; | |
350 | } | |
351 | ||
63565713 KH |
352 | if (! NILP (AREF (spec, FONT_ADSTYLE_INDEX)) |
353 | && ! EQ (AREF (spec, FONT_ADSTYLE_INDEX), null_string)) | |
c2f5bfd6 | 354 | return val; |
63565713 KH |
355 | if (! NILP (AREF (spec, FONT_SLANT_INDEX)) |
356 | && XINT (AREF (spec, FONT_SLANT_INDEX)) < 100) | |
357 | /* Fontconfig doesn't support reverse-italic/obligue. */ | |
358 | return val; | |
359 | ||
c2f5bfd6 KH |
360 | if (! NILP (AREF (spec, FONT_REGISTRY_INDEX))) |
361 | { | |
362 | registry = AREF (spec, FONT_REGISTRY_INDEX); | |
363 | if (EQ (registry, Qiso8859_1)) | |
364 | { | |
365 | if (! cs_iso8859_1 | |
366 | && ftfont_build_basic_charsets () < 0) | |
706b6995 | 367 | return Qnil; |
c2f5bfd6 | 368 | charset = cs_iso8859_1; |
c2f5bfd6 | 369 | } |
e1cae3d3 KH |
370 | else if (! EQ (registry, Qiso10646_1) |
371 | && ! EQ (registry, Qunicode_bmp) | |
372 | && ! EQ (registry, Qunicode_sip)) | |
706b6995 | 373 | return val; |
c2f5bfd6 KH |
374 | } |
375 | ||
a85f724a | 376 | otf_script[0] = '\0'; |
8daf5667 KH |
377 | script = Qnil; |
378 | for (extra = AREF (spec, FONT_EXTRA_INDEX); | |
379 | CONSP (extra); extra = XCDR (extra)) | |
c2f5bfd6 | 380 | { |
8daf5667 KH |
381 | Lisp_Object key, val; |
382 | ||
383 | tmp = XCAR (extra); | |
384 | key = XCAR (tmp), val = XCDR (tmp); | |
385 | if (EQ (key, QCotf)) | |
a85f724a | 386 | { |
de023c40 KH |
387 | tmp = XCAR (val); |
388 | if (NILP (tmp)) | |
389 | strcpy (otf_script, "otlayout:DFLT"); | |
390 | else | |
391 | { | |
392 | val = assq_no_quit (tmp, Votf_script_alist); | |
393 | if (CONSP (val) && SYMBOLP (XCDR (val))) | |
394 | { | |
395 | sprintf (otf_script, "otlayout:%s", | |
396 | (char *) SDATA (SYMBOL_NAME (tmp))); | |
397 | script = XCDR (val); | |
398 | } | |
399 | } | |
a85f724a | 400 | } |
8daf5667 | 401 | else if (EQ (key, QClanguage)) |
c2f5bfd6 KH |
402 | { |
403 | langset = FcLangSetCreate (); | |
404 | if (! langset) | |
405 | goto err; | |
8daf5667 | 406 | if (SYMBOLP (val)) |
c2f5bfd6 | 407 | { |
8daf5667 | 408 | if (! FcLangSetAdd (langset, SYMBOL_FcChar8 (val))) |
c2f5bfd6 KH |
409 | goto err; |
410 | } | |
411 | else | |
8daf5667 KH |
412 | for (; CONSP (val); val = XCDR (val)) |
413 | if (SYMBOLP (XCAR (val)) | |
414 | && ! FcLangSetAdd (langset, SYMBOL_FcChar8 (XCAR (val)))) | |
415 | goto err; | |
c2f5bfd6 | 416 | } |
8daf5667 KH |
417 | else if (EQ (key, QCscript)) |
418 | script = val; | |
419 | else if (EQ (key, QCdpi)) | |
420 | dpi = XINT (val); | |
421 | else if (EQ (key, QCspacing)) | |
422 | spacing = XINT (val); | |
423 | else if (EQ (key, QCscalable)) | |
424 | scalable = ! NILP (val); | |
425 | } | |
c2f5bfd6 | 426 | |
8daf5667 KH |
427 | if (! NILP (script) && ! charset) |
428 | { | |
429 | Lisp_Object chars = assq_no_quit (script, Vscript_representative_chars); | |
430 | ||
431 | if (CONSP (chars)) | |
432 | { | |
433 | charset = FcCharSetCreate (); | |
434 | if (! charset) | |
435 | goto err; | |
436 | for (chars = XCDR (chars); CONSP (chars); chars = XCDR (chars)) | |
437 | if (CHARACTERP (XCAR (chars)) | |
438 | && ! FcCharSetAddChar (charset, XUINT (XCAR (chars)))) | |
439 | goto err; | |
c2f5bfd6 KH |
440 | } |
441 | } | |
442 | ||
8daf5667 | 443 | pattern = FcPatternCreate (); |
706b6995 KH |
444 | if (! pattern) |
445 | goto err; | |
706b6995 KH |
446 | tmp = AREF (spec, FONT_FOUNDRY_INDEX); |
447 | if (SYMBOLP (tmp) && ! NILP (tmp) | |
448 | && ! FcPatternAddString (pattern, FC_FOUNDRY, SYMBOL_FcChar8 (tmp))) | |
449 | goto err; | |
450 | tmp = AREF (spec, FONT_FAMILY_INDEX); | |
451 | if (SYMBOLP (tmp) && ! NILP (tmp) | |
452 | && ! FcPatternAddString (pattern, FC_FAMILY, SYMBOL_FcChar8 (tmp))) | |
453 | goto err; | |
63565713 KH |
454 | /* Emacs conventionally doesn't distinguish normal, regular, and |
455 | medium weight, but fontconfig does. So, we can't restrict font | |
456 | listing by weight. We check it after getting a list. */ | |
706b6995 | 457 | tmp = AREF (spec, FONT_WEIGHT_INDEX); |
63565713 KH |
458 | if (INTEGERP (tmp)) |
459 | weight = XINT (tmp); | |
706b6995 KH |
460 | tmp = AREF (spec, FONT_SLANT_INDEX); |
461 | if (INTEGERP (tmp) | |
706b6995 KH |
462 | && ! FcPatternAddInteger (pattern, FC_SLANT, XINT (tmp) - 100)) |
463 | goto err; | |
464 | tmp = AREF (spec, FONT_WIDTH_INDEX); | |
465 | if (INTEGERP (tmp) | |
466 | && ! FcPatternAddInteger (pattern, FC_WIDTH, XINT (tmp))) | |
467 | goto err; | |
c2f5bfd6 KH |
468 | |
469 | if (charset | |
470 | && ! FcPatternAddCharSet (pattern, FC_CHARSET, charset)) | |
471 | goto err; | |
472 | if (langset | |
473 | && ! FcPatternAddLangSet (pattern, FC_LANG, langset)) | |
474 | goto err; | |
bc9a2afe KH |
475 | if (dpi >= 0 |
476 | && ! FcPatternAddDouble (pattern, FC_DPI, dpi)) | |
477 | goto err; | |
478 | if (spacing >= 0 | |
479 | && ! FcPatternAddInteger (pattern, FC_SPACING, spacing)) | |
480 | goto err; | |
481 | if (scalable >= 0 | |
25a5d05b | 482 | && ! FcPatternAddBool (pattern, FC_SCALABLE, scalable ? FcTrue : FcFalse)) |
bc9a2afe | 483 | goto err; |
c2f5bfd6 | 484 | |
706b6995 KH |
485 | objset = FcObjectSetBuild (FC_FOUNDRY, FC_FAMILY, FC_WEIGHT, FC_SLANT, |
486 | FC_WIDTH, FC_PIXEL_SIZE, FC_SPACING, | |
e907d979 KH |
487 | FC_CHARSET, FC_FILE, |
488 | #ifdef FC_FONTFORMAT | |
489 | FC_FONTFORMAT, | |
490 | #endif /* FC_FONTFORMAT */ | |
491 | NULL); | |
706b6995 KH |
492 | if (! objset) |
493 | goto err; | |
bc5f6c42 KH |
494 | if (otf_script[0]) |
495 | { | |
496 | #ifndef FC_CAPABILITY | |
497 | goto finish; | |
498 | #else /* not FC_CAPABILITY */ | |
499 | if (! FcObjectSetAdd (objset, FC_CAPABILITY)) | |
500 | goto err; | |
bc5f6c42 | 501 | #endif /* not FC_CAPABILITY */ |
5ed08958 | 502 | } |
f63d54dc | 503 | |
706b6995 KH |
504 | fontset = FcFontList (NULL, pattern, objset); |
505 | if (! fontset) | |
506 | goto err; | |
c2f5bfd6 | 507 | |
706b6995 KH |
508 | if (fontset->nfont > 0) |
509 | { | |
f63d54dc KH |
510 | double pixel_size; |
511 | ||
512 | if (NILP (AREF (spec, FONT_SIZE_INDEX))) | |
513 | pixel_size = 0; | |
514 | else | |
515 | pixel_size = XINT (AREF (spec, FONT_SIZE_INDEX)); | |
516 | ||
706b6995 | 517 | for (i = 0, val = Qnil; i < fontset->nfont; i++) |
c2f5bfd6 | 518 | { |
f63d54dc KH |
519 | Lisp_Object entity; |
520 | ||
521 | if (pixel_size > 0) | |
522 | { | |
523 | double this; | |
524 | ||
525 | if (FcPatternGetDouble (fontset->fonts[i], FC_PIXEL_SIZE, 0, | |
526 | &this) == FcResultMatch | |
63565713 KH |
527 | && ((this < pixel_size - FONT_PIXEL_SIZE_QUANTUM) |
528 | || (this > pixel_size + FONT_PIXEL_SIZE_QUANTUM))) | |
529 | continue; | |
530 | } | |
531 | if (weight > 0) | |
532 | { | |
533 | int this; | |
534 | ||
535 | if (FcPatternGetInteger (fontset->fonts[i], FC_WEIGHT, 0, | |
536 | &this) != FcResultMatch | |
537 | || (this != weight | |
538 | && (weight != 100 | |
539 | || this < FC_WEIGHT_REGULAR | |
540 | || this > FC_WEIGHT_MEDIUM))) | |
f63d54dc KH |
541 | continue; |
542 | } | |
bc5f6c42 | 543 | #ifdef FC_CAPABILITY |
a85f724a KH |
544 | if (otf_script[0]) |
545 | { | |
546 | FcChar8 *this; | |
547 | ||
548 | if (FcPatternGetString (fontset->fonts[i], FC_CAPABILITY, 0, | |
549 | &this) != FcResultMatch | |
550 | || ! strstr ((char *) this, otf_script)) | |
551 | continue; | |
552 | } | |
bc5f6c42 | 553 | #endif /* FC_CAPABILITY */ |
f63d54dc | 554 | entity = ftfont_pattern_entity (fontset->fonts[i], frame, registry); |
c2801c99 KH |
555 | if (! NILP (entity)) |
556 | val = Fcons (entity, val); | |
c2f5bfd6 | 557 | } |
c2801c99 | 558 | val = Fvconcat (1, &val); |
c2f5bfd6 | 559 | } |
706b6995 KH |
560 | else if (! NILP (AREF (spec, FONT_FAMILY_INDEX))) |
561 | val = ftfont_list_generic_family (spec, frame, registry); | |
c2f5bfd6 KH |
562 | goto finish; |
563 | ||
564 | err: | |
565 | /* We come here because of unexpected error in fontconfig API call | |
706b6995 | 566 | (usually insufficient memory). */ |
c2f5bfd6 KH |
567 | val = Qnil; |
568 | ||
569 | finish: | |
570 | if (charset && charset != cs_iso8859_1) FcCharSetDestroy (charset); | |
571 | if (objset) FcObjectSetDestroy (objset); | |
572 | if (fontset) FcFontSetDestroy (fontset); | |
573 | if (langset) FcLangSetDestroy (langset); | |
574 | if (pattern) FcPatternDestroy (pattern); | |
575 | ||
576 | return val; | |
577 | } | |
578 | ||
8daf5667 KH |
579 | static Lisp_Object |
580 | ftfont_match (frame, spec) | |
581 | Lisp_Object frame, spec; | |
582 | { | |
583 | Lisp_Object extra, val, entity; | |
584 | FcPattern *pattern = NULL, *match = NULL; | |
585 | FcResult result; | |
586 | ||
587 | if (! fc_initialized) | |
588 | { | |
589 | FcInit (); | |
590 | fc_initialized = 1; | |
591 | } | |
592 | ||
593 | extra = AREF (spec, FONT_EXTRA_INDEX); | |
594 | val = assq_no_quit (QCname, extra); | |
595 | if (! CONSP (val) || ! STRINGP (XCDR (val))) | |
596 | return Qnil; | |
597 | ||
598 | entity = Qnil; | |
599 | pattern = FcNameParse (SDATA (XCDR (val))); | |
600 | if (pattern) | |
601 | { | |
602 | if (FcConfigSubstitute (NULL, pattern, FcMatchPattern) == FcTrue) | |
603 | { | |
604 | FcDefaultSubstitute (pattern); | |
605 | match = FcFontMatch (NULL, pattern, &result); | |
8daf5667 KH |
606 | if (match) |
607 | { | |
608 | entity = ftfont_pattern_entity (match, frame, Qunicode_bmp); | |
609 | FcPatternDestroy (match); | |
610 | } | |
611 | } | |
612 | FcPatternDestroy (pattern); | |
613 | } | |
614 | ||
615 | return entity; | |
616 | } | |
617 | ||
c2f5bfd6 KH |
618 | static Lisp_Object |
619 | ftfont_list_family (frame) | |
620 | Lisp_Object frame; | |
621 | { | |
622 | Lisp_Object list; | |
623 | FcPattern *pattern = NULL; | |
624 | FcFontSet *fontset = NULL; | |
625 | FcObjectSet *objset = NULL; | |
626 | int i; | |
627 | ||
628 | if (! fc_initialized) | |
629 | { | |
630 | FcInit (); | |
631 | fc_initialized = 1; | |
632 | } | |
633 | ||
634 | pattern = FcPatternCreate (); | |
635 | if (! pattern) | |
636 | goto finish; | |
706b6995 | 637 | objset = FcObjectSetBuild (FC_FAMILY, NULL); |
c2f5bfd6 KH |
638 | if (! objset) |
639 | goto finish; | |
640 | fontset = FcFontList (NULL, pattern, objset); | |
641 | if (! fontset) | |
642 | goto finish; | |
643 | ||
644 | list = Qnil; | |
645 | for (i = 0; i < fontset->nfont; i++) | |
646 | { | |
647 | FcPattern *pat = fontset->fonts[i]; | |
648 | FcChar8 *str; | |
649 | ||
650 | if (FcPatternGetString (pat, FC_FAMILY, 0, &str) == FcResultMatch) | |
651 | list = Fcons (intern_downcase ((char *) str, strlen ((char *) str)), | |
652 | list); | |
653 | } | |
654 | ||
655 | finish: | |
656 | if (objset) FcObjectSetDestroy (objset); | |
657 | if (fontset) FcFontSetDestroy (fontset); | |
658 | if (pattern) FcPatternDestroy (pattern); | |
659 | ||
660 | return list; | |
661 | } | |
662 | ||
663 | ||
664 | static void | |
665 | ftfont_free_entity (entity) | |
666 | Lisp_Object entity; | |
667 | { | |
668 | Lisp_Object val = AREF (entity, FONT_EXTRA_INDEX); | |
669 | FcPattern *pattern = XSAVE_VALUE (val)->pointer; | |
670 | ||
671 | FcPatternDestroy (pattern); | |
672 | } | |
673 | ||
674 | static struct font * | |
675 | ftfont_open (f, entity, pixel_size) | |
676 | FRAME_PTR f; | |
677 | Lisp_Object entity; | |
678 | int pixel_size; | |
679 | { | |
680 | struct ftfont_info *ftfont_info; | |
681 | struct font *font; | |
682 | FT_Face ft_face; | |
683 | FT_Size ft_size; | |
684 | FT_UInt size; | |
685 | Lisp_Object val; | |
686 | FcPattern *pattern; | |
687 | FcChar8 *file; | |
688 | int spacing; | |
c9c0c429 KH |
689 | char *name; |
690 | int len; | |
c2f5bfd6 KH |
691 | |
692 | val = AREF (entity, FONT_EXTRA_INDEX); | |
693 | if (XTYPE (val) != Lisp_Misc | |
694 | || XMISCTYPE (val) != Lisp_Misc_Save_Value) | |
695 | return NULL; | |
696 | pattern = XSAVE_VALUE (val)->pointer; | |
697 | if (XSAVE_VALUE (val)->integer == 0) | |
698 | { | |
699 | /* We have not yet created FT_Face for this font. */ | |
700 | if (! ft_library | |
701 | && FT_Init_FreeType (&ft_library) != 0) | |
702 | return NULL; | |
703 | if (FcPatternGetString (pattern, FC_FILE, 0, &file) != FcResultMatch) | |
704 | return NULL; | |
705 | if (FT_New_Face (ft_library, (char *) file, 0, &ft_face) != 0) | |
706 | return NULL; | |
707 | FcPatternAddFTFace (pattern, FC_FT_FACE, ft_face); | |
708 | ft_size = ft_face->size; | |
709 | } | |
710 | else | |
711 | { | |
712 | if (FcPatternGetFTFace (pattern, FC_FT_FACE, 0, &ft_face) | |
713 | != FcResultMatch) | |
714 | return NULL; | |
715 | if (FT_New_Size (ft_face, &ft_size) != 0) | |
716 | return NULL; | |
717 | if (FT_Activate_Size (ft_size) != 0) | |
718 | { | |
719 | FT_Done_Size (ft_size); | |
720 | return NULL; | |
721 | } | |
722 | } | |
723 | ||
724 | size = XINT (AREF (entity, FONT_SIZE_INDEX)); | |
725 | if (size == 0) | |
726 | size = pixel_size; | |
727 | if (FT_Set_Pixel_Sizes (ft_face, size, size) != 0) | |
728 | { | |
729 | if (XSAVE_VALUE (val)->integer == 0) | |
730 | FT_Done_Face (ft_face); | |
731 | return NULL; | |
732 | } | |
733 | ||
734 | ftfont_info = malloc (sizeof (struct ftfont_info)); | |
735 | if (! ftfont_info) | |
736 | return NULL; | |
737 | ftfont_info->ft_size = ft_size; | |
0d674a05 | 738 | #ifdef HAVE_LIBOTF |
de023c40 KH |
739 | ftfont_info->maybe_otf = ft_face->face_flags & FT_FACE_FLAG_SFNT; |
740 | ftfont_info->otf = NULL; | |
0d674a05 | 741 | #endif /* HAVE_LIBOTF */ |
c2f5bfd6 KH |
742 | |
743 | font = (struct font *) ftfont_info; | |
0b966021 | 744 | font->format = ftfont_font_format (pattern); |
c2f5bfd6 KH |
745 | font->entity = entity; |
746 | font->pixel_size = size; | |
747 | font->driver = &ftfont_driver; | |
c9c0c429 KH |
748 | len = 96; |
749 | name = malloc (len); | |
750 | while (name && font_unparse_fcname (entity, pixel_size, name, len) < 0) | |
751 | { | |
752 | char *new = realloc (name, len += 32); | |
753 | ||
754 | if (! new) | |
755 | free (name); | |
756 | name = new; | |
757 | } | |
758 | font->font.full_name = font->font.name = name; | |
c2f5bfd6 KH |
759 | font->file_name = (char *) file; |
760 | font->font.size = ft_face->size->metrics.max_advance >> 6; | |
c9c0c429 KH |
761 | if (font->font.size <= 0) |
762 | font->font.size = size; | |
a85f724a | 763 | font->font.charset = font->encoding_charset = font->repertory_charset = -1; |
c2f5bfd6 KH |
764 | font->ascent = ft_face->size->metrics.ascender >> 6; |
765 | font->descent = - ft_face->size->metrics.descender >> 6; | |
c9c0c429 KH |
766 | font->font.height = font->ascent + font->descent; |
767 | if (FcPatternGetInteger (pattern, FC_SPACING, 0, &spacing) != FcResultMatch) | |
768 | spacing = FC_PROPORTIONAL; | |
769 | if (spacing != FC_PROPORTIONAL) | |
c2f5bfd6 KH |
770 | font->font.average_width = font->font.space_width = font->font.size; |
771 | else | |
772 | { | |
773 | int i; | |
774 | ||
775 | for (i = 32; i < 127; i++) | |
776 | { | |
777 | if (FT_Load_Char (ft_face, i, FT_LOAD_DEFAULT) != 0) | |
778 | break; | |
779 | if (i == 32) | |
780 | font->font.space_width = ft_face->glyph->metrics.horiAdvance >> 6; | |
781 | font->font.average_width += ft_face->glyph->metrics.horiAdvance >> 6; | |
782 | } | |
783 | if (i == 127) | |
784 | { | |
785 | /* The font contains all ASCII printable characters. */ | |
786 | font->font.average_width /= 95; | |
787 | } | |
788 | else | |
789 | { | |
790 | if (i == 32) | |
791 | font->font.space_width = font->font.size; | |
792 | font->font.average_width = font->font.size; | |
793 | } | |
794 | } | |
795 | ||
c9c0c429 KH |
796 | /* Unfortunately FreeType doesn't provide a way to get minimum char |
797 | width. So, we use space_width instead. */ | |
798 | font->min_width = font->font.space_width; | |
799 | ||
c2f5bfd6 KH |
800 | font->font.baseline_offset = 0; |
801 | font->font.relative_compose = 0; | |
802 | font->font.default_ascent = 0; | |
803 | font->font.vertical_centering = 0; | |
804 | ||
805 | (XSAVE_VALUE (val)->integer)++; | |
806 | ||
807 | return font; | |
808 | } | |
809 | ||
810 | static void | |
811 | ftfont_close (f, font) | |
812 | FRAME_PTR f; | |
813 | struct font *font; | |
814 | { | |
815 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
816 | Lisp_Object entity = font->entity; | |
817 | Lisp_Object val = AREF (entity, FONT_EXTRA_INDEX); | |
818 | ||
819 | (XSAVE_VALUE (val)->integer)--; | |
820 | if (XSAVE_VALUE (val)->integer == 0) | |
de023c40 KH |
821 | { |
822 | FT_Done_Face (ftfont_info->ft_size->face); | |
823 | #ifdef HAVE_LIBOTF | |
824 | if (ftfont_info->otf) | |
825 | OTF_close (ftfont_info->otf); | |
826 | #endif | |
827 | } | |
c2f5bfd6 KH |
828 | else |
829 | FT_Done_Size (ftfont_info->ft_size); | |
830 | ||
831 | free (font); | |
832 | } | |
833 | ||
834 | static int | |
835 | ftfont_has_char (entity, c) | |
836 | Lisp_Object entity; | |
837 | int c; | |
838 | { | |
839 | Lisp_Object val; | |
840 | FcPattern *pattern; | |
841 | FcCharSet *charset; | |
842 | ||
843 | val = AREF (entity, FONT_EXTRA_INDEX); | |
844 | pattern = XSAVE_VALUE (val)->pointer; | |
c2801c99 KH |
845 | if (FcPatternGetCharSet (pattern, FC_CHARSET, 0, &charset) != FcResultMatch) |
846 | return -1; | |
c2f5bfd6 KH |
847 | return (FcCharSetHasChar (charset, (FcChar32) c) == FcTrue); |
848 | } | |
849 | ||
850 | static unsigned | |
851 | ftfont_encode_char (font, c) | |
852 | struct font *font; | |
853 | int c; | |
854 | { | |
855 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
856 | FT_Face ft_face = ftfont_info->ft_size->face; | |
857 | FT_ULong charcode = c; | |
858 | FT_UInt code = FT_Get_Char_Index (ft_face, charcode); | |
859 | ||
860 | return (code > 0 ? code : 0xFFFFFFFF); | |
861 | } | |
862 | ||
863 | static int | |
864 | ftfont_text_extents (font, code, nglyphs, metrics) | |
865 | struct font *font; | |
866 | unsigned *code; | |
867 | int nglyphs; | |
868 | struct font_metrics *metrics; | |
869 | { | |
870 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
871 | FT_Face ft_face = ftfont_info->ft_size->face; | |
872 | int width = 0; | |
873 | int i; | |
874 | ||
875 | if (ftfont_info->ft_size != ft_face->size) | |
876 | FT_Activate_Size (ftfont_info->ft_size); | |
877 | if (metrics) | |
878 | bzero (metrics, sizeof (struct font_metrics)); | |
879 | for (i = 0; i < nglyphs; i++) | |
880 | { | |
881 | if (FT_Load_Glyph (ft_face, code[i], FT_LOAD_DEFAULT) == 0) | |
882 | { | |
883 | FT_Glyph_Metrics *m = &ft_face->glyph->metrics; | |
884 | ||
885 | if (metrics) | |
886 | { | |
887 | if (metrics->lbearing > width + (m->horiBearingX >> 6)) | |
888 | metrics->lbearing = width + (m->horiBearingX >> 6); | |
889 | if (metrics->rbearing | |
890 | < width + ((m->horiBearingX + m->width) >> 6)) | |
891 | metrics->rbearing | |
892 | = width + ((m->horiBearingX + m->width) >> 6); | |
893 | if (metrics->ascent < (m->horiBearingY >> 6)) | |
894 | metrics->ascent = m->horiBearingY >> 6; | |
895 | if (metrics->descent > ((m->horiBearingY + m->height) >> 6)) | |
896 | metrics->descent = (m->horiBearingY + m->height) >> 6; | |
897 | } | |
898 | width += m->horiAdvance >> 6; | |
899 | } | |
900 | else | |
901 | { | |
902 | width += font->font.space_width; | |
903 | } | |
904 | } | |
905 | if (metrics) | |
906 | metrics->width = width; | |
907 | ||
908 | return width; | |
909 | } | |
910 | ||
911 | static int | |
912 | ftfont_get_bitmap (font, code, bitmap, bits_per_pixel) | |
913 | struct font *font; | |
914 | unsigned code; | |
915 | struct font_bitmap *bitmap; | |
916 | int bits_per_pixel; | |
917 | { | |
918 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
919 | FT_Face ft_face = ftfont_info->ft_size->face; | |
920 | FT_Int32 load_flags = FT_LOAD_RENDER; | |
921 | ||
922 | if (ftfont_info->ft_size != ft_face->size) | |
923 | FT_Activate_Size (ftfont_info->ft_size); | |
924 | if (bits_per_pixel == 1) | |
925 | { | |
926 | #ifdef FT_LOAD_TARGET_MONO | |
927 | load_flags |= FT_LOAD_TARGET_MONO; | |
928 | #else | |
929 | load_flags |= FT_LOAD_MONOCHROME; | |
930 | #endif | |
931 | } | |
932 | else if (bits_per_pixel != 8) | |
933 | /* We don't support such a rendering. */ | |
934 | return -1; | |
935 | ||
936 | if (FT_Load_Glyph (ft_face, code, load_flags) != 0) | |
937 | return -1; | |
b51e5112 KH |
938 | bitmap->bits_per_pixel |
939 | = (ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO ? 1 | |
940 | : ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY ? 8 | |
941 | : ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD ? 8 | |
942 | : ft_face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V ? 8 | |
943 | : -1); | |
944 | if (bitmap->bits_per_pixel < 0) | |
945 | /* We don't suport that kind of pixel mode. */ | |
946 | return -1; | |
c2f5bfd6 KH |
947 | bitmap->rows = ft_face->glyph->bitmap.rows; |
948 | bitmap->width = ft_face->glyph->bitmap.width; | |
949 | bitmap->pitch = ft_face->glyph->bitmap.pitch; | |
950 | bitmap->buffer = ft_face->glyph->bitmap.buffer; | |
951 | bitmap->left = ft_face->glyph->bitmap_left; | |
952 | bitmap->top = ft_face->glyph->bitmap_top; | |
953 | bitmap->advance = ft_face->glyph->metrics.horiAdvance >> 6; | |
954 | bitmap->extra = NULL; | |
955 | ||
956 | return 0; | |
957 | } | |
958 | ||
959 | static int | |
960 | ftfont_anchor_point (font, code, index, x, y) | |
961 | struct font *font; | |
962 | unsigned code; | |
963 | int index; | |
964 | int *x, *y; | |
965 | { | |
966 | struct ftfont_info *ftfont_info = (struct ftfont_info *) font; | |
967 | FT_Face ft_face = ftfont_info->ft_size->face; | |
968 | ||
969 | if (ftfont_info->ft_size != ft_face->size) | |
970 | FT_Activate_Size (ftfont_info->ft_size); | |
971 | if (FT_Load_Glyph (ft_face, code, FT_LOAD_DEFAULT) != 0) | |
972 | return -1; | |
973 | if (ft_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE) | |
974 | return -1; | |
975 | if (index >= ft_face->glyph->outline.n_points) | |
976 | return -1; | |
977 | *x = ft_face->glyph->outline.points[index].x; | |
978 | *y = ft_face->glyph->outline.points[index].y; | |
979 | return 0; | |
980 | } | |
981 | ||
de023c40 KH |
982 | #ifdef HAVE_LIBOTF |
983 | #ifdef HAVE_M17N_FLT | |
984 | ||
985 | struct MFLTFontFT | |
986 | { | |
987 | MFLTFont flt_font; | |
988 | struct font *font; | |
989 | FT_Face ft_face; | |
990 | OTF *otf; | |
991 | }; | |
992 | ||
993 | static int | |
994 | ftfont_get_glyph_id (font, gstring, from, to) | |
995 | MFLTFont *font; | |
996 | MFLTGlyphString *gstring; | |
997 | int from, to; | |
998 | { | |
999 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | |
1000 | FT_Face ft_face = flt_font_ft->ft_face; | |
1001 | MFLTGlyph *g; | |
1002 | ||
1003 | for (g = gstring->glyphs + from; from < to; g++, from++) | |
1004 | if (! g->encoded) | |
1005 | { | |
1006 | FT_UInt code = FT_Get_Char_Index (ft_face, g->code); | |
1007 | ||
1008 | g->code = code > 0 ? code : FONT_INVALID_CODE; | |
1009 | g->encoded = 1; | |
1010 | } | |
1011 | return 0; | |
1012 | } | |
1013 | ||
1014 | static int | |
1015 | ftfont_get_metrics (font, gstring, from, to) | |
1016 | MFLTFont *font; | |
1017 | MFLTGlyphString *gstring; | |
1018 | int from, to; | |
1019 | { | |
1020 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | |
1021 | FT_Face ft_face = flt_font_ft->ft_face; | |
1022 | MFLTGlyph *g; | |
1023 | ||
1024 | for (g = gstring->glyphs + from; from < to; g++, from++) | |
1025 | if (! g->measured) | |
1026 | { | |
1027 | if (g->code != FONT_INVALID_CODE) | |
1028 | { | |
1029 | FT_Glyph_Metrics *m; | |
1030 | ||
1031 | if (FT_Load_Glyph (ft_face, g->code, FT_LOAD_DEFAULT) != 0) | |
1032 | abort (); | |
1033 | m = &ft_face->glyph->metrics; | |
1034 | ||
1035 | g->lbearing = m->horiBearingX; | |
1036 | g->rbearing = m->horiBearingX + m->width; | |
1037 | g->ascent = m->horiBearingY; | |
1038 | g->descent = m->height - m->horiBearingY; | |
1039 | g->xadv = m->horiAdvance; | |
1040 | } | |
1041 | else | |
1042 | { | |
1043 | g->lbearing = 0; | |
1044 | g->rbearing = g->xadv = flt_font_ft->font->font.space_width << 6; | |
1045 | g->ascent = flt_font_ft->font->ascent << 6; | |
1046 | g->descent = flt_font_ft->font->descent << 6; | |
1047 | } | |
1048 | g->yadv = 0; | |
1049 | g->measured = 1; | |
1050 | } | |
1051 | return 0; | |
1052 | } | |
1053 | ||
1054 | static int | |
1055 | ftfont_check_otf (MFLTFont *font, MFLTOtfSpec *spec) | |
1056 | { | |
1057 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | |
1058 | OTF *otf = flt_font_ft->otf; | |
1059 | OTF_Tag *tags; | |
1060 | int i, n, negative; | |
1061 | ||
1062 | for (i = 0; i < 2; i++) | |
1063 | { | |
1064 | if (! spec->features[i]) | |
1065 | continue; | |
1066 | for (n = 0; spec->features[i][n]; n++); | |
1067 | tags = alloca (sizeof (OTF_Tag) * n); | |
1068 | for (n = 0, negative = 0; spec->features[i][n]; n++) | |
1069 | { | |
1070 | if (spec->features[i][n] == 0xFFFFFFFF) | |
1071 | negative = 1; | |
1072 | else if (negative) | |
1073 | tags[n - 1] = spec->features[i][n] | 0x80000000; | |
1074 | else | |
1075 | tags[n] = spec->features[i][n]; | |
1076 | } | |
1077 | if (n - negative > 0 | |
1078 | && OTF_check_features (otf, i == 0, spec->script, spec->langsys, | |
1079 | tags, n - negative) != 1) | |
1080 | return 0; | |
1081 | } | |
1082 | return 1; | |
1083 | } | |
1084 | ||
1085 | #define DEVICE_DELTA(table, size) \ | |
1086 | (((size) >= (table).StartSize && (size) <= (table).EndSize) \ | |
1087 | ? (table).DeltaValue[(size) - (table).StartSize] << 6 \ | |
1088 | : 0) | |
1089 | ||
1090 | static void | |
1091 | adjust_anchor (FT_Face ft_face, OTF_Anchor *anchor, | |
1092 | unsigned code, int x_ppem, int y_ppem, int *x, int *y) | |
1093 | { | |
1094 | if (anchor->AnchorFormat == 2) | |
1095 | { | |
1096 | FT_Outline *outline; | |
1097 | int ap = anchor->f.f1.AnchorPoint; | |
1098 | ||
1099 | FT_Load_Glyph (ft_face, (FT_UInt) code, FT_LOAD_MONOCHROME); | |
1100 | outline = &ft_face->glyph->outline; | |
1101 | if (ap < outline->n_points) | |
1102 | { | |
1103 | *x = outline->points[ap].x << 6; | |
1104 | *y = outline->points[ap].y << 6; | |
1105 | } | |
1106 | } | |
1107 | else if (anchor->AnchorFormat == 3) | |
1108 | { | |
1109 | if (anchor->f.f2.XDeviceTable.offset) | |
1110 | *x += DEVICE_DELTA (anchor->f.f2.XDeviceTable, x_ppem); | |
1111 | if (anchor->f.f2.YDeviceTable.offset) | |
1112 | *y += DEVICE_DELTA (anchor->f.f2.YDeviceTable, y_ppem); | |
1113 | } | |
1114 | } | |
1115 | ||
1116 | static OTF_GlyphString otf_gstring; | |
1117 | ||
1118 | static int | |
1119 | ftfont_drive_otf (font, spec, in, from, to, out, adjustment) | |
1120 | MFLTFont *font; | |
1121 | MFLTOtfSpec *spec; | |
1122 | MFLTGlyphString *in; | |
1123 | int from, to; | |
1124 | MFLTGlyphString *out; | |
1125 | MFLTGlyphAdjustment *adjustment; | |
1126 | { | |
1127 | struct MFLTFontFT *flt_font_ft = (struct MFLTFontFT *) font; | |
1128 | FT_Face ft_face = flt_font_ft->ft_face; | |
1129 | OTF *otf = flt_font_ft->otf; | |
1130 | int len = to - from; | |
1131 | int i, j, gidx; | |
1132 | OTF_Glyph *otfg; | |
1133 | char script[5], *langsys = NULL; | |
1134 | char *gsub_features = NULL, *gpos_features = NULL; | |
1135 | ||
1136 | if (len == 0) | |
1137 | return from; | |
1138 | OTF_tag_name (spec->script, script); | |
1139 | if (spec->langsys) | |
1140 | { | |
1141 | langsys = alloca (5); | |
1142 | OTF_tag_name (spec->langsys, langsys); | |
1143 | } | |
1144 | for (i = 0; i < 2; i++) | |
1145 | { | |
1146 | char *p; | |
1147 | ||
1148 | if (spec->features[i] && spec->features[i][1] != 0xFFFFFFFF) | |
1149 | { | |
1150 | for (j = 0; spec->features[i][j]; j++); | |
1151 | if (i == 0) | |
1152 | p = gsub_features = alloca (6 * j); | |
1153 | else | |
1154 | p = gpos_features = alloca (6 * j); | |
1155 | for (j = 0; spec->features[i][j]; j++) | |
1156 | { | |
1157 | if (spec->features[i][j] == 0xFFFFFFFF) | |
1158 | *p++ = '*', *p++ = ','; | |
1159 | else | |
1160 | { | |
1161 | OTF_tag_name (spec->features[i][j], p); | |
1162 | p[4] = ','; | |
1163 | p += 5; | |
1164 | } | |
1165 | } | |
1166 | *--p = '\0'; | |
1167 | } | |
1168 | } | |
1169 | ||
1170 | if (otf_gstring.size == 0) | |
1171 | { | |
1172 | otf_gstring.glyphs = (OTF_Glyph *) malloc (sizeof (OTF_Glyph) * len); | |
1173 | otf_gstring.size = len; | |
1174 | } | |
1175 | else if (otf_gstring.size < len) | |
1176 | { | |
1177 | otf_gstring.glyphs = (OTF_Glyph *) realloc (otf_gstring.glyphs, | |
1178 | sizeof (OTF_Glyph) * len); | |
1179 | otf_gstring.size = len; | |
1180 | } | |
1181 | otf_gstring.used = len; | |
1182 | memset (otf_gstring.glyphs, 0, sizeof (OTF_Glyph) * len); | |
1183 | for (i = 0; i < len; i++) | |
1184 | { | |
1185 | otf_gstring.glyphs[i].c = in->glyphs[from + i].c; | |
1186 | otf_gstring.glyphs[i].glyph_id = in->glyphs[from + i].code; | |
1187 | } | |
1188 | ||
1189 | OTF_drive_gdef (otf, &otf_gstring); | |
1190 | gidx = out->used; | |
1191 | ||
1192 | if (gsub_features) | |
1193 | { | |
1194 | if (OTF_drive_gsub (otf, &otf_gstring, script, langsys, gsub_features) | |
1195 | < 0) | |
1196 | goto simple_copy; | |
1197 | if (out->allocated < out->used + otf_gstring.used) | |
1198 | return -2; | |
1199 | for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used; i++, otfg++) | |
1200 | { | |
1201 | MFLTGlyph *g = out->glyphs + out->used; | |
1202 | int j; | |
1203 | ||
1204 | *g = in->glyphs[from + otfg->f.index.from]; | |
1205 | g->c = 0; | |
1206 | for (j = from + otfg->f.index.from; j <= from + otfg->f.index.to; j++) | |
1207 | if (in->glyphs[j].code == otfg->glyph_id) | |
1208 | { | |
1209 | g->c = in->glyphs[j].c; | |
1210 | break; | |
1211 | } | |
1212 | if (g->code != otfg->glyph_id) | |
1213 | { | |
1214 | g->code = otfg->glyph_id; | |
1215 | g->measured = 0; | |
1216 | } | |
1217 | out->used++; | |
1218 | } | |
1219 | } | |
1220 | else | |
1221 | { | |
1222 | if (out->allocated < out->used + len) | |
1223 | return -2; | |
1224 | for (i = 0; i < len; i++) | |
1225 | out->glyphs[out->used++] = in->glyphs[from + i]; | |
1226 | } | |
1227 | ||
1228 | if (gpos_features) | |
1229 | { | |
1230 | MFLTGlyph *base = NULL, *mark = NULL, *g; | |
1231 | int x_ppem, y_ppem, x_scale, y_scale; | |
1232 | ||
1233 | if (OTF_drive_gpos (otf, &otf_gstring, script, langsys, gpos_features) | |
1234 | < 0) | |
1235 | return to; | |
1236 | ||
1237 | x_ppem = ft_face->size->metrics.x_ppem; | |
1238 | y_ppem = ft_face->size->metrics.y_ppem; | |
1239 | x_scale = ft_face->size->metrics.x_scale; | |
1240 | y_scale = ft_face->size->metrics.y_scale; | |
1241 | ||
1242 | for (i = 0, otfg = otf_gstring.glyphs, g = out->glyphs + gidx; | |
1243 | i < otf_gstring.used; i++, otfg++, g++) | |
1244 | { | |
1245 | MFLTGlyph *prev; | |
1246 | ||
1247 | if (! otfg->glyph_id) | |
1248 | continue; | |
1249 | switch (otfg->positioning_type) | |
1250 | { | |
1251 | case 0: | |
1252 | break; | |
1253 | case 1: /* Single */ | |
1254 | case 2: /* Pair */ | |
1255 | { | |
1256 | int format = otfg->f.f1.format; | |
1257 | ||
1258 | if (format & OTF_XPlacement) | |
1259 | adjustment[i].xoff | |
1260 | = otfg->f.f1.value->XPlacement * x_scale / 0x10000; | |
1261 | if (format & OTF_XPlaDevice) | |
1262 | adjustment[i].xoff | |
1263 | += DEVICE_DELTA (otfg->f.f1.value->XPlaDevice, x_ppem); | |
1264 | if (format & OTF_YPlacement) | |
1265 | adjustment[i].yoff | |
1266 | = - (otfg->f.f1.value->YPlacement * y_scale / 0x10000); | |
1267 | if (format & OTF_YPlaDevice) | |
1268 | adjustment[i].yoff | |
1269 | -= DEVICE_DELTA (otfg->f.f1.value->YPlaDevice, y_ppem); | |
1270 | if (format & OTF_XAdvance) | |
1271 | adjustment[i].xadv | |
1272 | += otfg->f.f1.value->XAdvance * x_scale / 0x10000; | |
1273 | if (format & OTF_XAdvDevice) | |
1274 | adjustment[i].xadv | |
1275 | += DEVICE_DELTA (otfg->f.f1.value->XAdvDevice, x_ppem); | |
1276 | if (format & OTF_YAdvance) | |
1277 | adjustment[i].yadv | |
1278 | += otfg->f.f1.value->YAdvance * y_scale / 0x10000; | |
1279 | if (format & OTF_YAdvDevice) | |
1280 | adjustment[i].yadv | |
1281 | += DEVICE_DELTA (otfg->f.f1.value->YAdvDevice, y_ppem); | |
1282 | adjustment[i].set = 1; | |
1283 | } | |
1284 | break; | |
1285 | case 3: /* Cursive */ | |
1286 | /* Not yet supported. */ | |
1287 | break; | |
1288 | case 4: /* Mark-to-Base */ | |
1289 | case 5: /* Mark-to-Ligature */ | |
1290 | if (! base) | |
1291 | break; | |
1292 | prev = base; | |
1293 | goto label_adjust_anchor; | |
1294 | default: /* i.e. case 6 Mark-to-Mark */ | |
1295 | if (! mark) | |
1296 | break; | |
1297 | prev = mark; | |
1298 | ||
1299 | label_adjust_anchor: | |
1300 | { | |
1301 | int base_x, base_y, mark_x, mark_y; | |
1302 | int this_from, this_to; | |
1303 | ||
1304 | base_x = otfg->f.f4.base_anchor->XCoordinate * x_scale / 0x10000; | |
1305 | base_y = otfg->f.f4.base_anchor->YCoordinate * y_scale / 0x10000; | |
1306 | mark_x = otfg->f.f4.mark_anchor->XCoordinate * x_scale / 0x10000; | |
1307 | mark_y = otfg->f.f4.mark_anchor->YCoordinate * y_scale / 0x10000;; | |
1308 | ||
1309 | if (otfg->f.f4.base_anchor->AnchorFormat != 1) | |
1310 | adjust_anchor (ft_face, otfg->f.f4.base_anchor, | |
1311 | prev->code, x_ppem, y_ppem, &base_x, &base_y); | |
1312 | if (otfg->f.f4.mark_anchor->AnchorFormat != 1) | |
1313 | adjust_anchor (ft_face, otfg->f.f4.mark_anchor, g->code, | |
1314 | x_ppem, y_ppem, &mark_x, &mark_y); | |
1315 | adjustment[i].xoff = (base_x - mark_x); | |
1316 | adjustment[i].yoff = - (base_y - mark_y); | |
1317 | adjustment[i].back = (g - prev); | |
1318 | adjustment[i].xadv = 0; | |
1319 | adjustment[i].advance_is_absolute = 1; | |
1320 | adjustment[i].set = 1; | |
1321 | this_from = g->from; | |
1322 | this_to = g->to; | |
1323 | for (j = 0; prev + j < g; j++) | |
1324 | { | |
1325 | if (this_from > prev[j].from) | |
1326 | this_from = prev[j].from; | |
1327 | if (this_to < prev[j].to) | |
1328 | this_to = prev[j].to; | |
1329 | } | |
1330 | for (; prev <= g; prev++) | |
1331 | { | |
1332 | prev->from = this_from; | |
1333 | prev->to = this_to; | |
1334 | } | |
1335 | } | |
1336 | } | |
1337 | if (otfg->GlyphClass == OTF_GlyphClass0) | |
1338 | base = mark = g; | |
1339 | else if (otfg->GlyphClass == OTF_GlyphClassMark) | |
1340 | mark = g; | |
1341 | else | |
1342 | base = g; | |
1343 | } | |
1344 | } | |
1345 | return to; | |
1346 | ||
1347 | simple_copy: | |
1348 | if (out->allocated < out->used + len) | |
1349 | return -2; | |
1350 | font->get_metrics (font, in, from, to); | |
1351 | memcpy (out->glyphs + out->used, in->glyphs + from, | |
1352 | sizeof (MFLTGlyph) * len); | |
1353 | out->used += len; | |
1354 | return to; | |
1355 | } | |
1356 | ||
1357 | static MFLTGlyphString gstring; | |
1358 | ||
1359 | static int m17n_flt_initialized; | |
1360 | ||
1361 | extern Lisp_Object QCfamily; | |
1362 | ||
1363 | Lisp_Object | |
1364 | ftfont_shape_by_flt (lgstring, font, ft_face, otf) | |
1365 | Lisp_Object lgstring; | |
1366 | struct font *font; | |
1367 | FT_Face ft_face; | |
1368 | OTF *otf; | |
1369 | { | |
1370 | EMACS_UINT len = LGSTRING_LENGTH (lgstring); | |
1371 | EMACS_UINT i; | |
1372 | struct MFLTFontFT flt_font_ft; | |
1373 | ||
1374 | if (! m17n_flt_initialized) | |
1375 | { | |
1376 | M17N_INIT (); | |
1377 | m17n_flt_initialized = 1; | |
1378 | } | |
1379 | ||
1380 | for (i = 0; i < len; i++) | |
1381 | if (NILP (LGSTRING_GLYPH (lgstring, i))) | |
1382 | break; | |
1383 | len = i; | |
1384 | ||
1385 | if (gstring.allocated == 0) | |
1386 | { | |
1387 | gstring.allocated = len * 2; | |
1388 | gstring.glyph_size = sizeof (MFLTGlyph); | |
1389 | gstring.glyphs = malloc (sizeof (MFLTGlyph) * gstring.allocated); | |
1390 | } | |
1391 | else if (gstring.allocated < len * 2) | |
1392 | { | |
1393 | gstring.allocated = len * 2; | |
1394 | gstring.glyphs = realloc (gstring.glyphs, | |
1395 | sizeof (MFLTGlyph) * gstring.allocated); | |
1396 | } | |
1397 | for (i = 0; i < len; i++) | |
1398 | gstring.glyphs[i].c = LGLYPH_CHAR (LGSTRING_GLYPH (lgstring, i)); | |
1399 | gstring.used = len; | |
1400 | gstring.r2l = 0; | |
1401 | ||
1402 | { | |
1403 | Lisp_Object family = Ffont_get (LGSTRING_FONT (lgstring), QCfamily); | |
1404 | ||
1405 | if (NILP (family)) | |
1406 | flt_font_ft.flt_font.family = Mnil; | |
1407 | else | |
1408 | flt_font_ft.flt_font.family = msymbol (SDATA (SYMBOL_NAME (family))); | |
1409 | } | |
1410 | flt_font_ft.flt_font.x_ppem = ft_face->size->metrics.x_ppem; | |
1411 | flt_font_ft.flt_font.y_ppem = ft_face->size->metrics.y_ppem; | |
1412 | flt_font_ft.flt_font.get_glyph_id = ftfont_get_glyph_id; | |
1413 | flt_font_ft.flt_font.get_metrics = ftfont_get_metrics; | |
1414 | flt_font_ft.flt_font.check_otf = ftfont_check_otf; | |
1415 | flt_font_ft.flt_font.drive_otf = ftfont_drive_otf; | |
1416 | flt_font_ft.flt_font.internal = NULL; | |
1417 | flt_font_ft.font = font; | |
1418 | flt_font_ft.ft_face = ft_face; | |
1419 | flt_font_ft.otf = otf; | |
1420 | for (i = 0; i < 3; i++) | |
1421 | { | |
1422 | int result = mflt_run (&gstring, 0, len, &flt_font_ft.flt_font, NULL); | |
1423 | if (result != -2) | |
1424 | break; | |
1425 | gstring.allocated += gstring.allocated; | |
1426 | gstring.glyphs = realloc (gstring.glyphs, | |
1427 | sizeof (MFLTGlyph) * gstring.allocated); | |
1428 | } | |
1429 | if (gstring.used > LGSTRING_LENGTH (lgstring)) | |
1430 | return Qnil; | |
1431 | for (i = 0; i < gstring.used; i++) | |
1432 | { | |
1433 | MFLTGlyph *g = gstring.glyphs + i; | |
1434 | ||
1435 | g->from = LGLYPH_FROM (LGSTRING_GLYPH (lgstring, g->from)); | |
1436 | g->to = LGLYPH_TO (LGSTRING_GLYPH (lgstring, g->to)); | |
1437 | } | |
1438 | ||
1439 | for (i = 0; i < gstring.used; i++) | |
1440 | { | |
1441 | Lisp_Object lglyph = LGSTRING_GLYPH (lgstring, i); | |
1442 | MFLTGlyph *g = gstring.glyphs + i; | |
1443 | ||
1444 | LGLYPH_SET_FROM (lglyph, g->from); | |
1445 | LGLYPH_SET_TO (lglyph, g->to); | |
1446 | LGLYPH_SET_CHAR (lglyph, g->c); | |
1447 | LGLYPH_SET_CODE (lglyph, g->code); | |
1448 | LGLYPH_SET_WIDTH (lglyph, g->xadv >> 6); | |
1449 | LGLYPH_SET_LBEARING (lglyph, g->lbearing >> 6); | |
1450 | LGLYPH_SET_RBEARING (lglyph, g->rbearing >> 6); | |
1451 | LGLYPH_SET_ASCENT (lglyph, g->ascent >> 6); | |
1452 | LGLYPH_SET_DESCENT (lglyph, g->descent >> 6); | |
1453 | if (g->adjusted) | |
1454 | { | |
1455 | Lisp_Object vec; | |
1456 | ||
1457 | vec = Fmake_vector (make_number (3), Qnil); | |
1458 | ASET (vec, 0, make_number (g->xoff >> 6)); | |
1459 | ASET (vec, 1, make_number (g->yoff >> 6)); | |
1460 | ASET (vec, 2, make_number (g->xadv >> 6)); | |
1461 | LGLYPH_SET_ADJUSTMENT (lglyph, vec); | |
1462 | } | |
1463 | } | |
1464 | return make_number (i); | |
1465 | } | |
1466 | ||
1467 | Lisp_Object | |
1468 | ftfont_shape (lgstring) | |
1469 | Lisp_Object lgstring; | |
1470 | { | |
1471 | struct font *font; | |
1472 | struct ftfont_info *ftfont_info; | |
1473 | ||
1474 | CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring), font); | |
1475 | ftfont_info = (struct ftfont_info *) font; | |
1476 | if (! ftfont_info->maybe_otf) | |
1477 | return 0; | |
1478 | if (! ftfont_info->otf) | |
1479 | { | |
1480 | OTF *otf = OTF_open_ft_face (ftfont_info->ft_size->face); | |
1481 | ||
1482 | if (! otf || OTF_get_table (otf, "head") < 0) | |
1483 | { | |
1484 | if (otf) | |
1485 | OTF_close (otf); | |
1486 | ftfont_info->maybe_otf = 0; | |
1487 | return 0; | |
1488 | } | |
1489 | ||
1490 | ftfont_info->otf = otf; | |
1491 | } | |
1492 | ||
1493 | return ftfont_shape_by_flt (lgstring, font, ftfont_info->ft_size->face, | |
1494 | ftfont_info->otf); | |
1495 | } | |
1496 | ||
1497 | #endif /* HAVE_M17N_FLT */ | |
1498 | #endif /* HAVE_LIBOTF */ | |
1499 | ||
0b966021 KH |
1500 | Lisp_Object |
1501 | ftfont_font_format (FcPattern *pattern) | |
1502 | { | |
e907d979 | 1503 | FcChar8 *str; |
0b966021 | 1504 | |
e907d979 KH |
1505 | #ifdef FC_FONTFORMAT |
1506 | if (FcPatternGetString (pattern, FC_FONTFORMAT, 0, &str) != FcResultMatch) | |
0b966021 | 1507 | return Qnil; |
e907d979 | 1508 | if (strcmp ((char *) str, "TrueType") == 0) |
0b966021 | 1509 | return intern ("truetype"); |
48875afe | 1510 | if (strcmp ((char *) str, "Type 1") == 0) |
0b966021 | 1511 | return intern ("type1"); |
e907d979 | 1512 | if (strcmp ((char *) str, "PCF") == 0) |
0b966021 | 1513 | return intern ("pcf"); |
e907d979 | 1514 | if (strcmp ((char *) str, "BDF") == 0) |
0b966021 | 1515 | return intern ("bdf"); |
e907d979 | 1516 | #else /* not FC_FONTFORMAT */ |
09a56ce4 | 1517 | if (FcPatternGetString (pattern, FC_FILE, 0, &str) != FcResultMatch) |
e907d979 KH |
1518 | return Qnil; |
1519 | if (strcasestr ((char *) str, ".ttf") == 0) | |
1520 | return intern ("truetype"); | |
1521 | if (strcasestr ((char *) str, "pfb") == 0) | |
1522 | return intern ("type1"); | |
1523 | if (strcasestr ((char *) str, "pcf") == 0) | |
1524 | return intern ("pcf"); | |
1525 | if (strcasestr ((char *) str, "bdf") == 0) | |
1526 | return intern ("bdf"); | |
1527 | #endif /* not FC_FONTFORMAT */ | |
0b966021 KH |
1528 | return intern ("unknown"); |
1529 | } | |
1530 | ||
c2f5bfd6 KH |
1531 | \f |
1532 | void | |
1533 | syms_of_ftfont () | |
1534 | { | |
706b6995 KH |
1535 | DEFSYM (Qfreetype, "freetype"); |
1536 | DEFSYM (Qmonospace, "monospace"); | |
1537 | DEFSYM (Qsans_serif, "sans-serif"); | |
1538 | DEFSYM (Qserif, "serif"); | |
1539 | DEFSYM (Qmono, "mono"); | |
1540 | DEFSYM (Qsans, "sans"); | |
1541 | DEFSYM (Qsans__serif, "sans serif"); | |
1542 | ||
c2f5bfd6 | 1543 | staticpro (&freetype_font_cache); |
c2801c99 | 1544 | freetype_font_cache = Fcons (Qt, Qnil); |
c2f5bfd6 | 1545 | |
706b6995 KH |
1546 | staticpro (&ftfont_generic_family_list); |
1547 | ftfont_generic_family_list | |
1548 | = Fcons (Fcons (Qmonospace, Qt), | |
1549 | Fcons (Fcons (Qsans_serif, Qt), | |
1550 | Fcons (Fcons (Qsans, Qt), Qnil))); | |
c2f5bfd6 KH |
1551 | |
1552 | ftfont_driver.type = Qfreetype; | |
1553 | register_font_driver (&ftfont_driver, NULL); | |
1554 | } | |
885b7d09 MB |
1555 | |
1556 | /* arch-tag: 7cfa432c-33a6-4988-83d2-a82ed8604aca | |
1557 | (do not change this comment) */ |