/*
- * $XFree86: $
+ * $XFree86: xc/lib/fontconfig/src/fcfreetype.c,v 1.7 2002/07/08 07:31:53 keithp Exp $
*
* Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
*
#include <freetype/freetype.h>
#include <freetype/internal/ftobjs.h>
#include <freetype/tttables.h>
-#include <fontconfig/fcfreetype.h>
+
+/*
+ * Keep Han languages separated by eliminating languages
+ * that the codePageRange bits says aren't supported
+ */
static const struct {
- int bit;
- FcChar8 *name;
+ int bit;
+ const FcChar8 *lang;
} FcCodePageRange[] = {
- { 0, (FcChar8 *) FC_LANG_LATIN_1 },
- { 1, (FcChar8 *) FC_LANG_LATIN_2_EASTERN_EUROPE },
- { 2, (FcChar8 *) FC_LANG_CYRILLIC },
- { 3, (FcChar8 *) FC_LANG_GREEK },
- { 4, (FcChar8 *) FC_LANG_TURKISH },
- { 5, (FcChar8 *) FC_LANG_HEBREW },
- { 6, (FcChar8 *) FC_LANG_ARABIC },
- { 7, (FcChar8 *) FC_LANG_WINDOWS_BALTIC },
- { 8, (FcChar8 *) FC_LANG_VIETNAMESE },
-/* 9-15 reserved for Alternate ANSI */
- { 16, (FcChar8 *) FC_LANG_THAI },
- { 17, (FcChar8 *) FC_LANG_JAPANESE },
- { 18, (FcChar8 *) FC_LANG_SIMPLIFIED_CHINESE },
- { 19, (FcChar8 *) FC_LANG_KOREAN_WANSUNG },
- { 20, (FcChar8 *) FC_LANG_TRADITIONAL_CHINESE },
- { 21, (FcChar8 *) FC_LANG_KOREAN_JOHAB },
-/* 22-28 reserved for Alternate ANSI & OEM */
- { 29, (FcChar8 *) FC_LANG_MACINTOSH },
- { 30, (FcChar8 *) FC_LANG_OEM },
- { 31, (FcChar8 *) FC_LANG_SYMBOL },
-/* 32-47 reserved for OEM */
- { 48, (FcChar8 *) FC_LANG_IBM_GREEK },
- { 49, (FcChar8 *) FC_LANG_MSDOS_RUSSIAN },
- { 50, (FcChar8 *) FC_LANG_MSDOS_NORDIC },
- { 51, (FcChar8 *) FC_LANG_ARABIC_864 },
- { 52, (FcChar8 *) FC_LANG_MSDOS_CANADIAN_FRENCH },
- { 53, (FcChar8 *) FC_LANG_HEBREW_862 },
- { 54, (FcChar8 *) FC_LANG_MSDOS_ICELANDIC },
- { 55, (FcChar8 *) FC_LANG_MSDOS_PORTUGUESE },
- { 56, (FcChar8 *) FC_LANG_IBM_TURKISH },
- { 57, (FcChar8 *) FC_LANG_IBM_CYRILLIC },
- { 58, (FcChar8 *) FC_LANG_LATIN_2 },
- { 59, (FcChar8 *) FC_LANG_MSDOS_BALTIC },
- { 60, (FcChar8 *) FC_LANG_GREEK_437_G },
- { 61, (FcChar8 *) FC_LANG_ARABIC_ASMO_708 },
- { 62, (FcChar8 *) FC_LANG_WE_LATIN_1 },
- { 63, (FcChar8 *) FC_LANG_US },
+ { 17, (const FcChar8 *) "ja" },
+ { 18, (const FcChar8 *) "zh-cn" },
+ { 19, (const FcChar8 *) "ko" },
+ { 20, (const FcChar8 *) "zh-tw" },
};
#define NUM_CODE_PAGE_RANGE (sizeof FcCodePageRange / sizeof FcCodePageRange[0])
+FcBool
+FcFreeTypeIsExclusiveLang (const FcChar8 *lang)
+{
+ int i;
+
+ for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
+ {
+ if (FcLangCompare (lang, FcCodePageRange[i].lang) != FcLangDifferentLang)
+ return FcTrue;
+ }
+ return FcFalse;
+}
+
FcPattern *
FcFreeTypeQuery (const FcChar8 *file,
int id,
FT_Library ftLibrary;
const FcChar8 *family;
TT_OS2 *os2;
+ const FcChar8 *exclusiveLang = 0;
if (FT_Init_FreeType (&ftLibrary))
return 0;
if (!FcPatternAddString (pat, FC_SOURCE, (FcChar8 *) "FreeType"))
goto bail1;
-#if 0
+#if 1
if ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0)
if (!FcPatternAddInteger (pat, FC_SPACING, FC_MONO))
goto bail1;
#endif
+ /*
+ * Get the OS/2 table and poke about
+ */
+ os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2);
+ if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
+ {
+ for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
+ {
+ FT_ULong bits;
+ int bit;
+ if (FcCodePageRange[i].bit < 32)
+ {
+ bits = os2->ulCodePageRange1;
+ bit = FcCodePageRange[i].bit;
+ }
+ else
+ {
+ bits = os2->ulCodePageRange2;
+ bit = FcCodePageRange[i].bit - 32;
+ }
+ if (bits & (1 << bit))
+ {
+ /*
+ * If the font advertises support for multiple
+ * "exclusive" languages, then include support
+ * for any language found to have coverage
+ */
+ if (exclusiveLang)
+ {
+ exclusiveLang = 0;
+ break;
+ }
+ exclusiveLang = FcCodePageRange[i].lang;
+ }
+ }
+ }
+
+ /*
+ * Compute the unicode coverage for the font
+ */
cs = FcFreeTypeCharSet (face, blanks);
if (!cs)
goto bail1;
if (!FcPatternAddCharSet (pat, FC_CHARSET, cs))
goto bail2;
+
+ if (!FcFreeTypeSetLang (pat, cs, exclusiveLang))
+ goto bail2;
+
/*
* Drop our reference to the charset
*/
goto bail1;
}
- /*
- * Get the OS/2 table and poke about
- */
- os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2);
- if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
- {
- for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
- {
- FT_ULong bits;
- int bit;
- if (FcCodePageRange[i].bit < 32)
- {
- bits = os2->ulCodePageRange1;
- bit = FcCodePageRange[i].bit;
- }
- else
- {
- bits = os2->ulCodePageRange2;
- bit = FcCodePageRange[i].bit - 32;
- }
- if (bits & (1 << bit))
- {
- if (!FcPatternAddString (pat, FC_LANG,
- FcCodePageRange[i].name))
- goto bail1;
- }
- }
- }
-
FT_Done_Face (face);
FT_Done_FreeType (ftLibrary);
return pat;