]> git.wh0rd.org - fontconfig.git/blob - src/fcfreetype.c
Switch to FreeType 2.1.7 style includes. Bug #150.
[fontconfig.git] / src / fcfreetype.c
1 /*
2 * $RCSId: xc/lib/fontconfig/src/fcfreetype.c,v 1.11 2002/08/31 22:17:32 keithp Exp $
3 *
4 * Copyright © 2001 Keith Packard
5 *
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.
15 *
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.
23 */
24
25 /*
26 Copyright © 2002-2003 by Juliusz Chroboczek
27
28 Permission is hereby granted, free of charge, to any person obtaining a copy
29 of this software and associated documentation files (the "Software"), to deal
30 in the Software without restriction, including without limitation the rights
31 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32 copies of the Software, and to permit persons to whom the Software is
33 furnished to do so, subject to the following conditions:
34
35 The above copyright notice and this permission notice shall be included in
36 all copies or substantial portions of the Software.
37
38 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44 THE SOFTWARE.
45 */
46
47 #include <stdlib.h>
48 #include <stdio.h>
49 #include <string.h>
50 #include "fcint.h"
51 #include <ft2build.h>
52 #include FT_FREETYPE_H
53 #include FT_INTERNAL_OBJECTS_H
54 #include FT_TRUETYPE_TABLES_H
55 #include FT_SFNT_NAMES_H
56 #include FT_TRUETYPE_IDS_H
57 #include FT_TYPE1_TABLES_H
58
59 #if HAVE_FT_GET_BDF_PROPERTY
60 #include FT_BDF_H
61 #include FT_MODULE_H
62 #define HAS_BDF_PROPERTY(f) ((f) && (f)->driver && \
63 (f)->driver->root.clazz->get_interface)
64 #define MY_Get_BDF_Property(f,n,p) (HAS_BDF_PROPERTY(f) ? \
65 FT_Get_BDF_Property(f,n,p) : \
66 FT_Err_Invalid_Argument)
67 #endif
68
69 #if !HAVE_FT_GET_BDF_PROPERTY
70 #warning "No FT_Get_BDF_Property"
71 #endif
72
73 #if !HAVE_FT_GET_PS_FONT_INFO
74 #warning "No FT_Get_Font_Info"
75 #endif
76
77 /*
78 * Keep Han languages separated by eliminating languages
79 * that the codePageRange bits says aren't supported
80 */
81
82 static const struct {
83 int bit;
84 const FcChar8 *lang;
85 } FcCodePageRange[] = {
86 { 17, (const FcChar8 *) "ja" },
87 { 18, (const FcChar8 *) "zh-cn" },
88 { 19, (const FcChar8 *) "ko" },
89 { 20, (const FcChar8 *) "zh-tw" },
90 };
91
92 #define NUM_CODE_PAGE_RANGE (sizeof FcCodePageRange / sizeof FcCodePageRange[0])
93
94 FcBool
95 FcFreeTypeIsExclusiveLang (const FcChar8 *lang)
96 {
97 int i;
98
99 for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
100 {
101 if (FcLangCompare (lang, FcCodePageRange[i].lang) != FcLangDifferentLang)
102 return FcTrue;
103 }
104 return FcFalse;
105 }
106
107 #define FC_NAME_PRIO_LANG 0x0f00
108 #define FC_NAME_PRIO_LANG_ENGLISH 0x0200
109 #define FC_NAME_PRIO_LANG_LATIN 0x0100
110 #define FC_NAME_PRIO_LANG_NONE 0x0000
111
112 #define FC_NAME_PRIO_ENC 0x00f0
113 #define FC_NAME_PRIO_ENC_UNICODE 0x0010
114 #define FC_NAME_PRIO_ENC_NONE 0x0000
115
116 #define FC_NAME_PRIO_NAME 0x000f
117 #define FC_NAME_PRIO_NAME_FAMILY 0x0002
118 #define FC_NAME_PRIO_NAME_PS 0x0001
119 #define FC_NAME_PRIO_NAME_NONE 0x0000
120
121 static FcBool
122 FcUcs4IsLatin (FcChar32 ucs4)
123 {
124 FcChar32 page = ucs4 >> 8;
125
126 if (page <= 2)
127 return FcTrue;
128 if (page == 0x1e)
129 return FcTrue;
130 if (0x20 <= page && page <= 0x23)
131 return FcTrue;
132 if (page == 0xfb)
133 return FcTrue;
134 /* halfwidth forms, don't include kana or white parens */
135 if (0xff01 <= ucs4 && ucs4 <= 0xff5e)
136 return FcTrue;
137 return FcFalse;
138 }
139
140 static FcBool
141 FcUtf8IsLatin (FcChar8 *str, int len)
142 {
143 while (len)
144 {
145 FcChar32 ucs4;
146 int clen = FcUtf8ToUcs4 (str, &ucs4, len);
147 if (clen <= 0)
148 return FcFalse;
149 if (!FcUcs4IsLatin (ucs4))
150 return FcFalse;
151 len -= clen;
152 str += clen;
153 }
154 return FcTrue;
155 }
156
157 /* Order is significant. For example, some B&H fonts are hinted by
158 URW++, and both strings appear in the notice. */
159
160 static const struct {
161 const FcChar8 *notice;
162 const FcChar8 *foundry;
163 } FcNoticeFoundries[] = {
164 { (const FcChar8*) "Bigelow", (const FcChar8 *) "b&h" },
165 { (const FcChar8*) "Adobe", (const FcChar8 *) "adobe" },
166 { (const FcChar8*) "Bitstream", (const FcChar8 *) "bitstream" },
167 { (const FcChar8*) "Monotype", (const FcChar8 *) "monotype" },
168 { (const FcChar8*) "Linotype", (const FcChar8 *) "linotype" },
169 { (const FcChar8*) "LINOTYPE-HELL", (const FcChar8 *) "linotype" },
170 { (const FcChar8*) "IBM", (const FcChar8 *) "ibm" },
171 { (const FcChar8*) "URW", (const FcChar8 *) "urw" },
172 { (const FcChar8*) "International Typeface Corporation",
173 (const FcChar8 *) "itc" },
174 { (const FcChar8*) "Tiro Typeworks",(const FcChar8 *) "tiro" },
175 { (const FcChar8*) "XFree86", (const FcChar8 *) "xfree86" },
176 { (const FcChar8*) "Microsoft", (const FcChar8 *) "microsoft" },
177 { (const FcChar8*) "Omega", (const FcChar8 *) "omega" },
178 { (const FcChar8*) "Font21", (const FcChar8 *) "hwan" },
179 { (const FcChar8*) "HanYang System",(const FcChar8 *) "hanyang" }
180 };
181
182 #define NUM_NOTICE_FOUNDRIES (sizeof (FcNoticeFoundries) / sizeof (FcNoticeFoundries[0]))
183
184 static const FcChar8 *
185 FcNoticeFoundry(const char *notice)
186 {
187 int i;
188
189 if (notice)
190 for(i = 0; i < NUM_NOTICE_FOUNDRIES; i++)
191 if (strstr ((const char *) notice, (const char *) FcNoticeFoundries[i].notice))
192 return FcNoticeFoundries[i].foundry;
193 return 0;
194 }
195
196 static FcBool
197 FcVendorMatch(const char *vendor, const char *vendor_string)
198 {
199 /* vendor is not necessarily NUL-terminated. */
200 int i, len;
201
202 len = strlen(vendor_string);
203 if (memcmp(vendor, vendor_string, len) != 0)
204 return FcFalse;
205 for (i = len; i < 4; i++)
206 if (vendor[i] != ' ' && vendor[i] != '\0')
207 return FcFalse;
208 return FcTrue;
209 }
210
211 /* This table is partly taken from ttmkfdir by Joerg Pommnitz. */
212
213 /* It should not contain useless entries (such as UNKN) nor duplicate
214 entries for padding both with spaces and NULs. */
215
216 static const struct {
217 const FcChar8 *vendor;
218 const FcChar8 *foundry;
219 } FcVendorFoundries[] = {
220 { (const FcChar8*) "ADBE", (const FcChar8 *) "adobe"},
221 { (const FcChar8*) "AGFA", (const FcChar8 *) "agfa"},
222 { (const FcChar8*) "ALTS", (const FcChar8 *) "altsys"},
223 { (const FcChar8*) "APPL", (const FcChar8 *) "apple"},
224 { (const FcChar8*) "ARPH", (const FcChar8 *) "arphic"},
225 { (const FcChar8*) "ATEC", (const FcChar8 *) "alltype"},
226 { (const FcChar8*) "B&H", (const FcChar8 *) "b&h"},
227 { (const FcChar8*) "BITS", (const FcChar8 *) "bitstream"},
228 { (const FcChar8*) "CANO", (const FcChar8 *) "cannon"},
229 { (const FcChar8*) "DYNA", (const FcChar8 *) "dynalab"},
230 { (const FcChar8*) "EPSN", (const FcChar8 *) "epson"},
231 { (const FcChar8*) "FJ", (const FcChar8 *) "fujitsu"},
232 { (const FcChar8*) "IBM", (const FcChar8 *) "ibm"},
233 { (const FcChar8*) "ITC", (const FcChar8 *) "itc"},
234 { (const FcChar8*) "IMPR", (const FcChar8 *) "impress"},
235 { (const FcChar8*) "LARA", (const FcChar8 *) "larabiefonts"},
236 { (const FcChar8*) "LEAF", (const FcChar8 *) "interleaf"},
237 { (const FcChar8*) "LETR", (const FcChar8 *) "letraset"},
238 { (const FcChar8*) "LINO", (const FcChar8 *) "linotype"},
239 { (const FcChar8*) "MACR", (const FcChar8 *) "macromedia"},
240 { (const FcChar8*) "MONO", (const FcChar8 *) "monotype"},
241 { (const FcChar8*) "MS", (const FcChar8 *) "microsoft"},
242 { (const FcChar8*) "MT", (const FcChar8 *) "monotype"},
243 { (const FcChar8*) "NEC", (const FcChar8 *) "nec"},
244 { (const FcChar8*) "PARA", (const FcChar8 *) "paratype"},
245 { (const FcChar8*) "QMSI", (const FcChar8 *) "qms"},
246 { (const FcChar8*) "RICO", (const FcChar8 *) "ricoh"},
247 { (const FcChar8*) "URW", (const FcChar8 *) "urw"},
248 { (const FcChar8*) "Y&Y", (const FcChar8 *) "y&y"}
249 };
250
251 #define NUM_VENDOR_FOUNDRIES (sizeof (FcVendorFoundries) / sizeof (FcVendorFoundries[0]))
252
253 static const FcChar8 *
254 FcVendorFoundry(const char *vendor)
255 {
256 int i;
257
258 if (vendor)
259 for(i = 0; i < NUM_VENDOR_FOUNDRIES; i++)
260 if (FcVendorMatch (vendor, FcVendorFoundries[i].vendor))
261 return FcVendorFoundries[i].foundry;
262 return 0;
263 }
264
265 typedef struct _FcStringConst {
266 const char *name;
267 int value;
268 } FcStringConst;
269
270 static int
271 FcStringIsConst (const FcChar8 *string,
272 const FcStringConst *c,
273 int nc)
274 {
275 int i;
276
277 for (i = 0; i < nc; i++)
278 if (FcStrCmpIgnoreBlanksAndCase (string, c[i].name) == 0)
279 return c[i].value;
280 return -1;
281 }
282
283 static int
284 FcStringContainsConst (const FcChar8 *string,
285 const FcStringConst *c,
286 int nc)
287 {
288 int i;
289
290 for (i = 0; i < nc; i++)
291 if (FcStrContainsIgnoreBlanksAndCase (string, c[i].name))
292 return c[i].value;
293 return -1;
294 }
295
296 static const FcStringConst weightConsts[] = {
297 { "thin", FC_WEIGHT_THIN },
298 { "extralight", FC_WEIGHT_EXTRALIGHT },
299 { "ultralight", FC_WEIGHT_ULTRALIGHT },
300 { "light", FC_WEIGHT_LIGHT },
301 { "book", FC_WEIGHT_BOOK },
302 { "regular", FC_WEIGHT_REGULAR },
303 { "normal", FC_WEIGHT_NORMAL },
304 { "medium", FC_WEIGHT_MEDIUM },
305 { "demibold", FC_WEIGHT_DEMIBOLD },
306 { "demi", FC_WEIGHT_DEMIBOLD },
307 { "semibold", FC_WEIGHT_SEMIBOLD },
308 { "bold", FC_WEIGHT_BOLD },
309 { "extrabold", FC_WEIGHT_EXTRABOLD },
310 { "ultrabold", FC_WEIGHT_ULTRABOLD },
311 { "black", FC_WEIGHT_BLACK },
312 { "heavy", FC_WEIGHT_HEAVY },
313 };
314
315 #define NUM_WEIGHT_CONSTS (sizeof (weightConsts) / sizeof (weightConsts[0]))
316
317 #define FcIsWeight(s) FcStringIsConst(s,weightConsts,NUM_WEIGHT_CONSTS)
318 #define FcContainsWeight(s) FcStringContainsConst (s,weightConsts,NUM_WEIGHT_CONSTS)
319
320 static const FcStringConst widthConsts[] = {
321 { "ultracondensed", FC_WIDTH_ULTRACONDENSED },
322 { "extracondensed", FC_WIDTH_EXTRACONDENSED },
323 { "semicondensed", FC_WIDTH_SEMICONDENSED },
324 { "condensed", FC_WIDTH_CONDENSED }, /* must be after *condensed */
325 { "normal", FC_WIDTH_NORMAL },
326 { "semiexpanded", FC_WIDTH_SEMIEXPANDED },
327 { "extraexpanded", FC_WIDTH_EXTRAEXPANDED },
328 { "ultraexpanded", FC_WIDTH_ULTRAEXPANDED },
329 { "expanded", FC_WIDTH_EXPANDED }, /* must be after *expanded */
330 };
331
332 #define NUM_WIDTH_CONSTS (sizeof (widthConsts) / sizeof (widthConsts[0]))
333
334 #define FcIsWidth(s) FcStringIsConst(s,widthConsts,NUM_WIDTH_CONSTS)
335 #define FcContainsWidth(s) FcStringContainsConst (s,widthConsts,NUM_WIDTH_CONSTS)
336
337 static const FcStringConst slantConsts[] = {
338 { "italic", FC_SLANT_ITALIC },
339 { "oblique", FC_SLANT_OBLIQUE },
340 };
341
342 #define NUM_SLANT_CONSTS (sizeof (slantConsts) / sizeof (slantConsts[0]))
343
344 #define FcIsSlant(s) FcStringIsConst(s,slantConsts,NUM_SLANT_CONSTS)
345 #define FcContainsSlant(s) FcStringContainsConst (s,slantConsts,NUM_SLANT_CONSTS)
346
347 FcPattern *
348 FcFreeTypeQuery (const FcChar8 *file,
349 int id,
350 FcBlanks *blanks,
351 int *count)
352 {
353 FT_Face face;
354 FcPattern *pat;
355 int slant = -1;
356 int weight = -1;
357 int width = -1;
358 int i;
359 FcCharSet *cs;
360 FcLangSet *ls;
361 FT_Library ftLibrary;
362 FcChar8 *family = 0;
363 FcChar8 *style = 0;
364 const FcChar8 *foundry = 0;
365 int spacing;
366 TT_OS2 *os2;
367 #if HAVE_FT_GET_PS_FONT_INFO
368 PS_FontInfoRec psfontinfo;
369 #endif
370 #if HAVE_FT_GET_BDF_PROPERTY
371 BDF_PropertyRec prop;
372 #endif
373 TT_Header *head;
374 const FcChar8 *exclusiveLang = 0;
375 FT_SfntName sname;
376 FT_UInt snamei, snamec;
377 FcBool family_allocated = FcFalse;
378 FcBool style_allocated = FcFalse;
379 int family_prio = 0;
380 int style_prio = 0;
381
382 if (FT_Init_FreeType (&ftLibrary))
383 return 0;
384
385 if (FT_New_Face (ftLibrary, (char *) file, id, &face))
386 goto bail;
387
388 *count = face->num_faces;
389
390 pat = FcPatternCreate ();
391 if (!pat)
392 goto bail0;
393
394 if (!FcPatternAddBool (pat, FC_OUTLINE,
395 (face->face_flags & FT_FACE_FLAG_SCALABLE) != 0))
396 goto bail1;
397
398 if (!FcPatternAddBool (pat, FC_SCALABLE,
399 (face->face_flags & FT_FACE_FLAG_SCALABLE) != 0))
400 goto bail1;
401
402
403 /*
404 * Get the OS/2 table
405 */
406 os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2);
407
408 /*
409 * Look first in the OS/2 table for the foundry, if
410 * not found here, the various notices will be searched for
411 * that information, either from the sfnt name tables or
412 * the Postscript FontInfo dictionary. Finally, the
413 * BDF properties will queried.
414 */
415
416 if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
417 foundry = FcVendorFoundry(os2->achVendID);
418
419 /*
420 * Grub through the name table looking for family
421 * and style names. FreeType makes quite a hash
422 * of them
423 */
424 snamec = FT_Get_Sfnt_Name_Count (face);
425 for (snamei = 0; snamei < snamec; snamei++)
426 {
427 FcChar8 *utf8;
428 int len;
429 int wchar;
430 FcChar8 *src;
431 int src_len;
432 FcChar8 *u8;
433 FcChar32 ucs4;
434 int ilen, olen;
435 int prio = 0;
436
437 const FcCharMap *map;
438 enum {
439 FcNameEncodingUtf16,
440 FcNameEncodingAppleRoman,
441 FcNameEncodingLatin1
442 } encoding;
443
444
445 if (FT_Get_Sfnt_Name (face, snamei, &sname) != 0)
446 break;
447
448 /*
449 * Look for Unicode strings
450 */
451 switch (sname.platform_id) {
452 case TT_PLATFORM_APPLE_UNICODE:
453 /*
454 * All APPLE_UNICODE encodings are Utf16 BE
455 *
456 * Because there's no language id for Unicode,
457 * assume it's English
458 */
459 prio |= FC_NAME_PRIO_LANG_ENGLISH;
460 prio |= FC_NAME_PRIO_ENC_UNICODE;
461 encoding = FcNameEncodingUtf16;
462 break;
463 case TT_PLATFORM_MACINTOSH:
464 switch (sname.encoding_id) {
465 case TT_MAC_ID_ROMAN:
466 encoding = FcNameEncodingAppleRoman;
467 break;
468 default:
469 continue;
470 }
471 switch (sname.language_id) {
472 case TT_MAC_LANGID_ENGLISH:
473 prio |= FC_NAME_PRIO_LANG_ENGLISH;
474 break;
475 default:
476 /*
477 * Sometimes Microsoft language ids
478 * end up in the macintosh table. This
479 * is often accompanied by data in
480 * some mystic encoding. Ignore these names
481 */
482 if (sname.language_id >= 0x100)
483 continue;
484 break;
485 }
486 break;
487 case TT_PLATFORM_MICROSOFT:
488 switch (sname.encoding_id) {
489 case TT_MS_ID_UNICODE_CS:
490 encoding = FcNameEncodingUtf16;
491 prio |= FC_NAME_PRIO_ENC_UNICODE;
492 break;
493 default:
494 continue;
495 }
496 switch (sname.language_id & 0xff) {
497 case 0x09:
498 prio |= FC_NAME_PRIO_LANG_ENGLISH;
499 break;
500 default:
501 break;
502 }
503 break;
504 case TT_PLATFORM_ISO:
505 switch (sname.encoding_id) {
506 case TT_ISO_ID_10646:
507 encoding = FcNameEncodingUtf16;
508 prio |= FC_NAME_PRIO_ENC_UNICODE;
509 break;
510 case TT_ISO_ID_7BIT_ASCII:
511 case TT_ISO_ID_8859_1:
512 encoding = FcNameEncodingLatin1;
513 break;
514 default:
515 continue;
516 }
517 break;
518 default:
519 continue;
520 }
521
522 /*
523 * Look for family and style names
524 */
525 switch (sname.name_id) {
526 case TT_NAME_ID_FONT_FAMILY:
527 prio |= FC_NAME_PRIO_NAME_FAMILY;
528 break;
529 case TT_NAME_ID_PS_NAME:
530 prio |= FC_NAME_PRIO_NAME_PS;
531 break;
532 case TT_NAME_ID_FONT_SUBFAMILY:
533 case TT_NAME_ID_TRADEMARK:
534 case TT_NAME_ID_MANUFACTURER:
535 break;
536 default:
537 continue;
538 }
539
540 src = (FcChar8 *) sname.string;
541 src_len = sname.string_len;
542
543 switch (encoding) {
544 case FcNameEncodingUtf16:
545 /*
546 * Convert Utf16 to Utf8
547 */
548
549 if (!FcUtf16Len (src, FcEndianBig, src_len, &len, &wchar))
550 continue;
551
552 /*
553 * Allocate plenty of space. Freed below
554 */
555 utf8 = malloc (len * FC_UTF8_MAX_LEN + 1);
556 if (!utf8)
557 continue;
558
559 u8 = utf8;
560
561 while ((ilen = FcUtf16ToUcs4 (src, FcEndianBig, &ucs4, src_len)) > 0)
562 {
563 src_len -= ilen;
564 src += ilen;
565 olen = FcUcs4ToUtf8 (ucs4, u8);
566 u8 += olen;
567 }
568 *u8 = '\0';
569 break;
570 case FcNameEncodingLatin1:
571 /*
572 * Convert Latin1 to Utf8. Freed below
573 */
574 utf8 = malloc (src_len * 2 + 1);
575 if (!utf8)
576 continue;
577
578 u8 = utf8;
579 while (src_len > 0)
580 {
581 ucs4 = *src++;
582 src_len--;
583 olen = FcUcs4ToUtf8 (ucs4, u8);
584 u8 += olen;
585 }
586 *u8 = '\0';
587 break;
588 case FcNameEncodingAppleRoman:
589 /*
590 * Convert AppleRoman to Utf8
591 */
592 map = FcFreeTypeGetPrivateMap (ft_encoding_apple_roman);
593 if (!map)
594 continue;
595
596 /* freed below */
597 utf8 = malloc (src_len * 3 + 1);
598 if (!utf8)
599 continue;
600
601 u8 = utf8;
602 while (src_len > 0)
603 {
604 ucs4 = FcFreeTypePrivateToUcs4 (*src++, map);
605 src_len--;
606 olen = FcUcs4ToUtf8 (ucs4, u8);
607 u8 += olen;
608 }
609 *u8 = '\0';
610 break;
611 default:
612 continue;
613 }
614 if ((prio & FC_NAME_PRIO_LANG) == FC_NAME_PRIO_LANG_NONE)
615 if (FcUtf8IsLatin (utf8, strlen ((char *) utf8)))
616 prio |= FC_NAME_PRIO_LANG_LATIN;
617
618 if (FcDebug () & FC_DBG_SCANV)
619 printf ("\nfound name (name %d platform %d encoding %d language 0x%x prio 0x%x) %s\n",
620 sname.name_id, sname.platform_id,
621 sname.encoding_id, sname.language_id,
622 prio, utf8);
623
624 switch (sname.name_id) {
625 case TT_NAME_ID_FONT_FAMILY:
626 case TT_NAME_ID_PS_NAME:
627 if (!family || prio > family_prio)
628 {
629 if (family)
630 free (family);
631 family = utf8;
632 utf8 = 0;
633 family_allocated = FcTrue;
634 family_prio = prio;
635 }
636 break;
637 case TT_NAME_ID_FONT_SUBFAMILY:
638 if (!style || prio > style_prio)
639 {
640 if (style)
641 free (style);
642 style = utf8;
643 utf8 = 0;
644 style_allocated = FcTrue;
645 style_prio = prio;
646 }
647 break;
648 case TT_NAME_ID_TRADEMARK:
649 case TT_NAME_ID_MANUFACTURER:
650 /* If the foundry wasn't found in the OS/2 table, look here */
651 if(!foundry)
652 foundry = FcNoticeFoundry(utf8);
653 break;
654 }
655 if (utf8)
656 free (utf8);
657 }
658
659 if (!family)
660 family = (FcChar8 *) face->family_name;
661
662 if (!style)
663 style = (FcChar8 *) face->style_name;
664
665 if (!family)
666 {
667 FcChar8 *start, *end;
668
669 start = (FcChar8 *) strrchr ((char *) file, '/');
670 if (start)
671 start++;
672 else
673 start = (FcChar8 *) file;
674 end = (FcChar8 *) strrchr ((char *) start, '.');
675 if (!end)
676 end = start + strlen ((char *) start);
677 /* freed below */
678 family = malloc (end - start + 1);
679 strncpy ((char *) family, (char *) start, end - start);
680 family[end - start] = '\0';
681 family_allocated = FcTrue;
682 }
683
684 if (FcDebug() & FC_DBG_SCAN)
685 printf ("\n\"%s\" \"%s\"\n", family, style ? style : (FcChar8 *) "<none>");
686
687 if (!FcPatternAddString (pat, FC_FAMILY, family))
688 goto bail1;
689
690 if (style)
691 {
692 if (!FcPatternAddString (pat, FC_STYLE, style))
693 goto bail1;
694 }
695
696 if (!FcPatternAddString (pat, FC_FILE, file))
697 goto bail1;
698
699 if (!FcPatternAddInteger (pat, FC_INDEX, id))
700 goto bail1;
701
702 if (!FcPatternAddString (pat, FC_SOURCE, (FcChar8 *) "FreeType"))
703 goto bail1;
704
705 #if 0
706 /*
707 * don't even try this -- CJK 'monospace' fonts are really
708 * dual width, and most other fonts don't bother to set
709 * the attribute. Sigh.
710 */
711 if ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0)
712 if (!FcPatternAddInteger (pat, FC_SPACING, FC_MONO))
713 goto bail1;
714 #endif
715
716 /*
717 * Find the font revision (if available)
718 */
719 head = (TT_Header *) FT_Get_Sfnt_Table (face, ft_sfnt_head);
720 if (head)
721 {
722 if (!FcPatternAddInteger (pat, FC_FONTVERSION, head->Font_Revision))
723 goto bail1;
724 }
725 else
726 {
727 if (!FcPatternAddInteger (pat, FC_FONTVERSION, 0))
728 goto bail1;
729 }
730
731 if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
732 {
733 for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
734 {
735 FT_ULong bits;
736 int bit;
737 if (FcCodePageRange[i].bit < 32)
738 {
739 bits = os2->ulCodePageRange1;
740 bit = FcCodePageRange[i].bit;
741 }
742 else
743 {
744 bits = os2->ulCodePageRange2;
745 bit = FcCodePageRange[i].bit - 32;
746 }
747 if (bits & (1 << bit))
748 {
749 /*
750 * If the font advertises support for multiple
751 * "exclusive" languages, then include support
752 * for any language found to have coverage
753 */
754 if (exclusiveLang)
755 {
756 exclusiveLang = 0;
757 break;
758 }
759 exclusiveLang = FcCodePageRange[i].lang;
760 }
761 }
762 }
763
764 if (os2 && os2->version != 0xffff)
765 {
766 if (os2->usWeightClass == 0)
767 ;
768 else if (os2->usWeightClass < 150)
769 weight = FC_WEIGHT_THIN;
770 else if (os2->usWeightClass < 250)
771 weight = FC_WEIGHT_EXTRALIGHT;
772 else if (os2->usWeightClass < 350)
773 weight = FC_WEIGHT_LIGHT;
774 else if (os2->usWeightClass < 450)
775 weight = FC_WEIGHT_REGULAR;
776 else if (os2->usWeightClass < 550)
777 weight = FC_WEIGHT_MEDIUM;
778 else if (os2->usWeightClass < 650)
779 weight = FC_WEIGHT_SEMIBOLD;
780 else if (os2->usWeightClass < 750)
781 weight = FC_WEIGHT_BOLD;
782 else if (os2->usWeightClass < 850)
783 weight = FC_WEIGHT_EXTRABOLD;
784 else if (os2->usWeightClass < 950)
785 weight = FC_WEIGHT_BLACK;
786
787 switch (os2->usWidthClass) {
788 case 1: width = FC_WIDTH_ULTRACONDENSED; break;
789 case 2: width = FC_WIDTH_EXTRACONDENSED; break;
790 case 3: width = FC_WIDTH_CONDENSED; break;
791 case 4: width = FC_WIDTH_SEMICONDENSED; break;
792 case 5: width = FC_WIDTH_NORMAL; break;
793 case 6: width = FC_WIDTH_SEMIEXPANDED; break;
794 case 7: width = FC_WIDTH_EXPANDED; break;
795 case 8: width = FC_WIDTH_EXTRAEXPANDED; break;
796 case 9: width = FC_WIDTH_ULTRAEXPANDED; break;
797 }
798 }
799
800 /*
801 * Type 1: Check for FontInfo dictionary information
802 * Code from g2@magestudios.net (Gerard Escalante)
803 */
804
805 #if HAVE_FT_GET_PS_FONT_INFO
806 if (FT_Get_PS_Font_Info(face, &psfontinfo) == 0)
807 {
808 if (weight == -1 && psfontinfo.weight)
809 {
810 weight = FcIsWeight (psfontinfo.weight);
811 if (FcDebug() & FC_DBG_SCANV)
812 printf ("\tType1 weight %s maps to %d\n",
813 psfontinfo.weight, weight);
814 }
815
816 #if 0
817 /*
818 * Don't bother with italic_angle; FreeType already extracts that
819 * information for us and sticks it into style_flags
820 */
821 if (psfontinfo.italic_angle)
822 slant = FC_SLANT_ITALIC;
823 else
824 slant = FC_SLANT_ROMAN;
825 #endif
826
827 if(!foundry)
828 foundry = FcNoticeFoundry(psfontinfo.notice);
829 }
830 #endif /* HAVE_FT_GET_PS_FONT_INFO */
831
832 #if HAVE_FT_GET_BDF_PROPERTY
833 /*
834 * Finally, look for a FOUNDRY BDF property if no other
835 * mechanism has managed to locate a foundry
836 */
837
838 if (!foundry)
839 {
840 int rc;
841 BDF_PropertyRec prop;
842 rc = MY_Get_BDF_Property(face, "FOUNDRY", &prop);
843 if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_ATOM)
844 foundry = prop.u.atom;
845 }
846
847 if (width == -1)
848 {
849 if (MY_Get_BDF_Property(face, "RELATIVE_SETWIDTH", &prop) == 0 &&
850 (prop.type == BDF_PROPERTY_TYPE_INTEGER ||
851 prop.type == BDF_PROPERTY_TYPE_CARDINAL))
852 {
853 FT_Int32 value;
854
855 if (prop.type == BDF_PROPERTY_TYPE_INTEGER)
856 value = prop.u.integer;
857 else
858 value = (FT_Int32) prop.u.cardinal;
859 switch ((value + 5) / 10) {
860 case 1: width = FC_WIDTH_ULTRACONDENSED; break;
861 case 2: width = FC_WIDTH_EXTRACONDENSED; break;
862 case 3: width = FC_WIDTH_CONDENSED; break;
863 case 4: width = FC_WIDTH_SEMICONDENSED; break;
864 case 5: width = FC_WIDTH_NORMAL; break;
865 case 6: width = FC_WIDTH_SEMIEXPANDED; break;
866 case 7: width = FC_WIDTH_EXPANDED; break;
867 case 8: width = FC_WIDTH_EXTRAEXPANDED; break;
868 case 9: width = FC_WIDTH_ULTRAEXPANDED; break;
869 }
870 }
871 if (width == -1 &&
872 MY_Get_BDF_Property (face, "SETWIDTH_NAME", &prop) == 0 &&
873 prop.type == BDF_PROPERTY_TYPE_ATOM)
874 {
875 width = FcIsWidth (prop.u.atom);
876 if (FcDebug () & FC_DBG_SCANV)
877 printf ("\tsetwidth %s maps to %d\n", prop.u.atom, width);
878 }
879 }
880 #endif
881
882 /*
883 * Look for weight, width and slant names in the style value
884 */
885 if (style)
886 {
887 if (weight == -1)
888 {
889 weight = FcContainsWeight (style);
890 if (FcDebug() & FC_DBG_SCANV)
891 printf ("\tStyle %s maps to weight %d\n", style, weight);
892 }
893 if (width == -1)
894 {
895 width = FcContainsWidth (style);
896 if (FcDebug() & FC_DBG_SCANV)
897 printf ("\tStyle %s maps to width %d\n", style, width);
898 }
899 if (slant == -1)
900 {
901 slant = FcContainsSlant (style);
902 if (FcDebug() & FC_DBG_SCANV)
903 printf ("\tStyle %s maps to slant %d\n", style, slant);
904 }
905 }
906 /*
907 * Pull default values from the FreeType flags if more
908 * specific values not found above
909 */
910 if (slant == -1)
911 {
912 slant = FC_SLANT_ROMAN;
913 if (face->style_flags & FT_STYLE_FLAG_ITALIC)
914 slant = FC_SLANT_ITALIC;
915 }
916
917 if (weight == -1)
918 {
919 weight = FC_WEIGHT_MEDIUM;
920 if (face->style_flags & FT_STYLE_FLAG_BOLD)
921 weight = FC_WEIGHT_BOLD;
922 }
923
924 if (!FcPatternAddInteger (pat, FC_SLANT, slant))
925 goto bail1;
926
927 if (!FcPatternAddInteger (pat, FC_WEIGHT, weight))
928 goto bail1;
929
930 if (width != -1)
931 if (!FcPatternAddInteger (pat, FC_WIDTH, width))
932 goto bail1;
933
934 if(foundry)
935 {
936 if(!FcPatternAddString (pat, FC_FOUNDRY, foundry))
937 goto bail1;
938 }
939
940 /*
941 * Compute the unicode coverage for the font
942 */
943 cs = FcFreeTypeCharSetAndSpacing (face, blanks, &spacing);
944 if (!cs)
945 goto bail1;
946
947 #if HAVE_FT_GET_BDF_PROPERTY
948 /* For PCF fonts, override the computed spacing with the one from
949 the property */
950 if(MY_Get_BDF_Property(face, "SPACING", &prop) == 0 &&
951 prop.type == BDF_PROPERTY_TYPE_ATOM) {
952 if(strcmp(prop.u.atom, "c") || strcmp(prop.u.atom, "C"))
953 spacing = FC_CHARCELL;
954 else if(strcmp(prop.u.atom, "m") || strcmp(prop.u.atom, "M"))
955 spacing = FC_MONO;
956 else if(strcmp(prop.u.atom, "p") || strcmp(prop.u.atom, "P"))
957 spacing = FC_PROPORTIONAL;
958 }
959 #endif
960
961 /*
962 * Skip over PCF fonts that have no encoded characters; they're
963 * usually just Unicode fonts transcoded to some legacy encoding
964 */
965 if (FcCharSetCount (cs) == 0)
966 {
967 if (!strcmp(FT_MODULE_CLASS(&face->driver->root)->module_name, "pcf"))
968 goto bail2;
969 }
970
971 if (!FcPatternAddCharSet (pat, FC_CHARSET, cs))
972 goto bail2;
973
974 ls = FcFreeTypeLangSet (cs, exclusiveLang);
975 if (!ls)
976 goto bail2;
977
978 if (!FcPatternAddLangSet (pat, FC_LANG, ls))
979 {
980 FcLangSetDestroy (ls);
981 goto bail2;
982 }
983
984 FcLangSetDestroy (ls);
985
986 if (spacing != FC_PROPORTIONAL)
987 if (!FcPatternAddInteger (pat, FC_SPACING, spacing))
988 goto bail2;
989
990 if (!(face->face_flags & FT_FACE_FLAG_SCALABLE))
991 {
992 for (i = 0; i < face->num_fixed_sizes; i++)
993 if (!FcPatternAddDouble (pat, FC_PIXEL_SIZE,
994 (double) face->available_sizes[i].height))
995 goto bail1;
996 if (!FcPatternAddBool (pat, FC_ANTIALIAS, FcFalse))
997 goto bail1;
998 #if HAVE_FT_GET_BDF_PROPERTY
999 if(face->num_fixed_sizes == 1) {
1000 int rc;
1001 int value;
1002 BDF_PropertyRec prop;
1003
1004 rc = MY_Get_BDF_Property(face, "PIXEL_SIZE", &prop);
1005 if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_INTEGER)
1006 value = prop.u.integer;
1007 else if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_CARDINAL)
1008 value = prop.u.cardinal;
1009 else
1010 goto nevermind;
1011 if(value != face->available_sizes[0].height)
1012 /* ``impossible'' */
1013 goto nevermind;
1014
1015 rc = MY_Get_BDF_Property(face, "POINT_SIZE", &prop);
1016 if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_INTEGER)
1017 value = prop.u.integer;
1018 else if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_CARDINAL)
1019 value = prop.u.cardinal;
1020 else
1021 goto nevermind;
1022 if(!FcPatternAddDouble(pat, FC_SIZE, value / 10.0))
1023 goto nevermind;
1024
1025 rc = MY_Get_BDF_Property(face, "RESOLUTION_Y", &prop);
1026 if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_INTEGER)
1027 value = prop.u.integer;
1028 else if(rc == 0 && prop.type == BDF_PROPERTY_TYPE_CARDINAL)
1029 value = prop.u.cardinal;
1030 else
1031 goto nevermind;
1032 if(!FcPatternAddDouble(pat, FC_DPI, (double)value))
1033 goto nevermind;
1034
1035 }
1036 nevermind:
1037 ;
1038 #endif
1039 }
1040
1041 /*
1042 * Drop our reference to the charset
1043 */
1044 FcCharSetDestroy (cs);
1045
1046 /*
1047 * Deallocate family/style values
1048 */
1049
1050 if (family_allocated)
1051 free (family);
1052 if (style_allocated)
1053 free (style);
1054
1055 FT_Done_Face (face);
1056 FT_Done_FreeType (ftLibrary);
1057 return pat;
1058
1059 bail2:
1060 FcCharSetDestroy (cs);
1061 bail1:
1062 FcPatternDestroy (pat);
1063 if (family_allocated)
1064 free (family);
1065 if (style_allocated)
1066 free (style);
1067 bail0:
1068 FT_Done_Face (face);
1069 bail:
1070 FT_Done_FreeType (ftLibrary);
1071 return 0;
1072 }
1073
1074
1075 /*
1076 * For our purposes, this approximation is sufficient
1077 */
1078 #if !HAVE_FT_GET_NEXT_CHAR
1079 #define FT_Get_Next_Char(face, ucs4, gi) ((ucs4) >= 0xffffff ? \
1080 (*(gi) = 0), 0 : \
1081 (*(gi) = 1), (ucs4) + 1)
1082 #warning "No FT_Get_Next_Char"
1083 #endif
1084
1085 typedef struct _FcCharEnt {
1086 FcChar16 bmp;
1087 unsigned char encode;
1088 } FcCharEnt;
1089
1090 struct _FcCharMap {
1091 const FcCharEnt *ent;
1092 int nent;
1093 };
1094
1095 typedef struct _FcFontDecode {
1096 FT_Encoding encoding;
1097 const FcCharMap *map;
1098 FcChar32 max;
1099 } FcFontDecode;
1100
1101 static const FcCharEnt AppleRomanEnt[] = {
1102 { 0x0020, 0x20 }, /* SPACE */
1103 { 0x0021, 0x21 }, /* EXCLAMATION MARK */
1104 { 0x0022, 0x22 }, /* QUOTATION MARK */
1105 { 0x0023, 0x23 }, /* NUMBER SIGN */
1106 { 0x0024, 0x24 }, /* DOLLAR SIGN */
1107 { 0x0025, 0x25 }, /* PERCENT SIGN */
1108 { 0x0026, 0x26 }, /* AMPERSAND */
1109 { 0x0027, 0x27 }, /* APOSTROPHE */
1110 { 0x0028, 0x28 }, /* LEFT PARENTHESIS */
1111 { 0x0029, 0x29 }, /* RIGHT PARENTHESIS */
1112 { 0x002A, 0x2A }, /* ASTERISK */
1113 { 0x002B, 0x2B }, /* PLUS SIGN */
1114 { 0x002C, 0x2C }, /* COMMA */
1115 { 0x002D, 0x2D }, /* HYPHEN-MINUS */
1116 { 0x002E, 0x2E }, /* FULL STOP */
1117 { 0x002F, 0x2F }, /* SOLIDUS */
1118 { 0x0030, 0x30 }, /* DIGIT ZERO */
1119 { 0x0031, 0x31 }, /* DIGIT ONE */
1120 { 0x0032, 0x32 }, /* DIGIT TWO */
1121 { 0x0033, 0x33 }, /* DIGIT THREE */
1122 { 0x0034, 0x34 }, /* DIGIT FOUR */
1123 { 0x0035, 0x35 }, /* DIGIT FIVE */
1124 { 0x0036, 0x36 }, /* DIGIT SIX */
1125 { 0x0037, 0x37 }, /* DIGIT SEVEN */
1126 { 0x0038, 0x38 }, /* DIGIT EIGHT */
1127 { 0x0039, 0x39 }, /* DIGIT NINE */
1128 { 0x003A, 0x3A }, /* COLON */
1129 { 0x003B, 0x3B }, /* SEMICOLON */
1130 { 0x003C, 0x3C }, /* LESS-THAN SIGN */
1131 { 0x003D, 0x3D }, /* EQUALS SIGN */
1132 { 0x003E, 0x3E }, /* GREATER-THAN SIGN */
1133 { 0x003F, 0x3F }, /* QUESTION MARK */
1134 { 0x0040, 0x40 }, /* COMMERCIAL AT */
1135 { 0x0041, 0x41 }, /* LATIN CAPITAL LETTER A */
1136 { 0x0042, 0x42 }, /* LATIN CAPITAL LETTER B */
1137 { 0x0043, 0x43 }, /* LATIN CAPITAL LETTER C */
1138 { 0x0044, 0x44 }, /* LATIN CAPITAL LETTER D */
1139 { 0x0045, 0x45 }, /* LATIN CAPITAL LETTER E */
1140 { 0x0046, 0x46 }, /* LATIN CAPITAL LETTER F */
1141 { 0x0047, 0x47 }, /* LATIN CAPITAL LETTER G */
1142 { 0x0048, 0x48 }, /* LATIN CAPITAL LETTER H */
1143 { 0x0049, 0x49 }, /* LATIN CAPITAL LETTER I */
1144 { 0x004A, 0x4A }, /* LATIN CAPITAL LETTER J */
1145 { 0x004B, 0x4B }, /* LATIN CAPITAL LETTER K */
1146 { 0x004C, 0x4C }, /* LATIN CAPITAL LETTER L */
1147 { 0x004D, 0x4D }, /* LATIN CAPITAL LETTER M */
1148 { 0x004E, 0x4E }, /* LATIN CAPITAL LETTER N */
1149 { 0x004F, 0x4F }, /* LATIN CAPITAL LETTER O */
1150 { 0x0050, 0x50 }, /* LATIN CAPITAL LETTER P */
1151 { 0x0051, 0x51 }, /* LATIN CAPITAL LETTER Q */
1152 { 0x0052, 0x52 }, /* LATIN CAPITAL LETTER R */
1153 { 0x0053, 0x53 }, /* LATIN CAPITAL LETTER S */
1154 { 0x0054, 0x54 }, /* LATIN CAPITAL LETTER T */
1155 { 0x0055, 0x55 }, /* LATIN CAPITAL LETTER U */
1156 { 0x0056, 0x56 }, /* LATIN CAPITAL LETTER V */
1157 { 0x0057, 0x57 }, /* LATIN CAPITAL LETTER W */
1158 { 0x0058, 0x58 }, /* LATIN CAPITAL LETTER X */
1159 { 0x0059, 0x59 }, /* LATIN CAPITAL LETTER Y */
1160 { 0x005A, 0x5A }, /* LATIN CAPITAL LETTER Z */
1161 { 0x005B, 0x5B }, /* LEFT SQUARE BRACKET */
1162 { 0x005C, 0x5C }, /* REVERSE SOLIDUS */
1163 { 0x005D, 0x5D }, /* RIGHT SQUARE BRACKET */
1164 { 0x005E, 0x5E }, /* CIRCUMFLEX ACCENT */
1165 { 0x005F, 0x5F }, /* LOW LINE */
1166 { 0x0060, 0x60 }, /* GRAVE ACCENT */
1167 { 0x0061, 0x61 }, /* LATIN SMALL LETTER A */
1168 { 0x0062, 0x62 }, /* LATIN SMALL LETTER B */
1169 { 0x0063, 0x63 }, /* LATIN SMALL LETTER C */
1170 { 0x0064, 0x64 }, /* LATIN SMALL LETTER D */
1171 { 0x0065, 0x65 }, /* LATIN SMALL LETTER E */
1172 { 0x0066, 0x66 }, /* LATIN SMALL LETTER F */
1173 { 0x0067, 0x67 }, /* LATIN SMALL LETTER G */
1174 { 0x0068, 0x68 }, /* LATIN SMALL LETTER H */
1175 { 0x0069, 0x69 }, /* LATIN SMALL LETTER I */
1176 { 0x006A, 0x6A }, /* LATIN SMALL LETTER J */
1177 { 0x006B, 0x6B }, /* LATIN SMALL LETTER K */
1178 { 0x006C, 0x6C }, /* LATIN SMALL LETTER L */
1179 { 0x006D, 0x6D }, /* LATIN SMALL LETTER M */
1180 { 0x006E, 0x6E }, /* LATIN SMALL LETTER N */
1181 { 0x006F, 0x6F }, /* LATIN SMALL LETTER O */
1182 { 0x0070, 0x70 }, /* LATIN SMALL LETTER P */
1183 { 0x0071, 0x71 }, /* LATIN SMALL LETTER Q */
1184 { 0x0072, 0x72 }, /* LATIN SMALL LETTER R */
1185 { 0x0073, 0x73 }, /* LATIN SMALL LETTER S */
1186 { 0x0074, 0x74 }, /* LATIN SMALL LETTER T */
1187 { 0x0075, 0x75 }, /* LATIN SMALL LETTER U */
1188 { 0x0076, 0x76 }, /* LATIN SMALL LETTER V */
1189 { 0x0077, 0x77 }, /* LATIN SMALL LETTER W */
1190 { 0x0078, 0x78 }, /* LATIN SMALL LETTER X */
1191 { 0x0079, 0x79 }, /* LATIN SMALL LETTER Y */
1192 { 0x007A, 0x7A }, /* LATIN SMALL LETTER Z */
1193 { 0x007B, 0x7B }, /* LEFT CURLY BRACKET */
1194 { 0x007C, 0x7C }, /* VERTICAL LINE */
1195 { 0x007D, 0x7D }, /* RIGHT CURLY BRACKET */
1196 { 0x007E, 0x7E }, /* TILDE */
1197 { 0x00A0, 0xCA }, /* NO-BREAK SPACE */
1198 { 0x00A1, 0xC1 }, /* INVERTED EXCLAMATION MARK */
1199 { 0x00A2, 0xA2 }, /* CENT SIGN */
1200 { 0x00A3, 0xA3 }, /* POUND SIGN */
1201 { 0x00A5, 0xB4 }, /* YEN SIGN */
1202 { 0x00A7, 0xA4 }, /* SECTION SIGN */
1203 { 0x00A8, 0xAC }, /* DIAERESIS */
1204 { 0x00A9, 0xA9 }, /* COPYRIGHT SIGN */
1205 { 0x00AA, 0xBB }, /* FEMININE ORDINAL INDICATOR */
1206 { 0x00AB, 0xC7 }, /* LEFT-POINTING DOUBLE ANGLE QUOTATION MARK */
1207 { 0x00AC, 0xC2 }, /* NOT SIGN */
1208 { 0x00AE, 0xA8 }, /* REGISTERED SIGN */
1209 { 0x00AF, 0xF8 }, /* MACRON */
1210 { 0x00B0, 0xA1 }, /* DEGREE SIGN */
1211 { 0x00B1, 0xB1 }, /* PLUS-MINUS SIGN */
1212 { 0x00B4, 0xAB }, /* ACUTE ACCENT */
1213 { 0x00B5, 0xB5 }, /* MICRO SIGN */
1214 { 0x00B6, 0xA6 }, /* PILCROW SIGN */
1215 { 0x00B7, 0xE1 }, /* MIDDLE DOT */
1216 { 0x00B8, 0xFC }, /* CEDILLA */
1217 { 0x00BA, 0xBC }, /* MASCULINE ORDINAL INDICATOR */
1218 { 0x00BB, 0xC8 }, /* RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK */
1219 { 0x00BF, 0xC0 }, /* INVERTED QUESTION MARK */
1220 { 0x00C0, 0xCB }, /* LATIN CAPITAL LETTER A WITH GRAVE */
1221 { 0x00C1, 0xE7 }, /* LATIN CAPITAL LETTER A WITH ACUTE */
1222 { 0x00C2, 0xE5 }, /* LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
1223 { 0x00C3, 0xCC }, /* LATIN CAPITAL LETTER A WITH TILDE */
1224 { 0x00C4, 0x80 }, /* LATIN CAPITAL LETTER A WITH DIAERESIS */
1225 { 0x00C5, 0x81 }, /* LATIN CAPITAL LETTER A WITH RING ABOVE */
1226 { 0x00C6, 0xAE }, /* LATIN CAPITAL LETTER AE */
1227 { 0x00C7, 0x82 }, /* LATIN CAPITAL LETTER C WITH CEDILLA */
1228 { 0x00C8, 0xE9 }, /* LATIN CAPITAL LETTER E WITH GRAVE */
1229 { 0x00C9, 0x83 }, /* LATIN CAPITAL LETTER E WITH ACUTE */
1230 { 0x00CA, 0xE6 }, /* LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
1231 { 0x00CB, 0xE8 }, /* LATIN CAPITAL LETTER E WITH DIAERESIS */
1232 { 0x00CC, 0xED }, /* LATIN CAPITAL LETTER I WITH GRAVE */
1233 { 0x00CD, 0xEA }, /* LATIN CAPITAL LETTER I WITH ACUTE */
1234 { 0x00CE, 0xEB }, /* LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
1235 { 0x00CF, 0xEC }, /* LATIN CAPITAL LETTER I WITH DIAERESIS */
1236 { 0x00D1, 0x84 }, /* LATIN CAPITAL LETTER N WITH TILDE */
1237 { 0x00D2, 0xF1 }, /* LATIN CAPITAL LETTER O WITH GRAVE */
1238 { 0x00D3, 0xEE }, /* LATIN CAPITAL LETTER O WITH ACUTE */
1239 { 0x00D4, 0xEF }, /* LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
1240 { 0x00D5, 0xCD }, /* LATIN CAPITAL LETTER O WITH TILDE */
1241 { 0x00D6, 0x85 }, /* LATIN CAPITAL LETTER O WITH DIAERESIS */
1242 { 0x00D8, 0xAF }, /* LATIN CAPITAL LETTER O WITH STROKE */
1243 { 0x00D9, 0xF4 }, /* LATIN CAPITAL LETTER U WITH GRAVE */
1244 { 0x00DA, 0xF2 }, /* LATIN CAPITAL LETTER U WITH ACUTE */
1245 { 0x00DB, 0xF3 }, /* LATIN CAPITAL LETTER U WITH CIRCUMFLEX */
1246 { 0x00DC, 0x86 }, /* LATIN CAPITAL LETTER U WITH DIAERESIS */
1247 { 0x00DF, 0xA7 }, /* LATIN SMALL LETTER SHARP S */
1248 { 0x00E0, 0x88 }, /* LATIN SMALL LETTER A WITH GRAVE */
1249 { 0x00E1, 0x87 }, /* LATIN SMALL LETTER A WITH ACUTE */
1250 { 0x00E2, 0x89 }, /* LATIN SMALL LETTER A WITH CIRCUMFLEX */
1251 { 0x00E3, 0x8B }, /* LATIN SMALL LETTER A WITH TILDE */
1252 { 0x00E4, 0x8A }, /* LATIN SMALL LETTER A WITH DIAERESIS */
1253 { 0x00E5, 0x8C }, /* LATIN SMALL LETTER A WITH RING ABOVE */
1254 { 0x00E6, 0xBE }, /* LATIN SMALL LETTER AE */
1255 { 0x00E7, 0x8D }, /* LATIN SMALL LETTER C WITH CEDILLA */
1256 { 0x00E8, 0x8F }, /* LATIN SMALL LETTER E WITH GRAVE */
1257 { 0x00E9, 0x8E }, /* LATIN SMALL LETTER E WITH ACUTE */
1258 { 0x00EA, 0x90 }, /* LATIN SMALL LETTER E WITH CIRCUMFLEX */
1259 { 0x00EB, 0x91 }, /* LATIN SMALL LETTER E WITH DIAERESIS */
1260 { 0x00EC, 0x93 }, /* LATIN SMALL LETTER I WITH GRAVE */
1261 { 0x00ED, 0x92 }, /* LATIN SMALL LETTER I WITH ACUTE */
1262 { 0x00EE, 0x94 }, /* LATIN SMALL LETTER I WITH CIRCUMFLEX */
1263 { 0x00EF, 0x95 }, /* LATIN SMALL LETTER I WITH DIAERESIS */
1264 { 0x00F1, 0x96 }, /* LATIN SMALL LETTER N WITH TILDE */
1265 { 0x00F2, 0x98 }, /* LATIN SMALL LETTER O WITH GRAVE */
1266 { 0x00F3, 0x97 }, /* LATIN SMALL LETTER O WITH ACUTE */
1267 { 0x00F4, 0x99 }, /* LATIN SMALL LETTER O WITH CIRCUMFLEX */
1268 { 0x00F5, 0x9B }, /* LATIN SMALL LETTER O WITH TILDE */
1269 { 0x00F6, 0x9A }, /* LATIN SMALL LETTER O WITH DIAERESIS */
1270 { 0x00F7, 0xD6 }, /* DIVISION SIGN */
1271 { 0x00F8, 0xBF }, /* LATIN SMALL LETTER O WITH STROKE */
1272 { 0x00F9, 0x9D }, /* LATIN SMALL LETTER U WITH GRAVE */
1273 { 0x00FA, 0x9C }, /* LATIN SMALL LETTER U WITH ACUTE */
1274 { 0x00FB, 0x9E }, /* LATIN SMALL LETTER U WITH CIRCUMFLEX */
1275 { 0x00FC, 0x9F }, /* LATIN SMALL LETTER U WITH DIAERESIS */
1276 { 0x00FF, 0xD8 }, /* LATIN SMALL LETTER Y WITH DIAERESIS */
1277 { 0x0131, 0xF5 }, /* LATIN SMALL LETTER DOTLESS I */
1278 { 0x0152, 0xCE }, /* LATIN CAPITAL LIGATURE OE */
1279 { 0x0153, 0xCF }, /* LATIN SMALL LIGATURE OE */
1280 { 0x0178, 0xD9 }, /* LATIN CAPITAL LETTER Y WITH DIAERESIS */
1281 { 0x0192, 0xC4 }, /* LATIN SMALL LETTER F WITH HOOK */
1282 { 0x02C6, 0xF6 }, /* MODIFIER LETTER CIRCUMFLEX ACCENT */
1283 { 0x02C7, 0xFF }, /* CARON */
1284 { 0x02D8, 0xF9 }, /* BREVE */
1285 { 0x02D9, 0xFA }, /* DOT ABOVE */
1286 { 0x02DA, 0xFB }, /* RING ABOVE */
1287 { 0x02DB, 0xFE }, /* OGONEK */
1288 { 0x02DC, 0xF7 }, /* SMALL TILDE */
1289 { 0x02DD, 0xFD }, /* DOUBLE ACUTE ACCENT */
1290 { 0x03A9, 0xBD }, /* GREEK CAPITAL LETTER OMEGA */
1291 { 0x03C0, 0xB9 }, /* GREEK SMALL LETTER PI */
1292 { 0x2013, 0xD0 }, /* EN DASH */
1293 { 0x2014, 0xD1 }, /* EM DASH */
1294 { 0x2018, 0xD4 }, /* LEFT SINGLE QUOTATION MARK */
1295 { 0x2019, 0xD5 }, /* RIGHT SINGLE QUOTATION MARK */
1296 { 0x201A, 0xE2 }, /* SINGLE LOW-9 QUOTATION MARK */
1297 { 0x201C, 0xD2 }, /* LEFT DOUBLE QUOTATION MARK */
1298 { 0x201D, 0xD3 }, /* RIGHT DOUBLE QUOTATION MARK */
1299 { 0x201E, 0xE3 }, /* DOUBLE LOW-9 QUOTATION MARK */
1300 { 0x2020, 0xA0 }, /* DAGGER */
1301 { 0x2021, 0xE0 }, /* DOUBLE DAGGER */
1302 { 0x2022, 0xA5 }, /* BULLET */
1303 { 0x2026, 0xC9 }, /* HORIZONTAL ELLIPSIS */
1304 { 0x2030, 0xE4 }, /* PER MILLE SIGN */
1305 { 0x2039, 0xDC }, /* SINGLE LEFT-POINTING ANGLE QUOTATION MARK */
1306 { 0x203A, 0xDD }, /* SINGLE RIGHT-POINTING ANGLE QUOTATION MARK */
1307 { 0x2044, 0xDA }, /* FRACTION SLASH */
1308 { 0x20AC, 0xDB }, /* EURO SIGN */
1309 { 0x2122, 0xAA }, /* TRADE MARK SIGN */
1310 { 0x2202, 0xB6 }, /* PARTIAL DIFFERENTIAL */
1311 { 0x2206, 0xC6 }, /* INCREMENT */
1312 { 0x220F, 0xB8 }, /* N-ARY PRODUCT */
1313 { 0x2211, 0xB7 }, /* N-ARY SUMMATION */
1314 { 0x221A, 0xC3 }, /* SQUARE ROOT */
1315 { 0x221E, 0xB0 }, /* INFINITY */
1316 { 0x222B, 0xBA }, /* INTEGRAL */
1317 { 0x2248, 0xC5 }, /* ALMOST EQUAL TO */
1318 { 0x2260, 0xAD }, /* NOT EQUAL TO */
1319 { 0x2264, 0xB2 }, /* LESS-THAN OR EQUAL TO */
1320 { 0x2265, 0xB3 }, /* GREATER-THAN OR EQUAL TO */
1321 { 0x25CA, 0xD7 }, /* LOZENGE */
1322 { 0xF8FF, 0xF0 }, /* Apple logo */
1323 { 0xFB01, 0xDE }, /* LATIN SMALL LIGATURE FI */
1324 { 0xFB02, 0xDF }, /* LATIN SMALL LIGATURE FL */
1325 };
1326
1327 static const FcCharMap AppleRoman = {
1328 AppleRomanEnt,
1329 sizeof (AppleRomanEnt) / sizeof (AppleRomanEnt[0])
1330 };
1331
1332 static const FcCharEnt AdobeSymbolEnt[] = {
1333 { 0x0020, 0x20 }, /* SPACE # space */
1334 { 0x0021, 0x21 }, /* EXCLAMATION MARK # exclam */
1335 { 0x0023, 0x23 }, /* NUMBER SIGN # numbersign */
1336 { 0x0025, 0x25 }, /* PERCENT SIGN # percent */
1337 { 0x0026, 0x26 }, /* AMPERSAND # ampersand */
1338 { 0x0028, 0x28 }, /* LEFT PARENTHESIS # parenleft */
1339 { 0x0029, 0x29 }, /* RIGHT PARENTHESIS # parenright */
1340 { 0x002B, 0x2B }, /* PLUS SIGN # plus */
1341 { 0x002C, 0x2C }, /* COMMA # comma */
1342 { 0x002E, 0x2E }, /* FULL STOP # period */
1343 { 0x002F, 0x2F }, /* SOLIDUS # slash */
1344 { 0x0030, 0x30 }, /* DIGIT ZERO # zero */
1345 { 0x0031, 0x31 }, /* DIGIT ONE # one */
1346 { 0x0032, 0x32 }, /* DIGIT TWO # two */
1347 { 0x0033, 0x33 }, /* DIGIT THREE # three */
1348 { 0x0034, 0x34 }, /* DIGIT FOUR # four */
1349 { 0x0035, 0x35 }, /* DIGIT FIVE # five */
1350 { 0x0036, 0x36 }, /* DIGIT SIX # six */
1351 { 0x0037, 0x37 }, /* DIGIT SEVEN # seven */
1352 { 0x0038, 0x38 }, /* DIGIT EIGHT # eight */
1353 { 0x0039, 0x39 }, /* DIGIT NINE # nine */
1354 { 0x003A, 0x3A }, /* COLON # colon */
1355 { 0x003B, 0x3B }, /* SEMICOLON # semicolon */
1356 { 0x003C, 0x3C }, /* LESS-THAN SIGN # less */
1357 { 0x003D, 0x3D }, /* EQUALS SIGN # equal */
1358 { 0x003E, 0x3E }, /* GREATER-THAN SIGN # greater */
1359 { 0x003F, 0x3F }, /* QUESTION MARK # question */
1360 { 0x005B, 0x5B }, /* LEFT SQUARE BRACKET # bracketleft */
1361 { 0x005D, 0x5D }, /* RIGHT SQUARE BRACKET # bracketright */
1362 { 0x005F, 0x5F }, /* LOW LINE # underscore */
1363 { 0x007B, 0x7B }, /* LEFT CURLY BRACKET # braceleft */
1364 { 0x007C, 0x7C }, /* VERTICAL LINE # bar */
1365 { 0x007D, 0x7D }, /* RIGHT CURLY BRACKET # braceright */
1366 { 0x00A0, 0x20 }, /* NO-BREAK SPACE # space */
1367 { 0x00AC, 0xD8 }, /* NOT SIGN # logicalnot */
1368 { 0x00B0, 0xB0 }, /* DEGREE SIGN # degree */
1369 { 0x00B1, 0xB1 }, /* PLUS-MINUS SIGN # plusminus */
1370 { 0x00B5, 0x6D }, /* MICRO SIGN # mu */
1371 { 0x00D7, 0xB4 }, /* MULTIPLICATION SIGN # multiply */
1372 { 0x00F7, 0xB8 }, /* DIVISION SIGN # divide */
1373 { 0x0192, 0xA6 }, /* LATIN SMALL LETTER F WITH HOOK # florin */
1374 { 0x0391, 0x41 }, /* GREEK CAPITAL LETTER ALPHA # Alpha */
1375 { 0x0392, 0x42 }, /* GREEK CAPITAL LETTER BETA # Beta */
1376 { 0x0393, 0x47 }, /* GREEK CAPITAL LETTER GAMMA # Gamma */
1377 { 0x0394, 0x44 }, /* GREEK CAPITAL LETTER DELTA # Delta */
1378 { 0x0395, 0x45 }, /* GREEK CAPITAL LETTER EPSILON # Epsilon */
1379 { 0x0396, 0x5A }, /* GREEK CAPITAL LETTER ZETA # Zeta */
1380 { 0x0397, 0x48 }, /* GREEK CAPITAL LETTER ETA # Eta */
1381 { 0x0398, 0x51 }, /* GREEK CAPITAL LETTER THETA # Theta */
1382 { 0x0399, 0x49 }, /* GREEK CAPITAL LETTER IOTA # Iota */
1383 { 0x039A, 0x4B }, /* GREEK CAPITAL LETTER KAPPA # Kappa */
1384 { 0x039B, 0x4C }, /* GREEK CAPITAL LETTER LAMDA # Lambda */
1385 { 0x039C, 0x4D }, /* GREEK CAPITAL LETTER MU # Mu */
1386 { 0x039D, 0x4E }, /* GREEK CAPITAL LETTER NU # Nu */
1387 { 0x039E, 0x58 }, /* GREEK CAPITAL LETTER XI # Xi */
1388 { 0x039F, 0x4F }, /* GREEK CAPITAL LETTER OMICRON # Omicron */
1389 { 0x03A0, 0x50 }, /* GREEK CAPITAL LETTER PI # Pi */
1390 { 0x03A1, 0x52 }, /* GREEK CAPITAL LETTER RHO # Rho */
1391 { 0x03A3, 0x53 }, /* GREEK CAPITAL LETTER SIGMA # Sigma */
1392 { 0x03A4, 0x54 }, /* GREEK CAPITAL LETTER TAU # Tau */
1393 { 0x03A5, 0x55 }, /* GREEK CAPITAL LETTER UPSILON # Upsilon */
1394 { 0x03A6, 0x46 }, /* GREEK CAPITAL LETTER PHI # Phi */
1395 { 0x03A7, 0x43 }, /* GREEK CAPITAL LETTER CHI # Chi */
1396 { 0x03A8, 0x59 }, /* GREEK CAPITAL LETTER PSI # Psi */
1397 { 0x03A9, 0x57 }, /* GREEK CAPITAL LETTER OMEGA # Omega */
1398 { 0x03B1, 0x61 }, /* GREEK SMALL LETTER ALPHA # alpha */
1399 { 0x03B2, 0x62 }, /* GREEK SMALL LETTER BETA # beta */
1400 { 0x03B3, 0x67 }, /* GREEK SMALL LETTER GAMMA # gamma */
1401 { 0x03B4, 0x64 }, /* GREEK SMALL LETTER DELTA # delta */
1402 { 0x03B5, 0x65 }, /* GREEK SMALL LETTER EPSILON # epsilon */
1403 { 0x03B6, 0x7A }, /* GREEK SMALL LETTER ZETA # zeta */
1404 { 0x03B7, 0x68 }, /* GREEK SMALL LETTER ETA # eta */
1405 { 0x03B8, 0x71 }, /* GREEK SMALL LETTER THETA # theta */
1406 { 0x03B9, 0x69 }, /* GREEK SMALL LETTER IOTA # iota */
1407 { 0x03BA, 0x6B }, /* GREEK SMALL LETTER KAPPA # kappa */
1408 { 0x03BB, 0x6C }, /* GREEK SMALL LETTER LAMDA # lambda */
1409 { 0x03BC, 0x6D }, /* GREEK SMALL LETTER MU # mu */
1410 { 0x03BD, 0x6E }, /* GREEK SMALL LETTER NU # nu */
1411 { 0x03BE, 0x78 }, /* GREEK SMALL LETTER XI # xi */
1412 { 0x03BF, 0x6F }, /* GREEK SMALL LETTER OMICRON # omicron */
1413 { 0x03C0, 0x70 }, /* GREEK SMALL LETTER PI # pi */
1414 { 0x03C1, 0x72 }, /* GREEK SMALL LETTER RHO # rho */
1415 { 0x03C2, 0x56 }, /* GREEK SMALL LETTER FINAL SIGMA # sigma1 */
1416 { 0x03C3, 0x73 }, /* GREEK SMALL LETTER SIGMA # sigma */
1417 { 0x03C4, 0x74 }, /* GREEK SMALL LETTER TAU # tau */
1418 { 0x03C5, 0x75 }, /* GREEK SMALL LETTER UPSILON # upsilon */
1419 { 0x03C6, 0x66 }, /* GREEK SMALL LETTER PHI # phi */
1420 { 0x03C7, 0x63 }, /* GREEK SMALL LETTER CHI # chi */
1421 { 0x03C8, 0x79 }, /* GREEK SMALL LETTER PSI # psi */
1422 { 0x03C9, 0x77 }, /* GREEK SMALL LETTER OMEGA # omega */
1423 { 0x03D1, 0x4A }, /* GREEK THETA SYMBOL # theta1 */
1424 { 0x03D2, 0xA1 }, /* GREEK UPSILON WITH HOOK SYMBOL # Upsilon1 */
1425 { 0x03D5, 0x6A }, /* GREEK PHI SYMBOL # phi1 */
1426 { 0x03D6, 0x76 }, /* GREEK PI SYMBOL # omega1 */
1427 { 0x2022, 0xB7 }, /* BULLET # bullet */
1428 { 0x2026, 0xBC }, /* HORIZONTAL ELLIPSIS # ellipsis */
1429 { 0x2032, 0xA2 }, /* PRIME # minute */
1430 { 0x2033, 0xB2 }, /* DOUBLE PRIME # second */
1431 { 0x2044, 0xA4 }, /* FRACTION SLASH # fraction */
1432 { 0x20AC, 0xA0 }, /* EURO SIGN # Euro */
1433 { 0x2111, 0xC1 }, /* BLACK-LETTER CAPITAL I # Ifraktur */
1434 { 0x2118, 0xC3 }, /* SCRIPT CAPITAL P # weierstrass */
1435 { 0x211C, 0xC2 }, /* BLACK-LETTER CAPITAL R # Rfraktur */
1436 { 0x2126, 0x57 }, /* OHM SIGN # Omega */
1437 { 0x2135, 0xC0 }, /* ALEF SYMBOL # aleph */
1438 { 0x2190, 0xAC }, /* LEFTWARDS ARROW # arrowleft */
1439 { 0x2191, 0xAD }, /* UPWARDS ARROW # arrowup */
1440 { 0x2192, 0xAE }, /* RIGHTWARDS ARROW # arrowright */
1441 { 0x2193, 0xAF }, /* DOWNWARDS ARROW # arrowdown */
1442 { 0x2194, 0xAB }, /* LEFT RIGHT ARROW # arrowboth */
1443 { 0x21B5, 0xBF }, /* DOWNWARDS ARROW WITH CORNER LEFTWARDS # carriagereturn */
1444 { 0x21D0, 0xDC }, /* LEFTWARDS DOUBLE ARROW # arrowdblleft */
1445 { 0x21D1, 0xDD }, /* UPWARDS DOUBLE ARROW # arrowdblup */
1446 { 0x21D2, 0xDE }, /* RIGHTWARDS DOUBLE ARROW # arrowdblright */
1447 { 0x21D3, 0xDF }, /* DOWNWARDS DOUBLE ARROW # arrowdbldown */
1448 { 0x21D4, 0xDB }, /* LEFT RIGHT DOUBLE ARROW # arrowdblboth */
1449 { 0x2200, 0x22 }, /* FOR ALL # universal */
1450 { 0x2202, 0xB6 }, /* PARTIAL DIFFERENTIAL # partialdiff */
1451 { 0x2203, 0x24 }, /* THERE EXISTS # existential */
1452 { 0x2205, 0xC6 }, /* EMPTY SET # emptyset */
1453 { 0x2206, 0x44 }, /* INCREMENT # Delta */
1454 { 0x2207, 0xD1 }, /* NABLA # gradient */
1455 { 0x2208, 0xCE }, /* ELEMENT OF # element */
1456 { 0x2209, 0xCF }, /* NOT AN ELEMENT OF # notelement */
1457 { 0x220B, 0x27 }, /* CONTAINS AS MEMBER # suchthat */
1458 { 0x220F, 0xD5 }, /* N-ARY PRODUCT # product */
1459 { 0x2211, 0xE5 }, /* N-ARY SUMMATION # summation */
1460 { 0x2212, 0x2D }, /* MINUS SIGN # minus */
1461 { 0x2215, 0xA4 }, /* DIVISION SLASH # fraction */
1462 { 0x2217, 0x2A }, /* ASTERISK OPERATOR # asteriskmath */
1463 { 0x221A, 0xD6 }, /* SQUARE ROOT # radical */
1464 { 0x221D, 0xB5 }, /* PROPORTIONAL TO # proportional */
1465 { 0x221E, 0xA5 }, /* INFINITY # infinity */
1466 { 0x2220, 0xD0 }, /* ANGLE # angle */
1467 { 0x2227, 0xD9 }, /* LOGICAL AND # logicaland */
1468 { 0x2228, 0xDA }, /* LOGICAL OR # logicalor */
1469 { 0x2229, 0xC7 }, /* INTERSECTION # intersection */
1470 { 0x222A, 0xC8 }, /* UNION # union */
1471 { 0x222B, 0xF2 }, /* INTEGRAL # integral */
1472 { 0x2234, 0x5C }, /* THEREFORE # therefore */
1473 { 0x223C, 0x7E }, /* TILDE OPERATOR # similar */
1474 { 0x2245, 0x40 }, /* APPROXIMATELY EQUAL TO # congruent */
1475 { 0x2248, 0xBB }, /* ALMOST EQUAL TO # approxequal */
1476 { 0x2260, 0xB9 }, /* NOT EQUAL TO # notequal */
1477 { 0x2261, 0xBA }, /* IDENTICAL TO # equivalence */
1478 { 0x2264, 0xA3 }, /* LESS-THAN OR EQUAL TO # lessequal */
1479 { 0x2265, 0xB3 }, /* GREATER-THAN OR EQUAL TO # greaterequal */
1480 { 0x2282, 0xCC }, /* SUBSET OF # propersubset */
1481 { 0x2283, 0xC9 }, /* SUPERSET OF # propersuperset */
1482 { 0x2284, 0xCB }, /* NOT A SUBSET OF # notsubset */
1483 { 0x2286, 0xCD }, /* SUBSET OF OR EQUAL TO # reflexsubset */
1484 { 0x2287, 0xCA }, /* SUPERSET OF OR EQUAL TO # reflexsuperset */
1485 { 0x2295, 0xC5 }, /* CIRCLED PLUS # circleplus */
1486 { 0x2297, 0xC4 }, /* CIRCLED TIMES # circlemultiply */
1487 { 0x22A5, 0x5E }, /* UP TACK # perpendicular */
1488 { 0x22C5, 0xD7 }, /* DOT OPERATOR # dotmath */
1489 { 0x2320, 0xF3 }, /* TOP HALF INTEGRAL # integraltp */
1490 { 0x2321, 0xF5 }, /* BOTTOM HALF INTEGRAL # integralbt */
1491 { 0x2329, 0xE1 }, /* LEFT-POINTING ANGLE BRACKET # angleleft */
1492 { 0x232A, 0xF1 }, /* RIGHT-POINTING ANGLE BRACKET # angleright */
1493 { 0x25CA, 0xE0 }, /* LOZENGE # lozenge */
1494 { 0x2660, 0xAA }, /* BLACK SPADE SUIT # spade */
1495 { 0x2663, 0xA7 }, /* BLACK CLUB SUIT # club */
1496 { 0x2665, 0xA9 }, /* BLACK HEART SUIT # heart */
1497 { 0x2666, 0xA8 }, /* BLACK DIAMOND SUIT # diamond */
1498 { 0xF6D9, 0xD3 }, /* COPYRIGHT SIGN SERIF # copyrightserif (CUS) */
1499 { 0xF6DA, 0xD2 }, /* REGISTERED SIGN SERIF # registerserif (CUS) */
1500 { 0xF6DB, 0xD4 }, /* TRADE MARK SIGN SERIF # trademarkserif (CUS) */
1501 { 0xF8E5, 0x60 }, /* RADICAL EXTENDER # radicalex (CUS) */
1502 { 0xF8E6, 0xBD }, /* VERTICAL ARROW EXTENDER # arrowvertex (CUS) */
1503 { 0xF8E7, 0xBE }, /* HORIZONTAL ARROW EXTENDER # arrowhorizex (CUS) */
1504 { 0xF8E8, 0xE2 }, /* REGISTERED SIGN SANS SERIF # registersans (CUS) */
1505 { 0xF8E9, 0xE3 }, /* COPYRIGHT SIGN SANS SERIF # copyrightsans (CUS) */
1506 { 0xF8EA, 0xE4 }, /* TRADE MARK SIGN SANS SERIF # trademarksans (CUS) */
1507 { 0xF8EB, 0xE6 }, /* LEFT PAREN TOP # parenlefttp (CUS) */
1508 { 0xF8EC, 0xE7 }, /* LEFT PAREN EXTENDER # parenleftex (CUS) */
1509 { 0xF8ED, 0xE8 }, /* LEFT PAREN BOTTOM # parenleftbt (CUS) */
1510 { 0xF8EE, 0xE9 }, /* LEFT SQUARE BRACKET TOP # bracketlefttp (CUS) */
1511 { 0xF8EF, 0xEA }, /* LEFT SQUARE BRACKET EXTENDER # bracketleftex (CUS) */
1512 { 0xF8F0, 0xEB }, /* LEFT SQUARE BRACKET BOTTOM # bracketleftbt (CUS) */
1513 { 0xF8F1, 0xEC }, /* LEFT CURLY BRACKET TOP # bracelefttp (CUS) */
1514 { 0xF8F2, 0xED }, /* LEFT CURLY BRACKET MID # braceleftmid (CUS) */
1515 { 0xF8F3, 0xEE }, /* LEFT CURLY BRACKET BOTTOM # braceleftbt (CUS) */
1516 { 0xF8F4, 0xEF }, /* CURLY BRACKET EXTENDER # braceex (CUS) */
1517 { 0xF8F5, 0xF4 }, /* INTEGRAL EXTENDER # integralex (CUS) */
1518 { 0xF8F6, 0xF6 }, /* RIGHT PAREN TOP # parenrighttp (CUS) */
1519 { 0xF8F7, 0xF7 }, /* RIGHT PAREN EXTENDER # parenrightex (CUS) */
1520 { 0xF8F8, 0xF8 }, /* RIGHT PAREN BOTTOM # parenrightbt (CUS) */
1521 { 0xF8F9, 0xF9 }, /* RIGHT SQUARE BRACKET TOP # bracketrighttp (CUS) */
1522 { 0xF8FA, 0xFA }, /* RIGHT SQUARE BRACKET EXTENDER # bracketrightex (CUS) */
1523 { 0xF8FB, 0xFB }, /* RIGHT SQUARE BRACKET BOTTOM # bracketrightbt (CUS) */
1524 { 0xF8FC, 0xFC }, /* RIGHT CURLY BRACKET TOP # bracerighttp (CUS) */
1525 { 0xF8FD, 0xFD }, /* RIGHT CURLY BRACKET MID # bracerightmid (CUS) */
1526 { 0xF8FE, 0xFE }, /* RIGHT CURLY BRACKET BOTTOM # bracerightbt (CUS) */
1527 };
1528
1529 static const FcCharMap AdobeSymbol = {
1530 AdobeSymbolEnt,
1531 sizeof (AdobeSymbolEnt) / sizeof (AdobeSymbolEnt[0]),
1532 };
1533
1534 static const FcFontDecode fcFontDecoders[] = {
1535 { ft_encoding_unicode, 0, (1 << 21) - 1 },
1536 { ft_encoding_symbol, &AdobeSymbol, (1 << 16) - 1 },
1537 { ft_encoding_apple_roman, &AppleRoman, (1 << 16) - 1 },
1538 };
1539
1540 #define NUM_DECODE (sizeof (fcFontDecoders) / sizeof (fcFontDecoders[0]))
1541
1542 FcChar32
1543 FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map)
1544 {
1545 int low, high, mid;
1546 FcChar16 bmp;
1547
1548 low = 0;
1549 high = map->nent - 1;
1550 if (ucs4 < map->ent[low].bmp || map->ent[high].bmp < ucs4)
1551 return ~0;
1552 while (low <= high)
1553 {
1554 mid = (high + low) >> 1;
1555 bmp = map->ent[mid].bmp;
1556 if (ucs4 == bmp)
1557 return (FT_ULong) map->ent[mid].encode;
1558 if (ucs4 < bmp)
1559 high = mid - 1;
1560 else
1561 low = mid + 1;
1562 }
1563 return ~0;
1564 }
1565
1566 FcChar32
1567 FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map)
1568 {
1569 int i;
1570
1571 for (i = 0; i < map->nent; i++)
1572 if (map->ent[i].encode == private)
1573 return (FcChar32) map->ent[i].bmp;
1574 return ~0;
1575 }
1576
1577 const FcCharMap *
1578 FcFreeTypeGetPrivateMap (FT_Encoding encoding)
1579 {
1580 int i;
1581
1582 for (i = 0; i < NUM_DECODE; i++)
1583 if (fcFontDecoders[i].encoding == encoding)
1584 return fcFontDecoders[i].map;
1585 return 0;
1586 }
1587
1588 #include "../fc-glyphname/fcglyphname.h"
1589
1590 static FcChar32
1591 FcHashGlyphName (const FcChar8 *name)
1592 {
1593 FcChar32 h = 0;
1594 FcChar8 c;
1595
1596 while ((c = *name++))
1597 {
1598 h = ((h << 1) | (h >> 31)) ^ c;
1599 }
1600 return h;
1601 }
1602
1603 #if HAVE_FT_HAS_PS_GLYPH_NAMES
1604 /*
1605 * Use Type1 glyph names for fonts which have reliable names
1606 * and which export an Adobe Custom mapping
1607 */
1608 static FcBool
1609 FcFreeTypeUseNames (FT_Face face)
1610 {
1611 FT_Int map;
1612
1613 if (!FT_Has_PS_Glyph_Names (face))
1614 return FcFalse;
1615 for (map = 0; map < face->num_charmaps; map++)
1616 if (face->charmaps[map]->encoding == ft_encoding_adobe_custom)
1617 return FcTrue;
1618 return FcFalse;
1619 }
1620
1621 static FcChar8 *
1622 FcUcs4ToGlyphName (FcChar32 ucs4)
1623 {
1624 int i = (int) (ucs4 % FC_GLYPHNAME_HASH);
1625 int r = 0;
1626 FcGlyphName *gn;
1627
1628 while ((gn = ucs_to_name[i]))
1629 {
1630 if (gn->ucs == ucs4)
1631 return gn->name;
1632 if (!r)
1633 {
1634 r = (int) (ucs4 % FC_GLYPHNAME_REHASH);
1635 if (!r)
1636 r = 1;
1637 }
1638 i += r;
1639 if (i >= FC_GLYPHNAME_HASH)
1640 i -= FC_GLYPHNAME_HASH;
1641 }
1642 return 0;
1643 }
1644
1645 static FcChar32
1646 FcGlyphNameToUcs4 (FcChar8 *name)
1647 {
1648 FcChar32 h = FcHashGlyphName (name);
1649 int i = (int) (h % FC_GLYPHNAME_HASH);
1650 int r = 0;
1651 FcGlyphName *gn;
1652
1653 while ((gn = name_to_ucs[i]))
1654 {
1655 if (!strcmp ((char *) name, (char *) gn->name))
1656 return gn->ucs;
1657 if (!r)
1658 {
1659 r = (int) (h % FC_GLYPHNAME_REHASH);
1660 if (!r)
1661 r = 1;
1662 }
1663 i += r;
1664 if (i >= FC_GLYPHNAME_HASH)
1665 i -= FC_GLYPHNAME_HASH;
1666 }
1667 return 0xffff;
1668 }
1669
1670 /*
1671 * Search through a font for a glyph by name. This is
1672 * currently a linear search as there doesn't appear to be
1673 * any defined order within the font
1674 */
1675 static FT_UInt
1676 FcFreeTypeGlyphNameIndex (FT_Face face, FcChar8 *name)
1677 {
1678 FT_UInt gindex;
1679 FcChar8 name_buf[FC_GLYPHNAME_MAXLEN + 2];
1680
1681 for (gindex = 0; gindex < face->num_glyphs; gindex++)
1682 {
1683 if (FT_Get_Glyph_Name (face, gindex, name_buf, FC_GLYPHNAME_MAXLEN+1) == 0)
1684 if (!strcmp ((char *) name, (char *) name_buf))
1685 return gindex;
1686 }
1687 return 0;
1688 }
1689 #endif
1690
1691 /*
1692 * Map a UCS4 glyph to a glyph index. Use all available encoding
1693 * tables to try and find one that works. This information is expected
1694 * to be cached by higher levels, so performance isn't critical
1695 */
1696
1697 FT_UInt
1698 FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4)
1699 {
1700 int initial, offset, decode;
1701 FT_UInt glyphindex;
1702 FcChar32 charcode;
1703
1704 initial = 0;
1705 /*
1706 * Find the current encoding
1707 */
1708 if (face->charmap)
1709 {
1710 for (; initial < NUM_DECODE; initial++)
1711 if (fcFontDecoders[initial].encoding == face->charmap->encoding)
1712 break;
1713 if (initial == NUM_DECODE)
1714 initial = 0;
1715 }
1716 /*
1717 * Check each encoding for the glyph, starting with the current one
1718 */
1719 for (offset = 0; offset < NUM_DECODE; offset++)
1720 {
1721 decode = (initial + offset) % NUM_DECODE;
1722 if (!face->charmap || face->charmap->encoding != fcFontDecoders[decode].encoding)
1723 if (FT_Select_Charmap (face, fcFontDecoders[decode].encoding) != 0)
1724 continue;
1725 if (fcFontDecoders[decode].map)
1726 {
1727 charcode = FcFreeTypeUcs4ToPrivate (ucs4, fcFontDecoders[decode].map);
1728 if (charcode == ~0)
1729 continue;
1730 }
1731 else
1732 charcode = ucs4;
1733 glyphindex = FT_Get_Char_Index (face, (FT_ULong) charcode);
1734 if (glyphindex)
1735 return glyphindex;
1736 }
1737 #if HAVE_FT_HAS_PS_GLYPH_NAMES
1738 /*
1739 * Check postscript name table if present
1740 */
1741 if (FcFreeTypeUseNames (face))
1742 {
1743 FcChar8 *name = FcUcs4ToGlyphName (ucs4);
1744 if (name)
1745 {
1746 glyphindex = FcFreeTypeGlyphNameIndex (face, name);
1747 if (glyphindex)
1748 return glyphindex;
1749 }
1750 }
1751 #endif
1752 return 0;
1753 }
1754
1755 static FcBool
1756 FcFreeTypeCheckGlyph (FT_Face face, FcChar32 ucs4,
1757 FT_UInt glyph, FcBlanks *blanks,
1758 FT_Pos *advance)
1759 {
1760 FT_Int load_flags = FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH | FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
1761 FT_GlyphSlot slot;
1762
1763 /*
1764 * When using scalable fonts, only report those glyphs
1765 * which can be scaled; otherwise those fonts will
1766 * only be available at some sizes, and never when
1767 * transformed. Avoid this by simply reporting bitmap-only
1768 * glyphs as missing
1769 */
1770 if (face->face_flags & FT_FACE_FLAG_SCALABLE)
1771 load_flags |= FT_LOAD_NO_BITMAP;
1772
1773 if (FT_Load_Glyph (face, glyph, load_flags))
1774 return FcFalse;
1775
1776 slot = face->glyph;
1777 if (!glyph)
1778 return FcFalse;
1779
1780 *advance = slot->metrics.horiAdvance;
1781
1782 switch (slot->format) {
1783 case ft_glyph_format_bitmap:
1784 /*
1785 * Bitmaps are assumed to be reasonable; if
1786 * this proves to be a rash assumption, this
1787 * code can be easily modified
1788 */
1789 return FcTrue;
1790 case ft_glyph_format_outline:
1791 /*
1792 * Glyphs with contours are always OK
1793 */
1794 if (slot->outline.n_contours != 0)
1795 return FcTrue;
1796 /*
1797 * Glyphs with no contours are only OK if
1798 * they're members of the Blanks set specified
1799 * in the configuration. If blanks isn't set,
1800 * then allow any glyph to be blank
1801 */
1802 if (!blanks || FcBlanksIsMember (blanks, ucs4))
1803 return FcTrue;
1804 /* fall through ... */
1805 default:
1806 break;
1807 }
1808 return FcFalse;
1809 }
1810
1811 #define APPROXIMATELY_EQUAL(x,y) (ABS ((x) - (y)) <= MAX (ABS (x), ABS (y)) / 33)
1812
1813 FcCharSet *
1814 FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
1815 {
1816 FcChar32 page, off, max, ucs4;
1817 #ifdef CHECK
1818 FcChar32 font_max = 0;
1819 #endif
1820 FcCharSet *fcs;
1821 FcCharLeaf *leaf;
1822 const FcCharMap *map;
1823 int o;
1824 int i;
1825 FT_UInt glyph;
1826 FT_Pos advance, advance_one = 0, advance_two = 0;
1827 FcBool has_advance = FcFalse, fixed_advance = FcTrue, dual_advance = FcFalse;
1828
1829 fcs = FcCharSetCreate ();
1830 if (!fcs)
1831 goto bail0;
1832
1833 #ifdef CHECK
1834 printf ("Family %s style %s\n", face->family_name, face->style_name);
1835 #endif
1836 for (o = 0; o < NUM_DECODE; o++)
1837 {
1838 if (FT_Select_Charmap (face, fcFontDecoders[o].encoding) != 0)
1839 continue;
1840 map = fcFontDecoders[o].map;
1841 if (map)
1842 {
1843 /*
1844 * Non-Unicode tables are easy; there's a list of all possible
1845 * characters
1846 */
1847 for (i = 0; i < map->nent; i++)
1848 {
1849 ucs4 = map->ent[i].bmp;
1850 glyph = FT_Get_Char_Index (face, map->ent[i].encode);
1851 if (glyph &&
1852 FcFreeTypeCheckGlyph (face, ucs4, glyph, blanks, &advance))
1853 {
1854 if (!has_advance)
1855 {
1856 has_advance = FcTrue;
1857 advance_one = advance;
1858 }
1859 else if (!APPROXIMATELY_EQUAL (advance, advance_one))
1860 {
1861 if (fixed_advance)
1862 {
1863 dual_advance = FcTrue;
1864 fixed_advance = FcFalse;
1865 advance_two = advance;
1866 }
1867 else if (!APPROXIMATELY_EQUAL (advance, advance_two))
1868 dual_advance = FcFalse;
1869 }
1870
1871 leaf = FcCharSetFindLeafCreate (fcs, ucs4);
1872 if (!leaf)
1873 goto bail1;
1874 leaf->map[(ucs4 & 0xff) >> 5] |= (1 << (ucs4 & 0x1f));
1875 #ifdef CHECK
1876 if (ucs4 > font_max)
1877 font_max = ucs4;
1878 #endif
1879 }
1880 }
1881 }
1882 else
1883 {
1884 FT_UInt gindex;
1885
1886 max = fcFontDecoders[o].max;
1887 /*
1888 * Find the first encoded character in the font
1889 */
1890 if (FT_Get_Char_Index (face, 0))
1891 {
1892 ucs4 = 0;
1893 gindex = 1;
1894 }
1895 else
1896 {
1897 ucs4 = FT_Get_Next_Char (face, 0, &gindex);
1898 if (!ucs4)
1899 gindex = 0;
1900 }
1901
1902 while (gindex)
1903 {
1904 page = ucs4 >> 8;
1905 leaf = 0;
1906 while ((ucs4 >> 8) == page)
1907 {
1908 glyph = FT_Get_Char_Index (face, ucs4);
1909 if (glyph && FcFreeTypeCheckGlyph (face, ucs4,
1910 glyph, blanks, &advance))
1911 {
1912 if (!has_advance)
1913 {
1914 has_advance = FcTrue;
1915 advance_one = advance;
1916 }
1917 else if (!APPROXIMATELY_EQUAL (advance, advance_one))
1918 {
1919 if (fixed_advance)
1920 {
1921 dual_advance = FcTrue;
1922 fixed_advance = FcFalse;
1923 advance_two = advance;
1924 }
1925 else if (!APPROXIMATELY_EQUAL (advance, advance_two))
1926 dual_advance = FcFalse;
1927 }
1928
1929 if (!leaf)
1930 {
1931 leaf = FcCharSetFindLeafCreate (fcs, ucs4);
1932 if (!leaf)
1933 goto bail1;
1934 }
1935 off = ucs4 & 0xff;
1936 leaf->map[off >> 5] |= (1 << (off & 0x1f));
1937 #ifdef CHECK
1938 if (ucs4 > font_max)
1939 font_max = ucs4;
1940 #endif
1941 }
1942 ucs4++;
1943 }
1944 ucs4 = FT_Get_Next_Char (face, ucs4 - 1, &gindex);
1945 if (!ucs4)
1946 gindex = 0;
1947 }
1948 #ifdef CHECK
1949 for (ucs4 = 0; ucs4 < 0x10000; ucs4++)
1950 {
1951 FcBool FT_Has, FC_Has;
1952
1953 FT_Has = FT_Get_Char_Index (face, ucs4) != 0;
1954 FC_Has = FcCharSetHasChar (fcs, ucs4);
1955 if (FT_Has != FC_Has)
1956 {
1957 printf ("0x%08x FT says %d FC says %d\n", ucs4, FT_Has, FC_Has);
1958 }
1959 }
1960 #endif
1961 }
1962 }
1963 #if HAVE_FT_HAS_PS_GLYPH_NAMES
1964 /*
1965 * Add mapping from PS glyph names if available
1966 */
1967 if (FcFreeTypeUseNames (face))
1968 {
1969 FcChar8 name_buf[FC_GLYPHNAME_MAXLEN + 2];
1970
1971 for (glyph = 0; glyph < face->num_glyphs; glyph++)
1972 {
1973 if (FT_Get_Glyph_Name (face, glyph, name_buf, FC_GLYPHNAME_MAXLEN+1) == 0)
1974 {
1975 ucs4 = FcGlyphNameToUcs4 (name_buf);
1976 if (ucs4 != 0xffff &&
1977 FcFreeTypeCheckGlyph (face, ucs4, glyph, blanks, &advance))
1978 {
1979 if (!has_advance)
1980 {
1981 has_advance = FcTrue;
1982 advance_one = advance;
1983 }
1984 else if (!APPROXIMATELY_EQUAL (advance, advance_one))
1985 {
1986 if (fixed_advance)
1987 {
1988 dual_advance = FcTrue;
1989 fixed_advance = FcFalse;
1990 advance_two = advance;
1991 }
1992 else if (!APPROXIMATELY_EQUAL (advance, advance_two))
1993 dual_advance = FcFalse;
1994 }
1995 leaf = FcCharSetFindLeafCreate (fcs, ucs4);
1996 if (!leaf)
1997 goto bail1;
1998 leaf->map[(ucs4 & 0xff) >> 5] |= (1 << (ucs4 & 0x1f));
1999 #ifdef CHECK
2000 if (ucs4 > font_max)
2001 font_max = ucs4;
2002 #endif
2003 }
2004 }
2005 }
2006 }
2007 #endif
2008 #ifdef CHECK
2009 printf ("%d glyphs %d encoded\n", (int) face->num_glyphs, FcCharSetCount (fcs));
2010 for (ucs4 = 0; ucs4 <= font_max; ucs4++)
2011 {
2012 FcBool has_char = (glyph = FcFreeTypeCharIndex (face, ucs4)) != 0;
2013 FcBool has_bit = FcCharSetHasChar (fcs, ucs4);
2014
2015 if (has_char && !has_bit)
2016 {
2017 if (!FcFreeTypeCheckGlyph (face, ucs4, glyph, blanks, &advance))
2018 printf ("Bitmap missing broken char 0x%x\n", ucs4);
2019 else
2020 printf ("Bitmap missing char 0x%x\n", ucs4);
2021 }
2022 else if (!has_char && has_bit)
2023 printf ("Bitmap extra char 0x%x\n", ucs4);
2024 }
2025 #endif
2026 if (fixed_advance)
2027 *spacing = FC_MONO;
2028 else if (dual_advance && APPROXIMATELY_EQUAL (2 * MIN (advance_one, advance_two), MAX (advance_one, advance_two)))
2029 *spacing = FC_DUAL;
2030 else
2031 *spacing = FC_PROPORTIONAL;
2032 return fcs;
2033 bail1:
2034 FcCharSetDestroy (fcs);
2035 bail0:
2036 return 0;
2037 }
2038
2039 FcCharSet *
2040 FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks)
2041 {
2042 int spacing;
2043
2044 return FcFreeTypeCharSetAndSpacing (face, blanks, &spacing);
2045 }