1 /* ftfont.c -- FreeType font driver.
2 Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
3 Copyright (C) 2006, 2007, 2008
4 National Institute of Advanced Industrial Science and Technology (AIST)
5 Registration Number H13PRO009
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/>. */
25 #include <fontconfig/fontconfig.h>
26 #include <fontconfig/fcfreetype.h>
29 #include "dispextern.h"
31 #include "blockinput.h"
32 #include "character.h"
39 /* Symbolic type of this font-driver. */
40 Lisp_Object Qfreetype
;
42 /* Fontconfig's generic families and their aliases. */
43 static Lisp_Object Qmonospace
, Qsans_serif
, Qserif
, Qmono
, Qsans
, Qsans__serif
;
45 /* Flag to tell if FcInit is already called or not. */
46 static int fc_initialized
;
48 /* Handle to a FreeType library instance. */
49 static FT_Library ft_library
;
51 /* Cache for FreeType fonts. */
52 static Lisp_Object freetype_font_cache
;
54 /* Cache for FT_Face */
55 static Lisp_Object ft_face_cache
;
57 /* The actual structure for FreeType font that can be casted to struct
66 int maybe_otf
; /* Flag to tell if this may be OTF or not. */
68 #endif /* HAVE_LIBOTF */
71 static Lisp_Object ftfont_pattern_entity
P_ ((FcPattern
*, Lisp_Object
,
74 static Lisp_Object ftfont_resolve_generic_family
P_ ((Lisp_Object
));
75 Lisp_Object ftfont_font_format
P_ ((FcPattern
*));
77 #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM))
83 /* characters to distinguish the charset from the others */
85 /* set in syms_of_ftfont */
88 FcCharSet
*fc_charset
;
89 } fc_charset_table
[] =
90 { { "iso-8859-1", { 0x00A0, 0x00A1, 0x00B4, 0x00BC, 0x00D0 }, -1 },
91 { "iso-8859-2", { 0x00A0, 0x010E }},
92 { "iso-8859-3", { 0x00A0, 0x0108 }},
93 { "iso-8859-4", { 0x00A0, 0x00AF, 0x0128, 0x0156, 0x02C7 }},
94 { "iso-8859-5", { 0x00A0, 0x0401 }},
95 { "iso-8859-6", { 0x00A0, 0x060C }},
96 { "iso-8859-7", { 0x00A0, 0x0384 }},
97 { "iso-8859-8", { 0x00A0, 0x05D0 }},
98 { "iso-8859-9", { 0x00A0, 0x00A1, 0x00BC, 0x011E }},
99 { "iso-8859-10", { 0x00A0, 0x00D0, 0x0128, 0x2015 }},
100 { "iso-8859-11", { 0x00A0, 0x0E01 }},
101 { "iso-8859-13", { 0x00A0, 0x201C }},
102 { "iso-8859-14", { 0x00A0, 0x0174 }},
103 { "iso-8859-15", { 0x00A0, 0x00A1, 0x00D0, 0x0152 }},
104 { "iso-8859-16", { 0x00A0, 0x0218}},
105 { "chinese-gb2312", { 0x4E13 }},
106 { "big5", { 0xF6B1 }},
107 { "japanese-jisx0208", { 0x4E55 }},
108 { "korean-ksc5601", { 0xAC00 }},
109 { "chinese-cns11643-1", { 0xFE32 }},
110 { "chinese-cns11643-2", { 0x4E33, 0x7934 }},
111 { "chinese-cns11643-3", { 0x201A9 }},
112 { "chinese-cns11643-4", { 0x20057 }},
113 { "chinese-cns11643-5", { 0x20000 }},
114 { "chinese-cns11643-6", { 0x20003 }},
115 { "chinese-cns11643-7", { 0x20055 }},
116 { "chinese-gbk", { 0x4E06 }},
117 { "japanese-jisx0212", { 0x4E44 }},
118 { "japanese-jisx0213-1", { 0xFA10 }},
119 { "japanese-jisx0213-2", { 0xFA49 }},
120 { "japanese-jisx0213.2004-1", { 0x20B9F }},
121 { "viscii", { 0x1EA0, 0x1EAE, 0x1ED2 }},
122 { "tis620", { 0x0E01 }},
123 { "windows-1251", { 0x0401, 0x0490 }},
124 { "koi8-r", { 0x0401, 0x2219 }},
125 { "mule-lao", { 0x0E81 }},
129 extern Lisp_Object Qc
, Qm
, Qp
, Qd
;
132 ftfont_pattern_entity (p
, registry
, extra
, fc_charset_idx
)
134 Lisp_Object registry
, extra
;
143 if (FcPatternGetString (p
, FC_FILE
, 0, (FcChar8
**) &file
) != FcResultMatch
)
146 entity
= font_make_entity ();
148 ASET (entity
, FONT_TYPE_INDEX
, Qfreetype
);
149 ASET (entity
, FONT_REGISTRY_INDEX
, registry
);
151 if (FcPatternGetString (p
, FC_FOUNDRY
, 0, (FcChar8
**) &str
) == FcResultMatch
)
152 ASET (entity
, FONT_FOUNDRY_INDEX
, font_intern_prop (str
, strlen (str
), 1));
153 if (FcPatternGetString (p
, FC_FAMILY
, 0, (FcChar8
**) &str
) == FcResultMatch
)
154 ASET (entity
, FONT_FAMILY_INDEX
, font_intern_prop (str
, strlen (str
), 1));
155 if (FcPatternGetInteger (p
, FC_WEIGHT
, 0, &numeric
) == FcResultMatch
)
157 if (numeric
>= FC_WEIGHT_REGULAR
&& numeric
< FC_WEIGHT_MEDIUM
)
158 numeric
= FC_WEIGHT_MEDIUM
;
159 FONT_SET_STYLE (entity
, FONT_WEIGHT_INDEX
, make_number (numeric
));
161 if (FcPatternGetInteger (p
, FC_SLANT
, 0, &numeric
) == FcResultMatch
)
164 FONT_SET_STYLE (entity
, FONT_SLANT_INDEX
, make_number (numeric
));
166 if (FcPatternGetInteger (p
, FC_WIDTH
, 0, &numeric
) == FcResultMatch
)
168 FONT_SET_STYLE (entity
, FONT_WIDTH_INDEX
, make_number (numeric
));
170 if (FcPatternGetDouble (p
, FC_PIXEL_SIZE
, 0, &dbl
) == FcResultMatch
)
171 ASET (entity
, FONT_SIZE_INDEX
, make_number (dbl
));
173 ASET (entity
, FONT_SIZE_INDEX
, make_number (0));
174 if (FcPatternGetInteger (p
, FC_SPACING
, 0, &numeric
) == FcResultMatch
)
175 ASET (entity
, FONT_SPACING_INDEX
, make_number (numeric
));
176 if (FcPatternGetDouble (p
, FC_DPI
, 0, &dbl
) == FcResultMatch
)
179 ASET (entity
, FONT_DPI_INDEX
, make_number (dpi
));
181 if (FcPatternGetBool (p
, FC_SCALABLE
, 0, &b
) == FcResultMatch
183 ASET (entity
, FONT_AVGWIDTH_INDEX
, make_number (0));
185 ASET (entity
, FONT_EXTRA_INDEX
, Fcopy_sequence (extra
));
186 font_put_extra (entity
, QCfont_entity
,
187 Fcons (make_unibyte_string ((char *) file
,
188 strlen ((char *) file
)),
189 make_number (fc_charset_idx
)));
194 static Lisp_Object ftfont_generic_family_list
;
197 ftfont_resolve_generic_family (family
)
201 FcPattern
*pattern
= NULL
, *match
;
204 family
= Fintern (Fdowncase (SYMBOL_NAME (family
)), Qnil
);
205 if (EQ (family
, Qmono
))
207 else if (EQ (family
, Qsans
) || EQ (family
, Qsans__serif
))
208 family
= Qsans_serif
;
209 slot
= assq_no_quit (family
, ftfont_generic_family_list
);
212 if (! EQ (XCDR (slot
), Qt
))
214 pattern
= FcPatternBuild (NULL
, FC_FAMILY
, FcTypeString
,
215 SYMBOL_FcChar8 (family
), (char *) 0);
218 FcConfigSubstitute (NULL
, pattern
, FcMatchPattern
);
219 FcDefaultSubstitute (pattern
);
220 match
= FcFontMatch (NULL
, pattern
, &result
);
225 if (FcPatternGetString (match
, FC_FAMILY
, 0, &fam
) == FcResultMatch
)
226 family
= intern ((char *) fam
);
230 XSETCDR (slot
, family
);
232 if (match
) FcPatternDestroy (match
);
233 if (pattern
) FcPatternDestroy (pattern
);
238 ftfont_lookup_cache (filename
)
239 Lisp_Object filename
;
241 Lisp_Object cache
, val
;
243 cache
= assoc_no_quit (filename
, ft_face_cache
);
246 val
= make_save_value (NULL
, 0);
247 cache
= Fcons (filename
, val
);
248 ft_face_cache
= Fcons (cache
, ft_face_cache
);
252 if (! XSAVE_VALUE (val
)->pointer
)
257 && FT_Init_FreeType (&ft_library
) != 0)
259 if (FT_New_Face (ft_library
, (char *) SDATA (filename
), 0, &ft_face
) != 0)
261 XSAVE_VALUE (val
)->pointer
= ft_face
;
266 static Lisp_Object ftfont_get_cache
P_ ((FRAME_PTR
));
267 static Lisp_Object ftfont_list
P_ ((Lisp_Object
, Lisp_Object
));
268 static Lisp_Object ftfont_match
P_ ((Lisp_Object
, Lisp_Object
));
269 static Lisp_Object ftfont_list_family
P_ ((Lisp_Object
));
270 static Lisp_Object 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,
280 static Lisp_Object ftfont_shape
P_ ((Lisp_Object
));
282 struct font_driver ftfont_driver
=
285 0, /* case insensitive */
293 /* We can't draw a text without device dependent functions. */
299 /* We can't draw a text without device dependent functions. */
310 #if defined (HAVE_M17N_FLT) && defined (HAVE_LIBOTF)
312 #else /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */
314 #endif /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */
317 extern Lisp_Object QCname
;
323 return freetype_font_cache
;
327 ftfont_get_charset (registry
)
328 Lisp_Object registry
;
330 struct charset
*encoding
;
333 if (font_registry_charsets (registry
, &encoding
, NULL
) < 0)
335 if (fc_charset_table
[0].charset_id
< 0)
336 /* Setup charset_id field of all elements. */
337 for (i
= 0; fc_charset_table
[i
].name
; i
++)
339 Lisp_Object sym
= intern (fc_charset_table
[i
].name
);
342 fc_charset_table
[i
].charset_id
= XINT (CHARSET_SYMBOL_ID (sym
));
344 fc_charset_table
[i
].charset_id
= -1;
347 for (i
= 0; fc_charset_table
[i
].name
; i
++)
348 if (encoding
->id
== fc_charset_table
[i
].charset_id
)
350 if (! fc_charset_table
[i
].name
)
352 if (! fc_charset_table
[i
].fc_charset
)
354 FcCharSet
*charset
= FcCharSetCreate ();
355 int *uniquifier
= fc_charset_table
[i
].uniquifier
;
359 for (j
= 0; uniquifier
[j
]; j
++)
360 if (! FcCharSetAddChar (charset
, uniquifier
[j
]))
362 FcCharSetDestroy (charset
);
365 fc_charset_table
[i
].fc_charset
= charset
;
373 unsigned int script_tag
, langsys_tag
;
375 unsigned int *features
[2];
378 #define OTF_SYM_TAG(SYM, TAG) \
380 unsigned char *p = SDATA (SYMBOL_NAME (SYM)); \
381 TAG = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; \
384 #define OTF_TAG_STR(TAG, P) \
386 (P)[0] = (char) (TAG >> 24); \
387 (P)[1] = (char) ((TAG >> 16) & 0xFF); \
388 (P)[2] = (char) ((TAG >> 8) & 0xFF); \
389 (P)[3] = (char) (TAG & 0xFF); \
393 static struct OpenTypeSpec
*
394 ftfont_get_open_type_spec (Lisp_Object otf_spec
)
396 struct OpenTypeSpec
*spec
= malloc (sizeof (struct OpenTypeSpec
));
402 spec
->script
= XCAR (otf_spec
);
403 if (! NILP (spec
->script
))
405 OTF_SYM_TAG (spec
->script
, spec
->script_tag
);
406 val
= assq_no_quit (spec
->script
, Votf_script_alist
);
407 if (CONSP (val
) && SYMBOLP (XCDR (val
)))
408 spec
->script
= XCDR (val
);
413 spec
->script_tag
= 0x44464C54; /* "DFLT" */
414 otf_spec
= XCDR (otf_spec
);
415 val
= XCAR (otf_spec
);
417 OTF_SYM_TAG (val
, spec
->langsys_tag
);
419 spec
->langsys_tag
= 0;
420 spec
->nfeatures
[0] = spec
->nfeatures
[1] = 0;
421 for (i
= 0; i
< 2; i
++)
425 otf_spec
= XCDR (otf_spec
);
428 val
= XCAR (otf_spec
);
432 spec
->features
[i
] = malloc (sizeof (int) * XINT (len
));
433 if (! spec
->features
[i
])
435 if (i
> 0 && spec
->features
[0])
436 free (spec
->features
[0]);
440 for (j
= 0, negative
= 0; CONSP (val
); val
= XCDR (val
))
442 if (NILP (XCAR (val
)))
448 OTF_SYM_TAG (XCAR (val
), tag
);
449 spec
->features
[i
][j
++] = negative
? tag
& 0x80000000 : tag
;
452 spec
->nfeatures
[i
] = j
;
457 static FcPattern
*ftfont_spec_pattern
P_ ((Lisp_Object
, int *, char *,
458 struct OpenTypeSpec
**));
461 ftfont_spec_pattern (spec
, fc_charset_idx
, otlayout
, otspec
)
465 struct OpenTypeSpec
**otspec
;
467 Lisp_Object tmp
, extra
;
468 FcPattern
*pattern
= NULL
;
469 FcCharSet
*charset
= NULL
;
470 FcLangSet
*langset
= NULL
;
474 Lisp_Object script
= Qnil
;
475 Lisp_Object registry
;
477 if (! NILP (AREF (spec
, FONT_ADSTYLE_INDEX
))
478 && SBYTES (SYMBOL_NAME (AREF (spec
, FONT_ADSTYLE_INDEX
))) > 0)
479 /* Fontconfig doesn't support adstyle property. */
481 if ((n
= FONT_SLANT_NUMERIC (spec
)) >= 0
483 /* Fontconfig doesn't support reverse-italic/obligue. */
486 if (INTEGERP (AREF (spec
, FONT_DPI_INDEX
)))
487 dpi
= XINT (AREF (spec
, FONT_DPI_INDEX
));
488 if (INTEGERP (AREF (spec
, FONT_AVGWIDTH_INDEX
))
489 && XINT (AREF (spec
, FONT_AVGWIDTH_INDEX
)) == 0)
492 registry
= AREF (spec
, FONT_REGISTRY_INDEX
);
494 || EQ (registry
, Qascii_0
)
495 || EQ (registry
, Qiso10646_1
)
496 || EQ (registry
, Qunicode_bmp
)
497 || EQ (registry
, Qunicode_sip
))
498 *fc_charset_idx
= -1;
501 *fc_charset_idx
= ftfont_get_charset (registry
);
502 if (*fc_charset_idx
< 0)
504 charset
= fc_charset_table
[*fc_charset_idx
].fc_charset
;
508 for (extra
= AREF (spec
, FONT_EXTRA_INDEX
);
509 CONSP (extra
); extra
= XCDR (extra
))
511 Lisp_Object key
, val
;
513 key
= XCAR (XCAR (extra
)), val
= XCDR (XCAR (extra
));
516 else if (EQ (key
, QClang
))
518 langset
= FcLangSetCreate ();
523 if (! FcLangSetAdd (langset
, SYMBOL_FcChar8 (val
)))
527 for (; CONSP (val
); val
= XCDR (val
))
528 if (SYMBOLP (XCAR (val
))
529 && ! FcLangSetAdd (langset
, SYMBOL_FcChar8 (XCAR (val
))))
532 else if (EQ (key
, QCotf
))
534 *otspec
= ftfont_get_open_type_spec (val
);
537 strcat (otlayout
, "otlayout:");
538 OTF_TAG_STR ((*otspec
)->script_tag
, otlayout
+ 9);
539 script
= (*otspec
)->script
;
541 else if (EQ (key
, QCscript
))
543 else if (EQ (key
, QCscalable
))
544 scalable
= ! NILP (val
);
547 if (! NILP (script
) && ! charset
)
549 Lisp_Object chars
= assq_no_quit (script
, Vscript_representative_chars
);
553 charset
= FcCharSetCreate ();
556 for (chars
= XCDR (chars
); CONSP (chars
); chars
= XCDR (chars
))
557 if (CHARACTERP (XCAR (chars
))
558 && ! FcCharSetAddChar (charset
, XUINT (XCAR (chars
))))
563 pattern
= FcPatternCreate ();
566 tmp
= AREF (spec
, FONT_FOUNDRY_INDEX
);
568 && ! FcPatternAddString (pattern
, FC_FOUNDRY
, SYMBOL_FcChar8 (tmp
)))
570 tmp
= AREF (spec
, FONT_FAMILY_INDEX
);
572 && ! FcPatternAddString (pattern
, FC_FAMILY
, SYMBOL_FcChar8 (tmp
)))
575 && ! FcPatternAddCharSet (pattern
, FC_CHARSET
, charset
))
578 && ! FcPatternAddLangSet (pattern
, FC_LANG
, langset
))
581 && ! FcPatternAddDouble (pattern
, FC_DPI
, dpi
))
584 && ! FcPatternAddBool (pattern
, FC_SCALABLE
, scalable
? FcTrue
: FcFalse
))
589 /* We come here because of unexpected error in fontconfig API call
590 (usually insufficient memory). */
593 FcPatternDestroy (pattern
);
598 if ((*otspec
)->nfeatures
[0] > 0)
599 free ((*otspec
)->features
[0]);
600 if ((*otspec
)->nfeatures
[1] > 0)
601 free ((*otspec
)->features
[1]);
607 if (langset
) FcLangSetDestroy (langset
);
608 if (charset
&& *fc_charset_idx
< 0) FcCharSetDestroy (charset
);
613 ftfont_list (frame
, spec
)
614 Lisp_Object frame
, spec
;
616 Lisp_Object val
= Qnil
, registry
, family
;
619 FcFontSet
*fontset
= NULL
;
620 FcObjectSet
*objset
= NULL
;
622 char otlayout
[15]; /* For "otlayout:XXXX" */
623 struct OpenTypeSpec
*otspec
= NULL
;
626 if (! fc_initialized
)
632 pattern
= ftfont_spec_pattern (spec
, &fc_charset_idx
, otlayout
, &otspec
);
635 if (INTEGERP (AREF (spec
, FONT_SPACING_INDEX
)))
636 spacing
= XINT (AREF (spec
, FONT_SPACING_INDEX
));
637 registry
= AREF (spec
, FONT_REGISTRY_INDEX
);
638 family
= AREF (spec
, FONT_FAMILY_INDEX
);
641 Lisp_Object resolved
;
643 resolved
= ftfont_resolve_generic_family (family
);
644 if (! NILP (resolved
))
646 FcPatternDel (pattern
, FC_FAMILY
);
647 if (! FcPatternAddString (pattern
, FC_FAMILY
,
648 SYMBOL_FcChar8 (resolved
)))
653 objset
= FcObjectSetBuild (FC_FOUNDRY
, FC_FAMILY
, FC_WEIGHT
, FC_SLANT
,
654 FC_WIDTH
, FC_PIXEL_SIZE
, FC_SPACING
, FC_SCALABLE
,
658 #endif /* FC_CAPABILITY */
666 fontset
= FcFontList (NULL
, pattern
, objset
);
670 /* Need fix because this finds any fonts. */
671 if (fontset
->nfont
== 0 && ! NILP (family
))
673 /* Try maching with configuration. For instance, the
674 configuration may specify "Nimbus Mono L" as an alias of
676 FcPattern
*pat
= FcPatternBuild (0, FC_FAMILY
, FcTypeString
,
677 SYMBOL_FcChar8 (family
), NULL
);
680 if (FcConfigSubstitute (NULL
, pat
, FcMatchPattern
) == FcTrue
)
683 FcPatternGetString (pat
, FC_FAMILY
, i
, &fam
) == FcResultMatch
;
686 FcPatternDel (pattern
, FC_FAMILY
);
687 FcPatternAddString (pattern
, FC_FAMILY
, fam
);
688 FcFontSetDestroy (fontset
);
689 fontset
= FcFontList (NULL
, pattern
, objset
);
690 if (fontset
->nfont
> 0)
696 for (i
= 0; i
< fontset
->nfont
; i
++)
704 if ((FcPatternGetInteger (fontset
->fonts
[i
], FC_SPACING
, 0, &this)
715 if (FcPatternGetString (fontset
->fonts
[i
], FC_CAPABILITY
, 0,
716 &this) != FcResultMatch
717 || ! strstr ((char *) this, otlayout
))
720 #endif /* FC_CAPABILITY */
727 if (FcPatternGetString (fontset
->fonts
[i
], FC_FILE
, 0, &file
)
730 otf
= OTF_open ((char *) file
);
733 if (OTF_check_features (otf
, 1,
734 otspec
->script_tag
, otspec
->langsys_tag
,
736 otspec
->nfeatures
[0]) != 1
737 || OTF_check_features (otf
, 0,
738 otspec
->script_tag
, otspec
->langsys_tag
,
740 otspec
->nfeatures
[1]) != 1)
743 #endif /* HAVE_LIBOTF */
744 entity
= ftfont_pattern_entity (fontset
->fonts
[i
], registry
,
745 AREF (spec
, FONT_EXTRA_INDEX
),
748 val
= Fcons (entity
, val
);
750 font_add_log ("ftfont-list", spec
, val
);
754 /* We come here because of unexpected error in fontconfig API call
755 (usually insufficient memory). */
759 if (objset
) FcObjectSetDestroy (objset
);
760 if (fontset
) FcFontSetDestroy (fontset
);
761 if (pattern
) FcPatternDestroy (pattern
);
766 ftfont_match (frame
, spec
)
767 Lisp_Object frame
, spec
;
770 FcPattern
*pattern
, *match
= NULL
;
772 char otlayout
[15]; /* For "otlayout:XXXX" */
773 struct OpenTypeSpec
*otspec
= NULL
;
776 if (! fc_initialized
)
782 pattern
= ftfont_spec_pattern (spec
, &fc_charset_idx
, otlayout
, &otspec
);
786 if (INTEGERP (AREF (spec
, FONT_SIZE_INDEX
)))
790 value
.type
= FcTypeDouble
;
791 value
.u
.d
= XINT (AREF (spec
, FONT_SIZE_INDEX
));
792 FcPatternAdd (pattern
, FC_PIXEL_SIZE
, value
, FcFalse
);
794 if (FcConfigSubstitute (NULL
, pattern
, FcMatchPattern
) == FcTrue
)
796 FcDefaultSubstitute (pattern
);
797 match
= FcFontMatch (NULL
, pattern
, &result
);
800 entity
= ftfont_pattern_entity (match
, Qunicode_bmp
,
801 AREF (spec
, FONT_EXTRA_INDEX
),
803 FcPatternDestroy (match
);
804 if (! NILP (AREF (spec
, FONT_FAMILY_INDEX
))
805 && NILP (assq_no_quit (AREF (spec
, FONT_FAMILY_INDEX
),
806 ftfont_generic_family_list
))
807 && NILP (Fstring_equal (AREF (spec
, FONT_FAMILY_INDEX
),
808 AREF (entity
, FONT_FAMILY_INDEX
))))
812 FcPatternDestroy (pattern
);
814 font_add_log ("ftfont-match", spec
, entity
);
819 ftfont_list_family (frame
)
823 FcPattern
*pattern
= NULL
;
824 FcFontSet
*fontset
= NULL
;
825 FcObjectSet
*objset
= NULL
;
828 if (! fc_initialized
)
834 pattern
= FcPatternCreate ();
837 objset
= FcObjectSetBuild (FC_FAMILY
, NULL
);
840 fontset
= FcFontList (NULL
, pattern
, objset
);
845 for (i
= 0; i
< fontset
->nfont
; i
++)
847 FcPattern
*pat
= fontset
->fonts
[i
];
850 if (FcPatternGetString (pat
, FC_FAMILY
, 0, &str
) == FcResultMatch
)
851 list
= Fcons (intern ((char *) str
), list
);
855 if (objset
) FcObjectSetDestroy (objset
);
856 if (fontset
) FcFontSetDestroy (fontset
);
857 if (pattern
) FcPatternDestroy (pattern
);
864 ftfont_open (f
, entity
, pixel_size
)
869 struct ftfont_info
*ftfont_info
;
874 Lisp_Object val
, filename
, cache
, font_object
;
883 val
= assq_no_quit (QCfont_entity
, AREF (entity
, FONT_EXTRA_INDEX
));
887 filename
= XCAR (val
);
888 fc_charset_idx
= XINT (XCDR (val
));
889 cache
= ftfont_lookup_cache (filename
);
892 filename
= XCAR (cache
);
894 ft_face
= XSAVE_VALUE (val
)->pointer
;
895 if (XSAVE_VALUE (val
)->integer
> 0)
897 /* FT_Face in this cache is already used by the different size. */
898 if (FT_New_Size (ft_face
, &ft_size
) != 0)
900 if (FT_Activate_Size (ft_size
) != 0)
902 FT_Done_Size (ft_size
);
906 XSAVE_VALUE (val
)->integer
++;
907 size
= XINT (AREF (entity
, FONT_SIZE_INDEX
));
910 if (FT_Set_Pixel_Sizes (ft_face
, size
, size
) != 0)
912 if (XSAVE_VALUE (val
)->integer
== 0)
913 FT_Done_Face (ft_face
);
917 font_object
= font_make_object (VECSIZE (struct ftfont_info
));
918 ASET (font_object
, FONT_TYPE_INDEX
, Qfreetype
);
919 for (i
= 1;i
< FONT_ENTITY_MAX
; i
++)
920 ASET (font_object
, i
, AREF (entity
, i
));
921 ASET (font_object
, FONT_SIZE_INDEX
, make_number (size
));
922 len
= font_unparse_xlfd (entity
, size
, name
, 256);
924 ASET (font_object
, FONT_NAME_INDEX
, make_unibyte_string (name
, len
));
925 len
= font_unparse_fcname (entity
, size
, name
, 256);
927 ASET (font_object
, FONT_FULLNAME_INDEX
, make_unibyte_string (name
, len
));
929 ASET (font_object
, FONT_FULLNAME_INDEX
,
930 AREF (font_object
, FONT_NAME_INDEX
));
931 ASET (font_object
, FONT_FILE_INDEX
, filename
);
932 ASET (font_object
, FONT_FORMAT_INDEX
, ftfont_font_format (pattern
));
933 font
= XFONT_OBJECT (font_object
);
934 ftfont_info
= (struct ftfont_info
*) font
;
935 ftfont_info
->ft_size
= ft_face
->size
;
936 ftfont_info
->fc_charset_idx
= fc_charset_idx
;
938 ftfont_info
->maybe_otf
= ft_face
->face_flags
& FT_FACE_FLAG_SFNT
;
939 ftfont_info
->otf
= NULL
;
940 #endif /* HAVE_LIBOTF */
941 font
->pixel_size
= size
;
942 font
->driver
= &ftfont_driver
;
943 font
->encoding_charset
= font
->repertory_charset
= -1;
945 upEM
= ft_face
->units_per_EM
;
946 scalable
= (INTEGERP (AREF (entity
, FONT_AVGWIDTH_INDEX
))
947 && XINT (AREF (entity
, FONT_AVGWIDTH_INDEX
)) == 0);
950 font
->ascent
= ft_face
->ascender
* size
/ upEM
;
951 font
->descent
= - ft_face
->descender
* size
/ upEM
;
952 font
->height
= ft_face
->height
* size
/ upEM
;
956 font
->ascent
= ft_face
->size
->metrics
.ascender
>> 6;
957 font
->descent
= - ft_face
->size
->metrics
.descender
>> 6;
958 font
->height
= ft_face
->size
->metrics
.height
>> 6;
960 if (INTEGERP (AREF (entity
, FONT_SPACING_INDEX
)))
961 spacing
= XINT (AREF (entity
, FONT_SPACING_INDEX
));
963 spacing
= FC_PROPORTIONAL
;
964 if (spacing
!= FC_PROPORTIONAL
)
965 font
->min_width
= font
->average_width
= font
->space_width
966 = (scalable
? ft_face
->max_advance_width
* size
/ upEM
967 : ft_face
->size
->metrics
.max_advance
>> 6);
972 font
->min_width
= font
->average_width
= font
->space_width
= 0;
973 for (i
= 32, n
= 0; i
< 127; i
++)
974 if (FT_Load_Char (ft_face
, i
, FT_LOAD_DEFAULT
) != 0)
976 int this_width
= ft_face
->glyph
->metrics
.horiAdvance
>> 6;
979 && (! font
->min_width
|| font
->min_width
> this_width
))
980 font
->min_width
= this_width
;
982 font
->space_width
= this_width
;
983 font
->average_width
+= this_width
;
987 font
->average_width
/= n
;
990 font
->baseline_offset
= 0;
991 font
->relative_compose
= 0;
992 font
->default_ascent
= 0;
993 font
->vertical_centering
= 0;
996 font
->underline_position
= -ft_face
->underline_position
* size
/ upEM
;
997 font
->underline_thickness
= -ft_face
->underline_thickness
* size
/ upEM
;
1001 font
->underline_position
= -1;
1002 font
->underline_thickness
= 0;
1009 ftfont_close (f
, font
)
1013 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1014 Lisp_Object val
, cache
;
1016 cache
= ftfont_lookup_cache (font
->props
[FONT_FILE_INDEX
]);
1018 (XSAVE_VALUE (val
)->integer
)--;
1019 if (XSAVE_VALUE (val
)->integer
== 0)
1021 FT_Face ft_face
= XSAVE_VALUE (val
)->pointer
;
1023 FT_Done_Face (ft_face
);
1025 if (ftfont_info
->otf
)
1026 OTF_close (ftfont_info
->otf
);
1028 XSAVE_VALUE (val
)->pointer
= NULL
;
1031 FT_Done_Size (ftfont_info
->ft_size
);
1035 ftfont_has_char (entity
, c
)
1041 struct charset
*charset
;
1043 val
= assq_no_quit (QCfont_entity
, AREF (entity
, FONT_EXTRA_INDEX
));
1044 fc_charset_idx
= XINT (XCDR (XCDR (val
)));
1045 if (fc_charset_idx
< 0)
1047 charset
= CHARSET_FROM_ID (fc_charset_table
[fc_charset_idx
].charset_id
);
1048 return (ENCODE_CHAR (charset
, c
) != CHARSET_INVALID_CODE (charset
));
1052 ftfont_encode_char (font
, c
)
1056 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1057 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1058 FT_ULong charcode
= c
;
1059 FT_UInt code
= FT_Get_Char_Index (ft_face
, charcode
);
1061 return (code
> 0 ? code
: FONT_INVALID_CODE
);
1065 ftfont_text_extents (font
, code
, nglyphs
, metrics
)
1069 struct font_metrics
*metrics
;
1071 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1072 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1076 if (ftfont_info
->ft_size
!= ft_face
->size
)
1077 FT_Activate_Size (ftfont_info
->ft_size
);
1079 bzero (metrics
, sizeof (struct font_metrics
));
1080 for (i
= 0; i
< nglyphs
; i
++)
1082 if (FT_Load_Glyph (ft_face
, code
[i
], FT_LOAD_DEFAULT
) == 0)
1084 FT_Glyph_Metrics
*m
= &ft_face
->glyph
->metrics
;
1088 if (metrics
->lbearing
> width
+ (m
->horiBearingX
>> 6))
1089 metrics
->lbearing
= width
+ (m
->horiBearingX
>> 6);
1090 if (metrics
->rbearing
1091 < width
+ ((m
->horiBearingX
+ m
->width
) >> 6))
1093 = width
+ ((m
->horiBearingX
+ m
->width
) >> 6);
1094 if (metrics
->ascent
< (m
->horiBearingY
>> 6))
1095 metrics
->ascent
= m
->horiBearingY
>> 6;
1096 if (metrics
->descent
> ((m
->horiBearingY
+ m
->height
) >> 6))
1097 metrics
->descent
= (m
->horiBearingY
+ m
->height
) >> 6;
1099 width
+= m
->horiAdvance
>> 6;
1103 width
+= font
->space_width
;
1107 metrics
->width
= width
;
1113 ftfont_get_bitmap (font
, code
, bitmap
, bits_per_pixel
)
1116 struct font_bitmap
*bitmap
;
1119 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1120 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1121 FT_Int32 load_flags
= FT_LOAD_RENDER
;
1123 if (ftfont_info
->ft_size
!= ft_face
->size
)
1124 FT_Activate_Size (ftfont_info
->ft_size
);
1125 if (bits_per_pixel
== 1)
1127 #ifdef FT_LOAD_TARGET_MONO
1128 load_flags
|= FT_LOAD_TARGET_MONO
;
1130 load_flags
|= FT_LOAD_MONOCHROME
;
1133 else if (bits_per_pixel
!= 8)
1134 /* We don't support such a rendering. */
1137 if (FT_Load_Glyph (ft_face
, code
, load_flags
) != 0)
1139 bitmap
->bits_per_pixel
1140 = (ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_MONO
? 1
1141 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_GRAY
? 8
1142 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_LCD
? 8
1143 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_LCD_V
? 8
1145 if (bitmap
->bits_per_pixel
< 0)
1146 /* We don't suport that kind of pixel mode. */
1148 bitmap
->rows
= ft_face
->glyph
->bitmap
.rows
;
1149 bitmap
->width
= ft_face
->glyph
->bitmap
.width
;
1150 bitmap
->pitch
= ft_face
->glyph
->bitmap
.pitch
;
1151 bitmap
->buffer
= ft_face
->glyph
->bitmap
.buffer
;
1152 bitmap
->left
= ft_face
->glyph
->bitmap_left
;
1153 bitmap
->top
= ft_face
->glyph
->bitmap_top
;
1154 bitmap
->advance
= ft_face
->glyph
->metrics
.horiAdvance
>> 6;
1155 bitmap
->extra
= NULL
;
1161 ftfont_anchor_point (font
, code
, index
, x
, y
)
1167 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1168 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1170 if (ftfont_info
->ft_size
!= ft_face
->size
)
1171 FT_Activate_Size (ftfont_info
->ft_size
);
1172 if (FT_Load_Glyph (ft_face
, code
, FT_LOAD_DEFAULT
) != 0)
1174 if (ft_face
->glyph
->format
!= FT_GLYPH_FORMAT_OUTLINE
)
1176 if (index
>= ft_face
->glyph
->outline
.n_points
)
1178 *x
= ft_face
->glyph
->outline
.points
[index
].x
;
1179 *y
= ft_face
->glyph
->outline
.points
[index
].y
;
1184 #ifdef HAVE_M17N_FLT
1195 ftfont_get_glyph_id (font
, gstring
, from
, to
)
1197 MFLTGlyphString
*gstring
;
1200 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1201 FT_Face ft_face
= flt_font_ft
->ft_face
;
1204 for (g
= gstring
->glyphs
+ from
; from
< to
; g
++, from
++)
1207 FT_UInt code
= FT_Get_Char_Index (ft_face
, g
->code
);
1209 g
->code
= code
> 0 ? code
: FONT_INVALID_CODE
;
1216 ftfont_get_metrics (font
, gstring
, from
, to
)
1218 MFLTGlyphString
*gstring
;
1221 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1222 FT_Face ft_face
= flt_font_ft
->ft_face
;
1225 for (g
= gstring
->glyphs
+ from
; from
< to
; g
++, from
++)
1228 if (g
->code
!= FONT_INVALID_CODE
)
1230 FT_Glyph_Metrics
*m
;
1232 if (FT_Load_Glyph (ft_face
, g
->code
, FT_LOAD_DEFAULT
) != 0)
1234 m
= &ft_face
->glyph
->metrics
;
1236 g
->lbearing
= m
->horiBearingX
;
1237 g
->rbearing
= m
->horiBearingX
+ m
->width
;
1238 g
->ascent
= m
->horiBearingY
;
1239 g
->descent
= m
->height
- m
->horiBearingY
;
1240 g
->xadv
= m
->horiAdvance
;
1245 g
->rbearing
= g
->xadv
= flt_font_ft
->font
->space_width
<< 6;
1246 g
->ascent
= flt_font_ft
->font
->ascent
<< 6;
1247 g
->descent
= flt_font_ft
->font
->descent
<< 6;
1256 ftfont_check_otf (MFLTFont
*font
, MFLTOtfSpec
*spec
)
1258 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1259 OTF
*otf
= flt_font_ft
->otf
;
1263 for (i
= 0; i
< 2; i
++)
1265 if (! spec
->features
[i
])
1267 for (n
= 0; spec
->features
[i
][n
]; n
++);
1268 tags
= alloca (sizeof (OTF_Tag
) * n
);
1269 for (n
= 0, negative
= 0; spec
->features
[i
][n
]; n
++)
1271 if (spec
->features
[i
][n
] == 0xFFFFFFFF)
1274 tags
[n
- 1] = spec
->features
[i
][n
] | 0x80000000;
1276 tags
[n
] = spec
->features
[i
][n
];
1278 if (n
- negative
> 0
1279 && OTF_check_features (otf
, i
== 0, spec
->script
, spec
->langsys
,
1280 tags
, n
- negative
) != 1)
1286 #define DEVICE_DELTA(table, size) \
1287 (((size) >= (table).StartSize && (size) <= (table).EndSize) \
1288 ? (table).DeltaValue[(size) - (table).StartSize] << 6 \
1292 adjust_anchor (FT_Face ft_face
, OTF_Anchor
*anchor
,
1293 unsigned code
, int x_ppem
, int y_ppem
, int *x
, int *y
)
1295 if (anchor
->AnchorFormat
== 2)
1297 FT_Outline
*outline
;
1298 int ap
= anchor
->f
.f1
.AnchorPoint
;
1300 FT_Load_Glyph (ft_face
, (FT_UInt
) code
, FT_LOAD_MONOCHROME
);
1301 outline
= &ft_face
->glyph
->outline
;
1302 if (ap
< outline
->n_points
)
1304 *x
= outline
->points
[ap
].x
<< 6;
1305 *y
= outline
->points
[ap
].y
<< 6;
1308 else if (anchor
->AnchorFormat
== 3)
1310 if (anchor
->f
.f2
.XDeviceTable
.offset
)
1311 *x
+= DEVICE_DELTA (anchor
->f
.f2
.XDeviceTable
, x_ppem
);
1312 if (anchor
->f
.f2
.YDeviceTable
.offset
)
1313 *y
+= DEVICE_DELTA (anchor
->f
.f2
.YDeviceTable
, y_ppem
);
1317 static OTF_GlyphString otf_gstring
;
1320 ftfont_drive_otf (font
, spec
, in
, from
, to
, out
, adjustment
)
1323 MFLTGlyphString
*in
;
1325 MFLTGlyphString
*out
;
1326 MFLTGlyphAdjustment
*adjustment
;
1328 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1329 FT_Face ft_face
= flt_font_ft
->ft_face
;
1330 OTF
*otf
= flt_font_ft
->otf
;
1331 int len
= to
- from
;
1334 char script
[5], *langsys
= NULL
;
1335 char *gsub_features
= NULL
, *gpos_features
= NULL
;
1339 OTF_tag_name (spec
->script
, script
);
1342 langsys
= alloca (5);
1343 OTF_tag_name (spec
->langsys
, langsys
);
1345 for (i
= 0; i
< 2; i
++)
1349 if (spec
->features
[i
] && spec
->features
[i
][1] != 0xFFFFFFFF)
1351 for (j
= 0; spec
->features
[i
][j
]; j
++);
1353 p
= gsub_features
= alloca (6 * j
);
1355 p
= gpos_features
= alloca (6 * j
);
1356 for (j
= 0; spec
->features
[i
][j
]; j
++)
1358 if (spec
->features
[i
][j
] == 0xFFFFFFFF)
1359 *p
++ = '*', *p
++ = ',';
1362 OTF_tag_name (spec
->features
[i
][j
], p
);
1371 if (otf_gstring
.size
== 0)
1373 otf_gstring
.glyphs
= (OTF_Glyph
*) malloc (sizeof (OTF_Glyph
) * len
);
1374 otf_gstring
.size
= len
;
1376 else if (otf_gstring
.size
< len
)
1378 otf_gstring
.glyphs
= (OTF_Glyph
*) realloc (otf_gstring
.glyphs
,
1379 sizeof (OTF_Glyph
) * len
);
1380 otf_gstring
.size
= len
;
1382 otf_gstring
.used
= len
;
1383 memset (otf_gstring
.glyphs
, 0, sizeof (OTF_Glyph
) * len
);
1384 for (i
= 0; i
< len
; i
++)
1386 otf_gstring
.glyphs
[i
].c
= in
->glyphs
[from
+ i
].c
;
1387 otf_gstring
.glyphs
[i
].glyph_id
= in
->glyphs
[from
+ i
].code
;
1390 OTF_drive_gdef (otf
, &otf_gstring
);
1395 if (OTF_drive_gsub (otf
, &otf_gstring
, script
, langsys
, gsub_features
)
1398 if (out
->allocated
< out
->used
+ otf_gstring
.used
)
1400 for (i
= 0, otfg
= otf_gstring
.glyphs
; i
< otf_gstring
.used
; )
1403 int min_from
, max_to
;
1406 g
= out
->glyphs
+ out
->used
;
1407 *g
= in
->glyphs
[from
+ otfg
->f
.index
.from
];
1408 if (g
->code
!= otfg
->glyph_id
)
1411 g
->code
= otfg
->glyph_id
;
1417 if (otfg
->f
.index
.from
< otfg
->f
.index
.to
)
1419 /* OTFG substitutes multiple glyphs in IN. */
1420 for (j
= from
+ otfg
->f
.index
.from
+ 1;
1421 j
<= from
+ otfg
->f
.index
.to
; j
++)
1423 if (min_from
> in
->glyphs
[j
].from
)
1424 min_from
= in
->glyphs
[j
].from
;
1425 if (max_to
< in
->glyphs
[j
].to
)
1426 max_to
= in
->glyphs
[j
].to
;
1431 for (i
++, otfg
++; (i
< otf_gstring
.used
1432 && otfg
->f
.index
.from
== otfg
[-1].f
.index
.from
);
1435 g
= out
->glyphs
+ out
->used
;
1436 *g
= in
->glyphs
[from
+ otfg
->f
.index
.to
];
1437 if (g
->code
!= otfg
->glyph_id
)
1440 g
->code
= otfg
->glyph_id
;
1449 if (out
->allocated
< out
->used
+ len
)
1451 for (i
= 0; i
< len
; i
++)
1452 out
->glyphs
[out
->used
++] = in
->glyphs
[from
+ i
];
1457 MFLTGlyph
*base
= NULL
, *mark
= NULL
, *g
;
1458 int x_ppem
, y_ppem
, x_scale
, y_scale
;
1460 if (OTF_drive_gpos (otf
, &otf_gstring
, script
, langsys
, gpos_features
)
1464 x_ppem
= ft_face
->size
->metrics
.x_ppem
;
1465 y_ppem
= ft_face
->size
->metrics
.y_ppem
;
1466 x_scale
= ft_face
->size
->metrics
.x_scale
;
1467 y_scale
= ft_face
->size
->metrics
.y_scale
;
1469 for (i
= 0, otfg
= otf_gstring
.glyphs
, g
= out
->glyphs
+ gidx
;
1470 i
< otf_gstring
.used
; i
++, otfg
++, g
++)
1474 if (! otfg
->glyph_id
)
1476 switch (otfg
->positioning_type
)
1480 case 1: /* Single */
1483 int format
= otfg
->f
.f1
.format
;
1485 if (format
& OTF_XPlacement
)
1487 = otfg
->f
.f1
.value
->XPlacement
* x_scale
/ 0x10000;
1488 if (format
& OTF_XPlaDevice
)
1490 += DEVICE_DELTA (otfg
->f
.f1
.value
->XPlaDevice
, x_ppem
);
1491 if (format
& OTF_YPlacement
)
1493 = - (otfg
->f
.f1
.value
->YPlacement
* y_scale
/ 0x10000);
1494 if (format
& OTF_YPlaDevice
)
1496 -= DEVICE_DELTA (otfg
->f
.f1
.value
->YPlaDevice
, y_ppem
);
1497 if (format
& OTF_XAdvance
)
1499 += otfg
->f
.f1
.value
->XAdvance
* x_scale
/ 0x10000;
1500 if (format
& OTF_XAdvDevice
)
1502 += DEVICE_DELTA (otfg
->f
.f1
.value
->XAdvDevice
, x_ppem
);
1503 if (format
& OTF_YAdvance
)
1505 += otfg
->f
.f1
.value
->YAdvance
* y_scale
/ 0x10000;
1506 if (format
& OTF_YAdvDevice
)
1508 += DEVICE_DELTA (otfg
->f
.f1
.value
->YAdvDevice
, y_ppem
);
1509 adjustment
[i
].set
= 1;
1512 case 3: /* Cursive */
1513 /* Not yet supported. */
1515 case 4: /* Mark-to-Base */
1516 case 5: /* Mark-to-Ligature */
1520 goto label_adjust_anchor
;
1521 default: /* i.e. case 6 Mark-to-Mark */
1526 label_adjust_anchor
:
1528 int base_x
, base_y
, mark_x
, mark_y
;
1529 int this_from
, this_to
;
1531 base_x
= otfg
->f
.f4
.base_anchor
->XCoordinate
* x_scale
/ 0x10000;
1532 base_y
= otfg
->f
.f4
.base_anchor
->YCoordinate
* y_scale
/ 0x10000;
1533 mark_x
= otfg
->f
.f4
.mark_anchor
->XCoordinate
* x_scale
/ 0x10000;
1534 mark_y
= otfg
->f
.f4
.mark_anchor
->YCoordinate
* y_scale
/ 0x10000;;
1536 if (otfg
->f
.f4
.base_anchor
->AnchorFormat
!= 1)
1537 adjust_anchor (ft_face
, otfg
->f
.f4
.base_anchor
,
1538 prev
->code
, x_ppem
, y_ppem
, &base_x
, &base_y
);
1539 if (otfg
->f
.f4
.mark_anchor
->AnchorFormat
!= 1)
1540 adjust_anchor (ft_face
, otfg
->f
.f4
.mark_anchor
, g
->code
,
1541 x_ppem
, y_ppem
, &mark_x
, &mark_y
);
1542 adjustment
[i
].xoff
= (base_x
- mark_x
);
1543 adjustment
[i
].yoff
= - (base_y
- mark_y
);
1544 adjustment
[i
].back
= (g
- prev
);
1545 adjustment
[i
].xadv
= 0;
1546 adjustment
[i
].advance_is_absolute
= 1;
1547 adjustment
[i
].set
= 1;
1548 this_from
= g
->from
;
1550 for (j
= 0; prev
+ j
< g
; j
++)
1552 if (this_from
> prev
[j
].from
)
1553 this_from
= prev
[j
].from
;
1554 if (this_to
< prev
[j
].to
)
1555 this_to
= prev
[j
].to
;
1557 for (; prev
<= g
; prev
++)
1559 prev
->from
= this_from
;
1564 if (otfg
->GlyphClass
== OTF_GlyphClass0
)
1566 else if (otfg
->GlyphClass
== OTF_GlyphClassMark
)
1575 if (out
->allocated
< out
->used
+ len
)
1577 font
->get_metrics (font
, in
, from
, to
);
1578 memcpy (out
->glyphs
+ out
->used
, in
->glyphs
+ from
,
1579 sizeof (MFLTGlyph
) * len
);
1584 static MFLTGlyphString gstring
;
1586 static int m17n_flt_initialized
;
1588 extern Lisp_Object QCfamily
;
1591 ftfont_shape_by_flt (lgstring
, font
, ft_face
, otf
)
1592 Lisp_Object lgstring
;
1597 EMACS_UINT len
= LGSTRING_LENGTH (lgstring
);
1599 struct MFLTFontFT flt_font_ft
;
1601 if (! m17n_flt_initialized
)
1604 m17n_flt_initialized
= 1;
1607 for (i
= 0; i
< len
; i
++)
1608 if (NILP (LGSTRING_GLYPH (lgstring
, i
)))
1612 if (gstring
.allocated
== 0)
1614 gstring
.allocated
= len
* 2;
1615 gstring
.glyph_size
= sizeof (MFLTGlyph
);
1616 gstring
.glyphs
= malloc (sizeof (MFLTGlyph
) * gstring
.allocated
);
1618 else if (gstring
.allocated
< len
* 2)
1620 gstring
.allocated
= len
* 2;
1621 gstring
.glyphs
= realloc (gstring
.glyphs
,
1622 sizeof (MFLTGlyph
) * gstring
.allocated
);
1624 for (i
= 0; i
< len
; i
++)
1625 gstring
.glyphs
[i
].c
= LGLYPH_CHAR (LGSTRING_GLYPH (lgstring
, i
));
1630 Lisp_Object family
= Ffont_get (LGSTRING_FONT (lgstring
), QCfamily
);
1633 flt_font_ft
.flt_font
.family
= Mnil
;
1635 flt_font_ft
.flt_font
.family
1636 = msymbol ((char *) SDATA (SYMBOL_NAME (family
)));
1638 flt_font_ft
.flt_font
.x_ppem
= ft_face
->size
->metrics
.x_ppem
;
1639 flt_font_ft
.flt_font
.y_ppem
= ft_face
->size
->metrics
.y_ppem
;
1640 flt_font_ft
.flt_font
.get_glyph_id
= ftfont_get_glyph_id
;
1641 flt_font_ft
.flt_font
.get_metrics
= ftfont_get_metrics
;
1642 flt_font_ft
.flt_font
.check_otf
= ftfont_check_otf
;
1643 flt_font_ft
.flt_font
.drive_otf
= ftfont_drive_otf
;
1644 flt_font_ft
.flt_font
.internal
= NULL
;
1645 flt_font_ft
.font
= font
;
1646 flt_font_ft
.ft_face
= ft_face
;
1647 flt_font_ft
.otf
= otf
;
1648 for (i
= 0; i
< 3; i
++)
1650 int result
= mflt_run (&gstring
, 0, len
, &flt_font_ft
.flt_font
, NULL
);
1653 gstring
.allocated
+= gstring
.allocated
;
1654 gstring
.glyphs
= realloc (gstring
.glyphs
,
1655 sizeof (MFLTGlyph
) * gstring
.allocated
);
1657 if (gstring
.used
> LGSTRING_LENGTH (lgstring
))
1659 for (i
= 0; i
< gstring
.used
; i
++)
1661 MFLTGlyph
*g
= gstring
.glyphs
+ i
;
1663 g
->from
= LGLYPH_FROM (LGSTRING_GLYPH (lgstring
, g
->from
));
1664 g
->to
= LGLYPH_TO (LGSTRING_GLYPH (lgstring
, g
->to
));
1667 for (i
= 0; i
< gstring
.used
; i
++)
1669 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
1670 MFLTGlyph
*g
= gstring
.glyphs
+ i
;
1674 lglyph
= Fmake_vector (make_number (LGLYPH_SIZE
), Qnil
);
1675 LGSTRING_SET_GLYPH (lgstring
, i
, lglyph
);
1677 LGLYPH_SET_FROM (lglyph
, g
->from
);
1678 LGLYPH_SET_TO (lglyph
, g
->to
);
1679 LGLYPH_SET_CHAR (lglyph
, g
->c
);
1680 LGLYPH_SET_CODE (lglyph
, g
->code
);
1681 LGLYPH_SET_WIDTH (lglyph
, g
->xadv
>> 6);
1682 LGLYPH_SET_LBEARING (lglyph
, g
->lbearing
>> 6);
1683 LGLYPH_SET_RBEARING (lglyph
, g
->rbearing
>> 6);
1684 LGLYPH_SET_ASCENT (lglyph
, g
->ascent
>> 6);
1685 LGLYPH_SET_DESCENT (lglyph
, g
->descent
>> 6);
1690 vec
= Fmake_vector (make_number (3), Qnil
);
1691 ASET (vec
, 0, make_number (g
->xoff
>> 6));
1692 ASET (vec
, 1, make_number (g
->yoff
>> 6));
1693 ASET (vec
, 2, make_number (g
->xadv
>> 6));
1694 LGLYPH_SET_ADJUSTMENT (lglyph
, vec
);
1697 return make_number (i
);
1701 ftfont_shape (lgstring
)
1702 Lisp_Object lgstring
;
1705 struct ftfont_info
*ftfont_info
;
1707 CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring
), font
);
1708 ftfont_info
= (struct ftfont_info
*) font
;
1709 if (! ftfont_info
->maybe_otf
)
1710 return make_number (0);
1711 if (! ftfont_info
->otf
)
1713 OTF
*otf
= OTF_open_ft_face (ftfont_info
->ft_size
->face
);
1715 if (! otf
|| OTF_get_table (otf
, "head") < 0)
1719 ftfont_info
->maybe_otf
= 0;
1720 return make_number (0);
1723 ftfont_info
->otf
= otf
;
1726 return ftfont_shape_by_flt (lgstring
, font
, ftfont_info
->ft_size
->face
,
1730 #endif /* HAVE_M17N_FLT */
1731 #endif /* HAVE_LIBOTF */
1734 ftfont_font_format (FcPattern
*pattern
)
1738 #ifdef FC_FONTFORMAT
1739 if (FcPatternGetString (pattern
, FC_FONTFORMAT
, 0, &str
) != FcResultMatch
)
1741 if (strcmp ((char *) str
, "TrueType") == 0)
1742 return intern ("truetype");
1743 if (strcmp ((char *) str
, "Type 1") == 0)
1744 return intern ("type1");
1745 if (strcmp ((char *) str
, "PCF") == 0)
1746 return intern ("pcf");
1747 if (strcmp ((char *) str
, "BDF") == 0)
1748 return intern ("bdf");
1749 #else /* not FC_FONTFORMAT */
1752 if (FcPatternGetString (pattern
, FC_FILE
, 0, &str
) != FcResultMatch
)
1754 len
= strlen ((char *) str
);
1758 if (xstrcasecmp ((char *) str
, ".ttf") == 0)
1759 return intern ("truetype");
1760 if (xstrcasecmp ((char *) str
, "pfb") == 0)
1761 return intern ("type1");
1762 if (xstrcasecmp ((char *) str
, "pcf") == 0)
1763 return intern ("pcf");
1764 if (xstrcasecmp ((char *) str
, "bdf") == 0)
1765 return intern ("bdf");
1767 #endif /* not FC_FONTFORMAT */
1768 return intern ("unknown");
1775 DEFSYM (Qfreetype
, "freetype");
1776 DEFSYM (Qmonospace
, "monospace");
1777 DEFSYM (Qsans_serif
, "sans-serif");
1778 DEFSYM (Qserif
, "serif");
1779 DEFSYM (Qmono
, "mono");
1780 DEFSYM (Qsans
, "sans");
1781 DEFSYM (Qsans__serif
, "sans serif");
1783 staticpro (&freetype_font_cache
);
1784 freetype_font_cache
= Fcons (Qt
, Qnil
);
1786 staticpro (&ftfont_generic_family_list
);
1787 ftfont_generic_family_list
1788 = Fcons (Fcons (Qmonospace
, Qt
),
1789 Fcons (Fcons (Qsans_serif
, Qt
),
1790 Fcons (Fcons (Qsans
, Qt
), Qnil
)));
1792 staticpro (&ft_face_cache
);
1793 ft_face_cache
= Qnil
;
1795 ftfont_driver
.type
= Qfreetype
;
1796 register_font_driver (&ftfont_driver
, NULL
);
1799 /* arch-tag: 7cfa432c-33a6-4988-83d2-a82ed8604aca
1800 (do not change this comment) */