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