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 areadly 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 /* Fontconfig's charset used for finding fonts of registry
56 static FcCharSet
*cs_iso8859_1
;
58 /* 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 int ftfont_build_basic_charsets
P_ ((void));
72 static Lisp_Object ftfont_pattern_entity
P_ ((FcPattern
*, Lisp_Object
));
73 static Lisp_Object ftfont_list_generic_family
P_ ((Lisp_Object
));
74 Lisp_Object ftfont_font_format
P_ ((FcPattern
*));
76 #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM))
79 ftfont_build_basic_charsets ()
83 cs_iso8859_1
= FcCharSetCreate ();
86 for (c
= ' '; c
< 127; c
++)
87 if (! FcCharSetAddChar (cs_iso8859_1
, c
))
90 /* This part is currently disabled. Should be fixed later. */
91 for (c
= 192; c
< 256; c
++)
92 if (! FcCharSetAddChar (cs_iso8859_1
, c
))
98 extern Lisp_Object Qc
, Qm
, Qp
, Qd
;
101 ftfont_pattern_entity (p
, registry
)
103 Lisp_Object registry
;
106 FcChar8
*file
, *fontformat
;
113 if (FcPatternGetString (p
, FC_FILE
, 0, &file
) != FcResultMatch
)
115 if (FcPatternGetCharSet (p
, FC_CHARSET
, 0, &charset
) != FcResultMatch
)
118 if (FcPatternGetString (p
, FC_FONTFORMAT
, 0, &fontformat
) != FcResultMatch
)
119 #endif /* FC_FONTFORMAT */
122 entity
= font_make_entity ();
124 ASET (entity
, FONT_TYPE_INDEX
, Qfreetype
);
125 ASET (entity
, FONT_REGISTRY_INDEX
, registry
);
127 if (FcPatternGetString (p
, FC_FOUNDRY
, 0, &str
) == FcResultMatch
)
128 ASET (entity
, FONT_FOUNDRY_INDEX
, font_intern_prop (str
, strlen (str
)));
129 if (FcPatternGetString (p
, FC_FAMILY
, 0, &str
) == FcResultMatch
)
130 ASET (entity
, FONT_FAMILY_INDEX
, font_intern_prop (str
, strlen (str
)));
131 if (FcPatternGetInteger (p
, FC_WEIGHT
, 0, &numeric
) == FcResultMatch
)
133 if (numeric
>= FC_WEIGHT_REGULAR
&& numeric
< FC_WEIGHT_MEDIUM
)
134 numeric
= FC_WEIGHT_MEDIUM
;
135 FONT_SET_STYLE (entity
, FONT_WEIGHT_INDEX
, make_number (numeric
));
137 if (FcPatternGetInteger (p
, FC_SLANT
, 0, &numeric
) == FcResultMatch
)
140 FONT_SET_STYLE (entity
, FONT_SLANT_INDEX
, make_number (numeric
));
142 if (FcPatternGetInteger (p
, FC_WIDTH
, 0, &numeric
) == FcResultMatch
)
144 FONT_SET_STYLE (entity
, FONT_WIDTH_INDEX
, make_number (numeric
));
146 if (FcPatternGetDouble (p
, FC_PIXEL_SIZE
, 0, &dbl
) == FcResultMatch
)
147 ASET (entity
, FONT_SIZE_INDEX
, make_number (dbl
));
149 ASET (entity
, FONT_SIZE_INDEX
, make_number (0));
150 if (FcPatternGetInteger (p
, FC_SPACING
, 0, &numeric
) == FcResultMatch
)
151 ASET (entity
, FONT_SPACING_INDEX
, make_number (numeric
));
152 if (FcPatternGetDouble (p
, FC_DPI
, 0, &dbl
) == FcResultMatch
)
155 ASET (entity
, FONT_DPI_INDEX
, make_number (dpi
));
157 if (FcPatternGetBool (p
, FC_SCALABLE
, 0, &b
) == FcResultMatch
159 ASET (entity
, FONT_AVGWIDTH_INDEX
, make_number (0));
161 file
= FcStrCopy (file
);
164 p
= FcPatternCreate ();
168 if (FcPatternAddString (p
, FC_FILE
, file
) == FcFalse
170 && FcPatternAddCharSet (p
, FC_CHARSET
, charset
) == FcFalse
)
173 && FcPatternAddString (p
, FC_FONTFORMAT
, fontformat
) == FcFalse
)
174 #endif /* FC_FONTFORMAT */
177 FcPatternDestroy (p
);
180 font_put_extra (entity
, QCfont_entity
, make_save_value (p
, 0));
185 static Lisp_Object ftfont_generic_family_list
;
188 ftfont_list_generic_family (family
)
191 Lisp_Object slot
, list
, val
;
192 FcObjectSet
*objset
= NULL
;
193 FcPattern
*pattern
= NULL
, *pat
= NULL
;
194 FcFontSet
*fontset
= NULL
;
198 if (EQ (family
, Qmono
))
200 else if (EQ (family
, Qsans
) || EQ (family
, Qsans__serif
))
201 family
= Qsans_serif
;
202 slot
= assq_no_quit (family
, ftfont_generic_family_list
);
209 objset
= FcObjectSetBuild (FC_FAMILY
, NULL
);
212 pattern
= FcPatternBuild (NULL
, FC_FAMILY
, FcTypeString
,
213 SYMBOL_FcChar8 (family
), (char *) 0);
216 pat
= FcPatternCreate ();
219 FcConfigSubstitute (NULL
, pattern
, FcMatchPattern
);
220 for (i
= 0, list
= Qnil
;
221 FcPatternGetString (pattern
, FC_FAMILY
, i
, &fam
) == FcResultMatch
;
224 if (strcmp ((char *) fam
, (char *) SYMBOL_FcChar8 (family
)) == 0)
226 if (! FcPatternAddString (pat
, FC_FAMILY
, fam
))
228 fontset
= FcFontList (NULL
, pat
, objset
);
231 if (fontset
->nfont
> 0)
232 list
= Fcons (intern ((char *) fam
), list
);
233 FcFontSetDestroy (fontset
);
235 FcPatternDel (pat
, FC_FAMILY
);
237 XSETCDR (slot
, list
);
239 if (pat
) FcPatternDestroy (pat
);
240 if (pattern
) FcPatternDestroy (pattern
);
241 if (fontset
) FcFontSetDestroy (fontset
);
242 if (objset
) FcObjectSetDestroy (objset
);
246 static Lisp_Object ftfont_get_cache
P_ ((FRAME_PTR
));
247 static Lisp_Object ftfont_list
P_ ((Lisp_Object
, Lisp_Object
));
248 static Lisp_Object ftfont_match
P_ ((Lisp_Object
, Lisp_Object
));
249 static Lisp_Object ftfont_list_family
P_ ((Lisp_Object
));
250 static Lisp_Object ftfont_open
P_ ((FRAME_PTR
, Lisp_Object
, int));
251 static void ftfont_close
P_ ((FRAME_PTR
, struct font
*));
252 static int ftfont_has_char
P_ ((Lisp_Object
, int));
253 static unsigned ftfont_encode_char
P_ ((struct font
*, int));
254 static int ftfont_text_extents
P_ ((struct font
*, unsigned *, int,
255 struct font_metrics
*));
256 static int ftfont_get_bitmap
P_ ((struct font
*, unsigned,
257 struct font_bitmap
*, int));
258 static int ftfont_anchor_point
P_ ((struct font
*, unsigned, int,
260 static Lisp_Object ftfont_shape
P_ ((Lisp_Object
));
262 struct font_driver ftfont_driver
=
265 0, /* case insensitive */
273 /* We can't draw a text without device dependent functions. */
279 /* We can't draw a text without device dependent functions. */
290 #if defined (HAVE_M17N_FLT) && defined (HAVE_LIBOTF)
292 #else /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */
294 #endif /* not (HAVE_M17N_FLT && HAVE_LIBOTF) */
297 extern Lisp_Object QCname
;
303 return freetype_font_cache
;
309 unsigned int script_tag
, langsys_tag
;
311 unsigned int *features
[2];
314 #define OTF_SYM_TAG(SYM, TAG) \
316 unsigned char *p = SDATA (SYMBOL_NAME (SYM)); \
317 TAG = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; \
320 #define OTF_TAG_STR(TAG, P) \
322 (P)[0] = (char) (TAG >> 24); \
323 (P)[1] = (char) ((TAG >> 16) & 0xFF); \
324 (P)[2] = (char) ((TAG >> 8) & 0xFF); \
325 (P)[3] = (char) (TAG & 0xFF); \
329 static struct OpenTypeSpec
*
330 ftfont_get_open_type_spec (Lisp_Object otf_spec
)
332 struct OpenTypeSpec
*spec
= malloc (sizeof (struct OpenTypeSpec
));
338 spec
->script
= XCAR (otf_spec
);
339 if (! NILP (spec
->script
))
341 OTF_SYM_TAG (spec
->script
, spec
->script_tag
);
342 val
= assq_no_quit (spec
->script
, Votf_script_alist
);
343 if (CONSP (val
) && SYMBOLP (XCDR (val
)))
344 spec
->script
= XCDR (val
);
349 spec
->script_tag
= 0x44464C54; /* "DFLT" */
350 otf_spec
= XCDR (otf_spec
);
351 val
= XCAR (otf_spec
);
353 OTF_SYM_TAG (val
, spec
->langsys_tag
);
355 spec
->langsys_tag
= 0;
356 spec
->nfeatures
[0] = spec
->nfeatures
[1] = 0;
357 for (i
= 0; i
< 2; i
++)
361 otf_spec
= XCDR (otf_spec
);
364 val
= XCAR (otf_spec
);
368 spec
->features
[i
] = malloc (sizeof (int) * XINT (len
));
369 if (! spec
->features
[i
])
371 if (i
> 0 && spec
->features
[0])
372 free (spec
->features
[0]);
376 for (j
= 0, negative
= 0; CONSP (val
); val
= XCDR (val
))
378 if (NILP (XCAR (val
)))
384 OTF_SYM_TAG (XCAR (val
), tag
);
385 spec
->features
[i
][j
++] = negative
? tag
& 0x80000000 : tag
;
388 spec
->nfeatures
[i
] = j
;
394 ftfont_spec_pattern (spec
, otlayout
, otspec
)
397 struct OpenTypeSpec
**otspec
;
399 Lisp_Object val
, tmp
, extra
;
401 FcPattern
*pattern
= NULL
;
402 FcCharSet
*charset
= NULL
;
403 FcLangSet
*langset
= NULL
;
408 Lisp_Object name
= Qnil
;
409 Lisp_Object script
= Qnil
;
410 Lisp_Object registry
= Qunicode_bmp
;
412 if (! NILP (AREF (spec
, FONT_ADSTYLE_INDEX
))
413 && SBYTES (SYMBOL_NAME (AREF (spec
, FONT_ADSTYLE_INDEX
))) > 0)
414 /* Fontconfig doesn't support adstyle property. */
416 if ((n
= FONT_SLANT_NUMERIC (spec
)) >= 0
418 /* Fontconfig doesn't support reverse-italic/obligue. */
421 if (INTEGERP (AREF (spec
, FONT_DPI_INDEX
)))
422 dpi
= XINT (AREF (spec
, FONT_DPI_INDEX
));
423 if (INTEGERP (AREF (spec
, FONT_SPACING_INDEX
)))
424 spacing
= XINT (AREF (spec
, FONT_SPACING_INDEX
));
425 if (INTEGERP (AREF (spec
, FONT_AVGWIDTH_INDEX
))
426 && XINT (AREF (spec
, FONT_AVGWIDTH_INDEX
)) == 0)
429 if (! NILP (AREF (spec
, FONT_REGISTRY_INDEX
)))
431 registry
= AREF (spec
, FONT_REGISTRY_INDEX
);
432 if (EQ (registry
, Qiso8859_1
))
435 && ftfont_build_basic_charsets () < 0)
437 charset
= cs_iso8859_1
;
439 else if (! EQ (registry
, Qiso10646_1
)
440 && ! EQ (registry
, Qunicode_bmp
)
441 && ! EQ (registry
, Qunicode_sip
))
446 for (extra
= AREF (spec
, FONT_EXTRA_INDEX
);
447 CONSP (extra
); extra
= XCDR (extra
))
449 Lisp_Object key
, val
;
451 key
= XCAR (XCAR (extra
)), val
= XCDR (XCAR (extra
));
454 else if (EQ (key
, QCfc_unknown_spec
))
456 else if (EQ (key
, QClang
))
458 langset
= FcLangSetCreate ();
463 if (! FcLangSetAdd (langset
, SYMBOL_FcChar8 (val
)))
467 for (; CONSP (val
); val
= XCDR (val
))
468 if (SYMBOLP (XCAR (val
))
469 && ! FcLangSetAdd (langset
, SYMBOL_FcChar8 (XCAR (val
))))
472 else if (EQ (key
, QCname
))
474 else if (EQ (key
, QCotf
))
476 *otspec
= ftfont_get_open_type_spec (val
);
479 strcat (otlayout
, "otlayout:");
480 OTF_TAG_STR ((*otspec
)->script_tag
, otlayout
+ 9);
481 script
= (*otspec
)->script
;
483 else if (EQ (key
, QCscript
))
485 else if (EQ (key
, QCscalable
))
486 scalable
= ! NILP (val
);
489 if (! NILP (script
) && ! charset
)
491 Lisp_Object chars
= assq_no_quit (script
, Vscript_representative_chars
);
495 charset
= FcCharSetCreate ();
498 for (chars
= XCDR (chars
); CONSP (chars
); chars
= XCDR (chars
))
499 if (CHARACTERP (XCAR (chars
))
500 && ! FcCharSetAddChar (charset
, XUINT (XCAR (chars
))))
505 pattern
= NILP (name
) ? FcPatternCreate () : FcNameParse (SDATA (name
));
508 FcPatternDel (pattern
, FC_SIZE
);
509 FcPatternDel (pattern
, FC_PIXEL_SIZE
);
510 tmp
= AREF (spec
, FONT_FOUNDRY_INDEX
);
512 && ! FcPatternAddString (pattern
, FC_FOUNDRY
, SYMBOL_FcChar8 (tmp
)))
515 && ! FcPatternAddCharSet (pattern
, FC_CHARSET
, charset
))
518 && ! FcPatternAddLangSet (pattern
, FC_LANG
, langset
))
521 && ! FcPatternAddDouble (pattern
, FC_DPI
, dpi
))
524 && ! FcPatternAddInteger (pattern
, FC_SPACING
, spacing
))
527 && ! FcPatternAddBool (pattern
, FC_SCALABLE
, scalable
? FcTrue
: FcFalse
))
532 /* We come here because of unexpected error in fontconfig API call
533 (usually insufficient memory). */
536 FcPatternDestroy (pattern
);
541 if ((*otspec
)->nfeatures
[0] > 0)
542 free ((*otspec
)->features
[0]);
543 if ((*otspec
)->nfeatures
[1] > 0)
544 free ((*otspec
)->features
[1]);
550 if (charset
&& charset
!= cs_iso8859_1
) FcCharSetDestroy (charset
);
551 if (langset
) FcLangSetDestroy (langset
);
556 ftfont_list (frame
, spec
)
557 Lisp_Object frame
, spec
;
559 Lisp_Object val
, tmp
, registry
, family
, family_list
;
562 FcFontSet
*fontset
= NULL
;
563 FcObjectSet
*objset
= NULL
;
564 double pixel_size
= 0;
565 int weight
= -1, slant
= -1, width
= -1;
569 char otlayout
[15]; /* For "otlayout:XXXX" */
570 struct OpenTypeSpec
*otspec
= NULL
;
572 if (! fc_initialized
)
578 pattern
= ftfont_spec_pattern (spec
, otlayout
, &otspec
);
581 objset
= FcObjectSetBuild (FC_FOUNDRY
, FC_FAMILY
, FC_WEIGHT
, FC_SLANT
,
582 FC_WIDTH
, FC_PIXEL_SIZE
, FC_SPACING
, FC_SCALABLE
,
586 #endif /* FC_CAPABILITY */
589 #endif /* FC_FONTFORMAT */
594 registry
= AREF (spec
, FONT_REGISTRY_INDEX
);
595 family
= AREF (spec
, FONT_FAMILY_INDEX
);
597 family_list
= Fcons (Qnil
, Qnil
);
600 family
= Fintern (Fdowncase (SYMBOL_NAME (family
)), Qnil
);
601 family_list
= ftfont_list_generic_family (family
);
602 if (NILP (family_list
))
603 family_list
= Fcons (family
, Qnil
);
606 for (val
= Qnil
; CONSP (family_list
); family_list
= XCDR (family_list
))
608 family
= XCAR (family_list
);
611 FcPatternDel (pattern
, FC_FAMILY
);
612 if (! FcPatternAddString (pattern
, FC_FAMILY
, SYMBOL_FcChar8 (family
)))
615 fontset
= FcFontList (NULL
, pattern
, objset
);
618 for (i
= 0; i
< fontset
->nfont
; i
++)
629 if (FcPatternGetString (fontset
->fonts
[i
], FC_CAPABILITY
, 0,
630 &this) != FcResultMatch
631 || ! strstr ((char *) this, otlayout
))
634 #endif /* FC_CAPABILITY */
641 if (FcPatternGetString (fontset
->fonts
[i
], FC_FILE
, 0, &file
)
644 otf
= OTF_open ((char *) file
);
647 if (OTF_check_features (otf
, 1,
648 otspec
->script_tag
, otspec
->langsys_tag
,
650 otspec
->nfeatures
[0]) != 1
651 || OTF_check_features (otf
, 0,
652 otspec
->script_tag
, otspec
->langsys_tag
,
654 otspec
->nfeatures
[1]) != 1)
657 #endif /* HAVE_LIBOTF */
658 entity
= ftfont_pattern_entity (fontset
->fonts
[i
], registry
);
660 val
= Fcons (entity
, val
);
662 FcFontSetDestroy (fontset
);
668 /* We come here because of unexpected error in fontconfig API call
669 (usually insufficient memory). */
673 if (objset
) FcObjectSetDestroy (objset
);
674 if (fontset
) FcFontSetDestroy (fontset
);
675 if (pattern
) FcPatternDestroy (pattern
);
680 ftfont_match (frame
, spec
)
681 Lisp_Object frame
, spec
;
683 Lisp_Object extra
, val
, entity
;
684 FcPattern
*pattern
, *match
= NULL
;
686 char otlayout
[15]; /* For "otlayout:XXXX" */
687 struct OpenTypeSpec
*otspec
= NULL
;
689 if (! fc_initialized
)
695 pattern
= ftfont_spec_pattern (spec
, otlayout
, &otspec
);
699 if (INTEGERP (AREF (spec
, FONT_SIZE_INDEX
)))
703 value
.type
= FcTypeDouble
;
704 value
.u
.d
= XINT (AREF (spec
, FONT_SIZE_INDEX
));
705 FcPatternAdd (pattern
, FC_PIXEL_SIZE
, value
, FcFalse
);
707 if (FcConfigSubstitute (NULL
, pattern
, FcMatchPattern
) == FcTrue
)
709 FcDefaultSubstitute (pattern
);
710 match
= FcFontMatch (NULL
, pattern
, &result
);
713 entity
= ftfont_pattern_entity (match
, Qunicode_bmp
);
714 FcPatternDestroy (match
);
715 if (! NILP (AREF (spec
, FONT_FAMILY_INDEX
))
716 && NILP (assq_no_quit (AREF (spec
, FONT_FAMILY_INDEX
),
717 ftfont_generic_family_list
))
718 && NILP (Fstring_equal (AREF (spec
, FONT_FAMILY_INDEX
),
719 AREF (entity
, FONT_FAMILY_INDEX
))))
723 FcPatternDestroy (pattern
);
729 ftfont_list_family (frame
)
733 FcPattern
*pattern
= NULL
;
734 FcFontSet
*fontset
= NULL
;
735 FcObjectSet
*objset
= NULL
;
738 if (! fc_initialized
)
744 pattern
= FcPatternCreate ();
747 objset
= FcObjectSetBuild (FC_FAMILY
, NULL
);
750 fontset
= FcFontList (NULL
, pattern
, objset
);
755 for (i
= 0; i
< fontset
->nfont
; i
++)
757 FcPattern
*pat
= fontset
->fonts
[i
];
760 if (FcPatternGetString (pat
, FC_FAMILY
, 0, &str
) == FcResultMatch
)
761 list
= Fcons (intern ((char *) str
), list
);
765 if (objset
) FcObjectSetDestroy (objset
);
766 if (fontset
) FcFontSetDestroy (fontset
);
767 if (pattern
) FcPatternDestroy (pattern
);
774 ftfont_open (f
, entity
, pixel_size
)
779 struct ftfont_info
*ftfont_info
;
784 Lisp_Object val
, font_object
;
786 FcChar8
*file
= NULL
, *fmt
= NULL
;
793 val
= assq_no_quit (QCfont_entity
, AREF (entity
, FONT_EXTRA_INDEX
));
797 pattern
= XSAVE_VALUE (val
)->pointer
;
798 if (XSAVE_VALUE (val
)->integer
== 0)
800 /* We have not yet created FT_Face for this font. */
802 && FT_Init_FreeType (&ft_library
) != 0)
804 if (FcPatternGetString (pattern
, FC_FILE
, 0, &file
) != FcResultMatch
)
806 if (FT_New_Face (ft_library
, (char *) file
, 0, &ft_face
) != 0)
808 FcPatternAddFTFace (pattern
, FC_FT_FACE
, ft_face
);
809 ft_size
= ft_face
->size
;
810 XSAVE_VALUE (val
)->integer
++;
814 if (FcPatternGetFTFace (pattern
, FC_FT_FACE
, 0, &ft_face
)
817 if (FT_New_Size (ft_face
, &ft_size
) != 0)
819 if (FT_Activate_Size (ft_size
) != 0)
821 FT_Done_Size (ft_size
);
826 size
= XINT (AREF (entity
, FONT_SIZE_INDEX
));
829 if (FT_Set_Pixel_Sizes (ft_face
, size
, size
) != 0)
831 if (XSAVE_VALUE (val
)->integer
== 0)
832 FT_Done_Face (ft_face
);
836 font_object
= font_make_object (VECSIZE (struct ftfont_info
));
837 ASET (font_object
, FONT_TYPE_INDEX
, Qfreetype
);
838 for (i
= 1;i
< FONT_ENTITY_MAX
; i
++)
839 ASET (font_object
, i
, AREF (entity
, i
));
840 ASET (font_object
, FONT_SIZE_INDEX
, make_number (size
));
841 len
= font_unparse_xlfd (entity
, size
, name
, 256);
843 ASET (font_object
, FONT_NAME_INDEX
, make_unibyte_string (name
, len
));
844 len
= font_unparse_fcname (entity
, size
, name
, 256);
846 ASET (font_object
, FONT_FULLNAME_INDEX
, make_unibyte_string (name
, len
));
848 ASET (font_object
, FONT_FULLNAME_INDEX
,
849 AREF (font_object
, FONT_NAME_INDEX
));
851 && ! FcPatternGetString (pattern
, FC_FILE
, 0, &file
) != FcResultMatch
)
853 ASET (font_object
, FONT_FILE_INDEX
,
854 make_unibyte_string ((char *) file
, strlen ((char *) file
)));
855 ASET (font_object
, FONT_FORMAT_INDEX
, ftfont_font_format (pattern
));
856 font
= XFONT_OBJECT (font_object
);
857 ftfont_info
= (struct ftfont_info
*) font
;
858 ftfont_info
->ft_size
= ft_size
;
860 ftfont_info
->maybe_otf
= ft_face
->face_flags
& FT_FACE_FLAG_SFNT
;
861 ftfont_info
->otf
= NULL
;
862 #endif /* HAVE_LIBOTF */
863 font
->pixel_size
= size
;
864 font
->driver
= &ftfont_driver
;
865 font
->encoding_charset
= font
->repertory_charset
= -1;
867 upEM
= ft_face
->units_per_EM
;
868 if (! FcPatternGetBool (pattern
, FC_SCALABLE
, 0, &scalable
) == FcResultMatch
)
872 font
->ascent
= ft_face
->ascender
* size
/ upEM
;
873 font
->descent
= - ft_face
->descender
* size
/ upEM
;
874 font
->height
= ft_face
->height
* size
/ upEM
;
878 font
->ascent
= ft_face
->size
->metrics
.ascender
>> 6;
879 font
->descent
= - ft_face
->size
->metrics
.descender
>> 6;
880 font
->height
= ft_face
->size
->metrics
.height
>> 6;
882 if (FcPatternGetInteger (pattern
, FC_SPACING
, 0, &spacing
) != FcResultMatch
)
883 spacing
= FC_PROPORTIONAL
;
884 if (spacing
!= FC_PROPORTIONAL
)
885 font
->min_width
= font
->average_width
= font
->space_width
886 = (scalable
? ft_face
->max_advance_width
* size
/ upEM
887 : ft_face
->size
->metrics
.max_advance
>> 6);
892 font
->min_width
= font
->average_width
= font
->space_width
= 0;
893 for (i
= 32, n
= 0; i
< 127; i
++)
894 if (FT_Load_Char (ft_face
, i
, FT_LOAD_DEFAULT
) != 0)
896 int this_width
= ft_face
->glyph
->metrics
.horiAdvance
>> 6;
899 && (! font
->min_width
|| font
->min_width
> this_width
))
900 font
->min_width
= this_width
;
902 font
->space_width
= this_width
;
903 font
->average_width
+= this_width
;
907 font
->average_width
/= n
;
910 font
->baseline_offset
= 0;
911 font
->relative_compose
= 0;
912 font
->default_ascent
= 0;
913 font
->vertical_centering
= 0;
916 font
->underline_position
= -ft_face
->underline_position
* size
/ upEM
;
917 font
->underline_thickness
= -ft_face
->underline_thickness
* size
/ upEM
;
921 font
->underline_position
= -1;
922 font
->underline_thickness
= 0;
929 ftfont_close (f
, font
)
933 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
936 val
= assq_no_quit (QCfont_entity
, font
->props
[FONT_EXTRA_INDEX
]);
938 (XSAVE_VALUE (val
)->integer
)--;
939 if (XSAVE_VALUE (val
)->integer
== 0)
941 FT_Done_Face (ftfont_info
->ft_size
->face
);
943 if (ftfont_info
->otf
)
944 OTF_close (ftfont_info
->otf
);
948 FT_Done_Size (ftfont_info
->ft_size
);
952 ftfont_has_char (entity
, c
)
960 val
= assq_no_quit (QCfont_entity
, AREF (entity
, FONT_EXTRA_INDEX
));
962 pattern
= XSAVE_VALUE (val
)->pointer
;
963 if (FcPatternGetCharSet (pattern
, FC_CHARSET
, 0, &charset
) != FcResultMatch
)
965 return (FcCharSetHasChar (charset
, (FcChar32
) c
) == FcTrue
);
969 ftfont_encode_char (font
, c
)
973 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
974 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
975 FT_ULong charcode
= c
;
976 FT_UInt code
= FT_Get_Char_Index (ft_face
, charcode
);
978 return (code
> 0 ? code
: FONT_INVALID_CODE
);
982 ftfont_text_extents (font
, code
, nglyphs
, metrics
)
986 struct font_metrics
*metrics
;
988 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
989 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
993 if (ftfont_info
->ft_size
!= ft_face
->size
)
994 FT_Activate_Size (ftfont_info
->ft_size
);
996 bzero (metrics
, sizeof (struct font_metrics
));
997 for (i
= 0; i
< nglyphs
; i
++)
999 if (FT_Load_Glyph (ft_face
, code
[i
], FT_LOAD_DEFAULT
) == 0)
1001 FT_Glyph_Metrics
*m
= &ft_face
->glyph
->metrics
;
1005 if (metrics
->lbearing
> width
+ (m
->horiBearingX
>> 6))
1006 metrics
->lbearing
= width
+ (m
->horiBearingX
>> 6);
1007 if (metrics
->rbearing
1008 < width
+ ((m
->horiBearingX
+ m
->width
) >> 6))
1010 = width
+ ((m
->horiBearingX
+ m
->width
) >> 6);
1011 if (metrics
->ascent
< (m
->horiBearingY
>> 6))
1012 metrics
->ascent
= m
->horiBearingY
>> 6;
1013 if (metrics
->descent
> ((m
->horiBearingY
+ m
->height
) >> 6))
1014 metrics
->descent
= (m
->horiBearingY
+ m
->height
) >> 6;
1016 width
+= m
->horiAdvance
>> 6;
1020 width
+= font
->space_width
;
1024 metrics
->width
= width
;
1030 ftfont_get_bitmap (font
, code
, bitmap
, bits_per_pixel
)
1033 struct font_bitmap
*bitmap
;
1036 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1037 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1038 FT_Int32 load_flags
= FT_LOAD_RENDER
;
1040 if (ftfont_info
->ft_size
!= ft_face
->size
)
1041 FT_Activate_Size (ftfont_info
->ft_size
);
1042 if (bits_per_pixel
== 1)
1044 #ifdef FT_LOAD_TARGET_MONO
1045 load_flags
|= FT_LOAD_TARGET_MONO
;
1047 load_flags
|= FT_LOAD_MONOCHROME
;
1050 else if (bits_per_pixel
!= 8)
1051 /* We don't support such a rendering. */
1054 if (FT_Load_Glyph (ft_face
, code
, load_flags
) != 0)
1056 bitmap
->bits_per_pixel
1057 = (ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_MONO
? 1
1058 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_GRAY
? 8
1059 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_LCD
? 8
1060 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_LCD_V
? 8
1062 if (bitmap
->bits_per_pixel
< 0)
1063 /* We don't suport that kind of pixel mode. */
1065 bitmap
->rows
= ft_face
->glyph
->bitmap
.rows
;
1066 bitmap
->width
= ft_face
->glyph
->bitmap
.width
;
1067 bitmap
->pitch
= ft_face
->glyph
->bitmap
.pitch
;
1068 bitmap
->buffer
= ft_face
->glyph
->bitmap
.buffer
;
1069 bitmap
->left
= ft_face
->glyph
->bitmap_left
;
1070 bitmap
->top
= ft_face
->glyph
->bitmap_top
;
1071 bitmap
->advance
= ft_face
->glyph
->metrics
.horiAdvance
>> 6;
1072 bitmap
->extra
= NULL
;
1078 ftfont_anchor_point (font
, code
, index
, x
, y
)
1084 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1085 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1087 if (ftfont_info
->ft_size
!= ft_face
->size
)
1088 FT_Activate_Size (ftfont_info
->ft_size
);
1089 if (FT_Load_Glyph (ft_face
, code
, FT_LOAD_DEFAULT
) != 0)
1091 if (ft_face
->glyph
->format
!= FT_GLYPH_FORMAT_OUTLINE
)
1093 if (index
>= ft_face
->glyph
->outline
.n_points
)
1095 *x
= ft_face
->glyph
->outline
.points
[index
].x
;
1096 *y
= ft_face
->glyph
->outline
.points
[index
].y
;
1101 #ifdef HAVE_M17N_FLT
1112 ftfont_get_glyph_id (font
, gstring
, from
, to
)
1114 MFLTGlyphString
*gstring
;
1117 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1118 FT_Face ft_face
= flt_font_ft
->ft_face
;
1121 for (g
= gstring
->glyphs
+ from
; from
< to
; g
++, from
++)
1124 FT_UInt code
= FT_Get_Char_Index (ft_face
, g
->code
);
1126 g
->code
= code
> 0 ? code
: FONT_INVALID_CODE
;
1133 ftfont_get_metrics (font
, gstring
, from
, to
)
1135 MFLTGlyphString
*gstring
;
1138 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1139 FT_Face ft_face
= flt_font_ft
->ft_face
;
1142 for (g
= gstring
->glyphs
+ from
; from
< to
; g
++, from
++)
1145 if (g
->code
!= FONT_INVALID_CODE
)
1147 FT_Glyph_Metrics
*m
;
1149 if (FT_Load_Glyph (ft_face
, g
->code
, FT_LOAD_DEFAULT
) != 0)
1151 m
= &ft_face
->glyph
->metrics
;
1153 g
->lbearing
= m
->horiBearingX
;
1154 g
->rbearing
= m
->horiBearingX
+ m
->width
;
1155 g
->ascent
= m
->horiBearingY
;
1156 g
->descent
= m
->height
- m
->horiBearingY
;
1157 g
->xadv
= m
->horiAdvance
;
1162 g
->rbearing
= g
->xadv
= flt_font_ft
->font
->space_width
<< 6;
1163 g
->ascent
= flt_font_ft
->font
->ascent
<< 6;
1164 g
->descent
= flt_font_ft
->font
->descent
<< 6;
1173 ftfont_check_otf (MFLTFont
*font
, MFLTOtfSpec
*spec
)
1175 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1176 OTF
*otf
= flt_font_ft
->otf
;
1180 for (i
= 0; i
< 2; i
++)
1182 if (! spec
->features
[i
])
1184 for (n
= 0; spec
->features
[i
][n
]; n
++);
1185 tags
= alloca (sizeof (OTF_Tag
) * n
);
1186 for (n
= 0, negative
= 0; spec
->features
[i
][n
]; n
++)
1188 if (spec
->features
[i
][n
] == 0xFFFFFFFF)
1191 tags
[n
- 1] = spec
->features
[i
][n
] | 0x80000000;
1193 tags
[n
] = spec
->features
[i
][n
];
1195 if (n
- negative
> 0
1196 && OTF_check_features (otf
, i
== 0, spec
->script
, spec
->langsys
,
1197 tags
, n
- negative
) != 1)
1203 #define DEVICE_DELTA(table, size) \
1204 (((size) >= (table).StartSize && (size) <= (table).EndSize) \
1205 ? (table).DeltaValue[(size) - (table).StartSize] << 6 \
1209 adjust_anchor (FT_Face ft_face
, OTF_Anchor
*anchor
,
1210 unsigned code
, int x_ppem
, int y_ppem
, int *x
, int *y
)
1212 if (anchor
->AnchorFormat
== 2)
1214 FT_Outline
*outline
;
1215 int ap
= anchor
->f
.f1
.AnchorPoint
;
1217 FT_Load_Glyph (ft_face
, (FT_UInt
) code
, FT_LOAD_MONOCHROME
);
1218 outline
= &ft_face
->glyph
->outline
;
1219 if (ap
< outline
->n_points
)
1221 *x
= outline
->points
[ap
].x
<< 6;
1222 *y
= outline
->points
[ap
].y
<< 6;
1225 else if (anchor
->AnchorFormat
== 3)
1227 if (anchor
->f
.f2
.XDeviceTable
.offset
)
1228 *x
+= DEVICE_DELTA (anchor
->f
.f2
.XDeviceTable
, x_ppem
);
1229 if (anchor
->f
.f2
.YDeviceTable
.offset
)
1230 *y
+= DEVICE_DELTA (anchor
->f
.f2
.YDeviceTable
, y_ppem
);
1234 static OTF_GlyphString otf_gstring
;
1237 ftfont_drive_otf (font
, spec
, in
, from
, to
, out
, adjustment
)
1240 MFLTGlyphString
*in
;
1242 MFLTGlyphString
*out
;
1243 MFLTGlyphAdjustment
*adjustment
;
1245 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1246 FT_Face ft_face
= flt_font_ft
->ft_face
;
1247 OTF
*otf
= flt_font_ft
->otf
;
1248 int len
= to
- from
;
1251 char script
[5], *langsys
= NULL
;
1252 char *gsub_features
= NULL
, *gpos_features
= NULL
;
1256 OTF_tag_name (spec
->script
, script
);
1259 langsys
= alloca (5);
1260 OTF_tag_name (spec
->langsys
, langsys
);
1262 for (i
= 0; i
< 2; i
++)
1266 if (spec
->features
[i
] && spec
->features
[i
][1] != 0xFFFFFFFF)
1268 for (j
= 0; spec
->features
[i
][j
]; j
++);
1270 p
= gsub_features
= alloca (6 * j
);
1272 p
= gpos_features
= alloca (6 * j
);
1273 for (j
= 0; spec
->features
[i
][j
]; j
++)
1275 if (spec
->features
[i
][j
] == 0xFFFFFFFF)
1276 *p
++ = '*', *p
++ = ',';
1279 OTF_tag_name (spec
->features
[i
][j
], p
);
1288 if (otf_gstring
.size
== 0)
1290 otf_gstring
.glyphs
= (OTF_Glyph
*) malloc (sizeof (OTF_Glyph
) * len
);
1291 otf_gstring
.size
= len
;
1293 else if (otf_gstring
.size
< len
)
1295 otf_gstring
.glyphs
= (OTF_Glyph
*) realloc (otf_gstring
.glyphs
,
1296 sizeof (OTF_Glyph
) * len
);
1297 otf_gstring
.size
= len
;
1299 otf_gstring
.used
= len
;
1300 memset (otf_gstring
.glyphs
, 0, sizeof (OTF_Glyph
) * len
);
1301 for (i
= 0; i
< len
; i
++)
1303 otf_gstring
.glyphs
[i
].c
= in
->glyphs
[from
+ i
].c
;
1304 otf_gstring
.glyphs
[i
].glyph_id
= in
->glyphs
[from
+ i
].code
;
1307 OTF_drive_gdef (otf
, &otf_gstring
);
1312 if (OTF_drive_gsub (otf
, &otf_gstring
, script
, langsys
, gsub_features
)
1315 if (out
->allocated
< out
->used
+ otf_gstring
.used
)
1317 for (i
= 0, otfg
= otf_gstring
.glyphs
; i
< otf_gstring
.used
; )
1321 int min_from
, max_to
;
1324 g
= out
->glyphs
+ out
->used
;
1325 *g
= in
->glyphs
[from
+ otfg
->f
.index
.from
];
1326 if (g
->code
!= otfg
->glyph_id
)
1329 g
->code
= otfg
->glyph_id
;
1335 if (otfg
->f
.index
.from
< otfg
->f
.index
.to
)
1337 /* OTFG substitutes multiple glyphs in IN. */
1338 for (j
= from
+ otfg
->f
.index
.from
+ 1;
1339 j
<= from
+ otfg
->f
.index
.to
; j
++)
1341 if (min_from
> in
->glyphs
[j
].from
)
1342 min_from
= in
->glyphs
[j
].from
;
1343 if (max_to
< in
->glyphs
[j
].to
)
1344 max_to
= in
->glyphs
[j
].to
;
1349 for (i
++, otfg
++; (i
< otf_gstring
.used
1350 && otfg
->f
.index
.from
== otfg
[-1].f
.index
.from
);
1353 g
= out
->glyphs
+ out
->used
;
1354 *g
= in
->glyphs
[from
+ otfg
->f
.index
.to
];
1355 if (g
->code
!= otfg
->glyph_id
)
1358 g
->code
= otfg
->glyph_id
;
1367 if (out
->allocated
< out
->used
+ len
)
1369 for (i
= 0; i
< len
; i
++)
1370 out
->glyphs
[out
->used
++] = in
->glyphs
[from
+ i
];
1375 MFLTGlyph
*base
= NULL
, *mark
= NULL
, *g
;
1376 int x_ppem
, y_ppem
, x_scale
, y_scale
;
1378 if (OTF_drive_gpos (otf
, &otf_gstring
, script
, langsys
, gpos_features
)
1382 x_ppem
= ft_face
->size
->metrics
.x_ppem
;
1383 y_ppem
= ft_face
->size
->metrics
.y_ppem
;
1384 x_scale
= ft_face
->size
->metrics
.x_scale
;
1385 y_scale
= ft_face
->size
->metrics
.y_scale
;
1387 for (i
= 0, otfg
= otf_gstring
.glyphs
, g
= out
->glyphs
+ gidx
;
1388 i
< otf_gstring
.used
; i
++, otfg
++, g
++)
1392 if (! otfg
->glyph_id
)
1394 switch (otfg
->positioning_type
)
1398 case 1: /* Single */
1401 int format
= otfg
->f
.f1
.format
;
1403 if (format
& OTF_XPlacement
)
1405 = otfg
->f
.f1
.value
->XPlacement
* x_scale
/ 0x10000;
1406 if (format
& OTF_XPlaDevice
)
1408 += DEVICE_DELTA (otfg
->f
.f1
.value
->XPlaDevice
, x_ppem
);
1409 if (format
& OTF_YPlacement
)
1411 = - (otfg
->f
.f1
.value
->YPlacement
* y_scale
/ 0x10000);
1412 if (format
& OTF_YPlaDevice
)
1414 -= DEVICE_DELTA (otfg
->f
.f1
.value
->YPlaDevice
, y_ppem
);
1415 if (format
& OTF_XAdvance
)
1417 += otfg
->f
.f1
.value
->XAdvance
* x_scale
/ 0x10000;
1418 if (format
& OTF_XAdvDevice
)
1420 += DEVICE_DELTA (otfg
->f
.f1
.value
->XAdvDevice
, x_ppem
);
1421 if (format
& OTF_YAdvance
)
1423 += otfg
->f
.f1
.value
->YAdvance
* y_scale
/ 0x10000;
1424 if (format
& OTF_YAdvDevice
)
1426 += DEVICE_DELTA (otfg
->f
.f1
.value
->YAdvDevice
, y_ppem
);
1427 adjustment
[i
].set
= 1;
1430 case 3: /* Cursive */
1431 /* Not yet supported. */
1433 case 4: /* Mark-to-Base */
1434 case 5: /* Mark-to-Ligature */
1438 goto label_adjust_anchor
;
1439 default: /* i.e. case 6 Mark-to-Mark */
1444 label_adjust_anchor
:
1446 int base_x
, base_y
, mark_x
, mark_y
;
1447 int this_from
, this_to
;
1449 base_x
= otfg
->f
.f4
.base_anchor
->XCoordinate
* x_scale
/ 0x10000;
1450 base_y
= otfg
->f
.f4
.base_anchor
->YCoordinate
* y_scale
/ 0x10000;
1451 mark_x
= otfg
->f
.f4
.mark_anchor
->XCoordinate
* x_scale
/ 0x10000;
1452 mark_y
= otfg
->f
.f4
.mark_anchor
->YCoordinate
* y_scale
/ 0x10000;;
1454 if (otfg
->f
.f4
.base_anchor
->AnchorFormat
!= 1)
1455 adjust_anchor (ft_face
, otfg
->f
.f4
.base_anchor
,
1456 prev
->code
, x_ppem
, y_ppem
, &base_x
, &base_y
);
1457 if (otfg
->f
.f4
.mark_anchor
->AnchorFormat
!= 1)
1458 adjust_anchor (ft_face
, otfg
->f
.f4
.mark_anchor
, g
->code
,
1459 x_ppem
, y_ppem
, &mark_x
, &mark_y
);
1460 adjustment
[i
].xoff
= (base_x
- mark_x
);
1461 adjustment
[i
].yoff
= - (base_y
- mark_y
);
1462 adjustment
[i
].back
= (g
- prev
);
1463 adjustment
[i
].xadv
= 0;
1464 adjustment
[i
].advance_is_absolute
= 1;
1465 adjustment
[i
].set
= 1;
1466 this_from
= g
->from
;
1468 for (j
= 0; prev
+ j
< g
; j
++)
1470 if (this_from
> prev
[j
].from
)
1471 this_from
= prev
[j
].from
;
1472 if (this_to
< prev
[j
].to
)
1473 this_to
= prev
[j
].to
;
1475 for (; prev
<= g
; prev
++)
1477 prev
->from
= this_from
;
1482 if (otfg
->GlyphClass
== OTF_GlyphClass0
)
1484 else if (otfg
->GlyphClass
== OTF_GlyphClassMark
)
1493 if (out
->allocated
< out
->used
+ len
)
1495 font
->get_metrics (font
, in
, from
, to
);
1496 memcpy (out
->glyphs
+ out
->used
, in
->glyphs
+ from
,
1497 sizeof (MFLTGlyph
) * len
);
1502 static MFLTGlyphString gstring
;
1504 static int m17n_flt_initialized
;
1506 extern Lisp_Object QCfamily
;
1509 ftfont_shape_by_flt (lgstring
, font
, ft_face
, otf
)
1510 Lisp_Object lgstring
;
1515 EMACS_UINT len
= LGSTRING_LENGTH (lgstring
);
1517 struct MFLTFontFT flt_font_ft
;
1519 if (! m17n_flt_initialized
)
1522 m17n_flt_initialized
= 1;
1525 for (i
= 0; i
< len
; i
++)
1526 if (NILP (LGSTRING_GLYPH (lgstring
, i
)))
1530 if (gstring
.allocated
== 0)
1532 gstring
.allocated
= len
* 2;
1533 gstring
.glyph_size
= sizeof (MFLTGlyph
);
1534 gstring
.glyphs
= malloc (sizeof (MFLTGlyph
) * gstring
.allocated
);
1536 else if (gstring
.allocated
< len
* 2)
1538 gstring
.allocated
= len
* 2;
1539 gstring
.glyphs
= realloc (gstring
.glyphs
,
1540 sizeof (MFLTGlyph
) * gstring
.allocated
);
1542 for (i
= 0; i
< len
; i
++)
1543 gstring
.glyphs
[i
].c
= LGLYPH_CHAR (LGSTRING_GLYPH (lgstring
, i
));
1548 Lisp_Object family
= Ffont_get (LGSTRING_FONT (lgstring
), QCfamily
);
1551 flt_font_ft
.flt_font
.family
= Mnil
;
1553 flt_font_ft
.flt_font
.family
= msymbol (SDATA (SYMBOL_NAME (family
)));
1555 flt_font_ft
.flt_font
.x_ppem
= ft_face
->size
->metrics
.x_ppem
;
1556 flt_font_ft
.flt_font
.y_ppem
= ft_face
->size
->metrics
.y_ppem
;
1557 flt_font_ft
.flt_font
.get_glyph_id
= ftfont_get_glyph_id
;
1558 flt_font_ft
.flt_font
.get_metrics
= ftfont_get_metrics
;
1559 flt_font_ft
.flt_font
.check_otf
= ftfont_check_otf
;
1560 flt_font_ft
.flt_font
.drive_otf
= ftfont_drive_otf
;
1561 flt_font_ft
.flt_font
.internal
= NULL
;
1562 flt_font_ft
.font
= font
;
1563 flt_font_ft
.ft_face
= ft_face
;
1564 flt_font_ft
.otf
= otf
;
1565 for (i
= 0; i
< 3; i
++)
1567 int result
= mflt_run (&gstring
, 0, len
, &flt_font_ft
.flt_font
, NULL
);
1570 gstring
.allocated
+= gstring
.allocated
;
1571 gstring
.glyphs
= realloc (gstring
.glyphs
,
1572 sizeof (MFLTGlyph
) * gstring
.allocated
);
1574 if (gstring
.used
> LGSTRING_LENGTH (lgstring
))
1576 for (i
= 0; i
< gstring
.used
; i
++)
1578 MFLTGlyph
*g
= gstring
.glyphs
+ i
;
1580 g
->from
= LGLYPH_FROM (LGSTRING_GLYPH (lgstring
, g
->from
));
1581 g
->to
= LGLYPH_TO (LGSTRING_GLYPH (lgstring
, g
->to
));
1584 for (i
= 0; i
< gstring
.used
; i
++)
1586 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
1587 MFLTGlyph
*g
= gstring
.glyphs
+ i
;
1591 lglyph
= Fmake_vector (make_number (LGLYPH_SIZE
), Qnil
);
1592 LGSTRING_SET_GLYPH (lgstring
, i
, lglyph
);
1594 LGLYPH_SET_FROM (lglyph
, g
->from
);
1595 LGLYPH_SET_TO (lglyph
, g
->to
);
1596 LGLYPH_SET_CHAR (lglyph
, g
->c
);
1597 LGLYPH_SET_CODE (lglyph
, g
->code
);
1598 LGLYPH_SET_WIDTH (lglyph
, g
->xadv
>> 6);
1599 LGLYPH_SET_LBEARING (lglyph
, g
->lbearing
>> 6);
1600 LGLYPH_SET_RBEARING (lglyph
, g
->rbearing
>> 6);
1601 LGLYPH_SET_ASCENT (lglyph
, g
->ascent
>> 6);
1602 LGLYPH_SET_DESCENT (lglyph
, g
->descent
>> 6);
1607 vec
= Fmake_vector (make_number (3), Qnil
);
1608 ASET (vec
, 0, make_number (g
->xoff
>> 6));
1609 ASET (vec
, 1, make_number (g
->yoff
>> 6));
1610 ASET (vec
, 2, make_number (g
->xadv
>> 6));
1611 LGLYPH_SET_ADJUSTMENT (lglyph
, vec
);
1614 return make_number (i
);
1618 ftfont_shape (lgstring
)
1619 Lisp_Object lgstring
;
1622 struct ftfont_info
*ftfont_info
;
1624 CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring
), font
);
1625 ftfont_info
= (struct ftfont_info
*) font
;
1626 if (! ftfont_info
->maybe_otf
)
1627 return make_number (0);
1628 if (! ftfont_info
->otf
)
1630 OTF
*otf
= OTF_open_ft_face (ftfont_info
->ft_size
->face
);
1632 if (! otf
|| OTF_get_table (otf
, "head") < 0)
1636 ftfont_info
->maybe_otf
= 0;
1637 return make_number (0);
1640 ftfont_info
->otf
= otf
;
1643 return ftfont_shape_by_flt (lgstring
, font
, ftfont_info
->ft_size
->face
,
1647 #endif /* HAVE_M17N_FLT */
1648 #endif /* HAVE_LIBOTF */
1651 ftfont_font_format (FcPattern
*pattern
)
1655 #ifdef FC_FONTFORMAT
1656 if (FcPatternGetString (pattern
, FC_FONTFORMAT
, 0, &str
) != FcResultMatch
)
1658 if (strcmp ((char *) str
, "TrueType") == 0)
1659 return intern ("truetype");
1660 if (strcmp ((char *) str
, "Type 1") == 0)
1661 return intern ("type1");
1662 if (strcmp ((char *) str
, "PCF") == 0)
1663 return intern ("pcf");
1664 if (strcmp ((char *) str
, "BDF") == 0)
1665 return intern ("bdf");
1666 #else /* not FC_FONTFORMAT */
1667 if (FcPatternGetString (pattern
, FC_FILE
, 0, &str
) != FcResultMatch
)
1669 if (strcasestr ((char *) str
, ".ttf") == 0)
1670 return intern ("truetype");
1671 if (strcasestr ((char *) str
, "pfb") == 0)
1672 return intern ("type1");
1673 if (strcasestr ((char *) str
, "pcf") == 0)
1674 return intern ("pcf");
1675 if (strcasestr ((char *) str
, "bdf") == 0)
1676 return intern ("bdf");
1677 #endif /* not FC_FONTFORMAT */
1678 return intern ("unknown");
1685 DEFSYM (Qfreetype
, "freetype");
1686 DEFSYM (Qmonospace
, "monospace");
1687 DEFSYM (Qsans_serif
, "sans-serif");
1688 DEFSYM (Qserif
, "serif");
1689 DEFSYM (Qmono
, "mono");
1690 DEFSYM (Qsans
, "sans");
1691 DEFSYM (Qsans__serif
, "sans serif");
1693 staticpro (&freetype_font_cache
);
1694 freetype_font_cache
= Fcons (Qt
, Qnil
);
1696 staticpro (&ftfont_generic_family_list
);
1697 ftfont_generic_family_list
1698 = Fcons (Fcons (Qmonospace
, Qt
),
1699 Fcons (Fcons (Qsans_serif
, Qt
),
1700 Fcons (Fcons (Qsans
, Qt
), Qnil
)));
1702 ftfont_driver
.type
= Qfreetype
;
1703 register_font_driver (&ftfont_driver
, NULL
);
1706 /* arch-tag: 7cfa432c-33a6-4988-83d2-a82ed8604aca
1707 (do not change this comment) */