4 * Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
29 #include <freetype/freetype.h>
30 #include <freetype/internal/ftobjs.h>
31 #include <freetype/tttables.h>
32 #include <fontconfig/fcfreetype.h>
37 } FcCodePageRange
[] = {
38 { 0, (FcChar8
*) FC_LANG_LATIN_1
},
39 { 1, (FcChar8
*) FC_LANG_LATIN_2_EASTERN_EUROPE
},
40 { 2, (FcChar8
*) FC_LANG_CYRILLIC
},
41 { 3, (FcChar8
*) FC_LANG_GREEK
},
42 { 4, (FcChar8
*) FC_LANG_TURKISH
},
43 { 5, (FcChar8
*) FC_LANG_HEBREW
},
44 { 6, (FcChar8
*) FC_LANG_ARABIC
},
45 { 7, (FcChar8
*) FC_LANG_WINDOWS_BALTIC
},
46 { 8, (FcChar8
*) FC_LANG_VIETNAMESE
},
47 /* 9-15 reserved for Alternate ANSI */
48 { 16, (FcChar8
*) FC_LANG_THAI
},
49 { 17, (FcChar8
*) FC_LANG_JAPANESE
},
50 { 18, (FcChar8
*) FC_LANG_SIMPLIFIED_CHINESE
},
51 { 19, (FcChar8
*) FC_LANG_KOREAN_WANSUNG
},
52 { 20, (FcChar8
*) FC_LANG_TRADITIONAL_CHINESE
},
53 { 21, (FcChar8
*) FC_LANG_KOREAN_JOHAB
},
54 /* 22-28 reserved for Alternate ANSI & OEM */
55 { 29, (FcChar8
*) FC_LANG_MACINTOSH
},
56 { 30, (FcChar8
*) FC_LANG_OEM
},
57 { 31, (FcChar8
*) FC_LANG_SYMBOL
},
58 /* 32-47 reserved for OEM */
59 { 48, (FcChar8
*) FC_LANG_IBM_GREEK
},
60 { 49, (FcChar8
*) FC_LANG_MSDOS_RUSSIAN
},
61 { 50, (FcChar8
*) FC_LANG_MSDOS_NORDIC
},
62 { 51, (FcChar8
*) FC_LANG_ARABIC_864
},
63 { 52, (FcChar8
*) FC_LANG_MSDOS_CANADIAN_FRENCH
},
64 { 53, (FcChar8
*) FC_LANG_HEBREW_862
},
65 { 54, (FcChar8
*) FC_LANG_MSDOS_ICELANDIC
},
66 { 55, (FcChar8
*) FC_LANG_MSDOS_PORTUGUESE
},
67 { 56, (FcChar8
*) FC_LANG_IBM_TURKISH
},
68 { 57, (FcChar8
*) FC_LANG_IBM_CYRILLIC
},
69 { 58, (FcChar8
*) FC_LANG_LATIN_2
},
70 { 59, (FcChar8
*) FC_LANG_MSDOS_BALTIC
},
71 { 60, (FcChar8
*) FC_LANG_GREEK_437_G
},
72 { 61, (FcChar8
*) FC_LANG_ARABIC_ASMO_708
},
73 { 62, (FcChar8
*) FC_LANG_WE_LATIN_1
},
74 { 63, (FcChar8
*) FC_LANG_US
},
77 #define NUM_CODE_PAGE_RANGE (sizeof FcCodePageRange / sizeof FcCodePageRange[0])
80 FcFreeTypeQuery (const FcChar8
*file
,
92 const FcChar8
*family
;
95 if (FT_Init_FreeType (&ftLibrary
))
98 if (FT_New_Face (ftLibrary
, (char *) file
, id
, &face
))
101 *count
= face
->num_faces
;
103 pat
= FcPatternCreate ();
107 if (!FcPatternAddBool (pat
, FC_OUTLINE
,
108 (face
->face_flags
& FT_FACE_FLAG_SCALABLE
) != 0))
111 if (!FcPatternAddBool (pat
, FC_SCALABLE
,
112 (face
->face_flags
& FT_FACE_FLAG_SCALABLE
) != 0))
116 slant
= FC_SLANT_ROMAN
;
117 if (face
->style_flags
& FT_STYLE_FLAG_ITALIC
)
118 slant
= FC_SLANT_ITALIC
;
120 if (!FcPatternAddInteger (pat
, FC_SLANT
, slant
))
123 weight
= FC_WEIGHT_MEDIUM
;
124 if (face
->style_flags
& FT_STYLE_FLAG_BOLD
)
125 weight
= FC_WEIGHT_BOLD
;
127 if (!FcPatternAddInteger (pat
, FC_WEIGHT
, weight
))
130 family
= (FcChar8
*) face
->family_name
;
133 family
= (FcChar8
*) strrchr ((char *) file
, '/');
139 if (!FcPatternAddString (pat
, FC_FAMILY
, family
))
142 if (face
->style_name
)
144 if (!FcPatternAddString (pat
, FC_STYLE
, (FcChar8
*) face
->style_name
))
148 if (!FcPatternAddString (pat
, FC_FILE
, file
))
151 if (!FcPatternAddInteger (pat
, FC_INDEX
, id
))
154 if (!FcPatternAddString (pat
, FC_SOURCE
, (FcChar8
*) "FreeType"))
158 if ((face
->face_flags
& FT_FACE_FLAG_FIXED_WIDTH
) != 0)
159 if (!FcPatternAddInteger (pat
, FC_SPACING
, FC_MONO
))
163 cs
= FcFreeTypeCharSet (face
, blanks
);
168 * Skip over PCF fonts that have no encoded characters; they're
169 * usually just Unicode fonts transcoded to some legacy encoding
171 if (FcCharSetCount (cs
) == 0)
173 if (!strcmp(FT_MODULE_CLASS(&face
->driver
->root
)->module_name
, "pcf"))
177 if (!FcPatternAddCharSet (pat
, FC_CHARSET
, cs
))
180 * Drop our reference to the charset
182 FcCharSetDestroy (cs
);
184 if (!(face
->face_flags
& FT_FACE_FLAG_SCALABLE
))
186 for (i
= 0; i
< face
->num_fixed_sizes
; i
++)
187 if (!FcPatternAddDouble (pat
, FC_PIXEL_SIZE
,
188 (double) face
->available_sizes
[i
].height
))
190 if (!FcPatternAddBool (pat
, FC_ANTIALIAS
, FcFalse
))
195 * Get the OS/2 table and poke about
197 os2
= (TT_OS2
*) FT_Get_Sfnt_Table (face
, ft_sfnt_os2
);
198 if (os2
&& os2
->version
>= 0x0001 && os2
->version
!= 0xffff)
200 for (i
= 0; i
< NUM_CODE_PAGE_RANGE
; i
++)
204 if (FcCodePageRange
[i
].bit
< 32)
206 bits
= os2
->ulCodePageRange1
;
207 bit
= FcCodePageRange
[i
].bit
;
211 bits
= os2
->ulCodePageRange2
;
212 bit
= FcCodePageRange
[i
].bit
- 32;
214 if (bits
& (1 << bit
))
216 if (!FcPatternAddString (pat
, FC_LANG
,
217 FcCodePageRange
[i
].name
))
224 FT_Done_FreeType (ftLibrary
);
228 FcCharSetDestroy (cs
);
230 FcPatternDestroy (pat
);
234 FT_Done_FreeType (ftLibrary
);