2 Copyright (c) 1998-2003 by Juliusz Chroboczek
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 #include <X11/fonts/fntfilst.h>
29 #include <X11/fonts/fontutil.h>
30 #include <X11/fonts/FSproto.h>
32 #include <X11/fonts/fontmisc.h>
33 #include <X11/fonts/fontenc.h>
35 #include FT_FREETYPE_H
36 #include FT_TRUETYPE_IDS_H
37 #include FT_TRUETYPE_TABLES_H
38 #include FT_TYPE1_TABLES_H
43 static int find_cmap(int, int, int, FT_Face, FT_CharMap *);
46 FTEncFontSpecific(const char *encoding)
48 const char *p = encoding;
50 if(strcasecmp(encoding, "microsoft-symbol") == 0)
59 return (strcasecmp(p, "fontspecific") == 0);
63 FTPickMapping(char *xlfd, int length, char *filename, FT_Face face,
71 const char *enc, *reg;
72 const char *encoding_name = 0;
76 encoding_name = FontEncFromXLFD(xlfd, length);
78 encoding_name = "iso8859-1";
80 symbol = FTEncFontSpecific(encoding_name);
83 ftrc = FT_Get_BDF_Charset_ID(face, &enc, ®);
88 /* Disable reencoding for non-Unicode fonts. This will
89 currently only work for BDFs. */
90 if(strlen(enc) + strlen(reg) > 18)
95 ErrorF("%s %s\n", buf, encoding_name);
96 if(strcasecmp(buf, "iso10646-1") != 0) {
97 if(strcasecmp(buf, encoding_name) == 0)
102 ftrc = FT_Select_Charmap(face, ft_encoding_adobe_custom);
107 encoding = FontEncFind(encoding_name, filename);
108 if(symbol && encoding == NULL)
109 encoding = FontEncFind("microsoft-symbol", filename);
110 if(encoding == NULL) {
111 ErrorF("FreeType: couldn't find encoding '%s' for '%s'\n",
112 encoding_name, filename);
116 if(FT_Has_PS_Glyph_Names(face)) {
117 for(mapping = encoding->mappings; mapping; mapping = mapping->next) {
118 if(mapping->type == FONT_ENCODING_POSTSCRIPT) {
121 tm->mapping = mapping;
127 for(mapping = encoding->mappings; mapping; mapping = mapping->next) {
128 if(find_cmap(mapping->type, mapping->pid, mapping->eid, face,
133 /* deal with an undocumented ``feature'' of the
134 Microsft-Symbol cmap */
136 os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
138 tm->base = os2->usFirstCharIndex - 0x20;
143 tm->mapping = mapping;
148 return BadFontFormat;
152 tm->cmap = face->charmap;
159 find_cmap(int type, int pid, int eid, FT_Face face, FT_CharMap *cmap_return)
162 FT_CharMap cmap = NULL;
164 n = face->num_charmaps;
167 case FONT_ENCODING_TRUETYPE: /* specific cmap */
169 cmap = face->charmaps[i];
170 if(cmap->platform_id == pid && cmap->encoding_id == eid) {
176 case FONT_ENCODING_UNICODE: /* any Unicode cmap */
177 /* prefer Microsoft Unicode */
179 cmap = face->charmaps[i];
180 if(cmap->platform_id == TT_PLATFORM_MICROSOFT &&
181 cmap->encoding_id == TT_MS_ID_UNICODE_CS) {
187 /* Try Apple Unicode */
189 cmap = face->charmaps[i];
190 if(cmap->platform_id == TT_PLATFORM_APPLE_UNICODE) {
197 cmap = face->charmaps[i];
198 if(cmap->platform_id == TT_PLATFORM_ISO) {
211 FTRemap(FT_Face face, FTMappingPtr tm, unsigned code)
215 unsigned glyph_index;
219 name = FontEncName(code, tm->mapping);
222 glyph_index = FT_Get_Name_Index(face, name);
225 index = FontEncRecode(code, tm->mapping) + tm->base;
226 FT_Set_Charmap(face, tm->cmap);
227 glyph_index = FT_Get_Char_Index(face, index);
233 FT_Set_Charmap(face, tm->cmap);
234 glyph_index = FT_Get_Char_Index(face, index);