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>
36 } FcCodePageRange[] = {
37 { 0, (FcChar8 *) FC_LANG_LATIN_1 },
38 { 1, (FcChar8 *) FC_LANG_LATIN_2_EASTERN_EUROPE },
39 { 2, (FcChar8 *) FC_LANG_CYRILLIC },
40 { 3, (FcChar8 *) FC_LANG_GREEK },
41 { 4, (FcChar8 *) FC_LANG_TURKISH },
42 { 5, (FcChar8 *) FC_LANG_HEBREW },
43 { 6, (FcChar8 *) FC_LANG_ARABIC },
44 { 7, (FcChar8 *) FC_LANG_WINDOWS_BALTIC },
45 { 8, (FcChar8 *) FC_LANG_VIETNAMESE },
46 /* 9-15 reserved for Alternate ANSI */
47 { 16, (FcChar8 *) FC_LANG_THAI },
48 { 17, (FcChar8 *) FC_LANG_JAPANESE },
49 { 18, (FcChar8 *) FC_LANG_SIMPLIFIED_CHINESE },
50 { 19, (FcChar8 *) FC_LANG_KOREAN_WANSUNG },
51 { 20, (FcChar8 *) FC_LANG_TRADITIONAL_CHINESE },
52 { 21, (FcChar8 *) FC_LANG_KOREAN_JOHAB },
53 /* 22-28 reserved for Alternate ANSI & OEM */
54 { 29, (FcChar8 *) FC_LANG_MACINTOSH },
55 { 30, (FcChar8 *) FC_LANG_OEM },
56 { 31, (FcChar8 *) FC_LANG_SYMBOL },
57 /* 32-47 reserved for OEM */
58 { 48, (FcChar8 *) FC_LANG_IBM_GREEK },
59 { 49, (FcChar8 *) FC_LANG_MSDOS_RUSSIAN },
60 { 50, (FcChar8 *) FC_LANG_MSDOS_NORDIC },
61 { 51, (FcChar8 *) FC_LANG_ARABIC_864 },
62 { 52, (FcChar8 *) FC_LANG_MSDOS_CANADIAN_FRENCH },
63 { 53, (FcChar8 *) FC_LANG_HEBREW_862 },
64 { 54, (FcChar8 *) FC_LANG_MSDOS_ICELANDIC },
65 { 55, (FcChar8 *) FC_LANG_MSDOS_PORTUGUESE },
66 { 56, (FcChar8 *) FC_LANG_IBM_TURKISH },
67 { 57, (FcChar8 *) FC_LANG_IBM_CYRILLIC },
68 { 58, (FcChar8 *) FC_LANG_LATIN_2 },
69 { 59, (FcChar8 *) FC_LANG_MSDOS_BALTIC },
70 { 60, (FcChar8 *) FC_LANG_GREEK_437_G },
71 { 61, (FcChar8 *) FC_LANG_ARABIC_ASMO_708 },
72 { 62, (FcChar8 *) FC_LANG_WE_LATIN_1 },
73 { 63, (FcChar8 *) FC_LANG_US },
76 #define NUM_CODE_PAGE_RANGE (sizeof FcCodePageRange / sizeof FcCodePageRange[0])
79 FcFreeTypeQuery (const FcChar8 *file,
91 const FcChar8 *family;
94 if (FT_Init_FreeType (&ftLibrary))
97 if (FT_New_Face (ftLibrary, (char *) file, id, &face))
100 *count = face->num_faces;
102 pat = FcPatternCreate ();
106 if (!FcPatternAddBool (pat, FC_OUTLINE,
107 (face->face_flags & FT_FACE_FLAG_SCALABLE) != 0))
110 if (!FcPatternAddBool (pat, FC_SCALABLE,
111 (face->face_flags & FT_FACE_FLAG_SCALABLE) != 0))
115 slant = FC_SLANT_ROMAN;
116 if (face->style_flags & FT_STYLE_FLAG_ITALIC)
117 slant = FC_SLANT_ITALIC;
119 if (!FcPatternAddInteger (pat, FC_SLANT, slant))
122 weight = FC_WEIGHT_MEDIUM;
123 if (face->style_flags & FT_STYLE_FLAG_BOLD)
124 weight = FC_WEIGHT_BOLD;
126 if (!FcPatternAddInteger (pat, FC_WEIGHT, weight))
129 family = (FcChar8 *) face->family_name;
132 family = (FcChar8 *) strrchr ((char *) file, '/');
138 if (!FcPatternAddString (pat, FC_FAMILY, family))
141 if (face->style_name)
143 if (!FcPatternAddString (pat, FC_STYLE, (FcChar8 *) face->style_name))
147 if (!FcPatternAddString (pat, FC_FILE, file))
150 if (!FcPatternAddInteger (pat, FC_INDEX, id))
153 if (!FcPatternAddString (pat, FC_SOURCE, (FcChar8 *) "FreeType"))
157 if ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0)
158 if (!FcPatternAddInteger (pat, FC_SPACING, FC_MONO))
162 cs = FcFreeTypeCharSet (face, blanks);
167 * Skip over PCF fonts that have no encoded characters; they're
168 * usually just Unicode fonts transcoded to some legacy encoding
170 if (FcCharSetCount (cs) == 0)
172 if (!strcmp(FT_MODULE_CLASS(&face->driver->root)->module_name, "pcf"))
176 if (!FcPatternAddCharSet (pat, FC_CHARSET, cs))
179 * Drop our reference to the charset
181 FcCharSetDestroy (cs);
183 if (!(face->face_flags & FT_FACE_FLAG_SCALABLE))
185 for (i = 0; i < face->num_fixed_sizes; i++)
186 if (!FcPatternAddDouble (pat, FC_PIXEL_SIZE,
187 (double) face->available_sizes[i].height))
189 if (!FcPatternAddBool (pat, FC_ANTIALIAS, FcFalse))
194 * Get the OS/2 table and poke about
196 os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2);
197 if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
199 for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
203 if (FcCodePageRange[i].bit < 32)
205 bits = os2->ulCodePageRange1;
206 bit = FcCodePageRange[i].bit;
210 bits = os2->ulCodePageRange2;
211 bit = FcCodePageRange[i].bit - 32;
213 if (bits & (1 << bit))
215 if (!FcPatternAddString (pat, FC_LANG,
216 FcCodePageRange[i].name))
223 FT_Done_FreeType (ftLibrary);
227 FcCharSetDestroy (cs);
229 FcPatternDestroy (pat);
233 FT_Done_FreeType (ftLibrary);