1 /* ftfont.c -- FreeType font driver.
2 Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
3 Copyright (C) 2006, 2007, 2008, 2009
4 National Institute of Advanced Industrial Science and Technology (AIST)
5 Registration Number H13PRO009
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26 #include <fontconfig/fontconfig.h>
27 #include <fontconfig/fcfreetype.h>
30 #include "dispextern.h"
32 #include "blockinput.h"
33 #include "character.h"
36 #include "composite.h"
41 /* Symbolic type of this font-driver. */
42 Lisp_Object Qfreetype
;
44 /* Fontconfig's generic families and their aliases. */
45 static Lisp_Object Qmonospace
, Qsans_serif
, Qserif
, Qmono
, Qsans
, Qsans__serif
;
47 /* Flag to tell if FcInit is already called or not. */
48 static int fc_initialized
;
50 /* Handle to a FreeType library instance. */
51 static FT_Library ft_library
;
53 /* Cache for FreeType fonts. */
54 static Lisp_Object freetype_font_cache
;
56 /* Cache for FT_Face and FcCharSet. */
57 static Lisp_Object ft_face_cache
;
59 /* The actual structure for FreeType font that can be casted to struct
66 /* The following four members must be here in this order to be
67 compatible with struct xftfont_info (in xftfont.c). */
68 int maybe_otf
; /* Flag to tell if this may be OTF or not. */
70 #endif /* HAVE_LIBOTF */
77 FTFONT_CACHE_FOR_FACE
,
78 FTFONT_CACHE_FOR_CHARSET
,
79 FTFONT_CACHE_FOR_ENTITY
82 static Lisp_Object ftfont_pattern_entity
P_ ((FcPattern
*, Lisp_Object
));
84 static Lisp_Object ftfont_resolve_generic_family
P_ ((Lisp_Object
,
86 static Lisp_Object ftfont_lookup_cache
P_ ((Lisp_Object
,
87 enum ftfont_cache_for
));
89 static void ftfont_filter_properties
P_ ((Lisp_Object font
, Lisp_Object alist
));
91 Lisp_Object ftfont_font_format
P_ ((FcPattern
*, Lisp_Object
));
93 #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM))
99 /* characters to distinguish the charset from the others */
101 /* additional constraint by language */
104 FcCharSet
*fc_charset
;
105 } fc_charset_table
[] =
106 { { "iso8859-1", { 0x00A0, 0x00A1, 0x00B4, 0x00BC, 0x00D0 } },
107 { "iso8859-2", { 0x00A0, 0x010E }},
108 { "iso8859-3", { 0x00A0, 0x0108 }},
109 { "iso8859-4", { 0x00A0, 0x00AF, 0x0128, 0x0156, 0x02C7 }},
110 { "iso8859-5", { 0x00A0, 0x0401 }},
111 { "iso8859-6", { 0x00A0, 0x060C }},
112 { "iso8859-7", { 0x00A0, 0x0384 }},
113 { "iso8859-8", { 0x00A0, 0x05D0 }},
114 { "iso8859-9", { 0x00A0, 0x00A1, 0x00BC, 0x011E }},
115 { "iso8859-10", { 0x00A0, 0x00D0, 0x0128, 0x2015 }},
116 { "iso8859-11", { 0x00A0, 0x0E01 }},
117 { "iso8859-13", { 0x00A0, 0x201C }},
118 { "iso8859-14", { 0x00A0, 0x0174 }},
119 { "iso8859-15", { 0x00A0, 0x00A1, 0x00D0, 0x0152 }},
120 { "iso8859-16", { 0x00A0, 0x0218}},
121 { "gb2312.1980-0", { 0x4E13 }, "zh-cn"},
122 { "big5-0", { 0xF6B1 }, "zh-tw" },
123 { "jisx0208.1983-0", { 0x4E55 }, "ja"},
124 { "ksc5601.1985-0", { 0xAC00 }, "ko"},
125 { "cns11643.1992-1", { 0xFE32 }, "zh-tw"},
126 { "cns11643.1992-2", { 0x4E33, 0x7934 }},
127 { "cns11643.1992-3", { 0x201A9 }},
128 { "cns11643.1992-4", { 0x20057 }},
129 { "cns11643.1992-5", { 0x20000 }},
130 { "cns11643.1992-6", { 0x20003 }},
131 { "cns11643.1992-7", { 0x20055 }},
132 { "gbk-0", { 0x4E06 }, "zh-cn"},
133 { "jisx0212.1990-0", { 0x4E44 }},
134 { "jisx0213.2000-1", { 0xFA10 }, "ja"},
135 { "jisx0213.2000-2", { 0xFA49 }},
136 { "jisx0213.2004-1", { 0x20B9F }},
137 { "viscii1.1-1", { 0x1EA0, 0x1EAE, 0x1ED2 }, "vi"},
138 { "tis620.2529-1", { 0x0E01 }, "th"},
139 { "windows-1251", { 0x0401, 0x0490 }, "ru"},
140 { "koi8-r", { 0x0401, 0x2219 }, "ru"},
141 { "mulelao-1", { 0x0E81 }, "lo"},
142 { "unicode-sip", { 0x20000 }},
146 extern Lisp_Object Qc
, Qm
, Qp
, Qd
;
148 /* Dirty hack for handing ADSTYLE property.
150 Fontconfig (actually the underlying FreeType) gives such ADSTYLE
151 font property of PCF/BDF fonts in FC_STYLE. And, "Bold",
152 "Oblique", "Italic", or any non-normal SWIDTH property names
153 (e.g. SemiCondensed) are appended. In addition, if there's no
154 ADSTYLE property nor non-normal WEIGHT/SLANT/SWIDTH properties,
155 "Regular" is used for FC_STYLE (see the function
156 pcf_interpret_style in src/pcf/pcfread.c of FreeType).
158 Unfortunately this behavior is not documented, so the following
159 code may fail if FreeType changes the behavior in the future. */
162 get_adstyle_property (FcPattern
*p
)
167 if (FcPatternGetString (p
, FC_STYLE
, 0, (FcChar8
**) &str
) != FcResultMatch
)
169 for (end
= str
; *end
&& *end
!= ' '; end
++);
172 char *p
= alloca (end
- str
+ 1);
173 memcpy (p
, str
, end
- str
);
175 end
= p
+ (end
- str
);
178 if (xstrcasecmp (str
, "Regular") == 0
179 || xstrcasecmp (str
, "Bold") == 0
180 || xstrcasecmp (str
, "Oblique") == 0
181 || xstrcasecmp (str
, "Italic") == 0)
183 adstyle
= font_intern_prop (str
, end
- str
, 1);
184 if (font_style_to_value (FONT_WIDTH_INDEX
, adstyle
, 0) >= 0)
190 ftfont_pattern_entity (p
, extra
)
194 Lisp_Object key
, cache
, entity
;
201 if (FcPatternGetString (p
, FC_FILE
, 0, (FcChar8
**) &file
) != FcResultMatch
)
203 if (FcPatternGetInteger (p
, FC_INDEX
, 0, &index
) != FcResultMatch
)
206 key
= Fcons (make_unibyte_string ((char *) file
, strlen ((char *) file
)),
207 make_number (index
));
208 cache
= ftfont_lookup_cache (key
, FTFONT_CACHE_FOR_ENTITY
);
209 entity
= XCAR (cache
);
212 Lisp_Object val
= font_make_entity ();
215 for (i
= 0; i
< FONT_OBJLIST_INDEX
; i
++)
216 ASET (val
, i
, AREF (entity
, i
));
219 entity
= font_make_entity ();
220 XSETCAR (cache
, entity
);
222 ASET (entity
, FONT_TYPE_INDEX
, Qfreetype
);
223 ASET (entity
, FONT_REGISTRY_INDEX
, Qiso10646_1
);
225 if (FcPatternGetString (p
, FC_FOUNDRY
, 0, (FcChar8
**) &str
) == FcResultMatch
)
226 ASET (entity
, FONT_FOUNDRY_INDEX
, font_intern_prop (str
, strlen (str
), 1));
227 if (FcPatternGetString (p
, FC_FAMILY
, 0, (FcChar8
**) &str
) == FcResultMatch
)
228 ASET (entity
, FONT_FAMILY_INDEX
, font_intern_prop (str
, strlen (str
), 1));
229 if (FcPatternGetInteger (p
, FC_WEIGHT
, 0, &numeric
) == FcResultMatch
)
231 if (numeric
>= FC_WEIGHT_REGULAR
&& numeric
< FC_WEIGHT_MEDIUM
)
232 numeric
= FC_WEIGHT_MEDIUM
;
233 FONT_SET_STYLE (entity
, FONT_WEIGHT_INDEX
, make_number (numeric
));
235 if (FcPatternGetInteger (p
, FC_SLANT
, 0, &numeric
) == FcResultMatch
)
238 FONT_SET_STYLE (entity
, FONT_SLANT_INDEX
, make_number (numeric
));
240 if (FcPatternGetInteger (p
, FC_WIDTH
, 0, &numeric
) == FcResultMatch
)
242 FONT_SET_STYLE (entity
, FONT_WIDTH_INDEX
, make_number (numeric
));
244 if (FcPatternGetDouble (p
, FC_PIXEL_SIZE
, 0, &dbl
) == FcResultMatch
)
246 ASET (entity
, FONT_SIZE_INDEX
, make_number (dbl
));
249 ASET (entity
, FONT_SIZE_INDEX
, make_number (0));
250 if (FcPatternGetInteger (p
, FC_SPACING
, 0, &numeric
) == FcResultMatch
)
251 ASET (entity
, FONT_SPACING_INDEX
, make_number (numeric
));
252 if (FcPatternGetDouble (p
, FC_DPI
, 0, &dbl
) == FcResultMatch
)
255 ASET (entity
, FONT_DPI_INDEX
, make_number (dpi
));
257 if (FcPatternGetBool (p
, FC_SCALABLE
, 0, &b
) == FcResultMatch
260 ASET (entity
, FONT_SIZE_INDEX
, make_number (0));
261 ASET (entity
, FONT_AVGWIDTH_INDEX
, make_number (0));
265 /* As this font is not scalable, parhaps this is a BDF or PCF
269 ASET (entity
, FONT_ADSTYLE_INDEX
, get_adstyle_property (p
));
270 if ((ft_library
|| FT_Init_FreeType (&ft_library
) == 0)
271 && FT_New_Face (ft_library
, file
, index
, &ft_face
) == 0)
275 if (FT_Get_BDF_Property (ft_face
, "AVERAGE_WIDTH", &rec
) == 0
276 && rec
.type
== BDF_PROPERTY_TYPE_INTEGER
)
277 ASET (entity
, FONT_AVGWIDTH_INDEX
, make_number (rec
.u
.integer
));
278 FT_Done_Face (ft_face
);
282 ASET (entity
, FONT_EXTRA_INDEX
, Fcopy_sequence (extra
));
283 font_put_extra (entity
, QCfont_entity
, key
);
288 static Lisp_Object ftfont_generic_family_list
;
291 ftfont_resolve_generic_family (family
, pattern
)
300 family
= Fintern (Fdowncase (SYMBOL_NAME (family
)), Qnil
);
301 if (EQ (family
, Qmono
))
303 else if (EQ (family
, Qsans
) || EQ (family
, Qsans__serif
))
304 family
= Qsans_serif
;
305 slot
= assq_no_quit (family
, ftfont_generic_family_list
);
308 if (! EQ (XCDR (slot
), Qt
))
310 pattern
= FcPatternDuplicate (pattern
);
313 FcPatternDel (pattern
, FC_FOUNDRY
);
314 FcPatternDel (pattern
, FC_FAMILY
);
315 FcPatternAddString (pattern
, FC_FAMILY
, SYMBOL_FcChar8 (family
));
316 if (FcPatternGetLangSet (pattern
, FC_LANG
, 0, &langset
) != FcResultMatch
)
318 /* This is to avoid the effect of locale. */
319 langset
= FcLangSetCreate ();
320 FcLangSetAdd (langset
, "en");
321 FcPatternAddLangSet (pattern
, FC_LANG
, langset
);
322 FcLangSetDestroy (langset
);
324 FcConfigSubstitute (NULL
, pattern
, FcMatchPattern
);
325 FcDefaultSubstitute (pattern
);
326 match
= FcFontMatch (NULL
, pattern
, &result
);
331 if (FcPatternGetString (match
, FC_FAMILY
, 0, &fam
) == FcResultMatch
)
332 family
= intern ((char *) fam
);
336 XSETCDR (slot
, family
);
337 if (match
) FcPatternDestroy (match
);
339 if (pattern
) FcPatternDestroy (pattern
);
343 struct ftfont_cache_data
346 FcCharSet
*fc_charset
;
350 ftfont_lookup_cache (key
, cache_for
)
352 enum ftfont_cache_for cache_for
;
354 Lisp_Object cache
, val
, entity
;
355 struct ftfont_cache_data
*cache_data
;
357 if (FONT_ENTITY_P (key
))
360 val
= assq_no_quit (QCfont_entity
, AREF (entity
, FONT_EXTRA_INDEX
));
361 xassert (CONSP (val
));
367 if (NILP (ft_face_cache
))
370 cache
= Fgethash (key
, ft_face_cache
, Qnil
);
373 if (NILP (ft_face_cache
))
379 ft_face_cache
= Fmake_hash_table (2, args
);
381 cache_data
= xmalloc (sizeof (struct ftfont_cache_data
));
382 cache_data
->ft_face
= NULL
;
383 cache_data
->fc_charset
= NULL
;
384 val
= make_save_value (NULL
, 0);
385 XSAVE_VALUE (val
)->integer
= 0;
386 XSAVE_VALUE (val
)->pointer
= cache_data
;
387 cache
= Fcons (Qnil
, val
);
388 Fputhash (key
, cache
, ft_face_cache
);
393 cache_data
= XSAVE_VALUE (val
)->pointer
;
396 if (cache_for
== FTFONT_CACHE_FOR_ENTITY
)
399 if (cache_for
== FTFONT_CACHE_FOR_FACE
400 ? ! cache_data
->ft_face
: ! cache_data
->fc_charset
)
402 char *filename
= (char *) SDATA (XCAR (key
));
403 int index
= XINT (XCDR (key
));
405 if (cache_for
== FTFONT_CACHE_FOR_FACE
)
408 && FT_Init_FreeType (&ft_library
) != 0)
410 if (FT_New_Face (ft_library
, filename
, index
, &cache_data
->ft_face
)
416 FcPattern
*pat
= NULL
;
417 FcFontSet
*fontset
= NULL
;
418 FcObjectSet
*objset
= NULL
;
419 FcCharSet
*charset
= NULL
;
421 pat
= FcPatternBuild (0, FC_FILE
, FcTypeString
, (FcChar8
*) filename
,
422 FC_INDEX
, FcTypeInteger
, index
, NULL
);
425 objset
= FcObjectSetBuild (FC_CHARSET
, FC_STYLE
, NULL
);
428 fontset
= FcFontList (NULL
, pat
, objset
);
431 if (fontset
&& fontset
->nfont
> 0
432 && (FcPatternGetCharSet (fontset
->fonts
[0], FC_CHARSET
, 0,
435 cache_data
->fc_charset
= FcCharSetCopy (charset
);
437 cache_data
->fc_charset
= FcCharSetCreate ();
441 FcFontSetDestroy (fontset
);
443 FcObjectSetDestroy (objset
);
445 FcPatternDestroy (pat
);
452 ftfont_get_fc_charset (entity
)
455 Lisp_Object val
, cache
;
456 struct ftfont_cache_data
*cache_data
;
458 cache
= ftfont_lookup_cache (entity
, FTFONT_CACHE_FOR_CHARSET
);
460 cache_data
= XSAVE_VALUE (val
)->pointer
;
461 return cache_data
->fc_charset
;
466 ftfont_get_otf (ftfont_info
)
467 struct ftfont_info
*ftfont_info
;
471 if (ftfont_info
->otf
)
472 return ftfont_info
->otf
;
473 if (! ftfont_info
->maybe_otf
)
475 otf
= OTF_open_ft_face (ftfont_info
->ft_size
->face
);
476 if (! otf
|| OTF_get_table (otf
, "head") < 0)
480 ftfont_info
->maybe_otf
= 0;
483 ftfont_info
->otf
= otf
;
486 #endif /* HAVE_LIBOTF */
488 static Lisp_Object ftfont_get_cache
P_ ((FRAME_PTR
));
489 static Lisp_Object ftfont_list
P_ ((Lisp_Object
, Lisp_Object
));
490 static Lisp_Object ftfont_match
P_ ((Lisp_Object
, Lisp_Object
));
491 static Lisp_Object ftfont_list_family
P_ ((Lisp_Object
));
492 static Lisp_Object ftfont_open
P_ ((FRAME_PTR
, Lisp_Object
, int));
493 static void ftfont_close
P_ ((FRAME_PTR
, struct font
*));
494 static int ftfont_has_char
P_ ((Lisp_Object
, int));
495 static unsigned ftfont_encode_char
P_ ((struct font
*, int));
496 static int ftfont_text_extents
P_ ((struct font
*, unsigned *, int,
497 struct font_metrics
*));
498 static int ftfont_get_bitmap
P_ ((struct font
*, unsigned,
499 struct font_bitmap
*, int));
500 static int ftfont_anchor_point
P_ ((struct font
*, unsigned, int,
502 static Lisp_Object ftfont_otf_capability
P_ ((struct font
*));
503 static Lisp_Object ftfont_shape
P_ ((Lisp_Object
));
505 #ifdef HAVE_OTF_GET_VARIATION_GLYPHS
506 static int ftfont_variation_glyphs
P_ ((struct font
*, int c
,
507 unsigned variations
[256]));
508 #endif /* HAVE_OTF_GET_VARIATION_GLYPHS */
510 struct font_driver ftfont_driver
=
513 0, /* case insensitive */
518 NULL
, /* free_entity */
521 /* We can't draw a text without device dependent functions. */
522 NULL
, /* prepare_face */
523 NULL
, /* done_face */
527 /* We can't draw a text without device dependent functions. */
530 NULL
, /* get_bitmap */
531 NULL
, /* free_bitmap */
532 NULL
, /* get_outline */
535 ftfont_otf_capability
,
536 #else /* not HAVE_LIBOTF */
538 #endif /* not HAVE_LIBOTF */
539 NULL
, /* otf_drive */
540 NULL
, /* start_for_frame */
541 NULL
, /* end_for_frame */
542 #if defined (HAVE_M17N_FLT) && defined (HAVE_LIBOTF)
544 #else /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */
546 #endif /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */
549 #ifdef HAVE_OTF_GET_VARIATION_GLYPHS
550 ftfont_variation_glyphs
,
555 ftfont_filter_properties
, /* filter_properties */
558 extern Lisp_Object QCname
;
564 return freetype_font_cache
;
568 ftfont_get_charset (registry
)
569 Lisp_Object registry
;
571 char *str
= (char *) SDATA (SYMBOL_NAME (registry
));
572 char *re
= alloca (SBYTES (SYMBOL_NAME (registry
)) * 2 + 1);
576 for (i
= j
= 0; i
< SBYTES (SYMBOL_NAME (registry
)); i
++, j
++)
580 else if (str
[i
] == '*')
587 regexp
= make_unibyte_string (re
, j
);
588 for (i
= 0; fc_charset_table
[i
].name
; i
++)
589 if (fast_c_string_match_ignore_case (regexp
, fc_charset_table
[i
].name
) >= 0)
591 if (! fc_charset_table
[i
].name
)
593 if (! fc_charset_table
[i
].fc_charset
)
595 FcCharSet
*charset
= FcCharSetCreate ();
596 int *uniquifier
= fc_charset_table
[i
].uniquifier
;
600 for (j
= 0; uniquifier
[j
]; j
++)
601 if (! FcCharSetAddChar (charset
, uniquifier
[j
]))
603 FcCharSetDestroy (charset
);
606 fc_charset_table
[i
].fc_charset
= charset
;
614 unsigned int script_tag
, langsys_tag
;
616 unsigned int *features
[2];
619 #define OTF_SYM_TAG(SYM, TAG) \
621 unsigned char *p = SDATA (SYMBOL_NAME (SYM)); \
622 TAG = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; \
625 #define OTF_TAG_STR(TAG, P) \
627 (P)[0] = (char) (TAG >> 24); \
628 (P)[1] = (char) ((TAG >> 16) & 0xFF); \
629 (P)[2] = (char) ((TAG >> 8) & 0xFF); \
630 (P)[3] = (char) (TAG & 0xFF); \
634 #define OTF_TAG_SYM(SYM, TAG) \
638 OTF_TAG_STR (TAG, str); \
639 (SYM) = font_intern_prop (str, 4, 1); \
643 static struct OpenTypeSpec
*
644 ftfont_get_open_type_spec (Lisp_Object otf_spec
)
646 struct OpenTypeSpec
*spec
= malloc (sizeof (struct OpenTypeSpec
));
652 spec
->script
= XCAR (otf_spec
);
653 if (! NILP (spec
->script
))
655 OTF_SYM_TAG (spec
->script
, spec
->script_tag
);
656 val
= assq_no_quit (spec
->script
, Votf_script_alist
);
657 if (CONSP (val
) && SYMBOLP (XCDR (val
)))
658 spec
->script
= XCDR (val
);
663 spec
->script_tag
= 0x44464C54; /* "DFLT" */
664 otf_spec
= XCDR (otf_spec
);
665 val
= XCAR (otf_spec
);
667 OTF_SYM_TAG (val
, spec
->langsys_tag
);
669 spec
->langsys_tag
= 0;
670 spec
->nfeatures
[0] = spec
->nfeatures
[1] = 0;
671 for (i
= 0; i
< 2; i
++)
675 otf_spec
= XCDR (otf_spec
);
678 val
= XCAR (otf_spec
);
682 spec
->features
[i
] = malloc (sizeof (int) * XINT (len
));
683 if (! spec
->features
[i
])
685 if (i
> 0 && spec
->features
[0])
686 free (spec
->features
[0]);
690 for (j
= 0, negative
= 0; CONSP (val
); val
= XCDR (val
))
692 if (NILP (XCAR (val
)))
698 OTF_SYM_TAG (XCAR (val
), tag
);
699 spec
->features
[i
][j
++] = negative
? tag
& 0x80000000 : tag
;
702 spec
->nfeatures
[i
] = j
;
707 static FcPattern
*ftfont_spec_pattern
P_ ((Lisp_Object
, char *,
708 struct OpenTypeSpec
**,
712 ftfont_spec_pattern (spec
, otlayout
, otspec
, langname
)
715 struct OpenTypeSpec
**otspec
;
718 Lisp_Object tmp
, extra
;
719 FcPattern
*pattern
= NULL
;
720 FcCharSet
*charset
= NULL
;
721 FcLangSet
*langset
= NULL
;
725 Lisp_Object script
= Qnil
;
726 Lisp_Object registry
;
729 if ((n
= FONT_SLANT_NUMERIC (spec
)) >= 0
731 /* Fontconfig doesn't support reverse-italic/obligue. */
734 if (INTEGERP (AREF (spec
, FONT_DPI_INDEX
)))
735 dpi
= XINT (AREF (spec
, FONT_DPI_INDEX
));
736 if (INTEGERP (AREF (spec
, FONT_AVGWIDTH_INDEX
))
737 && XINT (AREF (spec
, FONT_AVGWIDTH_INDEX
)) == 0)
740 registry
= AREF (spec
, FONT_REGISTRY_INDEX
);
742 || EQ (registry
, Qascii_0
)
743 || EQ (registry
, Qiso10646_1
)
744 || EQ (registry
, Qunicode_bmp
))
750 fc_charset_idx
= ftfont_get_charset (registry
);
751 if (fc_charset_idx
< 0)
753 charset
= fc_charset_table
[fc_charset_idx
].fc_charset
;
754 *langname
= fc_charset_table
[fc_charset_idx
].lang
;
755 lang
= (FcChar8
*) *langname
;
758 langset
= FcLangSetCreate ();
761 FcLangSetAdd (langset
, lang
);
766 for (extra
= AREF (spec
, FONT_EXTRA_INDEX
);
767 CONSP (extra
); extra
= XCDR (extra
))
769 Lisp_Object key
, val
;
771 key
= XCAR (XCAR (extra
)), val
= XCDR (XCAR (extra
));
774 else if (EQ (key
, QClang
))
777 langset
= FcLangSetCreate ();
782 if (! FcLangSetAdd (langset
, SYMBOL_FcChar8 (val
)))
786 for (; CONSP (val
); val
= XCDR (val
))
787 if (SYMBOLP (XCAR (val
))
788 && ! FcLangSetAdd (langset
, SYMBOL_FcChar8 (XCAR (val
))))
791 else if (EQ (key
, QCotf
))
793 *otspec
= ftfont_get_open_type_spec (val
);
796 strcat (otlayout
, "otlayout:");
797 OTF_TAG_STR ((*otspec
)->script_tag
, otlayout
+ 9);
798 script
= (*otspec
)->script
;
800 else if (EQ (key
, QCscript
))
802 else if (EQ (key
, QCscalable
))
803 scalable
= ! NILP (val
);
806 if (! NILP (script
) && ! charset
)
808 Lisp_Object chars
= assq_no_quit (script
, Vscript_representative_chars
);
810 if (CONSP (chars
) && CONSP (CDR (chars
)))
812 charset
= FcCharSetCreate ();
815 for (chars
= XCDR (chars
); CONSP (chars
); chars
= XCDR (chars
))
816 if (CHARACTERP (XCAR (chars
))
817 && ! FcCharSetAddChar (charset
, XUINT (XCAR (chars
))))
822 pattern
= FcPatternCreate ();
825 tmp
= AREF (spec
, FONT_FOUNDRY_INDEX
);
827 && ! FcPatternAddString (pattern
, FC_FOUNDRY
, SYMBOL_FcChar8 (tmp
)))
829 tmp
= AREF (spec
, FONT_FAMILY_INDEX
);
831 && ! FcPatternAddString (pattern
, FC_FAMILY
, SYMBOL_FcChar8 (tmp
)))
834 && ! FcPatternAddCharSet (pattern
, FC_CHARSET
, charset
))
837 && ! FcPatternAddLangSet (pattern
, FC_LANG
, langset
))
840 && ! FcPatternAddDouble (pattern
, FC_DPI
, dpi
))
843 && ! FcPatternAddBool (pattern
, FC_SCALABLE
, scalable
? FcTrue
: FcFalse
))
849 /* We come here because of unexpected error in fontconfig API call
850 (usually insufficient memory). */
853 FcPatternDestroy (pattern
);
858 if ((*otspec
)->nfeatures
[0] > 0)
859 free ((*otspec
)->features
[0]);
860 if ((*otspec
)->nfeatures
[1] > 0)
861 free ((*otspec
)->features
[1]);
867 if (langset
) FcLangSetDestroy (langset
);
868 if (charset
&& fc_charset_idx
< 0) FcCharSetDestroy (charset
);
873 ftfont_list (frame
, spec
)
874 Lisp_Object frame
, spec
;
876 Lisp_Object val
= Qnil
, family
, adstyle
;
879 FcFontSet
*fontset
= NULL
;
880 FcObjectSet
*objset
= NULL
;
882 Lisp_Object chars
= Qnil
;
884 char otlayout
[15]; /* For "otlayout:XXXX" */
885 struct OpenTypeSpec
*otspec
= NULL
;
887 char *langname
= NULL
;
889 if (! fc_initialized
)
895 pattern
= ftfont_spec_pattern (spec
, otlayout
, &otspec
, &langname
);
898 if (FcPatternGetCharSet (pattern
, FC_CHARSET
, 0, &charset
) != FcResultMatch
)
900 val
= assq_no_quit (QCscript
, AREF (spec
, FONT_EXTRA_INDEX
));
903 val
= assq_no_quit (XCDR (val
), Vscript_representative_chars
);
904 if (CONSP (val
) && VECTORP (XCDR (val
)))
909 if (INTEGERP (AREF (spec
, FONT_SPACING_INDEX
)))
910 spacing
= XINT (AREF (spec
, FONT_SPACING_INDEX
));
911 family
= AREF (spec
, FONT_FAMILY_INDEX
);
914 Lisp_Object resolved
;
916 resolved
= ftfont_resolve_generic_family (family
, pattern
);
917 if (! NILP (resolved
))
919 FcPatternDel (pattern
, FC_FAMILY
);
920 if (! FcPatternAddString (pattern
, FC_FAMILY
,
921 SYMBOL_FcChar8 (resolved
)))
925 adstyle
= AREF (spec
, FONT_ADSTYLE_INDEX
);
926 if (! NILP (adstyle
) && SBYTES (SYMBOL_NAME (adstyle
)) == 0)
928 objset
= FcObjectSetBuild (FC_FOUNDRY
, FC_FAMILY
, FC_WEIGHT
, FC_SLANT
,
929 FC_WIDTH
, FC_PIXEL_SIZE
, FC_SPACING
, FC_SCALABLE
,
930 FC_STYLE
, FC_FILE
, FC_INDEX
,
933 #endif /* FC_CAPABILITY */
941 FcObjectSetAdd (objset
, FC_CHARSET
);
943 fontset
= FcFontList (NULL
, pattern
, objset
);
944 if (! fontset
|| fontset
->nfont
== 0)
947 /* Need fix because this finds any fonts. */
948 if (fontset
->nfont
== 0 && ! NILP (family
))
950 /* Try maching with configuration. For instance, the
951 configuration may specify "Nimbus Mono L" as an alias of
953 FcPattern
*pat
= FcPatternBuild (0, FC_FAMILY
, FcTypeString
,
954 SYMBOL_FcChar8 (family
), NULL
);
957 if (FcConfigSubstitute (NULL
, pat
, FcMatchPattern
) == FcTrue
)
960 FcPatternGetString (pat
, FC_FAMILY
, i
, &fam
) == FcResultMatch
;
963 FcPatternDel (pattern
, FC_FAMILY
);
964 FcPatternAddString (pattern
, FC_FAMILY
, fam
);
965 FcFontSetDestroy (fontset
);
966 fontset
= FcFontList (NULL
, pattern
, objset
);
967 if (fontset
&& fontset
->nfont
> 0)
973 for (i
= 0; i
< fontset
->nfont
; i
++)
981 if ((FcPatternGetInteger (fontset
->fonts
[i
], FC_SPACING
, 0, &this)
992 if (FcPatternGetString (fontset
->fonts
[i
], FC_CAPABILITY
, 0, &this)
994 || ! strstr ((char *) this, otlayout
))
997 #endif /* FC_CAPABILITY */
1004 if (FcPatternGetString (fontset
->fonts
[i
], FC_FILE
, 0, &file
)
1007 otf
= OTF_open ((char *) file
);
1010 if (OTF_check_features (otf
, 1,
1011 otspec
->script_tag
, otspec
->langsys_tag
,
1012 otspec
->features
[0],
1013 otspec
->nfeatures
[0]) != 1
1014 || OTF_check_features (otf
, 0,
1015 otspec
->script_tag
, otspec
->langsys_tag
,
1016 otspec
->features
[1],
1017 otspec
->nfeatures
[1]) != 1)
1020 #endif /* HAVE_LIBOTF */
1021 if (VECTORP (chars
))
1025 if (FcPatternGetCharSet (fontset
->fonts
[i
], FC_CHARSET
, 0, &charset
)
1028 for (j
= 0; j
< ASIZE (chars
); j
++)
1029 if (NATNUMP (AREF (chars
, j
))
1030 && FcCharSetHasChar (charset
, XFASTINT (AREF (chars
, j
))))
1032 if (j
== ASIZE (chars
))
1035 if (! NILP (adstyle
) || langname
)
1037 Lisp_Object this_adstyle
= get_adstyle_property (fontset
->fonts
[i
]);
1039 if (! NILP (adstyle
)
1040 && (NILP (this_adstyle
)
1041 || xstrcasecmp (SDATA (SYMBOL_NAME (adstyle
)),
1042 SDATA (SYMBOL_NAME (this_adstyle
))) != 0))
1045 && ! NILP (this_adstyle
)
1046 && xstrcasecmp (langname
, SDATA (SYMBOL_NAME (this_adstyle
))))
1049 entity
= ftfont_pattern_entity (fontset
->fonts
[i
],
1050 AREF (spec
, FONT_EXTRA_INDEX
));
1051 if (! NILP (entity
))
1052 val
= Fcons (entity
, val
);
1054 val
= Fnreverse (val
);
1058 /* We come here because of unexpected error in fontconfig API call
1059 (usually insufficient memory). */
1063 FONT_ADD_LOG ("ftfont-list", spec
, val
);
1064 if (objset
) FcObjectSetDestroy (objset
);
1065 if (fontset
) FcFontSetDestroy (fontset
);
1066 if (pattern
) FcPatternDestroy (pattern
);
1071 ftfont_match (frame
, spec
)
1072 Lisp_Object frame
, spec
;
1074 Lisp_Object entity
= Qnil
;
1075 FcPattern
*pattern
, *match
= NULL
;
1077 char otlayout
[15]; /* For "otlayout:XXXX" */
1078 struct OpenTypeSpec
*otspec
= NULL
;
1079 char *langname
= NULL
;
1081 if (! fc_initialized
)
1087 pattern
= ftfont_spec_pattern (spec
, otlayout
, &otspec
, &langname
);
1091 if (INTEGERP (AREF (spec
, FONT_SIZE_INDEX
)))
1095 value
.type
= FcTypeDouble
;
1096 value
.u
.d
= XINT (AREF (spec
, FONT_SIZE_INDEX
));
1097 FcPatternAdd (pattern
, FC_PIXEL_SIZE
, value
, FcFalse
);
1099 if (FcConfigSubstitute (NULL
, pattern
, FcMatchPattern
) == FcTrue
)
1101 FcDefaultSubstitute (pattern
);
1102 match
= FcFontMatch (NULL
, pattern
, &result
);
1105 entity
= ftfont_pattern_entity (match
, AREF (spec
, FONT_EXTRA_INDEX
));
1106 FcPatternDestroy (match
);
1107 if (! NILP (AREF (spec
, FONT_FAMILY_INDEX
))
1108 && NILP (assq_no_quit (AREF (spec
, FONT_FAMILY_INDEX
),
1109 ftfont_generic_family_list
))
1110 && NILP (Fstring_equal (AREF (spec
, FONT_FAMILY_INDEX
),
1111 AREF (entity
, FONT_FAMILY_INDEX
))))
1115 FcPatternDestroy (pattern
);
1117 FONT_ADD_LOG ("ftfont-match", spec
, entity
);
1122 ftfont_list_family (frame
)
1125 Lisp_Object list
= Qnil
;
1126 FcPattern
*pattern
= NULL
;
1127 FcFontSet
*fontset
= NULL
;
1128 FcObjectSet
*objset
= NULL
;
1131 if (! fc_initialized
)
1137 pattern
= FcPatternCreate ();
1140 objset
= FcObjectSetBuild (FC_FAMILY
, NULL
);
1143 fontset
= FcFontList (NULL
, pattern
, objset
);
1147 for (i
= 0; i
< fontset
->nfont
; i
++)
1149 FcPattern
*pat
= fontset
->fonts
[i
];
1152 if (FcPatternGetString (pat
, FC_FAMILY
, 0, &str
) == FcResultMatch
)
1153 list
= Fcons (intern ((char *) str
), list
);
1157 if (objset
) FcObjectSetDestroy (objset
);
1158 if (fontset
) FcFontSetDestroy (fontset
);
1159 if (pattern
) FcPatternDestroy (pattern
);
1166 ftfont_open (f
, entity
, pixel_size
)
1171 struct ftfont_info
*ftfont_info
;
1173 struct ftfont_cache_data
*cache_data
;
1177 Lisp_Object val
, filename
, index
, cache
, font_object
;
1184 val
= assq_no_quit (QCfont_entity
, AREF (entity
, FONT_EXTRA_INDEX
));
1188 cache
= ftfont_lookup_cache (entity
, FTFONT_CACHE_FOR_FACE
);
1191 filename
= XCAR (val
);
1194 cache_data
= XSAVE_VALUE (XCDR (cache
))->pointer
;
1195 ft_face
= cache_data
->ft_face
;
1196 if (XSAVE_VALUE (val
)->integer
> 0)
1198 /* FT_Face in this cache is already used by the different size. */
1199 if (FT_New_Size (ft_face
, &ft_size
) != 0)
1201 if (FT_Activate_Size (ft_size
) != 0)
1203 FT_Done_Size (ft_size
);
1207 XSAVE_VALUE (val
)->integer
++;
1208 size
= XINT (AREF (entity
, FONT_SIZE_INDEX
));
1211 if (FT_Set_Pixel_Sizes (ft_face
, size
, size
) != 0)
1213 if (XSAVE_VALUE (val
)->integer
== 0)
1214 FT_Done_Face (ft_face
);
1218 font_object
= font_make_object (VECSIZE (struct ftfont_info
), entity
, size
);
1219 ASET (font_object
, FONT_TYPE_INDEX
, Qfreetype
);
1220 len
= font_unparse_xlfd (entity
, size
, name
, 256);
1222 ASET (font_object
, FONT_NAME_INDEX
, make_string (name
, len
));
1223 len
= font_unparse_fcname (entity
, size
, name
, 256);
1225 ASET (font_object
, FONT_FULLNAME_INDEX
, make_string (name
, len
));
1227 ASET (font_object
, FONT_FULLNAME_INDEX
,
1228 AREF (font_object
, FONT_NAME_INDEX
));
1229 ASET (font_object
, FONT_FILE_INDEX
, filename
);
1230 ASET (font_object
, FONT_FORMAT_INDEX
, ftfont_font_format (NULL
, filename
));
1231 font
= XFONT_OBJECT (font_object
);
1232 ftfont_info
= (struct ftfont_info
*) font
;
1233 ftfont_info
->ft_size
= ft_face
->size
;
1234 ftfont_info
->index
= XINT (index
);
1236 ftfont_info
->maybe_otf
= ft_face
->face_flags
& FT_FACE_FLAG_SFNT
;
1237 ftfont_info
->otf
= NULL
;
1238 #endif /* HAVE_LIBOTF */
1239 font
->pixel_size
= size
;
1240 font
->driver
= &ftfont_driver
;
1241 font
->encoding_charset
= font
->repertory_charset
= -1;
1243 upEM
= ft_face
->units_per_EM
;
1244 scalable
= (INTEGERP (AREF (entity
, FONT_AVGWIDTH_INDEX
))
1245 && XINT (AREF (entity
, FONT_AVGWIDTH_INDEX
)) == 0);
1248 font
->ascent
= ft_face
->ascender
* size
/ upEM
;
1249 font
->descent
= - ft_face
->descender
* size
/ upEM
;
1250 font
->height
= ft_face
->height
* size
/ upEM
;
1254 font
->ascent
= ft_face
->size
->metrics
.ascender
>> 6;
1255 font
->descent
= - ft_face
->size
->metrics
.descender
>> 6;
1256 font
->height
= ft_face
->size
->metrics
.height
>> 6;
1258 if (INTEGERP (AREF (entity
, FONT_SPACING_INDEX
)))
1259 spacing
= XINT (AREF (entity
, FONT_SPACING_INDEX
));
1261 spacing
= FC_PROPORTIONAL
;
1262 if (spacing
!= FC_PROPORTIONAL
)
1263 font
->min_width
= font
->average_width
= font
->space_width
1264 = (scalable
? ft_face
->max_advance_width
* size
/ upEM
1265 : ft_face
->size
->metrics
.max_advance
>> 6);
1270 font
->min_width
= font
->average_width
= font
->space_width
= 0;
1271 for (i
= 32, n
= 0; i
< 127; i
++)
1272 if (FT_Load_Char (ft_face
, i
, FT_LOAD_DEFAULT
) == 0)
1274 int this_width
= ft_face
->glyph
->metrics
.horiAdvance
>> 6;
1277 && (! font
->min_width
|| font
->min_width
> this_width
))
1278 font
->min_width
= this_width
;
1280 font
->space_width
= this_width
;
1281 font
->average_width
+= this_width
;
1285 font
->average_width
/= n
;
1288 font
->baseline_offset
= 0;
1289 font
->relative_compose
= 0;
1290 font
->default_ascent
= 0;
1291 font
->vertical_centering
= 0;
1294 font
->underline_position
= -ft_face
->underline_position
* size
/ upEM
;
1295 font
->underline_thickness
= ft_face
->underline_thickness
* size
/ upEM
;
1299 font
->underline_position
= -1;
1300 font
->underline_thickness
= 0;
1307 ftfont_close (f
, font
)
1311 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1312 Lisp_Object val
, cache
;
1314 val
= Fcons (font
->props
[FONT_FILE_INDEX
], make_number (ftfont_info
->index
));
1315 cache
= ftfont_lookup_cache (val
, FTFONT_CACHE_FOR_FACE
);
1316 xassert (CONSP (cache
));
1318 (XSAVE_VALUE (val
)->integer
)--;
1319 if (XSAVE_VALUE (val
)->integer
== 0)
1321 struct ftfont_cache_data
*cache_data
= XSAVE_VALUE (val
)->pointer
;
1323 FT_Done_Face (cache_data
->ft_face
);
1325 if (ftfont_info
->otf
)
1326 OTF_close (ftfont_info
->otf
);
1328 cache_data
->ft_face
= NULL
;
1331 FT_Done_Size (ftfont_info
->ft_size
);
1335 ftfont_has_char (font
, c
)
1339 struct charset
*cs
= NULL
;
1341 if (EQ (AREF (font
, FONT_ADSTYLE_INDEX
), Qja
)
1342 && charset_jisx0208
>= 0)
1343 cs
= CHARSET_FROM_ID (charset_jisx0208
);
1344 else if (EQ (AREF (font
, FONT_ADSTYLE_INDEX
), Qko
)
1345 && charset_ksc5601
>= 0)
1346 cs
= CHARSET_FROM_ID (charset_ksc5601
);
1348 return (ENCODE_CHAR (cs
, c
) != CHARSET_INVALID_CODE (cs
));
1350 if (FONT_ENTITY_P (font
))
1352 FcCharSet
*charset
= ftfont_get_fc_charset (font
);
1354 return (FcCharSetHasChar (charset
, c
) == FcTrue
);
1358 struct ftfont_info
*ftfont_info
;
1360 ftfont_info
= (struct ftfont_info
*) XFONT_OBJECT (font
);
1361 return (FT_Get_Char_Index (ftfont_info
->ft_size
->face
, (FT_ULong
) c
)
1367 ftfont_encode_char (font
, c
)
1371 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1372 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1373 FT_ULong charcode
= c
;
1374 FT_UInt code
= FT_Get_Char_Index (ft_face
, charcode
);
1376 return (code
> 0 ? code
: FONT_INVALID_CODE
);
1380 ftfont_text_extents (font
, code
, nglyphs
, metrics
)
1384 struct font_metrics
*metrics
;
1386 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1387 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1391 if (ftfont_info
->ft_size
!= ft_face
->size
)
1392 FT_Activate_Size (ftfont_info
->ft_size
);
1394 bzero (metrics
, sizeof (struct font_metrics
));
1395 for (i
= 0, first
= 1; i
< nglyphs
; i
++)
1397 if (FT_Load_Glyph (ft_face
, code
[i
], FT_LOAD_DEFAULT
) == 0)
1399 FT_Glyph_Metrics
*m
= &ft_face
->glyph
->metrics
;
1405 metrics
->lbearing
= m
->horiBearingX
>> 6;
1406 metrics
->rbearing
= (m
->horiBearingX
+ m
->width
) >> 6;
1407 metrics
->ascent
= m
->horiBearingY
>> 6;
1408 metrics
->descent
= (m
->height
- m
->horiBearingY
) >> 6;
1414 if (metrics
->lbearing
> width
+ (m
->horiBearingX
>> 6))
1415 metrics
->lbearing
= width
+ (m
->horiBearingX
>> 6);
1416 if (metrics
->rbearing
1417 < width
+ ((m
->horiBearingX
+ m
->width
) >> 6))
1419 = width
+ ((m
->horiBearingX
+ m
->width
) >> 6);
1420 if (metrics
->ascent
< (m
->horiBearingY
>> 6))
1421 metrics
->ascent
= m
->horiBearingY
>> 6;
1422 if (metrics
->descent
> ((m
->height
- m
->horiBearingY
) >> 6))
1423 metrics
->descent
= (m
->height
- m
->horiBearingY
) >> 6;
1425 width
+= m
->horiAdvance
>> 6;
1429 width
+= font
->space_width
;
1433 metrics
->width
= width
;
1439 ftfont_get_bitmap (font
, code
, bitmap
, bits_per_pixel
)
1442 struct font_bitmap
*bitmap
;
1445 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1446 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1447 FT_Int32 load_flags
= FT_LOAD_RENDER
;
1449 if (ftfont_info
->ft_size
!= ft_face
->size
)
1450 FT_Activate_Size (ftfont_info
->ft_size
);
1451 if (bits_per_pixel
== 1)
1453 #ifdef FT_LOAD_TARGET_MONO
1454 load_flags
|= FT_LOAD_TARGET_MONO
;
1456 load_flags
|= FT_LOAD_MONOCHROME
;
1459 else if (bits_per_pixel
!= 8)
1460 /* We don't support such a rendering. */
1463 if (FT_Load_Glyph (ft_face
, code
, load_flags
) != 0)
1465 bitmap
->bits_per_pixel
1466 = (ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_MONO
? 1
1467 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_GRAY
? 8
1468 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_LCD
? 8
1469 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_LCD_V
? 8
1471 if (bitmap
->bits_per_pixel
< 0)
1472 /* We don't suport that kind of pixel mode. */
1474 bitmap
->rows
= ft_face
->glyph
->bitmap
.rows
;
1475 bitmap
->width
= ft_face
->glyph
->bitmap
.width
;
1476 bitmap
->pitch
= ft_face
->glyph
->bitmap
.pitch
;
1477 bitmap
->buffer
= ft_face
->glyph
->bitmap
.buffer
;
1478 bitmap
->left
= ft_face
->glyph
->bitmap_left
;
1479 bitmap
->top
= ft_face
->glyph
->bitmap_top
;
1480 bitmap
->advance
= ft_face
->glyph
->metrics
.horiAdvance
>> 6;
1481 bitmap
->extra
= NULL
;
1487 ftfont_anchor_point (font
, code
, index
, x
, y
)
1493 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1494 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1496 if (ftfont_info
->ft_size
!= ft_face
->size
)
1497 FT_Activate_Size (ftfont_info
->ft_size
);
1498 if (FT_Load_Glyph (ft_face
, code
, FT_LOAD_DEFAULT
) != 0)
1500 if (ft_face
->glyph
->format
!= FT_GLYPH_FORMAT_OUTLINE
)
1502 if (index
>= ft_face
->glyph
->outline
.n_points
)
1504 *x
= ft_face
->glyph
->outline
.points
[index
].x
;
1505 *y
= ft_face
->glyph
->outline
.points
[index
].y
;
1512 ftfont_otf_features (gsub_gpos
)
1513 OTF_GSUB_GPOS
*gsub_gpos
;
1515 Lisp_Object scripts
, langsyses
, features
, sym
;
1518 for (scripts
= Qnil
, i
= gsub_gpos
->ScriptList
.ScriptCount
- 1; i
>= 0; i
--)
1520 OTF_Script
*otf_script
= gsub_gpos
->ScriptList
.Script
+ i
;
1522 for (langsyses
= Qnil
, j
= otf_script
->LangSysCount
- 1; j
>= -1; j
--)
1524 OTF_LangSys
*otf_langsys
;
1527 otf_langsys
= otf_script
->LangSys
+ j
;
1528 else if (otf_script
->DefaultLangSysOffset
)
1529 otf_langsys
= &otf_script
->DefaultLangSys
;
1533 for (features
= Qnil
, k
= otf_langsys
->FeatureCount
- 1; k
>= 0; k
--)
1535 l
= otf_langsys
->FeatureIndex
[k
];
1536 if (l
>= gsub_gpos
->FeatureList
.FeatureCount
)
1538 OTF_TAG_SYM (sym
, gsub_gpos
->FeatureList
.Feature
[l
].FeatureTag
);
1539 features
= Fcons (sym
, features
);
1542 OTF_TAG_SYM (sym
, otf_script
->LangSysRecord
[j
].LangSysTag
);
1545 langsyses
= Fcons (Fcons (sym
, features
), langsyses
);
1548 OTF_TAG_SYM (sym
, gsub_gpos
->ScriptList
.Script
[i
].ScriptTag
);
1549 scripts
= Fcons (Fcons (sym
, langsyses
), scripts
);
1557 ftfont_otf_capability (font
)
1560 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1561 OTF
*otf
= ftfont_get_otf (ftfont_info
);
1562 Lisp_Object gsub_gpos
;
1566 gsub_gpos
= Fcons (Qnil
, Qnil
);
1567 if (OTF_get_table (otf
, "GSUB") == 0
1568 && otf
->gsub
->FeatureList
.FeatureCount
> 0)
1569 XSETCAR (gsub_gpos
, ftfont_otf_features (otf
->gsub
));
1570 if (OTF_get_table (otf
, "GPOS") == 0
1571 && otf
->gpos
->FeatureList
.FeatureCount
> 0)
1572 XSETCDR (gsub_gpos
, ftfont_otf_features (otf
->gpos
));
1576 #ifdef HAVE_M17N_FLT
1587 ftfont_get_glyph_id (font
, gstring
, from
, to
)
1589 MFLTGlyphString
*gstring
;
1592 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1593 FT_Face ft_face
= flt_font_ft
->ft_face
;
1596 for (g
= gstring
->glyphs
+ from
; from
< to
; g
++, from
++)
1599 FT_UInt code
= FT_Get_Char_Index (ft_face
, g
->code
);
1601 g
->code
= code
> 0 ? code
: FONT_INVALID_CODE
;
1608 ftfont_get_metrics (font
, gstring
, from
, to
)
1610 MFLTGlyphString
*gstring
;
1613 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1614 FT_Face ft_face
= flt_font_ft
->ft_face
;
1617 for (g
= gstring
->glyphs
+ from
; from
< to
; g
++, from
++)
1620 if (g
->code
!= FONT_INVALID_CODE
)
1622 FT_Glyph_Metrics
*m
;
1624 if (FT_Load_Glyph (ft_face
, g
->code
, FT_LOAD_DEFAULT
) != 0)
1626 m
= &ft_face
->glyph
->metrics
;
1628 g
->lbearing
= m
->horiBearingX
;
1629 g
->rbearing
= m
->horiBearingX
+ m
->width
;
1630 g
->ascent
= m
->horiBearingY
;
1631 g
->descent
= m
->height
- m
->horiBearingY
;
1632 g
->xadv
= m
->horiAdvance
;
1637 g
->rbearing
= g
->xadv
= flt_font_ft
->font
->space_width
<< 6;
1638 g
->ascent
= flt_font_ft
->font
->ascent
<< 6;
1639 g
->descent
= flt_font_ft
->font
->descent
<< 6;
1648 ftfont_check_otf (MFLTFont
*font
, MFLTOtfSpec
*spec
)
1650 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1651 OTF
*otf
= flt_font_ft
->otf
;
1655 for (i
= 0; i
< 2; i
++)
1657 if (! spec
->features
[i
])
1659 for (n
= 0; spec
->features
[i
][n
]; n
++);
1660 tags
= alloca (sizeof (OTF_Tag
) * n
);
1661 for (n
= 0, negative
= 0; spec
->features
[i
][n
]; n
++)
1663 if (spec
->features
[i
][n
] == 0xFFFFFFFF)
1666 tags
[n
- 1] = spec
->features
[i
][n
] | 0x80000000;
1668 tags
[n
] = spec
->features
[i
][n
];
1670 if (n
- negative
> 0
1671 && OTF_check_features (otf
, i
== 0, spec
->script
, spec
->langsys
,
1672 tags
, n
- negative
) != 1)
1678 #define DEVICE_DELTA(table, size) \
1679 (((size) >= (table).StartSize && (size) <= (table).EndSize) \
1680 ? (table).DeltaValue[(size) - (table).StartSize] << 6 \
1684 adjust_anchor (FT_Face ft_face
, OTF_Anchor
*anchor
,
1685 unsigned code
, int x_ppem
, int y_ppem
, int *x
, int *y
)
1687 if (anchor
->AnchorFormat
== 2)
1689 FT_Outline
*outline
;
1690 int ap
= anchor
->f
.f1
.AnchorPoint
;
1692 FT_Load_Glyph (ft_face
, (FT_UInt
) code
, FT_LOAD_MONOCHROME
);
1693 outline
= &ft_face
->glyph
->outline
;
1694 if (ap
< outline
->n_points
)
1696 *x
= outline
->points
[ap
].x
<< 6;
1697 *y
= outline
->points
[ap
].y
<< 6;
1700 else if (anchor
->AnchorFormat
== 3)
1702 if (anchor
->f
.f2
.XDeviceTable
.offset
1703 && anchor
->f
.f2
.XDeviceTable
.DeltaValue
)
1704 *x
+= DEVICE_DELTA (anchor
->f
.f2
.XDeviceTable
, x_ppem
);
1705 if (anchor
->f
.f2
.YDeviceTable
.offset
1706 && anchor
->f
.f2
.YDeviceTable
.DeltaValue
)
1707 *y
+= DEVICE_DELTA (anchor
->f
.f2
.YDeviceTable
, y_ppem
);
1711 static OTF_GlyphString otf_gstring
;
1714 setup_otf_gstring (int size
)
1716 if (otf_gstring
.size
== 0)
1718 otf_gstring
.glyphs
= (OTF_Glyph
*) xmalloc (sizeof (OTF_Glyph
) * size
);
1719 otf_gstring
.size
= size
;
1721 else if (otf_gstring
.size
< size
)
1723 otf_gstring
.glyphs
= xrealloc (otf_gstring
.glyphs
,
1724 sizeof (OTF_Glyph
) * size
);
1725 otf_gstring
.size
= size
;
1727 otf_gstring
.used
= size
;
1728 memset (otf_gstring
.glyphs
, 0, sizeof (OTF_Glyph
) * size
);
1733 ftfont_drive_otf (font
, spec
, in
, from
, to
, out
, adjustment
)
1736 MFLTGlyphString
*in
;
1738 MFLTGlyphString
*out
;
1739 MFLTGlyphAdjustment
*adjustment
;
1741 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1742 FT_Face ft_face
= flt_font_ft
->ft_face
;
1743 OTF
*otf
= flt_font_ft
->otf
;
1744 int len
= to
- from
;
1747 char script
[5], *langsys
= NULL
;
1748 char *gsub_features
= NULL
, *gpos_features
= NULL
;
1752 OTF_tag_name (spec
->script
, script
);
1755 langsys
= alloca (5);
1756 OTF_tag_name (spec
->langsys
, langsys
);
1758 for (i
= 0; i
< 2; i
++)
1762 if (spec
->features
[i
] && spec
->features
[i
][1] != 0xFFFFFFFF)
1764 for (j
= 0; spec
->features
[i
][j
]; j
++);
1766 p
= gsub_features
= alloca (6 * j
);
1768 p
= gpos_features
= alloca (6 * j
);
1769 for (j
= 0; spec
->features
[i
][j
]; j
++)
1771 if (spec
->features
[i
][j
] == 0xFFFFFFFF)
1772 *p
++ = '*', *p
++ = ',';
1775 OTF_tag_name (spec
->features
[i
][j
], p
);
1784 setup_otf_gstring (len
);
1785 for (i
= 0; i
< len
; i
++)
1787 otf_gstring
.glyphs
[i
].c
= in
->glyphs
[from
+ i
].c
;
1788 otf_gstring
.glyphs
[i
].glyph_id
= in
->glyphs
[from
+ i
].code
;
1791 OTF_drive_gdef (otf
, &otf_gstring
);
1796 if (OTF_drive_gsub (otf
, &otf_gstring
, script
, langsys
, gsub_features
)
1799 if (out
->allocated
< out
->used
+ otf_gstring
.used
)
1801 for (i
= 0, otfg
= otf_gstring
.glyphs
; i
< otf_gstring
.used
; )
1804 int min_from
, max_to
;
1807 g
= out
->glyphs
+ out
->used
;
1808 *g
= in
->glyphs
[from
+ otfg
->f
.index
.from
];
1809 if (g
->code
!= otfg
->glyph_id
)
1812 g
->code
= otfg
->glyph_id
;
1818 if (otfg
->f
.index
.from
< otfg
->f
.index
.to
)
1820 /* OTFG substitutes multiple glyphs in IN. */
1821 for (j
= from
+ otfg
->f
.index
.from
+ 1;
1822 j
<= from
+ otfg
->f
.index
.to
; j
++)
1824 if (min_from
> in
->glyphs
[j
].from
)
1825 min_from
= in
->glyphs
[j
].from
;
1826 if (max_to
< in
->glyphs
[j
].to
)
1827 max_to
= in
->glyphs
[j
].to
;
1832 for (i
++, otfg
++; (i
< otf_gstring
.used
1833 && otfg
->f
.index
.from
== otfg
[-1].f
.index
.from
);
1836 g
= out
->glyphs
+ out
->used
;
1837 *g
= in
->glyphs
[from
+ otfg
->f
.index
.to
];
1838 if (g
->code
!= otfg
->glyph_id
)
1841 g
->code
= otfg
->glyph_id
;
1850 if (out
->allocated
< out
->used
+ len
)
1852 for (i
= 0; i
< len
; i
++)
1853 out
->glyphs
[out
->used
++] = in
->glyphs
[from
+ i
];
1858 MFLTGlyph
*base
= NULL
, *mark
= NULL
, *g
;
1859 int x_ppem
, y_ppem
, x_scale
, y_scale
;
1861 if (OTF_drive_gpos (otf
, &otf_gstring
, script
, langsys
, gpos_features
)
1865 x_ppem
= ft_face
->size
->metrics
.x_ppem
;
1866 y_ppem
= ft_face
->size
->metrics
.y_ppem
;
1867 x_scale
= ft_face
->size
->metrics
.x_scale
;
1868 y_scale
= ft_face
->size
->metrics
.y_scale
;
1870 for (i
= 0, otfg
= otf_gstring
.glyphs
, g
= out
->glyphs
+ gidx
;
1871 i
< otf_gstring
.used
; i
++, otfg
++, g
++)
1875 if (! otfg
->glyph_id
)
1877 switch (otfg
->positioning_type
)
1881 case 1: /* Single */
1884 int format
= otfg
->f
.f1
.format
;
1886 if (format
& OTF_XPlacement
)
1888 = otfg
->f
.f1
.value
->XPlacement
* x_scale
/ 0x10000;
1889 if (format
& OTF_XPlaDevice
)
1891 += DEVICE_DELTA (otfg
->f
.f1
.value
->XPlaDevice
, x_ppem
);
1892 if (format
& OTF_YPlacement
)
1894 = - (otfg
->f
.f1
.value
->YPlacement
* y_scale
/ 0x10000);
1895 if (format
& OTF_YPlaDevice
)
1897 -= DEVICE_DELTA (otfg
->f
.f1
.value
->YPlaDevice
, y_ppem
);
1898 if (format
& OTF_XAdvance
)
1900 += otfg
->f
.f1
.value
->XAdvance
* x_scale
/ 0x10000;
1901 if (format
& OTF_XAdvDevice
)
1903 += DEVICE_DELTA (otfg
->f
.f1
.value
->XAdvDevice
, x_ppem
);
1904 if (format
& OTF_YAdvance
)
1906 += otfg
->f
.f1
.value
->YAdvance
* y_scale
/ 0x10000;
1907 if (format
& OTF_YAdvDevice
)
1909 += DEVICE_DELTA (otfg
->f
.f1
.value
->YAdvDevice
, y_ppem
);
1910 adjustment
[i
].set
= 1;
1913 case 3: /* Cursive */
1914 /* Not yet supported. */
1916 case 4: /* Mark-to-Base */
1917 case 5: /* Mark-to-Ligature */
1921 goto label_adjust_anchor
;
1922 default: /* i.e. case 6 Mark-to-Mark */
1927 label_adjust_anchor
:
1929 int base_x
, base_y
, mark_x
, mark_y
;
1930 int this_from
, this_to
;
1932 base_x
= otfg
->f
.f4
.base_anchor
->XCoordinate
* x_scale
/ 0x10000;
1933 base_y
= otfg
->f
.f4
.base_anchor
->YCoordinate
* y_scale
/ 0x10000;
1934 mark_x
= otfg
->f
.f4
.mark_anchor
->XCoordinate
* x_scale
/ 0x10000;
1935 mark_y
= otfg
->f
.f4
.mark_anchor
->YCoordinate
* y_scale
/ 0x10000;
1937 if (otfg
->f
.f4
.base_anchor
->AnchorFormat
!= 1)
1938 adjust_anchor (ft_face
, otfg
->f
.f4
.base_anchor
,
1939 prev
->code
, x_ppem
, y_ppem
, &base_x
, &base_y
);
1940 if (otfg
->f
.f4
.mark_anchor
->AnchorFormat
!= 1)
1941 adjust_anchor (ft_face
, otfg
->f
.f4
.mark_anchor
, g
->code
,
1942 x_ppem
, y_ppem
, &mark_x
, &mark_y
);
1943 adjustment
[i
].xoff
= (base_x
- mark_x
);
1944 adjustment
[i
].yoff
= - (base_y
- mark_y
);
1945 adjustment
[i
].back
= (g
- prev
);
1946 adjustment
[i
].xadv
= 0;
1947 adjustment
[i
].advance_is_absolute
= 1;
1948 adjustment
[i
].set
= 1;
1949 this_from
= g
->from
;
1951 for (j
= 0; prev
+ j
< g
; j
++)
1953 if (this_from
> prev
[j
].from
)
1954 this_from
= prev
[j
].from
;
1955 if (this_to
< prev
[j
].to
)
1956 this_to
= prev
[j
].to
;
1958 for (; prev
<= g
; prev
++)
1960 prev
->from
= this_from
;
1965 if (otfg
->GlyphClass
== OTF_GlyphClass0
)
1967 else if (otfg
->GlyphClass
== OTF_GlyphClassMark
)
1976 if (out
->allocated
< out
->used
+ len
)
1978 font
->get_metrics (font
, in
, from
, to
);
1979 memcpy (out
->glyphs
+ out
->used
, in
->glyphs
+ from
,
1980 sizeof (MFLTGlyph
) * len
);
1985 static MFLTGlyphString gstring
;
1987 static int m17n_flt_initialized
;
1989 extern Lisp_Object QCfamily
;
1992 ftfont_shape_by_flt (lgstring
, font
, ft_face
, otf
)
1993 Lisp_Object lgstring
;
1998 EMACS_UINT len
= LGSTRING_GLYPH_LEN (lgstring
);
2000 struct MFLTFontFT flt_font_ft
;
2002 int with_variation_selector
= 0;
2004 if (! m17n_flt_initialized
)
2007 m17n_flt_initialized
= 1;
2010 for (i
= 0; i
< len
; i
++)
2012 Lisp_Object g
= LGSTRING_GLYPH (lgstring
, i
);
2017 c
= LGLYPH_CHAR (g
);
2018 if (CHAR_VARIATION_SELECTOR_P (c
))
2019 with_variation_selector
++;
2022 if (with_variation_selector
)
2024 setup_otf_gstring (len
);
2025 for (i
= 0; i
< len
; i
++)
2027 Lisp_Object g
= LGSTRING_GLYPH (lgstring
, i
);
2029 otf_gstring
.glyphs
[i
].c
= LGLYPH_CHAR (g
);
2030 otf_gstring
.glyphs
[i
].f
.index
.from
= LGLYPH_FROM (g
);
2031 otf_gstring
.glyphs
[i
].f
.index
.to
= LGLYPH_TO (g
);
2033 OTF_drive_cmap (otf
, &otf_gstring
);
2034 for (i
= 0; i
< otf_gstring
.used
; i
++)
2036 OTF_Glyph
*otfg
= otf_gstring
.glyphs
+ i
;
2037 Lisp_Object g0
= LGSTRING_GLYPH (lgstring
, otfg
->f
.index
.from
);
2038 Lisp_Object g1
= LGSTRING_GLYPH (lgstring
, otfg
->f
.index
.to
);
2040 LGLYPH_SET_CODE (g0
, otfg
->glyph_id
);
2041 LGLYPH_SET_TO (g0
, LGLYPH_TO (g1
));
2042 LGSTRING_SET_GLYPH (lgstring
, i
, g0
);
2044 if (len
> otf_gstring
.used
)
2046 len
= otf_gstring
.used
;
2047 LGSTRING_SET_GLYPH (lgstring
, len
, Qnil
);
2051 if (gstring
.allocated
== 0)
2053 gstring
.allocated
= len
* 2;
2054 gstring
.glyph_size
= sizeof (MFLTGlyph
);
2055 gstring
.glyphs
= xmalloc (sizeof (MFLTGlyph
) * gstring
.allocated
);
2057 else if (gstring
.allocated
< len
* 2)
2059 gstring
.allocated
= len
* 2;
2060 gstring
.glyphs
= xrealloc (gstring
.glyphs
,
2061 sizeof (MFLTGlyph
) * gstring
.allocated
);
2063 memset (gstring
.glyphs
, 0, sizeof (MFLTGlyph
) * len
);
2064 for (i
= 0; i
< len
; i
++)
2066 Lisp_Object g
= LGSTRING_GLYPH (lgstring
, i
);
2068 gstring
.glyphs
[i
].c
= LGLYPH_CHAR (g
);
2069 if (with_variation_selector
)
2071 gstring
.glyphs
[i
].code
= LGLYPH_CODE (g
);
2072 gstring
.glyphs
[i
].encoded
= 1;
2080 Lisp_Object family
= Ffont_get (LGSTRING_FONT (lgstring
), QCfamily
);
2083 flt_font_ft
.flt_font
.family
= Mnil
;
2085 flt_font_ft
.flt_font
.family
2086 = msymbol ((char *) SDATA (Fdowncase (SYMBOL_NAME (family
))));
2088 flt_font_ft
.flt_font
.x_ppem
= ft_face
->size
->metrics
.x_ppem
;
2089 flt_font_ft
.flt_font
.y_ppem
= ft_face
->size
->metrics
.y_ppem
;
2090 flt_font_ft
.flt_font
.get_glyph_id
= ftfont_get_glyph_id
;
2091 flt_font_ft
.flt_font
.get_metrics
= ftfont_get_metrics
;
2092 flt_font_ft
.flt_font
.check_otf
= ftfont_check_otf
;
2093 flt_font_ft
.flt_font
.drive_otf
= ftfont_drive_otf
;
2094 flt_font_ft
.flt_font
.internal
= NULL
;
2095 flt_font_ft
.font
= font
;
2096 flt_font_ft
.ft_face
= ft_face
;
2097 flt_font_ft
.otf
= otf
;
2099 && gstring
.glyphs
[1].c
>= 0x300 && gstring
.glyphs
[1].c
<= 0x36F)
2100 /* A little bit ad hoc. Perhaps, shaper must get script and
2101 language information, and select a proper flt for them
2103 flt
= mflt_get (msymbol ("combining"));
2104 for (i
= 0; i
< 3; i
++)
2106 int result
= mflt_run (&gstring
, 0, len
, &flt_font_ft
.flt_font
, flt
);
2109 gstring
.allocated
+= gstring
.allocated
;
2110 gstring
.glyphs
= xrealloc (gstring
.glyphs
,
2111 sizeof (MFLTGlyph
) * gstring
.allocated
);
2113 if (gstring
.used
> LGSTRING_GLYPH_LEN (lgstring
))
2115 for (i
= 0; i
< gstring
.used
; i
++)
2117 MFLTGlyph
*g
= gstring
.glyphs
+ i
;
2119 g
->from
= LGLYPH_FROM (LGSTRING_GLYPH (lgstring
, g
->from
));
2120 g
->to
= LGLYPH_TO (LGSTRING_GLYPH (lgstring
, g
->to
));
2123 for (i
= 0; i
< gstring
.used
; i
++)
2125 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
2126 MFLTGlyph
*g
= gstring
.glyphs
+ i
;
2130 lglyph
= Fmake_vector (make_number (LGLYPH_SIZE
), Qnil
);
2131 LGSTRING_SET_GLYPH (lgstring
, i
, lglyph
);
2133 LGLYPH_SET_FROM (lglyph
, g
->from
);
2134 LGLYPH_SET_TO (lglyph
, g
->to
);
2135 LGLYPH_SET_CHAR (lglyph
, g
->c
);
2136 LGLYPH_SET_CODE (lglyph
, g
->code
);
2137 LGLYPH_SET_WIDTH (lglyph
, g
->xadv
>> 6);
2138 LGLYPH_SET_LBEARING (lglyph
, g
->lbearing
>> 6);
2139 LGLYPH_SET_RBEARING (lglyph
, g
->rbearing
>> 6);
2140 LGLYPH_SET_ASCENT (lglyph
, g
->ascent
>> 6);
2141 LGLYPH_SET_DESCENT (lglyph
, g
->descent
>> 6);
2146 vec
= Fmake_vector (make_number (3), Qnil
);
2147 ASET (vec
, 0, make_number (g
->xoff
>> 6));
2148 ASET (vec
, 1, make_number (g
->yoff
>> 6));
2149 ASET (vec
, 2, make_number (g
->xadv
>> 6));
2150 LGLYPH_SET_ADJUSTMENT (lglyph
, vec
);
2153 return make_number (i
);
2157 ftfont_shape (lgstring
)
2158 Lisp_Object lgstring
;
2161 struct ftfont_info
*ftfont_info
;
2164 CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring
), font
);
2165 ftfont_info
= (struct ftfont_info
*) font
;
2166 otf
= ftfont_get_otf (ftfont_info
);
2168 return make_number (0);
2169 return ftfont_shape_by_flt (lgstring
, font
, ftfont_info
->ft_size
->face
, otf
);
2172 #endif /* HAVE_M17N_FLT */
2174 #ifdef HAVE_OTF_GET_VARIATION_GLYPHS
2177 ftfont_variation_glyphs (font
, c
, variations
)
2180 unsigned variations
[256];
2182 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
2183 OTF
*otf
= ftfont_get_otf (ftfont_info
);
2187 return OTF_get_variation_glyphs (otf
, c
, variations
);
2190 #endif /* HAVE_OTF_GET_VARIATION_GLYPHS */
2191 #endif /* HAVE_LIBOTF */
2194 ftfont_font_format (FcPattern
*pattern
, Lisp_Object filename
)
2198 #ifdef FC_FONTFORMAT
2201 if (FcPatternGetString (pattern
, FC_FONTFORMAT
, 0, &str
) != FcResultMatch
)
2203 if (strcmp ((char *) str
, "TrueType") == 0)
2204 return intern ("truetype");
2205 if (strcmp ((char *) str
, "Type 1") == 0)
2206 return intern ("type1");
2207 if (strcmp ((char *) str
, "PCF") == 0)
2208 return intern ("pcf");
2209 if (strcmp ((char *) str
, "BDF") == 0)
2210 return intern ("bdf");
2212 #endif /* FC_FONTFORMAT */
2213 if (STRINGP (filename
))
2215 int len
= SBYTES (filename
);
2219 str
= (FcChar8
*) (SDATA (filename
) + len
- 4);
2220 if (xstrcasecmp ((char *) str
, ".ttf") == 0)
2221 return intern ("truetype");
2222 if (xstrcasecmp ((char *) str
, ".pfb") == 0)
2223 return intern ("type1");
2224 if (xstrcasecmp ((char *) str
, ".pcf") == 0)
2225 return intern ("pcf");
2226 if (xstrcasecmp ((char *) str
, ".bdf") == 0)
2227 return intern ("bdf");
2230 return intern ("unknown");
2233 static const char *ftfont_booleans
[] = {
2246 static const char *ftfont_non_booleans
[] = {
2278 ftfont_filter_properties (font
, alist
)
2285 /* Set boolean values to Qt or Qnil */
2286 for (i
= 0; ftfont_booleans
[i
] != NULL
; ++i
)
2287 for (it
= alist
; ! NILP (it
); it
= XCDR (it
))
2289 Lisp_Object key
= XCAR (XCAR (it
));
2290 Lisp_Object val
= XCDR (XCAR (it
));
2291 char *keystr
= SDATA (SYMBOL_NAME (key
));
2293 if (strcmp (ftfont_booleans
[i
], keystr
) == 0)
2295 char *str
= SYMBOLP (val
) ? SDATA (SYMBOL_NAME (val
)) : NULL
;
2296 if (INTEGERP (val
)) str
= XINT (val
) != 0 ? "true" : "false";
2297 if (str
== NULL
) str
= "true";
2300 if (strcmp ("false", str
) == 0 || strcmp ("False", str
) == 0
2301 || strcmp ("FALSE", str
) == 0 || strcmp ("FcFalse", str
) == 0
2302 || strcmp ("off", str
) == 0 || strcmp ("OFF", str
) == 0
2303 || strcmp ("Off", str
) == 0)
2305 Ffont_put (font
, key
, val
);
2309 for (i
= 0; ftfont_non_booleans
[i
] != NULL
; ++i
)
2310 for (it
= alist
; ! NILP (it
); it
= XCDR (it
))
2312 Lisp_Object key
= XCAR (XCAR (it
));
2313 Lisp_Object val
= XCDR (XCAR (it
));
2314 char *keystr
= SDATA (SYMBOL_NAME (key
));
2315 if (strcmp (ftfont_non_booleans
[i
], keystr
) == 0)
2316 Ffont_put (font
, key
, val
);
2324 DEFSYM (Qfreetype
, "freetype");
2325 DEFSYM (Qmonospace
, "monospace");
2326 DEFSYM (Qsans_serif
, "sans-serif");
2327 DEFSYM (Qserif
, "serif");
2328 DEFSYM (Qmono
, "mono");
2329 DEFSYM (Qsans
, "sans");
2330 DEFSYM (Qsans__serif
, "sans serif");
2332 staticpro (&freetype_font_cache
);
2333 freetype_font_cache
= Fcons (Qt
, Qnil
);
2335 staticpro (&ftfont_generic_family_list
);
2336 ftfont_generic_family_list
2337 = Fcons (Fcons (Qmonospace
, Qt
),
2338 Fcons (Fcons (Qsans_serif
, Qt
),
2339 Fcons (Fcons (Qsans
, Qt
), Qnil
)));
2341 staticpro (&ft_face_cache
);
2342 ft_face_cache
= Qnil
;
2344 ftfont_driver
.type
= Qfreetype
;
2345 register_font_driver (&ftfont_driver
, NULL
);
2348 /* arch-tag: 7cfa432c-33a6-4988-83d2-a82ed8604aca
2349 (do not change this comment) */