]>
git.wh0rd.org - fontconfig.git/blob - src/fcfreetype.c
2 * $XFree86: xc/lib/fontconfig/src/fcfreetype.c,v 1.7 2002/07/08 07:31:53 keithp Exp $
4 * Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
29 #include <freetype/freetype.h>
30 #include <freetype/internal/ftobjs.h>
31 #include <freetype/tttables.h>
34 * Keep Han languages separated by eliminating languages
35 * that the codePageRange bits says aren't supported
41 } FcCodePageRange
[] = {
42 { 17, (const FcChar8
*) "ja" },
43 { 18, (const FcChar8
*) "zh-cn" },
44 { 19, (const FcChar8
*) "ko" },
45 { 20, (const FcChar8
*) "zh-tw" },
48 #define NUM_CODE_PAGE_RANGE (sizeof FcCodePageRange / sizeof FcCodePageRange[0])
51 FcFreeTypeIsExclusiveLang (const FcChar8
*lang
)
55 for (i
= 0; i
< NUM_CODE_PAGE_RANGE
; i
++)
57 if (FcLangCompare (lang
, FcCodePageRange
[i
].lang
) != FcLangDifferentLang
)
64 FcFreeTypeQuery (const FcChar8
*file
,
76 const FcChar8
*family
;
78 const FcChar8
*exclusiveLang
= 0;
80 if (FT_Init_FreeType (&ftLibrary
))
83 if (FT_New_Face (ftLibrary
, (char *) file
, id
, &face
))
86 *count
= face
->num_faces
;
88 pat
= FcPatternCreate ();
92 if (!FcPatternAddBool (pat
, FC_OUTLINE
,
93 (face
->face_flags
& FT_FACE_FLAG_SCALABLE
) != 0))
96 if (!FcPatternAddBool (pat
, FC_SCALABLE
,
97 (face
->face_flags
& FT_FACE_FLAG_SCALABLE
) != 0))
101 slant
= FC_SLANT_ROMAN
;
102 if (face
->style_flags
& FT_STYLE_FLAG_ITALIC
)
103 slant
= FC_SLANT_ITALIC
;
105 if (!FcPatternAddInteger (pat
, FC_SLANT
, slant
))
108 weight
= FC_WEIGHT_MEDIUM
;
109 if (face
->style_flags
& FT_STYLE_FLAG_BOLD
)
110 weight
= FC_WEIGHT_BOLD
;
112 if (!FcPatternAddInteger (pat
, FC_WEIGHT
, weight
))
115 family
= (FcChar8
*) face
->family_name
;
118 family
= (FcChar8
*) strrchr ((char *) file
, '/');
124 if (!FcPatternAddString (pat
, FC_FAMILY
, family
))
127 if (face
->style_name
)
129 if (!FcPatternAddString (pat
, FC_STYLE
, (FcChar8
*) face
->style_name
))
133 if (!FcPatternAddString (pat
, FC_FILE
, file
))
136 if (!FcPatternAddInteger (pat
, FC_INDEX
, id
))
139 if (!FcPatternAddString (pat
, FC_SOURCE
, (FcChar8
*) "FreeType"))
143 if ((face
->face_flags
& FT_FACE_FLAG_FIXED_WIDTH
) != 0)
144 if (!FcPatternAddInteger (pat
, FC_SPACING
, FC_MONO
))
149 * Get the OS/2 table and poke about
151 os2
= (TT_OS2
*) FT_Get_Sfnt_Table (face
, ft_sfnt_os2
);
152 if (os2
&& os2
->version
>= 0x0001 && os2
->version
!= 0xffff)
154 for (i
= 0; i
< NUM_CODE_PAGE_RANGE
; i
++)
158 if (FcCodePageRange
[i
].bit
< 32)
160 bits
= os2
->ulCodePageRange1
;
161 bit
= FcCodePageRange
[i
].bit
;
165 bits
= os2
->ulCodePageRange2
;
166 bit
= FcCodePageRange
[i
].bit
- 32;
168 if (bits
& (1 << bit
))
171 * If the font advertises support for multiple
172 * "exclusive" languages, then include support
173 * for any language found to have coverage
180 exclusiveLang
= FcCodePageRange
[i
].lang
;
186 * Compute the unicode coverage for the font
188 cs
= FcFreeTypeCharSet (face
, blanks
);
193 * Skip over PCF fonts that have no encoded characters; they're
194 * usually just Unicode fonts transcoded to some legacy encoding
196 if (FcCharSetCount (cs
) == 0)
198 if (!strcmp(FT_MODULE_CLASS(&face
->driver
->root
)->module_name
, "pcf"))
202 if (!FcPatternAddCharSet (pat
, FC_CHARSET
, cs
))
205 if (!FcFreeTypeSetLang (pat
, cs
, exclusiveLang
))
209 * Drop our reference to the charset
211 FcCharSetDestroy (cs
);
213 if (!(face
->face_flags
& FT_FACE_FLAG_SCALABLE
))
215 for (i
= 0; i
< face
->num_fixed_sizes
; i
++)
216 if (!FcPatternAddDouble (pat
, FC_PIXEL_SIZE
,
217 (double) face
->available_sizes
[i
].height
))
219 if (!FcPatternAddBool (pat
, FC_ANTIALIAS
, FcFalse
))
224 FT_Done_FreeType (ftLibrary
);
228 FcCharSetDestroy (cs
);
230 FcPatternDestroy (pat
);
234 FT_Done_FreeType (ftLibrary
);