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