1 /* ftfont.c -- FreeType font driver.
2 Copyright (C) 2006 Free Software Foundation, Inc.
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 2, or (at your option)
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; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
27 #include <fontconfig/fontconfig.h>
28 #include <fontconfig/fcfreetype.h>
31 #include "dispextern.h"
33 #include "blockinput.h"
34 #include "character.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 areadly 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 /* Fontconfig's charset used for finding fonts of registry
58 static FcCharSet
*cs_iso8859_1
;
60 /* The actual structure for FreeType font that can be casted to struct
68 int maybe_otf
; /* Flag to tell if this may be OTF or not. */
70 #endif /* HAVE_LIBOTF */
73 static int ftfont_build_basic_charsets
P_ ((void));
74 static Lisp_Object ftfont_pattern_entity
P_ ((FcPattern
*,
75 Lisp_Object
, Lisp_Object
));
76 static Lisp_Object ftfont_list_generic_family
P_ ((Lisp_Object
, Lisp_Object
,
78 Lisp_Object ftfont_font_format
P_ ((FcPattern
*));
80 #define SYMBOL_FcChar8(SYM) (FcChar8 *) SDATA (SYMBOL_NAME (SYM))
83 ftfont_build_basic_charsets ()
87 cs_iso8859_1
= FcCharSetCreate ();
90 for (c
= ' '; c
< 127; c
++)
91 if (! FcCharSetAddChar (cs_iso8859_1
, c
))
94 /* This part is currently disabled. Should be fixed later. */
95 for (c
= 192; c
< 256; c
++)
96 if (! FcCharSetAddChar (cs_iso8859_1
, c
))
103 ftfont_pattern_entity (p
, frame
, registry
)
105 Lisp_Object frame
, registry
;
108 FcChar8
*file
, *fontformat
;
114 if (FcPatternGetString (p
, FC_FILE
, 0, &file
) != FcResultMatch
)
116 if (FcPatternGetCharSet (p
, FC_CHARSET
, 0, &charset
) != FcResultMatch
)
119 if (FcPatternGetString (p
, FC_FONTFORMAT
, 0, &fontformat
) != FcResultMatch
)
120 #endif /* FC_FONTFORMAT */
123 entity
= Fmake_vector (make_number (FONT_ENTITY_MAX
), null_string
);
125 ASET (entity
, FONT_TYPE_INDEX
, Qfreetype
);
126 ASET (entity
, FONT_REGISTRY_INDEX
, registry
);
127 ASET (entity
, FONT_FRAME_INDEX
, frame
);
128 ASET (entity
, FONT_OBJLIST_INDEX
, Qnil
);
130 if (FcPatternGetString (p
, FC_FOUNDRY
, 0, (FcChar8
**) &str
) == FcResultMatch
)
131 ASET (entity
, FONT_FOUNDRY_INDEX
, intern_downcase (str
, strlen (str
)));
132 if (FcPatternGetString (p
, FC_FAMILY
, 0, (FcChar8
**) &str
) == FcResultMatch
)
133 ASET (entity
, FONT_FAMILY_INDEX
, intern_downcase (str
, strlen (str
)));
134 if (FcPatternGetInteger (p
, FC_WEIGHT
, 0, &numeric
) == FcResultMatch
)
136 if (numeric
== FC_WEIGHT_REGULAR
)
138 ASET (entity
, FONT_WEIGHT_INDEX
, make_number (numeric
));
140 if (FcPatternGetInteger (p
, FC_SLANT
, 0, &numeric
) == FcResultMatch
)
141 ASET (entity
, FONT_SLANT_INDEX
, make_number (numeric
+ 100));
142 if (FcPatternGetInteger (p
, FC_WIDTH
, 0, &numeric
) == FcResultMatch
)
143 ASET (entity
, FONT_WIDTH_INDEX
, make_number (numeric
));
144 if (FcPatternGetDouble (p
, FC_PIXEL_SIZE
, 0, &dbl
) == FcResultMatch
)
145 ASET (entity
, FONT_SIZE_INDEX
, make_number (dbl
));
147 ASET (entity
, FONT_SIZE_INDEX
, make_number (0));
149 if (FcPatternGetInteger (p
, FC_SPACING
, 0, &numeric
) != FcResultMatch
)
151 file
= FcStrCopy (file
);
155 p
= FcPatternCreate ();
159 if (FcPatternAddString (p
, FC_FILE
, file
) == FcFalse
161 && FcPatternAddCharSet (p
, FC_CHARSET
, charset
) == FcFalse
)
164 && FcPatternAddString (p
, FC_FONTFORMAT
, fontformat
) == FcFalse
)
165 #endif /* FC_FONTFORMAT */
167 && FcPatternAddInteger (p
, FC_SPACING
, numeric
) == FcFalse
))
169 FcPatternDestroy (p
);
172 ASET (entity
, FONT_EXTRA_INDEX
, make_save_value (p
, 0));
176 static Lisp_Object ftfont_generic_family_list
;
179 ftfont_list_generic_family (spec
, frame
, registry
)
180 Lisp_Object spec
, frame
, registry
;
182 Lisp_Object family
= AREF (spec
, FONT_FAMILY_INDEX
);
183 Lisp_Object slot
, list
, val
;
185 if (EQ (family
, Qmono
))
187 else if (EQ (family
, Qsans
) || EQ (family
, Qsans__serif
))
188 family
= Qsans_serif
;
189 slot
= assq_no_quit (family
, ftfont_generic_family_list
);
195 /* Not yet listed. */
196 FcObjectSet
*objset
= NULL
;
197 FcPattern
*pattern
= NULL
, *pat
= NULL
;
198 FcFontSet
*fontset
= NULL
;
202 objset
= FcObjectSetBuild (FC_FOUNDRY
, FC_FAMILY
, FC_WEIGHT
, FC_SLANT
,
203 FC_WIDTH
, FC_PIXEL_SIZE
, FC_SPACING
,
207 #endif /* FC_FONTFORMAT */
211 pattern
= FcPatternBuild (NULL
, FC_FAMILY
, FcTypeString
,
212 SYMBOL_FcChar8 (family
), (char *) 0);
215 pat
= FcPatternCreate ();
218 FcConfigSubstitute (NULL
, pattern
, FcMatchPattern
);
219 for (i
= 0, val
= Qnil
;
220 FcPatternGetString (pattern
, FC_FAMILY
, i
, &fam
) == FcResultMatch
;
223 if (strcmp ((char *) fam
, (char *) SYMBOL_FcChar8 (family
)) == 0)
225 if (! FcPatternAddString (pat
, FC_FAMILY
, fam
))
227 fontset
= FcFontList (NULL
, pat
, objset
);
230 /* Here we build the list in reverse order so that the last
231 loop in this function build a list in the correct
233 for (j
= 0; j
< fontset
->nfont
; j
++)
237 entity
= ftfont_pattern_entity (fontset
->fonts
[j
],
240 val
= Fcons (entity
, val
);
242 FcFontSetDestroy (fontset
);
244 FcPatternDel (pat
, FC_FAMILY
);
247 XSETCDR (slot
, list
);
249 if (pat
) FcPatternDestroy (pat
);
250 if (pattern
) FcPatternDestroy (pattern
);
251 if (fontset
) FcFontSetDestroy (fontset
);
252 if (objset
) FcObjectSetDestroy (objset
);
256 ASET (spec
, FONT_FAMILY_INDEX
, Qnil
);
257 for (val
= Qnil
; CONSP (list
); list
= XCDR (list
))
258 if (font_match_p (spec
, XCAR (list
)))
259 val
= Fcons (XCAR (list
), val
);
260 ASET (spec
, FONT_FAMILY_INDEX
, family
);
261 return Fvconcat (1, &val
);
265 static Lisp_Object ftfont_get_cache
P_ ((Lisp_Object
));
266 static Lisp_Object ftfont_list
P_ ((Lisp_Object
, Lisp_Object
));
267 static Lisp_Object ftfont_match
P_ ((Lisp_Object
, Lisp_Object
));
268 static Lisp_Object ftfont_list_family
P_ ((Lisp_Object
));
269 static void ftfont_free_entity
P_ ((Lisp_Object
));
270 static struct font
*ftfont_open
P_ ((FRAME_PTR
, Lisp_Object
, int));
271 static void ftfont_close
P_ ((FRAME_PTR
, struct font
*));
272 static int ftfont_has_char
P_ ((Lisp_Object
, int));
273 static unsigned ftfont_encode_char
P_ ((struct font
*, int));
274 static int ftfont_text_extents
P_ ((struct font
*, unsigned *, int,
275 struct font_metrics
*));
276 static int ftfont_get_bitmap
P_ ((struct font
*, unsigned,
277 struct font_bitmap
*, int));
278 static int ftfont_anchor_point
P_ ((struct font
*, unsigned, int,
280 static Lisp_Object ftfont_shape
P_ ((Lisp_Object
));
282 struct font_driver ftfont_driver
=
292 /* We can't draw a text without device dependent functions. */
298 /* We can't draw a text without device dependent functions. */
311 #else /* not HAVE_M17N_FLT */
313 #endif /* not HAVE_M17N_FLT */
316 extern Lisp_Object QCname
;
319 ftfont_get_cache (frame
)
322 return freetype_font_cache
;
328 unsigned int script_tag
, langsys_tag
;
330 unsigned int *features
[2];
333 #define OTF_SYM_TAG(SYM, TAG) \
335 unsigned char *p = SDATA (SYMBOL_NAME (SYM)); \
336 TAG = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; \
339 #define OTF_TAG_STR(TAG, P) \
341 (P)[0] = (char) (TAG >> 24); \
342 (P)[1] = (char) ((TAG >> 16) & 0xFF); \
343 (P)[2] = (char) ((TAG >> 8) & 0xFF); \
344 (P)[3] = (char) (TAG & 0xFF); \
348 static struct OpenTypeSpec
*
349 ftfont_get_open_type_spec (Lisp_Object otf_spec
)
351 struct OpenTypeSpec
*spec
= malloc (sizeof (struct OpenTypeSpec
));
357 spec
->script
= XCAR (otf_spec
);
360 OTF_SYM_TAG (spec
->script
, spec
->script_tag
);
361 val
= assq_no_quit (spec
->script
, Votf_script_alist
);
362 if (CONSP (val
) && SYMBOLP (XCDR (val
)))
363 spec
->script
= XCDR (val
);
368 spec
->script_tag
= 0x44464C54; /* "DFLT" */
369 otf_spec
= XCDR (otf_spec
);
370 val
= XCAR (otf_spec
);
372 OTF_SYM_TAG (val
, spec
->langsys_tag
);
374 spec
->langsys_tag
= 0;
375 spec
->nfeatures
[0] = spec
->nfeatures
[1] = 0;
376 for (i
= 0; i
< 2; i
++)
380 otf_spec
= XCDR (otf_spec
);
383 val
= XCAR (otf_spec
);
387 spec
->features
[i
] = malloc (sizeof (int) * XINT (len
));
388 if (! spec
->features
[i
])
390 if (i
> 0 && spec
->features
[0])
391 free (spec
->features
[0]);
395 for (j
= 0, negative
= 0; CONSP (val
); val
= XCDR (val
))
397 if (NILP (XCAR (val
)))
403 OTF_SYM_TAG (XCAR (val
), tag
);
404 spec
->features
[i
][j
++] = negative
? tag
& 0x80000000 : tag
;
407 spec
->nfeatures
[i
] = j
;
413 ftfont_list (frame
, spec
)
414 Lisp_Object frame
, spec
;
416 Lisp_Object val
, tmp
, extra
;
418 FcPattern
*pattern
= NULL
;
419 FcCharSet
*charset
= NULL
;
420 FcLangSet
*langset
= NULL
;
421 FcFontSet
*fontset
= NULL
;
422 FcObjectSet
*objset
= NULL
;
424 Lisp_Object registry
= Qunicode_bmp
;
425 struct OpenTypeSpec
*otspec
= NULL
;
430 char otlayout
[15]; /* For "otlayout:XXXX" */
434 if (! fc_initialized
)
440 if (! NILP (AREF (spec
, FONT_ADSTYLE_INDEX
))
441 && ! EQ (AREF (spec
, FONT_ADSTYLE_INDEX
), null_string
))
443 if (! NILP (AREF (spec
, FONT_SLANT_INDEX
))
444 && XINT (AREF (spec
, FONT_SLANT_INDEX
)) < 100)
445 /* Fontconfig doesn't support reverse-italic/obligue. */
448 if (! NILP (AREF (spec
, FONT_REGISTRY_INDEX
)))
450 registry
= AREF (spec
, FONT_REGISTRY_INDEX
);
451 if (EQ (registry
, Qiso8859_1
))
454 && ftfont_build_basic_charsets () < 0)
456 charset
= cs_iso8859_1
;
458 else if (! EQ (registry
, Qiso10646_1
)
459 && ! EQ (registry
, Qunicode_bmp
)
460 && ! EQ (registry
, Qunicode_sip
))
466 for (extra
= AREF (spec
, FONT_EXTRA_INDEX
);
467 CONSP (extra
); extra
= XCDR (extra
))
469 Lisp_Object key
, val
;
472 key
= XCAR (tmp
), val
= XCDR (tmp
);
475 otspec
= ftfont_get_open_type_spec (val
);
478 strcat (otlayout
, "otlayout:");
479 OTF_TAG_STR (otspec
->script_tag
, otlayout
+ 9);
480 script
= otspec
->script
;
482 else if (EQ (key
, QClanguage
))
484 langset
= FcLangSetCreate ();
489 if (! FcLangSetAdd (langset
, SYMBOL_FcChar8 (val
)))
493 for (; CONSP (val
); val
= XCDR (val
))
494 if (SYMBOLP (XCAR (val
))
495 && ! FcLangSetAdd (langset
, SYMBOL_FcChar8 (XCAR (val
))))
498 else if (EQ (key
, QCscript
))
500 else if (EQ (key
, QCdpi
))
502 else if (EQ (key
, QCspacing
))
503 spacing
= XINT (val
);
504 else if (EQ (key
, QCscalable
))
505 scalable
= ! NILP (val
);
508 if (! NILP (script
) && ! charset
)
510 Lisp_Object chars
= assq_no_quit (script
, Vscript_representative_chars
);
514 charset
= FcCharSetCreate ();
517 for (chars
= XCDR (chars
); CONSP (chars
); chars
= XCDR (chars
))
518 if (CHARACTERP (XCAR (chars
))
519 && ! FcCharSetAddChar (charset
, XUINT (XCAR (chars
))))
524 pattern
= FcPatternCreate ();
527 tmp
= AREF (spec
, FONT_FOUNDRY_INDEX
);
528 if (SYMBOLP (tmp
) && ! NILP (tmp
)
529 && ! FcPatternAddString (pattern
, FC_FOUNDRY
, SYMBOL_FcChar8 (tmp
)))
531 tmp
= AREF (spec
, FONT_FAMILY_INDEX
);
532 if (SYMBOLP (tmp
) && ! NILP (tmp
)
533 && ! FcPatternAddString (pattern
, FC_FAMILY
, SYMBOL_FcChar8 (tmp
)))
535 /* Emacs conventionally doesn't distinguish normal, regular, and
536 medium weight, but fontconfig does. So, we can't restrict font
537 listing by weight. We check it after getting a list. */
538 tmp
= AREF (spec
, FONT_WEIGHT_INDEX
);
541 tmp
= AREF (spec
, FONT_SLANT_INDEX
);
543 && ! FcPatternAddInteger (pattern
, FC_SLANT
, XINT (tmp
) - 100))
545 tmp
= AREF (spec
, FONT_WIDTH_INDEX
);
547 && ! FcPatternAddInteger (pattern
, FC_WIDTH
, XINT (tmp
)))
551 && ! FcPatternAddCharSet (pattern
, FC_CHARSET
, charset
))
554 && ! FcPatternAddLangSet (pattern
, FC_LANG
, langset
))
557 && ! FcPatternAddDouble (pattern
, FC_DPI
, dpi
))
560 && ! FcPatternAddInteger (pattern
, FC_SPACING
, spacing
))
563 && ! FcPatternAddBool (pattern
, FC_SCALABLE
, scalable
? FcTrue
: FcFalse
))
566 objset
= FcObjectSetBuild (FC_FOUNDRY
, FC_FAMILY
, FC_WEIGHT
, FC_SLANT
,
567 FC_WIDTH
, FC_PIXEL_SIZE
, FC_SPACING
,
571 #endif /* FC_FONTFORMAT */
578 if (! FcObjectSetAdd (objset
, FC_CAPABILITY
))
580 #else /* not FC_CAPABILITY */
582 #endif /* not FC_CAPABILITY */
585 fontset
= FcFontList (NULL
, pattern
, objset
);
589 if (fontset
->nfont
> 0)
593 if (NILP (AREF (spec
, FONT_SIZE_INDEX
)))
596 pixel_size
= XINT (AREF (spec
, FONT_SIZE_INDEX
));
598 for (i
= 0, val
= Qnil
; i
< fontset
->nfont
; i
++)
606 if (FcPatternGetDouble (fontset
->fonts
[i
], FC_PIXEL_SIZE
, 0,
607 &this) == FcResultMatch
608 && ((this < pixel_size
- FONT_PIXEL_SIZE_QUANTUM
)
609 || (this > pixel_size
+ FONT_PIXEL_SIZE_QUANTUM
)))
616 if (FcPatternGetInteger (fontset
->fonts
[i
], FC_WEIGHT
, 0,
617 &this) != FcResultMatch
620 || this < FC_WEIGHT_REGULAR
621 || this > FC_WEIGHT_MEDIUM
)))
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
], frame
, registry
);
660 val
= Fcons (entity
, val
);
662 val
= Fvconcat (1, &val
);
664 else if (! NILP (AREF (spec
, FONT_FAMILY_INDEX
)))
665 val
= ftfont_list_generic_family (spec
, frame
, registry
);
669 /* We come here because of unexpected error in fontconfig API call
670 (usually insufficient memory). */
674 if (charset
&& charset
!= cs_iso8859_1
) FcCharSetDestroy (charset
);
675 if (objset
) FcObjectSetDestroy (objset
);
676 if (fontset
) FcFontSetDestroy (fontset
);
677 if (langset
) FcLangSetDestroy (langset
);
678 if (pattern
) FcPatternDestroy (pattern
);
681 if (otspec
->nfeatures
[0] > 0)
682 free (otspec
->features
[0]);
683 if (otspec
->nfeatures
[1] > 0)
684 free (otspec
->features
[1]);
691 ftfont_match (frame
, spec
)
692 Lisp_Object frame
, spec
;
694 Lisp_Object extra
, val
, entity
;
695 FcPattern
*pattern
= NULL
, *match
= NULL
;
698 if (! fc_initialized
)
704 extra
= AREF (spec
, FONT_EXTRA_INDEX
);
705 val
= assq_no_quit (QCname
, extra
);
706 if (! CONSP (val
) || ! STRINGP (XCDR (val
)))
710 pattern
= FcNameParse (SDATA (XCDR (val
)));
713 if (FcConfigSubstitute (NULL
, pattern
, FcMatchPattern
) == FcTrue
)
715 FcDefaultSubstitute (pattern
);
716 match
= FcFontMatch (NULL
, pattern
, &result
);
719 entity
= ftfont_pattern_entity (match
, frame
, Qunicode_bmp
);
720 FcPatternDestroy (match
);
723 FcPatternDestroy (pattern
);
730 ftfont_list_family (frame
)
734 FcPattern
*pattern
= NULL
;
735 FcFontSet
*fontset
= NULL
;
736 FcObjectSet
*objset
= NULL
;
739 if (! fc_initialized
)
745 pattern
= FcPatternCreate ();
748 objset
= FcObjectSetBuild (FC_FAMILY
, NULL
);
751 fontset
= FcFontList (NULL
, pattern
, objset
);
756 for (i
= 0; i
< fontset
->nfont
; i
++)
758 FcPattern
*pat
= fontset
->fonts
[i
];
761 if (FcPatternGetString (pat
, FC_FAMILY
, 0, &str
) == FcResultMatch
)
762 list
= Fcons (intern_downcase ((char *) str
, strlen ((char *) str
)),
767 if (objset
) FcObjectSetDestroy (objset
);
768 if (fontset
) FcFontSetDestroy (fontset
);
769 if (pattern
) FcPatternDestroy (pattern
);
776 ftfont_free_entity (entity
)
779 Lisp_Object val
= AREF (entity
, FONT_EXTRA_INDEX
);
780 FcPattern
*pattern
= XSAVE_VALUE (val
)->pointer
;
782 FcPatternDestroy (pattern
);
786 ftfont_open (f
, entity
, pixel_size
)
791 struct ftfont_info
*ftfont_info
;
803 val
= AREF (entity
, FONT_EXTRA_INDEX
);
804 if (XTYPE (val
) != Lisp_Misc
805 || XMISCTYPE (val
) != Lisp_Misc_Save_Value
)
807 pattern
= XSAVE_VALUE (val
)->pointer
;
808 if (XSAVE_VALUE (val
)->integer
== 0)
810 /* We have not yet created FT_Face for this font. */
812 && FT_Init_FreeType (&ft_library
) != 0)
814 if (FcPatternGetString (pattern
, FC_FILE
, 0, &file
) != FcResultMatch
)
816 if (FT_New_Face (ft_library
, (char *) file
, 0, &ft_face
) != 0)
818 FcPatternAddFTFace (pattern
, FC_FT_FACE
, ft_face
);
819 ft_size
= ft_face
->size
;
823 if (FcPatternGetFTFace (pattern
, FC_FT_FACE
, 0, &ft_face
)
826 if (FT_New_Size (ft_face
, &ft_size
) != 0)
828 if (FT_Activate_Size (ft_size
) != 0)
830 FT_Done_Size (ft_size
);
835 size
= XINT (AREF (entity
, FONT_SIZE_INDEX
));
838 if (FT_Set_Pixel_Sizes (ft_face
, size
, size
) != 0)
840 if (XSAVE_VALUE (val
)->integer
== 0)
841 FT_Done_Face (ft_face
);
845 ftfont_info
= malloc (sizeof (struct ftfont_info
));
848 ftfont_info
->ft_size
= ft_size
;
850 ftfont_info
->maybe_otf
= ft_face
->face_flags
& FT_FACE_FLAG_SFNT
;
851 ftfont_info
->otf
= NULL
;
852 #endif /* HAVE_LIBOTF */
854 font
= (struct font
*) ftfont_info
;
855 font
->format
= ftfont_font_format (pattern
);
856 font
->entity
= entity
;
857 font
->pixel_size
= size
;
858 font
->driver
= &ftfont_driver
;
861 while (name
&& font_unparse_fcname (entity
, pixel_size
, name
, len
) < 0)
863 char *new = realloc (name
, len
+= 32);
869 font
->font
.full_name
= font
->font
.name
= name
;
870 font
->file_name
= (char *) file
;
871 font
->font
.size
= ft_face
->size
->metrics
.max_advance
>> 6;
872 if (font
->font
.size
<= 0)
873 font
->font
.size
= size
;
874 font
->font
.charset
= font
->encoding_charset
= font
->repertory_charset
= -1;
875 font
->ascent
= ft_face
->size
->metrics
.ascender
>> 6;
876 font
->descent
= - ft_face
->size
->metrics
.descender
>> 6;
877 font
->font
.height
= font
->ascent
+ font
->descent
;
878 if (FcPatternGetInteger (pattern
, FC_SPACING
, 0, &spacing
) != FcResultMatch
)
879 spacing
= FC_PROPORTIONAL
;
880 if (spacing
!= FC_PROPORTIONAL
)
881 font
->font
.average_width
= font
->font
.space_width
= font
->font
.size
;
886 for (i
= 32; i
< 127; i
++)
888 if (FT_Load_Char (ft_face
, i
, FT_LOAD_DEFAULT
) != 0)
891 font
->font
.space_width
= ft_face
->glyph
->metrics
.horiAdvance
>> 6;
892 font
->font
.average_width
+= ft_face
->glyph
->metrics
.horiAdvance
>> 6;
896 /* The font contains all ASCII printable characters. */
897 font
->font
.average_width
/= 95;
902 font
->font
.space_width
= font
->font
.size
;
903 font
->font
.average_width
= font
->font
.size
;
907 /* Unfortunately FreeType doesn't provide a way to get minimum char
908 width. So, we use space_width instead. */
909 font
->min_width
= font
->font
.space_width
;
911 font
->font
.baseline_offset
= 0;
912 font
->font
.relative_compose
= 0;
913 font
->font
.default_ascent
= 0;
914 font
->font
.vertical_centering
= 0;
916 (XSAVE_VALUE (val
)->integer
)++;
922 ftfont_close (f
, font
)
926 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
927 Lisp_Object entity
= font
->entity
;
928 Lisp_Object val
= AREF (entity
, FONT_EXTRA_INDEX
);
930 (XSAVE_VALUE (val
)->integer
)--;
931 if (XSAVE_VALUE (val
)->integer
== 0)
933 FT_Done_Face (ftfont_info
->ft_size
->face
);
935 if (ftfont_info
->otf
)
936 OTF_close (ftfont_info
->otf
);
940 FT_Done_Size (ftfont_info
->ft_size
);
946 ftfont_has_char (entity
, c
)
954 val
= AREF (entity
, FONT_EXTRA_INDEX
);
955 pattern
= XSAVE_VALUE (val
)->pointer
;
956 if (FcPatternGetCharSet (pattern
, FC_CHARSET
, 0, &charset
) != FcResultMatch
)
958 return (FcCharSetHasChar (charset
, (FcChar32
) c
) == FcTrue
);
962 ftfont_encode_char (font
, c
)
966 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
967 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
968 FT_ULong charcode
= c
;
969 FT_UInt code
= FT_Get_Char_Index (ft_face
, charcode
);
971 return (code
> 0 ? code
: 0xFFFFFFFF);
975 ftfont_text_extents (font
, code
, nglyphs
, metrics
)
979 struct font_metrics
*metrics
;
981 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
982 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
986 if (ftfont_info
->ft_size
!= ft_face
->size
)
987 FT_Activate_Size (ftfont_info
->ft_size
);
989 bzero (metrics
, sizeof (struct font_metrics
));
990 for (i
= 0; i
< nglyphs
; i
++)
992 if (FT_Load_Glyph (ft_face
, code
[i
], FT_LOAD_DEFAULT
) == 0)
994 FT_Glyph_Metrics
*m
= &ft_face
->glyph
->metrics
;
998 if (metrics
->lbearing
> width
+ (m
->horiBearingX
>> 6))
999 metrics
->lbearing
= width
+ (m
->horiBearingX
>> 6);
1000 if (metrics
->rbearing
1001 < width
+ ((m
->horiBearingX
+ m
->width
) >> 6))
1003 = width
+ ((m
->horiBearingX
+ m
->width
) >> 6);
1004 if (metrics
->ascent
< (m
->horiBearingY
>> 6))
1005 metrics
->ascent
= m
->horiBearingY
>> 6;
1006 if (metrics
->descent
> ((m
->horiBearingY
+ m
->height
) >> 6))
1007 metrics
->descent
= (m
->horiBearingY
+ m
->height
) >> 6;
1009 width
+= m
->horiAdvance
>> 6;
1013 width
+= font
->font
.space_width
;
1017 metrics
->width
= width
;
1023 ftfont_get_bitmap (font
, code
, bitmap
, bits_per_pixel
)
1026 struct font_bitmap
*bitmap
;
1029 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1030 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1031 FT_Int32 load_flags
= FT_LOAD_RENDER
;
1033 if (ftfont_info
->ft_size
!= ft_face
->size
)
1034 FT_Activate_Size (ftfont_info
->ft_size
);
1035 if (bits_per_pixel
== 1)
1037 #ifdef FT_LOAD_TARGET_MONO
1038 load_flags
|= FT_LOAD_TARGET_MONO
;
1040 load_flags
|= FT_LOAD_MONOCHROME
;
1043 else if (bits_per_pixel
!= 8)
1044 /* We don't support such a rendering. */
1047 if (FT_Load_Glyph (ft_face
, code
, load_flags
) != 0)
1049 bitmap
->bits_per_pixel
1050 = (ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_MONO
? 1
1051 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_GRAY
? 8
1052 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_LCD
? 8
1053 : ft_face
->glyph
->bitmap
.pixel_mode
== FT_PIXEL_MODE_LCD_V
? 8
1055 if (bitmap
->bits_per_pixel
< 0)
1056 /* We don't suport that kind of pixel mode. */
1058 bitmap
->rows
= ft_face
->glyph
->bitmap
.rows
;
1059 bitmap
->width
= ft_face
->glyph
->bitmap
.width
;
1060 bitmap
->pitch
= ft_face
->glyph
->bitmap
.pitch
;
1061 bitmap
->buffer
= ft_face
->glyph
->bitmap
.buffer
;
1062 bitmap
->left
= ft_face
->glyph
->bitmap_left
;
1063 bitmap
->top
= ft_face
->glyph
->bitmap_top
;
1064 bitmap
->advance
= ft_face
->glyph
->metrics
.horiAdvance
>> 6;
1065 bitmap
->extra
= NULL
;
1071 ftfont_anchor_point (font
, code
, index
, x
, y
)
1077 struct ftfont_info
*ftfont_info
= (struct ftfont_info
*) font
;
1078 FT_Face ft_face
= ftfont_info
->ft_size
->face
;
1080 if (ftfont_info
->ft_size
!= ft_face
->size
)
1081 FT_Activate_Size (ftfont_info
->ft_size
);
1082 if (FT_Load_Glyph (ft_face
, code
, FT_LOAD_DEFAULT
) != 0)
1084 if (ft_face
->glyph
->format
!= FT_GLYPH_FORMAT_OUTLINE
)
1086 if (index
>= ft_face
->glyph
->outline
.n_points
)
1088 *x
= ft_face
->glyph
->outline
.points
[index
].x
;
1089 *y
= ft_face
->glyph
->outline
.points
[index
].y
;
1094 #ifdef HAVE_M17N_FLT
1105 ftfont_get_glyph_id (font
, gstring
, from
, to
)
1107 MFLTGlyphString
*gstring
;
1110 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1111 FT_Face ft_face
= flt_font_ft
->ft_face
;
1114 for (g
= gstring
->glyphs
+ from
; from
< to
; g
++, from
++)
1117 FT_UInt code
= FT_Get_Char_Index (ft_face
, g
->code
);
1119 g
->code
= code
> 0 ? code
: FONT_INVALID_CODE
;
1126 ftfont_get_metrics (font
, gstring
, from
, to
)
1128 MFLTGlyphString
*gstring
;
1131 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1132 FT_Face ft_face
= flt_font_ft
->ft_face
;
1135 for (g
= gstring
->glyphs
+ from
; from
< to
; g
++, from
++)
1138 if (g
->code
!= FONT_INVALID_CODE
)
1140 FT_Glyph_Metrics
*m
;
1142 if (FT_Load_Glyph (ft_face
, g
->code
, FT_LOAD_DEFAULT
) != 0)
1144 m
= &ft_face
->glyph
->metrics
;
1146 g
->lbearing
= m
->horiBearingX
;
1147 g
->rbearing
= m
->horiBearingX
+ m
->width
;
1148 g
->ascent
= m
->horiBearingY
;
1149 g
->descent
= m
->height
- m
->horiBearingY
;
1150 g
->xadv
= m
->horiAdvance
;
1155 g
->rbearing
= g
->xadv
= flt_font_ft
->font
->font
.space_width
<< 6;
1156 g
->ascent
= flt_font_ft
->font
->ascent
<< 6;
1157 g
->descent
= flt_font_ft
->font
->descent
<< 6;
1166 ftfont_check_otf (MFLTFont
*font
, MFLTOtfSpec
*spec
)
1168 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1169 OTF
*otf
= flt_font_ft
->otf
;
1173 for (i
= 0; i
< 2; i
++)
1175 if (! spec
->features
[i
])
1177 for (n
= 0; spec
->features
[i
][n
]; n
++);
1178 tags
= alloca (sizeof (OTF_Tag
) * n
);
1179 for (n
= 0, negative
= 0; spec
->features
[i
][n
]; n
++)
1181 if (spec
->features
[i
][n
] == 0xFFFFFFFF)
1184 tags
[n
- 1] = spec
->features
[i
][n
] | 0x80000000;
1186 tags
[n
] = spec
->features
[i
][n
];
1188 if (n
- negative
> 0
1189 && OTF_check_features (otf
, i
== 0, spec
->script
, spec
->langsys
,
1190 tags
, n
- negative
) != 1)
1196 #define DEVICE_DELTA(table, size) \
1197 (((size) >= (table).StartSize && (size) <= (table).EndSize) \
1198 ? (table).DeltaValue[(size) - (table).StartSize] << 6 \
1202 adjust_anchor (FT_Face ft_face
, OTF_Anchor
*anchor
,
1203 unsigned code
, int x_ppem
, int y_ppem
, int *x
, int *y
)
1205 if (anchor
->AnchorFormat
== 2)
1207 FT_Outline
*outline
;
1208 int ap
= anchor
->f
.f1
.AnchorPoint
;
1210 FT_Load_Glyph (ft_face
, (FT_UInt
) code
, FT_LOAD_MONOCHROME
);
1211 outline
= &ft_face
->glyph
->outline
;
1212 if (ap
< outline
->n_points
)
1214 *x
= outline
->points
[ap
].x
<< 6;
1215 *y
= outline
->points
[ap
].y
<< 6;
1218 else if (anchor
->AnchorFormat
== 3)
1220 if (anchor
->f
.f2
.XDeviceTable
.offset
)
1221 *x
+= DEVICE_DELTA (anchor
->f
.f2
.XDeviceTable
, x_ppem
);
1222 if (anchor
->f
.f2
.YDeviceTable
.offset
)
1223 *y
+= DEVICE_DELTA (anchor
->f
.f2
.YDeviceTable
, y_ppem
);
1227 static OTF_GlyphString otf_gstring
;
1230 ftfont_drive_otf (font
, spec
, in
, from
, to
, out
, adjustment
)
1233 MFLTGlyphString
*in
;
1235 MFLTGlyphString
*out
;
1236 MFLTGlyphAdjustment
*adjustment
;
1238 struct MFLTFontFT
*flt_font_ft
= (struct MFLTFontFT
*) font
;
1239 FT_Face ft_face
= flt_font_ft
->ft_face
;
1240 OTF
*otf
= flt_font_ft
->otf
;
1241 int len
= to
- from
;
1244 char script
[5], *langsys
= NULL
;
1245 char *gsub_features
= NULL
, *gpos_features
= NULL
;
1249 OTF_tag_name (spec
->script
, script
);
1252 langsys
= alloca (5);
1253 OTF_tag_name (spec
->langsys
, langsys
);
1255 for (i
= 0; i
< 2; i
++)
1259 if (spec
->features
[i
] && spec
->features
[i
][1] != 0xFFFFFFFF)
1261 for (j
= 0; spec
->features
[i
][j
]; j
++);
1263 p
= gsub_features
= alloca (6 * j
);
1265 p
= gpos_features
= alloca (6 * j
);
1266 for (j
= 0; spec
->features
[i
][j
]; j
++)
1268 if (spec
->features
[i
][j
] == 0xFFFFFFFF)
1269 *p
++ = '*', *p
++ = ',';
1272 OTF_tag_name (spec
->features
[i
][j
], p
);
1281 if (otf_gstring
.size
== 0)
1283 otf_gstring
.glyphs
= (OTF_Glyph
*) malloc (sizeof (OTF_Glyph
) * len
);
1284 otf_gstring
.size
= len
;
1286 else if (otf_gstring
.size
< len
)
1288 otf_gstring
.glyphs
= (OTF_Glyph
*) realloc (otf_gstring
.glyphs
,
1289 sizeof (OTF_Glyph
) * len
);
1290 otf_gstring
.size
= len
;
1292 otf_gstring
.used
= len
;
1293 memset (otf_gstring
.glyphs
, 0, sizeof (OTF_Glyph
) * len
);
1294 for (i
= 0; i
< len
; i
++)
1296 otf_gstring
.glyphs
[i
].c
= in
->glyphs
[from
+ i
].c
;
1297 otf_gstring
.glyphs
[i
].glyph_id
= in
->glyphs
[from
+ i
].code
;
1300 OTF_drive_gdef (otf
, &otf_gstring
);
1305 if (OTF_drive_gsub (otf
, &otf_gstring
, script
, langsys
, gsub_features
)
1308 if (out
->allocated
< out
->used
+ otf_gstring
.used
)
1310 for (i
= 0, otfg
= otf_gstring
.glyphs
; i
< otf_gstring
.used
; i
++, otfg
++)
1312 MFLTGlyph
*g
= out
->glyphs
+ out
->used
;
1315 *g
= in
->glyphs
[from
+ otfg
->f
.index
.from
];
1317 for (j
= from
+ otfg
->f
.index
.from
; j
<= from
+ otfg
->f
.index
.to
; j
++)
1318 if (in
->glyphs
[j
].code
== otfg
->glyph_id
)
1320 g
->c
= in
->glyphs
[j
].c
;
1323 if (g
->code
!= otfg
->glyph_id
)
1325 g
->code
= otfg
->glyph_id
;
1333 if (out
->allocated
< out
->used
+ len
)
1335 for (i
= 0; i
< len
; i
++)
1336 out
->glyphs
[out
->used
++] = in
->glyphs
[from
+ i
];
1341 MFLTGlyph
*base
= NULL
, *mark
= NULL
, *g
;
1342 int x_ppem
, y_ppem
, x_scale
, y_scale
;
1344 if (OTF_drive_gpos (otf
, &otf_gstring
, script
, langsys
, gpos_features
)
1348 x_ppem
= ft_face
->size
->metrics
.x_ppem
;
1349 y_ppem
= ft_face
->size
->metrics
.y_ppem
;
1350 x_scale
= ft_face
->size
->metrics
.x_scale
;
1351 y_scale
= ft_face
->size
->metrics
.y_scale
;
1353 for (i
= 0, otfg
= otf_gstring
.glyphs
, g
= out
->glyphs
+ gidx
;
1354 i
< otf_gstring
.used
; i
++, otfg
++, g
++)
1358 if (! otfg
->glyph_id
)
1360 switch (otfg
->positioning_type
)
1364 case 1: /* Single */
1367 int format
= otfg
->f
.f1
.format
;
1369 if (format
& OTF_XPlacement
)
1371 = otfg
->f
.f1
.value
->XPlacement
* x_scale
/ 0x10000;
1372 if (format
& OTF_XPlaDevice
)
1374 += DEVICE_DELTA (otfg
->f
.f1
.value
->XPlaDevice
, x_ppem
);
1375 if (format
& OTF_YPlacement
)
1377 = - (otfg
->f
.f1
.value
->YPlacement
* y_scale
/ 0x10000);
1378 if (format
& OTF_YPlaDevice
)
1380 -= DEVICE_DELTA (otfg
->f
.f1
.value
->YPlaDevice
, y_ppem
);
1381 if (format
& OTF_XAdvance
)
1383 += otfg
->f
.f1
.value
->XAdvance
* x_scale
/ 0x10000;
1384 if (format
& OTF_XAdvDevice
)
1386 += DEVICE_DELTA (otfg
->f
.f1
.value
->XAdvDevice
, x_ppem
);
1387 if (format
& OTF_YAdvance
)
1389 += otfg
->f
.f1
.value
->YAdvance
* y_scale
/ 0x10000;
1390 if (format
& OTF_YAdvDevice
)
1392 += DEVICE_DELTA (otfg
->f
.f1
.value
->YAdvDevice
, y_ppem
);
1393 adjustment
[i
].set
= 1;
1396 case 3: /* Cursive */
1397 /* Not yet supported. */
1399 case 4: /* Mark-to-Base */
1400 case 5: /* Mark-to-Ligature */
1404 goto label_adjust_anchor
;
1405 default: /* i.e. case 6 Mark-to-Mark */
1410 label_adjust_anchor
:
1412 int base_x
, base_y
, mark_x
, mark_y
;
1413 int this_from
, this_to
;
1415 base_x
= otfg
->f
.f4
.base_anchor
->XCoordinate
* x_scale
/ 0x10000;
1416 base_y
= otfg
->f
.f4
.base_anchor
->YCoordinate
* y_scale
/ 0x10000;
1417 mark_x
= otfg
->f
.f4
.mark_anchor
->XCoordinate
* x_scale
/ 0x10000;
1418 mark_y
= otfg
->f
.f4
.mark_anchor
->YCoordinate
* y_scale
/ 0x10000;;
1420 if (otfg
->f
.f4
.base_anchor
->AnchorFormat
!= 1)
1421 adjust_anchor (ft_face
, otfg
->f
.f4
.base_anchor
,
1422 prev
->code
, x_ppem
, y_ppem
, &base_x
, &base_y
);
1423 if (otfg
->f
.f4
.mark_anchor
->AnchorFormat
!= 1)
1424 adjust_anchor (ft_face
, otfg
->f
.f4
.mark_anchor
, g
->code
,
1425 x_ppem
, y_ppem
, &mark_x
, &mark_y
);
1426 adjustment
[i
].xoff
= (base_x
- mark_x
);
1427 adjustment
[i
].yoff
= - (base_y
- mark_y
);
1428 adjustment
[i
].back
= (g
- prev
);
1429 adjustment
[i
].xadv
= 0;
1430 adjustment
[i
].advance_is_absolute
= 1;
1431 adjustment
[i
].set
= 1;
1432 this_from
= g
->from
;
1434 for (j
= 0; prev
+ j
< g
; j
++)
1436 if (this_from
> prev
[j
].from
)
1437 this_from
= prev
[j
].from
;
1438 if (this_to
< prev
[j
].to
)
1439 this_to
= prev
[j
].to
;
1441 for (; prev
<= g
; prev
++)
1443 prev
->from
= this_from
;
1448 if (otfg
->GlyphClass
== OTF_GlyphClass0
)
1450 else if (otfg
->GlyphClass
== OTF_GlyphClassMark
)
1459 if (out
->allocated
< out
->used
+ len
)
1461 font
->get_metrics (font
, in
, from
, to
);
1462 memcpy (out
->glyphs
+ out
->used
, in
->glyphs
+ from
,
1463 sizeof (MFLTGlyph
) * len
);
1468 static MFLTGlyphString gstring
;
1470 static int m17n_flt_initialized
;
1472 extern Lisp_Object QCfamily
;
1475 ftfont_shape_by_flt (lgstring
, font
, ft_face
, otf
)
1476 Lisp_Object lgstring
;
1481 EMACS_UINT len
= LGSTRING_LENGTH (lgstring
);
1483 struct MFLTFontFT flt_font_ft
;
1485 if (! m17n_flt_initialized
)
1488 m17n_flt_initialized
= 1;
1491 for (i
= 0; i
< len
; i
++)
1492 if (NILP (LGSTRING_GLYPH (lgstring
, i
)))
1496 if (gstring
.allocated
== 0)
1498 gstring
.allocated
= len
* 2;
1499 gstring
.glyph_size
= sizeof (MFLTGlyph
);
1500 gstring
.glyphs
= malloc (sizeof (MFLTGlyph
) * gstring
.allocated
);
1502 else if (gstring
.allocated
< len
* 2)
1504 gstring
.allocated
= len
* 2;
1505 gstring
.glyphs
= realloc (gstring
.glyphs
,
1506 sizeof (MFLTGlyph
) * gstring
.allocated
);
1508 for (i
= 0; i
< len
; i
++)
1509 gstring
.glyphs
[i
].c
= LGLYPH_CHAR (LGSTRING_GLYPH (lgstring
, i
));
1514 Lisp_Object family
= Ffont_get (LGSTRING_FONT (lgstring
), QCfamily
);
1517 flt_font_ft
.flt_font
.family
= Mnil
;
1519 flt_font_ft
.flt_font
.family
= msymbol (SDATA (SYMBOL_NAME (family
)));
1521 flt_font_ft
.flt_font
.x_ppem
= ft_face
->size
->metrics
.x_ppem
;
1522 flt_font_ft
.flt_font
.y_ppem
= ft_face
->size
->metrics
.y_ppem
;
1523 flt_font_ft
.flt_font
.get_glyph_id
= ftfont_get_glyph_id
;
1524 flt_font_ft
.flt_font
.get_metrics
= ftfont_get_metrics
;
1525 flt_font_ft
.flt_font
.check_otf
= ftfont_check_otf
;
1526 flt_font_ft
.flt_font
.drive_otf
= ftfont_drive_otf
;
1527 flt_font_ft
.flt_font
.internal
= NULL
;
1528 flt_font_ft
.font
= font
;
1529 flt_font_ft
.ft_face
= ft_face
;
1530 flt_font_ft
.otf
= otf
;
1531 for (i
= 0; i
< 3; i
++)
1533 int result
= mflt_run (&gstring
, 0, len
, &flt_font_ft
.flt_font
, NULL
);
1536 gstring
.allocated
+= gstring
.allocated
;
1537 gstring
.glyphs
= realloc (gstring
.glyphs
,
1538 sizeof (MFLTGlyph
) * gstring
.allocated
);
1540 if (gstring
.used
> LGSTRING_LENGTH (lgstring
))
1542 for (i
= 0; i
< gstring
.used
; i
++)
1544 MFLTGlyph
*g
= gstring
.glyphs
+ i
;
1546 g
->from
= LGLYPH_FROM (LGSTRING_GLYPH (lgstring
, g
->from
));
1547 g
->to
= LGLYPH_TO (LGSTRING_GLYPH (lgstring
, g
->to
));
1550 for (i
= 0; i
< gstring
.used
; i
++)
1552 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
1553 MFLTGlyph
*g
= gstring
.glyphs
+ i
;
1555 LGLYPH_SET_FROM (lglyph
, g
->from
);
1556 LGLYPH_SET_TO (lglyph
, g
->to
);
1557 LGLYPH_SET_CHAR (lglyph
, g
->c
);
1558 LGLYPH_SET_CODE (lglyph
, g
->code
);
1559 LGLYPH_SET_WIDTH (lglyph
, g
->xadv
>> 6);
1560 LGLYPH_SET_LBEARING (lglyph
, g
->lbearing
>> 6);
1561 LGLYPH_SET_RBEARING (lglyph
, g
->rbearing
>> 6);
1562 LGLYPH_SET_ASCENT (lglyph
, g
->ascent
>> 6);
1563 LGLYPH_SET_DESCENT (lglyph
, g
->descent
>> 6);
1568 vec
= Fmake_vector (make_number (3), Qnil
);
1569 ASET (vec
, 0, make_number (g
->xoff
>> 6));
1570 ASET (vec
, 1, make_number (g
->yoff
>> 6));
1571 ASET (vec
, 2, make_number (g
->xadv
>> 6));
1572 LGLYPH_SET_ADJUSTMENT (lglyph
, vec
);
1575 return make_number (i
);
1579 ftfont_shape (lgstring
)
1580 Lisp_Object lgstring
;
1583 struct ftfont_info
*ftfont_info
;
1585 CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring
), font
);
1586 ftfont_info
= (struct ftfont_info
*) font
;
1587 if (! ftfont_info
->maybe_otf
)
1589 if (! ftfont_info
->otf
)
1591 OTF
*otf
= OTF_open_ft_face (ftfont_info
->ft_size
->face
);
1593 if (! otf
|| OTF_get_table (otf
, "head") < 0)
1597 ftfont_info
->maybe_otf
= 0;
1601 ftfont_info
->otf
= otf
;
1604 return ftfont_shape_by_flt (lgstring
, font
, ftfont_info
->ft_size
->face
,
1608 #endif /* HAVE_M17N_FLT */
1609 #endif /* HAVE_LIBOTF */
1612 ftfont_font_format (FcPattern
*pattern
)
1616 #ifdef FC_FONTFORMAT
1617 if (FcPatternGetString (pattern
, FC_FONTFORMAT
, 0, &str
) != FcResultMatch
)
1619 if (strcmp ((char *) str
, "TrueType") == 0)
1620 return intern ("truetype");
1621 if (strcmp ((char *) str
, "Type 1") == 0)
1622 return intern ("type1");
1623 if (strcmp ((char *) str
, "PCF") == 0)
1624 return intern ("pcf");
1625 if (strcmp ((char *) str
, "BDF") == 0)
1626 return intern ("bdf");
1627 #else /* not FC_FONTFORMAT */
1628 if (FcPatternGetString (pattern
, FC_FILE
, 0, &str
) != FcResultMatch
)
1630 if (strcasestr ((char *) str
, ".ttf") == 0)
1631 return intern ("truetype");
1632 if (strcasestr ((char *) str
, "pfb") == 0)
1633 return intern ("type1");
1634 if (strcasestr ((char *) str
, "pcf") == 0)
1635 return intern ("pcf");
1636 if (strcasestr ((char *) str
, "bdf") == 0)
1637 return intern ("bdf");
1638 #endif /* not FC_FONTFORMAT */
1639 return intern ("unknown");
1646 DEFSYM (Qfreetype
, "freetype");
1647 DEFSYM (Qmonospace
, "monospace");
1648 DEFSYM (Qsans_serif
, "sans-serif");
1649 DEFSYM (Qserif
, "serif");
1650 DEFSYM (Qmono
, "mono");
1651 DEFSYM (Qsans
, "sans");
1652 DEFSYM (Qsans__serif
, "sans serif");
1654 staticpro (&freetype_font_cache
);
1655 freetype_font_cache
= Fcons (Qt
, Qnil
);
1657 staticpro (&ftfont_generic_family_list
);
1658 ftfont_generic_family_list
1659 = Fcons (Fcons (Qmonospace
, Qt
),
1660 Fcons (Fcons (Qsans_serif
, Qt
),
1661 Fcons (Fcons (Qsans
, Qt
), Qnil
)));
1663 ftfont_driver
.type
= Qfreetype
;
1664 register_font_driver (&ftfont_driver
, NULL
);
1667 /* arch-tag: 7cfa432c-33a6-4988-83d2-a82ed8604aca
1668 (do not change this comment) */