Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: core/src/fxge/ge/fx_ge_fontmap.cpp

Issue 453133004: clang-format all code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../include/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 #include "../../../include/fxge/fx_freetype.h" 8 #include "../../../include/fxge/fx_freetype.h"
9 #include "text_int.h" 9 #include "text_int.h"
10 #define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1]) 10 #define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1])
11 #define GET_TT_LONG(w) (FX_DWORD)(((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8 ) | (w)[3]) 11 #define GET_TT_LONG(w) \
12 CFX_SubstFont::CFX_SubstFont() 12 (FX_DWORD)(((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
13 { 13 CFX_SubstFont::CFX_SubstFont() {
14 m_ExtHandle = NULL; 14 m_ExtHandle = NULL;
15 m_Charset = 0; 15 m_Charset = 0;
16 m_SubstFlags = 0; 16 m_SubstFlags = 0;
17 m_Weight = 0; 17 m_Weight = 0;
18 m_ItalicAngle = 0; 18 m_ItalicAngle = 0;
19 m_bSubstOfCJK = FALSE; 19 m_bSubstOfCJK = FALSE;
20 m_WeightCJK = 0; 20 m_WeightCJK = 0;
21 m_bItlicCJK = FALSE; 21 m_bItlicCJK = FALSE;
22 } 22 }
23 CTTFontDesc::~CTTFontDesc() 23 CTTFontDesc::~CTTFontDesc() {
24 { 24 if (m_Type == 1) {
25 if (m_Type == 1) { 25 if (m_SingleFace.m_pFace) {
26 if (m_SingleFace.m_pFace) { 26 FXFT_Done_Face(m_SingleFace.m_pFace);
27 FXFT_Done_Face(m_SingleFace.m_pFace); 27 }
28 } 28 } else if (m_Type == 2) {
29 } else if (m_Type == 2) { 29 for (int i = 0; i < 16; i++)
30 for (int i = 0; i < 16; i ++) 30 if (m_TTCFace.m_pFaces[i]) {
31 if (m_TTCFace.m_pFaces[i]) { 31 FXFT_Done_Face(m_TTCFace.m_pFaces[i]);
32 FXFT_Done_Face(m_TTCFace.m_pFaces[i]); 32 }
33 } 33 }
34 } 34 if (m_pFontData) {
35 if (m_pFontData) { 35 FX_Free(m_pFontData);
36 FX_Free(m_pFontData); 36 }
37 } 37 }
38 } 38 FX_BOOL CTTFontDesc::ReleaseFace(FXFT_Face face) {
39 FX_BOOL CTTFontDesc::ReleaseFace(FXFT_Face face) 39 if (m_Type == 1) {
40 { 40 if (m_SingleFace.m_pFace != face) {
41 if (m_Type == 1) { 41 return FALSE;
42 if (m_SingleFace.m_pFace != face) { 42 }
43 return FALSE; 43 } else if (m_Type == 2) {
44 } 44 int i;
45 } else if (m_Type == 2) { 45 for (i = 0; i < 16; i++)
46 int i; 46 if (m_TTCFace.m_pFaces[i] == face) {
47 for (i = 0; i < 16; i ++) 47 break;
48 if (m_TTCFace.m_pFaces[i] == face) { 48 }
49 break; 49 if (i == 16) {
50 } 50 return FALSE;
51 if (i == 16) { 51 }
52 return FALSE; 52 }
53 } 53 m_RefCount--;
54 } 54 if (m_RefCount) {
55 m_RefCount --; 55 return FALSE;
56 if (m_RefCount) { 56 }
57 return FALSE; 57 delete this;
58 } 58 return TRUE;
59 delete this; 59 }
60 return TRUE; 60 CFX_FontMgr::CFX_FontMgr() {
61 } 61 m_pBuiltinMapper = FX_NEW CFX_FontMapper;
62 CFX_FontMgr::CFX_FontMgr() 62 if (!m_pBuiltinMapper) {
63 { 63 return;
64 m_pBuiltinMapper = FX_NEW CFX_FontMapper; 64 }
65 if (!m_pBuiltinMapper) { 65 m_pBuiltinMapper->m_pFontMgr = this;
66 return; 66 m_pExtMapper = NULL;
67 } 67 m_FTLibrary = NULL;
68 m_pBuiltinMapper->m_pFontMgr = this; 68 FXSYS_memset32(m_ExternalFonts, 0, sizeof m_ExternalFonts);
69 m_pExtMapper = NULL; 69 }
70 m_FTLibrary = NULL; 70 CFX_FontMgr::~CFX_FontMgr() {
71 FXSYS_memset32(m_ExternalFonts, 0, sizeof m_ExternalFonts); 71 if (m_pBuiltinMapper) {
72 } 72 delete m_pBuiltinMapper;
73 CFX_FontMgr::~CFX_FontMgr() 73 }
74 { 74 FreeCache();
75 if (m_pBuiltinMapper) { 75 if (m_FTLibrary) {
76 delete m_pBuiltinMapper; 76 FXFT_Done_FreeType(m_FTLibrary);
77 } 77 }
78 FreeCache(); 78 }
79 if (m_FTLibrary) { 79 void CFX_FontMgr::InitFTLibrary() {
80 FXFT_Done_FreeType(m_FTLibrary); 80 if (m_FTLibrary == NULL) {
81 } 81 FXFT_Init_FreeType(&m_FTLibrary);
82 } 82 }
83 void CFX_FontMgr::InitFTLibrary() 83 }
84 { 84 void CFX_FontMgr::FreeCache() {
85 if (m_FTLibrary == NULL) { 85 FX_POSITION pos = m_FaceMap.GetStartPosition();
86 FXFT_Init_FreeType(&m_FTLibrary); 86 while (pos) {
87 } 87 CFX_ByteString Key;
88 } 88 CTTFontDesc* face;
89 void CFX_FontMgr::FreeCache() 89 m_FaceMap.GetNextAssoc(pos, Key, (void*&)face);
90 { 90 delete face;
91 FX_POSITION pos = m_FaceMap.GetStartPosition(); 91 }
92 while(pos) { 92 m_FaceMap.RemoveAll();
93 CFX_ByteString Key; 93 }
94 CTTFontDesc* face; 94 void CFX_FontMgr::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) {
95 m_FaceMap.GetNextAssoc(pos, Key, (void*&)face); 95 m_pBuiltinMapper->SetSystemFontInfo(pFontInfo);
96 delete face; 96 }
97 } 97 FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name,
98 m_FaceMap.RemoveAll(); 98 FX_BOOL bTrueType,
99 } 99 FX_DWORD flags,
100 void CFX_FontMgr::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) 100 int weight,
101 { 101 int italic_angle,
102 m_pBuiltinMapper->SetSystemFontInfo(pFontInfo); 102 int CharsetCP,
103 } 103 CFX_SubstFont* pSubstFont) {
104 FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name, FX_BOOL bT rueType, 104 if (m_FTLibrary == NULL) {
105 FX_DWORD flags, int weight, int italic_angl e, int CharsetCP, CFX_SubstFont* pSubstFont) 105 FXFT_Init_FreeType(&m_FTLibrary);
106 { 106 }
107 if (m_FTLibrary == NULL) { 107 if (m_pExtMapper) {
108 FXFT_Init_FreeType(&m_FTLibrary); 108 FXFT_Face face = m_pExtMapper->FindSubstFont(face_name,
109 } 109 bTrueType,
110 if (m_pExtMapper) { 110 flags,
111 FXFT_Face face = m_pExtMapper->FindSubstFont(face_name, bTrueType, flags , weight, italic_angle, 111 weight,
112 CharsetCP, pSubstFont); 112 italic_angle,
113 if (face) { 113 CharsetCP,
114 return face; 114 pSubstFont);
115 } 115 if (face) {
116 } 116 return face;
117 return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight, italic_angle, 117 }
118 CharsetCP, pSubstFont); 118 }
119 return m_pBuiltinMapper->FindSubstFont(
120 face_name, bTrueType, flags, weight, italic_angle, CharsetCP, pSubstFont);
119 } 121 }
120 FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name, 122 FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name,
121 int weight, FX_BOOL bItalic, FX_LPBYTE& pFo ntData) 123 int weight,
122 { 124 FX_BOOL bItalic,
123 CFX_ByteString key(face_name); 125 FX_LPBYTE& pFontData) {
124 key += ','; 126 CFX_ByteString key(face_name);
125 key += CFX_ByteString::FormatInteger(weight); 127 key += ',';
126 key += bItalic ? 'I' : 'N'; 128 key += CFX_ByteString::FormatInteger(weight);
127 CTTFontDesc* pFontDesc = NULL; 129 key += bItalic ? 'I' : 'N';
128 m_FaceMap.Lookup(key, (void*&)pFontDesc); 130 CTTFontDesc* pFontDesc = NULL;
129 if(pFontDesc) { 131 m_FaceMap.Lookup(key, (void*&)pFontDesc);
130 pFontData = pFontDesc->m_pFontData; 132 if (pFontDesc) {
131 pFontDesc->m_RefCount ++; 133 pFontData = pFontDesc->m_pFontData;
132 return pFontDesc->m_SingleFace.m_pFace; 134 pFontDesc->m_RefCount++;
133 } 135 return pFontDesc->m_SingleFace.m_pFace;
136 }
137 return NULL;
138 }
139 FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name,
140 int weight,
141 FX_BOOL bItalic,
142 FX_LPBYTE pData,
143 FX_DWORD size,
144 int face_index) {
145 CTTFontDesc* pFontDesc = FX_NEW CTTFontDesc;
146 if (!pFontDesc) {
134 return NULL; 147 return NULL;
135 } 148 }
136 FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, 149 pFontDesc->m_Type = 1;
137 int weight, FX_BOOL bItalic, FX_LPBYTE pDat a, FX_DWORD size, int face_index) 150 pFontDesc->m_SingleFace.m_pFace = NULL;
138 { 151 pFontDesc->m_SingleFace.m_bBold = weight;
139 CTTFontDesc* pFontDesc = FX_NEW CTTFontDesc; 152 pFontDesc->m_SingleFace.m_bItalic = bItalic;
140 if (!pFontDesc) { 153 pFontDesc->m_pFontData = pData;
141 return NULL; 154 pFontDesc->m_RefCount = 1;
142 } 155 FXFT_Library library;
143 pFontDesc->m_Type = 1; 156 if (m_FTLibrary == NULL) {
144 pFontDesc->m_SingleFace.m_pFace = NULL; 157 FXFT_Init_FreeType(&m_FTLibrary);
145 pFontDesc->m_SingleFace.m_bBold = weight; 158 }
146 pFontDesc->m_SingleFace.m_bItalic = bItalic; 159 library = m_FTLibrary;
147 pFontDesc->m_pFontData = pData; 160 int ret = FXFT_New_Memory_Face(
148 pFontDesc->m_RefCount = 1; 161 library, pData, size, face_index, &pFontDesc->m_SingleFace.m_pFace);
149 FXFT_Library library; 162 if (ret) {
150 if (m_FTLibrary == NULL) { 163 delete pFontDesc;
151 FXFT_Init_FreeType(&m_FTLibrary); 164 return NULL;
152 } 165 }
153 library = m_FTLibrary; 166 ret = FXFT_Set_Pixel_Sizes(pFontDesc->m_SingleFace.m_pFace, 64, 64);
154 int ret = FXFT_New_Memory_Face(library, pData, size, face_index, &pFontDesc- >m_SingleFace.m_pFace); 167 if (ret) {
155 if (ret) { 168 delete pFontDesc;
156 delete pFontDesc; 169 return NULL;
157 return NULL; 170 }
158 } 171 CFX_ByteString key(face_name);
159 ret = FXFT_Set_Pixel_Sizes(pFontDesc->m_SingleFace.m_pFace, 64, 64); 172 key += ',';
160 if (ret) { 173 key += CFX_ByteString::FormatInteger(weight);
161 delete pFontDesc; 174 key += bItalic ? 'I' : 'N';
162 return NULL; 175 m_FaceMap.SetAt(key, pFontDesc);
163 } 176 return pFontDesc->m_SingleFace.m_pFace;
164 CFX_ByteString key(face_name);
165 key += ',';
166 key += CFX_ByteString::FormatInteger(weight);
167 key += bItalic ? 'I' : 'N';
168 m_FaceMap.SetAt(key, pFontDesc);
169 return pFontDesc->m_SingleFace.m_pFace;
170 } 177 }
171 const FX_LPCSTR g_Base14FontNames[14] = { 178 const FX_LPCSTR g_Base14FontNames[14] = {
172 "Courier", 179 "Courier", "Courier-Bold", "Courier-BoldOblique", "Courier-Oblique",
173 "Courier-Bold", 180 "Helvetica", "Helvetica-Bold", "Helvetica-BoldOblique", "Helvetica-Oblique",
174 "Courier-BoldOblique", 181 "Times-Roman", "Times-Bold", "Times-BoldItalic", "Times-Italic",
175 "Courier-Oblique", 182 "Symbol", "ZapfDingbats",
176 "Helvetica",
177 "Helvetica-Bold",
178 "Helvetica-BoldOblique",
179 "Helvetica-Oblique",
180 "Times-Roman",
181 "Times-Bold",
182 "Times-BoldItalic",
183 "Times-Italic",
184 "Symbol",
185 "ZapfDingbats",
186 }; 183 };
187 const struct _AltFontName { 184 const struct _AltFontName {
188 const FX_CHAR*» m_pName; 185 const FX_CHAR* m_pName;
189 int»» m_Index; 186 int m_Index;
190 } 187 } g_AltFontNames[] = {
191 g_AltFontNames[] = { 188 { "Arial", 4 },
192 {"Arial", 4}, 189 { "Arial,Bold", 5 },
193 {"Arial,Bold", 5}, 190 { "Arial,BoldItalic", 6 },
194 {"Arial,BoldItalic", 6}, 191 { "Arial,Italic", 7 },
195 {"Arial,Italic", 7}, 192 { "Arial-Bold", 5 },
196 {"Arial-Bold", 5}, 193 { "Arial-BoldItalic", 6 },
197 {"Arial-BoldItalic", 6}, 194 { "Arial-BoldItalicMT", 6 },
198 {"Arial-BoldItalicMT", 6}, 195 { "Arial-BoldMT", 5 },
199 {"Arial-BoldMT", 5}, 196 { "Arial-Italic", 7 },
200 {"Arial-Italic", 7}, 197 { "Arial-ItalicMT", 7 },
201 {"Arial-ItalicMT", 7}, 198 { "ArialBold", 5 },
202 {"ArialBold", 5}, 199 { "ArialBoldItalic", 6 },
203 {"ArialBoldItalic", 6}, 200 { "ArialItalic", 7 },
204 {"ArialItalic", 7}, 201 { "ArialMT", 4 },
205 {"ArialMT", 4}, 202 { "ArialMT,Bold", 5 },
206 {"ArialMT,Bold", 5}, 203 { "ArialMT,BoldItalic", 6 },
207 {"ArialMT,BoldItalic", 6}, 204 { "ArialMT,Italic", 7 },
208 {"ArialMT,Italic", 7}, 205 { "ArialRoundedMTBold", 5 },
209 {"ArialRoundedMTBold", 5}, 206 { "Courier", 0 },
210 {"Courier", 0}, 207 { "Courier,Bold", 1 },
211 {"Courier,Bold", 1}, 208 { "Courier,BoldItalic", 2 },
212 {"Courier,BoldItalic", 2}, 209 { "Courier,Italic", 3 },
213 {"Courier,Italic", 3}, 210 { "Courier-Bold", 1 },
214 {"Courier-Bold", 1}, 211 { "Courier-BoldOblique", 2 },
215 {"Courier-BoldOblique", 2}, 212 { "Courier-Oblique", 3 },
216 {"Courier-Oblique", 3}, 213 { "CourierBold", 1 },
217 {"CourierBold", 1}, 214 { "CourierBoldItalic", 2 },
218 {"CourierBoldItalic", 2}, 215 { "CourierItalic", 3 },
219 {"CourierItalic", 3}, 216 { "CourierNew", 0 },
220 {"CourierNew", 0}, 217 { "CourierNew,Bold", 1 },
221 {"CourierNew,Bold", 1}, 218 { "CourierNew,BoldItalic", 2 },
222 {"CourierNew,BoldItalic", 2}, 219 { "CourierNew,Italic", 3 },
223 {"CourierNew,Italic", 3}, 220 { "CourierNew-Bold", 1 },
224 {"CourierNew-Bold", 1}, 221 { "CourierNew-BoldItalic", 2 },
225 {"CourierNew-BoldItalic", 2}, 222 { "CourierNew-Italic", 3 },
226 {"CourierNew-Italic", 3}, 223 { "CourierNewBold", 1 },
227 {"CourierNewBold", 1}, 224 { "CourierNewBoldItalic", 2 },
228 {"CourierNewBoldItalic", 2}, 225 { "CourierNewItalic", 3 },
229 {"CourierNewItalic", 3}, 226 { "CourierNewPS-BoldItalicMT", 2 },
230 {"CourierNewPS-BoldItalicMT", 2}, 227 { "CourierNewPS-BoldMT", 1 },
231 {"CourierNewPS-BoldMT", 1}, 228 { "CourierNewPS-ItalicMT", 3 },
232 {"CourierNewPS-ItalicMT", 3}, 229 { "CourierNewPSMT", 0 },
233 {"CourierNewPSMT", 0}, 230 { "CourierStd", 0 },
234 {"CourierStd", 0}, 231 { "CourierStd-Bold", 1 },
235 {"CourierStd-Bold", 1}, 232 { "CourierStd-BoldOblique", 2 },
236 {"CourierStd-BoldOblique", 2}, 233 { "CourierStd-Oblique", 3 },
237 {"CourierStd-Oblique", 3}, 234 { "Helvetica", 4 },
238 {"Helvetica", 4}, 235 { "Helvetica,Bold", 5 },
239 {"Helvetica,Bold", 5}, 236 { "Helvetica,BoldItalic", 6 },
240 {"Helvetica,BoldItalic", 6}, 237 { "Helvetica,Italic", 7 },
241 {"Helvetica,Italic", 7}, 238 { "Helvetica-Bold", 5 },
242 {"Helvetica-Bold", 5}, 239 { "Helvetica-BoldItalic", 6 },
243 {"Helvetica-BoldItalic", 6}, 240 { "Helvetica-BoldOblique", 6 },
244 {"Helvetica-BoldOblique", 6}, 241 { "Helvetica-Italic", 7 },
245 {"Helvetica-Italic", 7}, 242 { "Helvetica-Oblique", 7 },
246 {"Helvetica-Oblique", 7}, 243 { "HelveticaBold", 5 },
247 {"HelveticaBold", 5}, 244 { "HelveticaBoldItalic", 6 },
248 {"HelveticaBoldItalic", 6}, 245 { "HelveticaItalic", 7 },
249 {"HelveticaItalic", 7}, 246 { "Symbol", 12 },
250 {"Symbol", 12}, 247 { "SymbolMT", 12 },
251 {"SymbolMT", 12}, 248 { "Times-Bold", 9 },
252 {"Times-Bold", 9}, 249 { "Times-BoldItalic", 10 },
253 {"Times-BoldItalic", 10}, 250 { "Times-Italic", 11 },
254 {"Times-Italic", 11}, 251 { "Times-Roman", 8 },
255 {"Times-Roman", 8}, 252 { "TimesBold", 9 },
256 {"TimesBold", 9}, 253 { "TimesBoldItalic", 10 },
257 {"TimesBoldItalic", 10}, 254 { "TimesItalic", 11 },
258 {"TimesItalic", 11}, 255 { "TimesNewRoman", 8 },
259 {"TimesNewRoman", 8}, 256 { "TimesNewRoman,Bold", 9 },
260 {"TimesNewRoman,Bold", 9}, 257 { "TimesNewRoman,BoldItalic", 10 },
261 {"TimesNewRoman,BoldItalic", 10}, 258 { "TimesNewRoman,Italic", 11 },
262 {"TimesNewRoman,Italic", 11}, 259 { "TimesNewRoman-Bold", 9 },
263 {"TimesNewRoman-Bold", 9}, 260 { "TimesNewRoman-BoldItalic", 10 },
264 {"TimesNewRoman-BoldItalic", 10}, 261 { "TimesNewRoman-Italic", 11 },
265 {"TimesNewRoman-Italic", 11}, 262 { "TimesNewRomanBold", 9 },
266 {"TimesNewRomanBold", 9}, 263 { "TimesNewRomanBoldItalic", 10 },
267 {"TimesNewRomanBoldItalic", 10}, 264 { "TimesNewRomanItalic", 11 },
268 {"TimesNewRomanItalic", 11}, 265 { "TimesNewRomanPS", 8 },
269 {"TimesNewRomanPS", 8}, 266 { "TimesNewRomanPS-Bold", 9 },
270 {"TimesNewRomanPS-Bold", 9}, 267 { "TimesNewRomanPS-BoldItalic", 10 },
271 {"TimesNewRomanPS-BoldItalic", 10}, 268 { "TimesNewRomanPS-BoldItalicMT", 10 },
272 {"TimesNewRomanPS-BoldItalicMT", 10}, 269 { "TimesNewRomanPS-BoldMT", 9 },
273 {"TimesNewRomanPS-BoldMT", 9}, 270 { "TimesNewRomanPS-Italic", 11 },
274 {"TimesNewRomanPS-Italic", 11}, 271 { "TimesNewRomanPS-ItalicMT", 11 },
275 {"TimesNewRomanPS-ItalicMT", 11}, 272 { "TimesNewRomanPSMT", 8 },
276 {"TimesNewRomanPSMT", 8}, 273 { "TimesNewRomanPSMT,Bold", 9 },
277 {"TimesNewRomanPSMT,Bold", 9}, 274 { "TimesNewRomanPSMT,BoldItalic", 10 },
278 {"TimesNewRomanPSMT,BoldItalic", 10}, 275 { "TimesNewRomanPSMT,Italic", 11 },
279 {"TimesNewRomanPSMT,Italic", 11}, 276 { "ZapfDingbats", 13 },
280 {"ZapfDingbats", 13}, 277 };
281 };
282 extern "C" { 278 extern "C" {
283 static int compareString(const void* key, const void* element) 279 static int compareString(const void* key, const void* element) {
284 { 280 return FXSYS_stricmp((FX_LPCSTR)key, ((_AltFontName*)element)->m_pName);
285 return FXSYS_stricmp((FX_LPCSTR)key, ((_AltFontName*)element)->m_pName); 281 }
286 } 282 }
287 } 283 int _PDF_GetStandardFontName(CFX_ByteString& name) {
288 int _PDF_GetStandardFontName(CFX_ByteString& name) 284 _AltFontName* found =
289 { 285 (_AltFontName*)FXSYS_bsearch((FX_LPCSTR)name,
290 _AltFontName* found = (_AltFontName*)FXSYS_bsearch((FX_LPCSTR)name, g_AltFon tNames, 286 g_AltFontNames,
291 sizeof g_AltFontNames / sizeof (_AltFontName), sizeof (_AltFontName), compareString); 287 sizeof g_AltFontNames / sizeof(_AltFontName),
292 if (found == NULL) { 288 sizeof(_AltFontName),
293 return -1; 289 compareString);
294 } 290 if (found == NULL) {
295 name = g_Base14FontNames[found->m_Index]; 291 return -1;
296 return found->m_Index; 292 }
297 } 293 name = g_Base14FontNames[found->m_Index];
298 int GetTTCIndex(FX_LPCBYTE pFontData, FX_DWORD ttc_size, FX_DWORD font_offset) 294 return found->m_Index;
299 { 295 }
300 int face_index = 0; 296 int GetTTCIndex(FX_LPCBYTE pFontData, FX_DWORD ttc_size, FX_DWORD font_offset) {
301 FX_LPCBYTE p = pFontData + 8; 297 int face_index = 0;
302 FX_DWORD nfont = GET_TT_LONG(p); 298 FX_LPCBYTE p = pFontData + 8;
303 FX_DWORD index; 299 FX_DWORD nfont = GET_TT_LONG(p);
304 for (index = 0; index < nfont; index ++) { 300 FX_DWORD index;
305 p = pFontData + 12 + index * 4; 301 for (index = 0; index < nfont; index++) {
306 if (GET_TT_LONG(p) == font_offset) { 302 p = pFontData + 12 + index * 4;
307 break; 303 if (GET_TT_LONG(p) == font_offset) {
308 } 304 break;
309 } 305 }
310 if(index >= nfont) { 306 }
311 face_index = 0; 307 if (index >= nfont) {
312 } else { 308 face_index = 0;
313 face_index = index; 309 } else {
314 } 310 face_index = index;
315 return face_index; 311 }
316 } 312 return face_index;
317 FXFT_Face CFX_FontMgr::GetCachedTTCFace(int ttc_size, FX_DWORD checksum, 313 }
318 int font_offset, FX_LPBYTE& pFontData) 314 FXFT_Face CFX_FontMgr::GetCachedTTCFace(int ttc_size,
319 { 315 FX_DWORD checksum,
320 CFX_ByteString key; 316 int font_offset,
321 key.Format("%d:%d", ttc_size, checksum); 317 FX_LPBYTE& pFontData) {
322 CTTFontDesc* pFontDesc = NULL; 318 CFX_ByteString key;
323 m_FaceMap.Lookup(key, (void*&)pFontDesc); 319 key.Format("%d:%d", ttc_size, checksum);
324 if (pFontDesc == NULL) { 320 CTTFontDesc* pFontDesc = NULL;
325 return NULL; 321 m_FaceMap.Lookup(key, (void*&)pFontDesc);
326 } 322 if (pFontDesc == NULL) {
327 pFontData = pFontDesc->m_pFontData; 323 return NULL;
328 pFontDesc->m_RefCount ++; 324 }
329 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); 325 pFontData = pFontDesc->m_pFontData;
330 if (pFontDesc->m_TTCFace.m_pFaces[face_index] == NULL) { 326 pFontDesc->m_RefCount++;
331 pFontDesc->m_TTCFace.m_pFaces[face_index] = GetFixedFace(pFontDesc->m_pF ontData, ttc_size, face_index); 327 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset);
332 } 328 if (pFontDesc->m_TTCFace.m_pFaces[face_index] == NULL) {
333 return pFontDesc->m_TTCFace.m_pFaces[face_index]; 329 pFontDesc->m_TTCFace.m_pFaces[face_index] =
334 } 330 GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index);
335 FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size, FX_DWORD checksum, 331 }
336 FX_LPBYTE pData, FX_DWORD size, int font _offset) 332 return pFontDesc->m_TTCFace.m_pFaces[face_index];
337 { 333 }
338 CFX_ByteString key; 334 FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size,
339 key.Format("%d:%d", ttc_size, checksum); 335 FX_DWORD checksum,
340 CTTFontDesc* pFontDesc = FX_NEW CTTFontDesc; 336 FX_LPBYTE pData,
341 if (!pFontDesc) { 337 FX_DWORD size,
342 return NULL; 338 int font_offset) {
343 } 339 CFX_ByteString key;
344 pFontDesc->m_Type = 2; 340 key.Format("%d:%d", ttc_size, checksum);
345 pFontDesc->m_pFontData = pData; 341 CTTFontDesc* pFontDesc = FX_NEW CTTFontDesc;
346 for (int i = 0; i < 16; i ++) { 342 if (!pFontDesc) {
347 pFontDesc->m_TTCFace.m_pFaces[i] = NULL; 343 return NULL;
348 } 344 }
349 pFontDesc->m_RefCount ++; 345 pFontDesc->m_Type = 2;
350 key.Format("%d:%d", ttc_size, checksum); 346 pFontDesc->m_pFontData = pData;
351 m_FaceMap.SetAt(key, pFontDesc); 347 for (int i = 0; i < 16; i++) {
352 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); 348 pFontDesc->m_TTCFace.m_pFaces[i] = NULL;
353 pFontDesc->m_TTCFace.m_pFaces[face_index] = GetFixedFace(pFontDesc->m_pFontD ata, ttc_size, face_index); 349 }
354 return pFontDesc->m_TTCFace.m_pFaces[face_index]; 350 pFontDesc->m_RefCount++;
355 } 351 key.Format("%d:%d", ttc_size, checksum);
356 FXFT_Face CFX_FontMgr::GetFixedFace(FX_LPCBYTE pData, FX_DWORD size, int face_in dex) 352 m_FaceMap.SetAt(key, pFontDesc);
357 { 353 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset);
358 FXFT_Library library; 354 pFontDesc->m_TTCFace.m_pFaces[face_index] =
359 if (m_FTLibrary == NULL) { 355 GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index);
360 FXFT_Init_FreeType(&m_FTLibrary); 356 return pFontDesc->m_TTCFace.m_pFaces[face_index];
361 } 357 }
362 library = m_FTLibrary; 358 FXFT_Face CFX_FontMgr::GetFixedFace(FX_LPCBYTE pData,
363 FXFT_Face face = NULL; 359 FX_DWORD size,
364 int ret = FXFT_New_Memory_Face(library, pData, size, face_index, &face); 360 int face_index) {
365 if (ret) { 361 FXFT_Library library;
366 return NULL; 362 if (m_FTLibrary == NULL) {
367 } 363 FXFT_Init_FreeType(&m_FTLibrary);
368 ret = FXFT_Set_Pixel_Sizes(face, 64, 64); 364 }
369 if (ret) { 365 library = m_FTLibrary;
370 return NULL; 366 FXFT_Face face = NULL;
371 } 367 int ret = FXFT_New_Memory_Face(library, pData, size, face_index, &face);
372 return face; 368 if (ret) {
373 } 369 return NULL;
374 FXFT_Face CFX_FontMgr::GetFileFace(FX_LPCSTR filename, int face_index) 370 }
375 { 371 ret = FXFT_Set_Pixel_Sizes(face, 64, 64);
376 FXFT_Library library; 372 if (ret) {
377 if (m_FTLibrary == NULL) { 373 return NULL;
378 FXFT_Init_FreeType(&m_FTLibrary); 374 }
379 } 375 return face;
380 library = m_FTLibrary; 376 }
381 FXFT_Face face = NULL; 377 FXFT_Face CFX_FontMgr::GetFileFace(FX_LPCSTR filename, int face_index) {
382 int ret = FXFT_New_Face(library, filename, face_index, &face); 378 FXFT_Library library;
383 if (ret) { 379 if (m_FTLibrary == NULL) {
384 return NULL; 380 FXFT_Init_FreeType(&m_FTLibrary);
385 } 381 }
386 ret = FXFT_Set_Pixel_Sizes(face, 64, 64); 382 library = m_FTLibrary;
387 if (ret) { 383 FXFT_Face face = NULL;
388 return NULL; 384 int ret = FXFT_New_Face(library, filename, face_index, &face);
389 } 385 if (ret) {
390 return face; 386 return NULL;
391 } 387 }
392 void CFX_FontMgr::ReleaseFace(FXFT_Face face) 388 ret = FXFT_Set_Pixel_Sizes(face, 64, 64);
393 { 389 if (ret) {
394 if (face == NULL) { 390 return NULL;
395 return; 391 }
396 } 392 return face;
397 FX_POSITION pos = m_FaceMap.GetStartPosition(); 393 }
398 while(pos) { 394 void CFX_FontMgr::ReleaseFace(FXFT_Face face) {
399 CFX_ByteString Key; 395 if (face == NULL) {
400 CTTFontDesc* ttface; 396 return;
401 m_FaceMap.GetNextAssoc(pos, Key, (void*&)ttface); 397 }
402 if (ttface->ReleaseFace(face)) { 398 FX_POSITION pos = m_FaceMap.GetStartPosition();
403 m_FaceMap.RemoveKey(Key); 399 while (pos) {
404 } 400 CFX_ByteString Key;
405 } 401 CTTFontDesc* ttface;
402 m_FaceMap.GetNextAssoc(pos, Key, (void*&)ttface);
403 if (ttface->ReleaseFace(face)) {
404 m_FaceMap.RemoveKey(Key);
405 }
406 }
406 } 407 }
407 extern "C" { 408 extern "C" {
408 extern const unsigned char g_FoxitFixedItalicFontData [18746]; 409 extern const unsigned char g_FoxitFixedItalicFontData[18746];
409 extern const unsigned char g_FoxitFixedFontData [17597]; 410 extern const unsigned char g_FoxitFixedFontData[17597];
410 extern const unsigned char g_FoxitSansItalicFontData [16339]; 411 extern const unsigned char g_FoxitSansItalicFontData[16339];
411 extern const unsigned char g_FoxitSansFontData [15025]; 412 extern const unsigned char g_FoxitSansFontData[15025];
412 extern const unsigned char g_FoxitSerifItalicFontData [21227]; 413 extern const unsigned char g_FoxitSerifItalicFontData[21227];
413 extern const unsigned char g_FoxitSerifFontData [19469]; 414 extern const unsigned char g_FoxitSerifFontData[19469];
414 extern const unsigned char g_FoxitFixedBoldItalicFontData [19151]; 415 extern const unsigned char g_FoxitFixedBoldItalicFontData[19151];
415 extern const unsigned char g_FoxitFixedBoldFontData [18055]; 416 extern const unsigned char g_FoxitFixedBoldFontData[18055];
416 extern const unsigned char g_FoxitSansBoldItalicFontData [16418]; 417 extern const unsigned char g_FoxitSansBoldItalicFontData[16418];
417 extern const unsigned char g_FoxitSansBoldFontData [16344]; 418 extern const unsigned char g_FoxitSansBoldFontData[16344];
418 extern const unsigned char g_FoxitSerifBoldItalicFontData [20733]; 419 extern const unsigned char g_FoxitSerifBoldItalicFontData[20733];
419 extern const unsigned char g_FoxitSerifBoldFontData [19395]; 420 extern const unsigned char g_FoxitSerifBoldFontData[19395];
420 extern const unsigned char g_FoxitSymbolFontData[16729]; 421 extern const unsigned char g_FoxitSymbolFontData[16729];
421 extern const unsigned char g_FoxitDingbatsFontData[29513]; 422 extern const unsigned char g_FoxitDingbatsFontData[29513];
422 extern const unsigned char g_FoxitSerifMMFontData[113417]; 423 extern const unsigned char g_FoxitSerifMMFontData[113417];
423 extern const unsigned char g_FoxitSansMMFontData[66919]; 424 extern const unsigned char g_FoxitSansMMFontData[66919];
424 }; 425 };
425 const FoxitFonts g_FoxitFonts[14] = { 426 const FoxitFonts g_FoxitFonts[14] = {
426 {g_FoxitFixedFontData, 17597}, 427 { g_FoxitFixedFontData, 17597 },
427 {g_FoxitFixedBoldFontData, 18055}, 428 { g_FoxitFixedBoldFontData, 18055 },
428 {g_FoxitFixedBoldItalicFontData, 19151}, 429 { g_FoxitFixedBoldItalicFontData, 19151 },
429 {g_FoxitFixedItalicFontData, 18746}, 430 { g_FoxitFixedItalicFontData, 18746 },
430 {g_FoxitSansFontData, 15025}, 431 { g_FoxitSansFontData, 15025 },
431 {g_FoxitSansBoldFontData, 16344}, 432 { g_FoxitSansBoldFontData, 16344 },
432 {g_FoxitSansBoldItalicFontData, 16418}, 433 { g_FoxitSansBoldItalicFontData, 16418 },
433 {g_FoxitSansItalicFontData, 16339}, 434 { g_FoxitSansItalicFontData, 16339 },
434 {g_FoxitSerifFontData, 19469}, 435 { g_FoxitSerifFontData, 19469 },
435 {g_FoxitSerifBoldFontData, 19395}, 436 { g_FoxitSerifBoldFontData, 19395 },
436 {g_FoxitSerifBoldItalicFontData, 20733}, 437 { g_FoxitSerifBoldItalicFontData, 20733 },
437 {g_FoxitSerifItalicFontData, 21227}, 438 { g_FoxitSerifItalicFontData, 21227 },
438 {g_FoxitSymbolFontData, 16729}, 439 { g_FoxitSymbolFontData, 16729 },
439 {g_FoxitDingbatsFontData, 29513}, 440 { g_FoxitDingbatsFontData, 29513 },
440 }; 441 };
441 void _FPDFAPI_GetInternalFontData(int id, FX_LPCBYTE& data, FX_DWORD& size) 442 void _FPDFAPI_GetInternalFontData(int id, FX_LPCBYTE& data, FX_DWORD& size) {
442 { 443 CFX_GEModule::Get()->GetFontMgr()->GetStandardFont(data, size, id);
443 CFX_GEModule::Get()->GetFontMgr()->GetStandardFont(data, size, id); 444 }
444 } 445 FX_BOOL CFX_FontMgr::GetStandardFont(FX_LPCBYTE& pFontData,
445 FX_BOOL CFX_FontMgr::GetStandardFont(FX_LPCBYTE& pFontData, FX_DWORD& size, int index) 446 FX_DWORD& size,
446 { 447 int index) {
447 if (index > 15 || index < 0) { 448 if (index > 15 || index < 0) {
448 return FALSE; 449 return FALSE;
449 } 450 }
450 { 451 {
451 if (index >= 14) { 452 if (index >= 14) {
452 if (index == 14) { 453 if (index == 14) {
453 pFontData = g_FoxitSerifMMFontData; 454 pFontData = g_FoxitSerifMMFontData;
454 size = 113417; 455 size = 113417;
455 } else { 456 } else {
456 pFontData = g_FoxitSansMMFontData; 457 pFontData = g_FoxitSansMMFontData;
457 size = 66919; 458 size = 66919;
458 } 459 }
459 } else { 460 } else {
460 pFontData = g_FoxitFonts[index].m_pFontData; 461 pFontData = g_FoxitFonts[index].m_pFontData;
461 size = g_FoxitFonts[index].m_dwSize; 462 size = g_FoxitFonts[index].m_dwSize;
462 } 463 }
463 } 464 }
464 return TRUE; 465 return TRUE;
465 } 466 }
466 CFX_FontMapper::CFX_FontMapper() 467 CFX_FontMapper::CFX_FontMapper() {
467 { 468 FXSYS_memset32(m_FoxitFaces, 0, sizeof m_FoxitFaces);
468 FXSYS_memset32(m_FoxitFaces, 0, sizeof m_FoxitFaces); 469 m_MMFaces[0] = m_MMFaces[1] = NULL;
469 m_MMFaces[0] = m_MMFaces[1] = NULL; 470 m_pFontInfo = NULL;
470 m_pFontInfo = NULL; 471 m_bListLoaded = FALSE;
471 m_bListLoaded = FALSE; 472 m_pFontEnumerator = NULL;
472 m_pFontEnumerator = NULL; 473 }
473 } 474 CFX_FontMapper::~CFX_FontMapper() {
474 CFX_FontMapper::~CFX_FontMapper() 475 for (int i = 0; i < 14; i++)
475 { 476 if (m_FoxitFaces[i]) {
476 for (int i = 0; i < 14; i ++) 477 FXFT_Done_Face(m_FoxitFaces[i]);
477 if (m_FoxitFaces[i]) { 478 }
478 FXFT_Done_Face(m_FoxitFaces[i]); 479 if (m_MMFaces[0]) {
479 } 480 FXFT_Done_Face(m_MMFaces[0]);
480 if (m_MMFaces[0]) { 481 }
481 FXFT_Done_Face(m_MMFaces[0]); 482 if (m_MMFaces[1]) {
482 } 483 FXFT_Done_Face(m_MMFaces[1]);
483 if (m_MMFaces[1]) { 484 }
484 FXFT_Done_Face(m_MMFaces[1]); 485 if (m_pFontInfo) {
485 } 486 m_pFontInfo->Release();
486 if (m_pFontInfo) { 487 }
487 m_pFontInfo->Release(); 488 }
488 } 489 void CFX_FontMapper::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) {
489 } 490 if (pFontInfo == NULL) {
490 void CFX_FontMapper::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) 491 return;
491 { 492 }
492 if (pFontInfo == NULL) { 493 if (m_pFontInfo) {
494 m_pFontInfo->Release();
495 }
496 m_pFontInfo = pFontInfo;
497 }
498 static CFX_ByteString _TT_NormalizeName(FX_LPCSTR family) {
499 CFX_ByteString norm(family, -1);
500 norm.Remove(' ');
501 norm.Remove('-');
502 norm.Remove(',');
503 int pos = norm.Find('+');
504 if (pos > 0) {
505 norm = norm.Left(pos);
506 }
507 norm.MakeLower();
508 return norm;
509 }
510 CFX_ByteString _FPDF_GetNameFromTT(FX_LPCBYTE name_table, FX_DWORD name_id) {
511 FX_LPCBYTE ptr = name_table + 2;
512 int name_count = GET_TT_SHORT(ptr);
513 int string_offset = GET_TT_SHORT(ptr + 2);
514 FX_LPCBYTE string_ptr = name_table + string_offset;
515 ptr += 4;
516 for (int i = 0; i < name_count; i++) {
517 if (GET_TT_SHORT(ptr + 6) == name_id && GET_TT_SHORT(ptr) == 1 &&
518 GET_TT_SHORT(ptr + 2) == 0) {
519 return CFX_ByteStringC(string_ptr + GET_TT_SHORT(ptr + 10),
520 GET_TT_SHORT(ptr + 8));
521 }
522 ptr += 12;
523 }
524 return CFX_ByteString();
525 }
526 static CFX_ByteString _FPDF_ReadStringFromFile(FXSYS_FILE* pFile,
527 FX_DWORD size) {
528 CFX_ByteString buffer;
529 if (!FXSYS_fread(buffer.GetBuffer(size), size, 1, pFile)) {
530 return CFX_ByteString();
531 }
532 buffer.ReleaseBuffer(size);
533 return buffer;
534 }
535 CFX_ByteString _FPDF_LoadTableFromTT(FXSYS_FILE* pFile,
536 FX_LPCBYTE pTables,
537 FX_DWORD nTables,
538 FX_DWORD tag) {
539 for (FX_DWORD i = 0; i < nTables; i++) {
540 FX_LPCBYTE p = pTables + i * 16;
541 if (GET_TT_LONG(p) == tag) {
542 FX_DWORD offset = GET_TT_LONG(p + 8);
543 FX_DWORD size = GET_TT_LONG(p + 12);
544 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
545 return _FPDF_ReadStringFromFile(pFile, size);
546 }
547 }
548 return CFX_ByteString();
549 }
550 CFX_ByteString _FPDF_LoadTableFromTTStreamFile(IFX_FileStream* pFile,
551 FX_LPCBYTE pTables,
552 FX_DWORD nTables,
553 FX_DWORD tag) {
554 for (FX_DWORD i = 0; i < nTables; i++) {
555 FX_LPCBYTE p = pTables + i * 16;
556 if (GET_TT_LONG(p) == tag) {
557 FX_DWORD offset = GET_TT_LONG(p + 8);
558 FX_DWORD size = GET_TT_LONG(p + 12);
559 CFX_ByteString buffer;
560 if (!pFile->ReadBlock(buffer.GetBuffer(size), offset, size)) {
561 return CFX_ByteString();
562 }
563 buffer.ReleaseBuffer(size);
564 return buffer;
565 }
566 }
567 return CFX_ByteString();
568 }
569 CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) {
570 if (m_pFontInfo == NULL) {
571 CFX_ByteString();
572 }
573 CFX_ByteString result;
574 FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0);
575 if (size) {
576 FX_LPBYTE buffer = FX_Alloc(FX_BYTE, size);
577 if (!buffer) {
578 return result;
579 }
580 m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size);
581 result = _FPDF_GetNameFromTT(buffer, 6);
582 FX_Free(buffer);
583 }
584 return result;
585 }
586 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) {
587 if (m_pFontInfo == NULL) {
588 return;
589 }
590 if (m_CharsetArray.Find((FX_DWORD)charset) == -1) {
591 m_CharsetArray.Add((FX_DWORD)charset);
592 m_FaceArray.Add(name);
593 }
594 if (name == m_LastFamily) {
595 return;
596 }
597 FX_LPCBYTE ptr = name;
598 FX_BOOL bLocalized = FALSE;
599 for (int i = 0; i < name.GetLength(); i++)
600 if (ptr[i] > 0x80) {
601 bLocalized = TRUE;
602 break;
603 }
604 if (bLocalized) {
605 void* hFont = m_pFontInfo->GetFont(name);
606 if (hFont == NULL) {
607 FX_BOOL bExact;
608 hFont =
609 m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, name, bExact);
610 if (hFont == NULL) {
493 return; 611 return;
494 } 612 }
495 if (m_pFontInfo) { 613 }
496 m_pFontInfo->Release(); 614 CFX_ByteString new_name = GetPSNameFromTT(hFont);
497 } 615 if (!new_name.IsEmpty()) {
498 m_pFontInfo = pFontInfo; 616 new_name.Insert(0, ' ');
499 } 617 m_InstalledTTFonts.Add(new_name);
500 static CFX_ByteString _TT_NormalizeName(FX_LPCSTR family) 618 }
501 { 619 m_pFontInfo->DeleteFont(hFont);
502 CFX_ByteString norm(family, -1); 620 }
503 norm.Remove(' '); 621 m_InstalledTTFonts.Add(name);
504 norm.Remove('-'); 622 m_LastFamily = name;
505 norm.Remove(','); 623 }
506 int pos = norm.Find('+'); 624 void CFX_FontMapper::LoadInstalledFonts() {
507 if (pos > 0) { 625 if (m_pFontInfo == NULL) {
508 norm = norm.Left(pos); 626 return;
509 } 627 }
510 norm.MakeLower(); 628 if (m_bListLoaded) {
511 return norm; 629 return;
512 } 630 }
513 CFX_ByteString _FPDF_GetNameFromTT(FX_LPCBYTE name_table, FX_DWORD name_id) 631 if (m_bListLoaded) {
514 { 632 return;
515 FX_LPCBYTE ptr = name_table + 2; 633 }
516 int name_count = GET_TT_SHORT(ptr); 634 m_pFontInfo->EnumFontList(this);
517 int string_offset = GET_TT_SHORT(ptr + 2); 635 m_bListLoaded = TRUE;
518 FX_LPCBYTE string_ptr = name_table + string_offset; 636 }
519 ptr += 4; 637 CFX_ByteString CFX_FontMapper::MatchInstalledFonts(
520 for (int i = 0; i < name_count; i ++) { 638 const CFX_ByteString& norm_name) {
521 if (GET_TT_SHORT(ptr + 6) == name_id && GET_TT_SHORT(ptr) == 1 && GET_TT _SHORT(ptr + 2) == 0) { 639 LoadInstalledFonts();
522 return CFX_ByteStringC(string_ptr + GET_TT_SHORT(ptr + 10), GET_TT_S HORT(ptr + 8)); 640 int i;
523 } 641 for (i = m_InstalledTTFonts.GetSize() - 1; i >= 0; i--) {
524 ptr += 12; 642 CFX_ByteString norm1 = _TT_NormalizeName(m_InstalledTTFonts[i]);
525 } 643 if (norm1 == norm_name) {
644 break;
645 }
646 }
647 if (i < 0) {
526 return CFX_ByteString(); 648 return CFX_ByteString();
527 } 649 }
528 static CFX_ByteString _FPDF_ReadStringFromFile(FXSYS_FILE* pFile, FX_DWORD size) 650 CFX_ByteString match = m_InstalledTTFonts[i];
529 { 651 if (match[0] == ' ') {
530 CFX_ByteString buffer; 652 match = m_InstalledTTFonts[i + 1];
531 if (!FXSYS_fread(buffer.GetBuffer(size), size, 1, pFile)) { 653 }
532 return CFX_ByteString(); 654 return match;
533 }
534 buffer.ReleaseBuffer(size);
535 return buffer;
536 }
537 CFX_ByteString _FPDF_LoadTableFromTT(FXSYS_FILE* pFile, FX_LPCBYTE pTables, FX_D WORD nTables, FX_DWORD tag)
538 {
539 for (FX_DWORD i = 0; i < nTables; i ++) {
540 FX_LPCBYTE p = pTables + i * 16;
541 if (GET_TT_LONG(p) == tag) {
542 FX_DWORD offset = GET_TT_LONG(p + 8);
543 FX_DWORD size = GET_TT_LONG(p + 12);
544 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
545 return _FPDF_ReadStringFromFile(pFile, size);
546 }
547 }
548 return CFX_ByteString();
549 }
550 CFX_ByteString _FPDF_LoadTableFromTTStreamFile(IFX_FileStream* pFile, FX_LPCBYTE pTables, FX_DWORD nTables, FX_DWORD tag)
551 {
552 for (FX_DWORD i = 0; i < nTables; i ++) {
553 FX_LPCBYTE p = pTables + i * 16;
554 if (GET_TT_LONG(p) == tag) {
555 FX_DWORD offset = GET_TT_LONG(p + 8);
556 FX_DWORD size = GET_TT_LONG(p + 12);
557 CFX_ByteString buffer;
558 if (!pFile->ReadBlock(buffer.GetBuffer(size), offset, size)) {
559 return CFX_ByteString();
560 }
561 buffer.ReleaseBuffer(size);
562 return buffer;
563 }
564 }
565 return CFX_ByteString();
566 }
567 CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont)
568 {
569 if (m_pFontInfo == NULL) {
570 CFX_ByteString();
571 }
572 CFX_ByteString result;
573 FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0);
574 if (size) {
575 FX_LPBYTE buffer = FX_Alloc(FX_BYTE, size);
576 if (!buffer) {
577 return result;
578 }
579 m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size);
580 result = _FPDF_GetNameFromTT(buffer, 6);
581 FX_Free(buffer);
582 }
583 return result;
584 }
585 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset)
586 {
587 if (m_pFontInfo == NULL) {
588 return;
589 }
590 if (m_CharsetArray.Find((FX_DWORD)charset) == -1) {
591 m_CharsetArray.Add((FX_DWORD)charset);
592 m_FaceArray.Add(name);
593 }
594 if (name == m_LastFamily) {
595 return;
596 }
597 FX_LPCBYTE ptr = name;
598 FX_BOOL bLocalized = FALSE;
599 for (int i = 0; i < name.GetLength(); i ++)
600 if (ptr[i] > 0x80) {
601 bLocalized = TRUE;
602 break;
603 }
604 if (bLocalized) {
605 void* hFont = m_pFontInfo->GetFont(name);
606 if (hFont == NULL) {
607 FX_BOOL bExact;
608 hFont = m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, name, bExact);
609 if (hFont == NULL) {
610 return;
611 }
612 }
613 CFX_ByteString new_name = GetPSNameFromTT(hFont);
614 if (!new_name.IsEmpty()) {
615 new_name.Insert(0, ' ');
616 m_InstalledTTFonts.Add(new_name);
617 }
618 m_pFontInfo->DeleteFont(hFont);
619 }
620 m_InstalledTTFonts.Add(name);
621 m_LastFamily = name;
622 }
623 void CFX_FontMapper::LoadInstalledFonts()
624 {
625 if (m_pFontInfo == NULL) {
626 return;
627 }
628 if (m_bListLoaded) {
629 return;
630 }
631 if (m_bListLoaded) {
632 return;
633 }
634 m_pFontInfo->EnumFontList(this);
635 m_bListLoaded = TRUE;
636 }
637 CFX_ByteString CFX_FontMapper::MatchInstalledFonts(const CFX_ByteString& norm_na me)
638 {
639 LoadInstalledFonts();
640 int i;
641 for (i = m_InstalledTTFonts.GetSize() - 1; i >= 0; i --) {
642 CFX_ByteString norm1 = _TT_NormalizeName(m_InstalledTTFonts[i]);
643 if (norm1 == norm_name) {
644 break;
645 }
646 }
647 if (i < 0) {
648 return CFX_ByteString();
649 }
650 CFX_ByteString match = m_InstalledTTFonts[i];
651 if (match[0] == ' ') {
652 match = m_InstalledTTFonts[i + 1];
653 }
654 return match;
655 } 655 }
656 typedef struct _CHARSET_MAP_ { 656 typedef struct _CHARSET_MAP_ {
657 FX_BYTE charset; 657 FX_BYTE charset;
658 FX_WORD codepage; 658 FX_WORD codepage;
659 } CHARSET_MAP; 659 } CHARSET_MAP;
660 static const CHARSET_MAP g_Codepage2CharsetTable[] = { 660 static const CHARSET_MAP g_Codepage2CharsetTable[] = {
661 { 1» , 0» }, 661 { 1, 0 },
662 { 2» , 42» }, 662 { 2, 42 },
663 { 254, 437» }, 663 { 254, 437 },
664 { 255, 850» }, 664 { 255, 850 },
665 { 222, 874» }, 665 { 222, 874 },
666 { 128, 932» }, 666 { 128, 932 },
667 { 134, 936» }, 667 { 134, 936 },
668 { 129, 949» }, 668 { 129, 949 },
669 { 136, 950» }, 669 { 136, 950 },
670 { 238, 1250»}, 670 { 238, 1250 },
671 { 204, 1251»}, 671 { 204, 1251 },
672 { 0, 1252»}, 672 { 0, 1252 },
673 { 161, 1253»}, 673 { 161, 1253 },
674 { 162, 1254»}, 674 { 162, 1254 },
675 { 177, 1255»}, 675 { 177, 1255 },
676 { 178, 1256»}, 676 { 178, 1256 },
677 { 186, 1257»}, 677 { 186, 1257 },
678 { 163, 1258 }, 678 { 163, 1258 },
679 { 130, 1361 }, 679 { 130, 1361 },
680 { 77, 10000 }, 680 { 77, 10000 },
681 { 78, 10001 }, 681 { 78, 10001 },
682 { 79, 10003 }, 682 { 79, 10003 },
683 { 80, 10008 }, 683 { 80, 10008 },
684 { 81, 10002 }, 684 { 81, 10002 },
685 { 83, 10005 }, 685 { 83, 10005 },
686 { 84, 10004 }, 686 { 84, 10004 },
687 { 85, 10006 }, 687 { 85, 10006 },
688 { 86, 10081 }, 688 { 86, 10081 },
689 { 87, 10021 }, 689 { 87, 10021 },
690 { 88, 10029 }, 690 { 88, 10029 },
691 { 89, 10007 }, 691 { 89, 10007 },
692 }; 692 };
693 FX_BYTE _GetCharsetFromCodePage(FX_WORD codepage) 693 FX_BYTE _GetCharsetFromCodePage(FX_WORD codepage) {
694 { 694 FX_INT32 iEnd = sizeof(g_Codepage2CharsetTable) / sizeof(CHARSET_MAP) - 1;
695 FX_INT32 iEnd = sizeof(g_Codepage2CharsetTable) / sizeof(CHARSET_MAP) - 1; 695 FXSYS_assert(iEnd >= 0);
696 FXSYS_assert(iEnd >= 0); 696 FX_INT32 iStart = 0, iMid;
697 FX_INT32 iStart = 0, iMid; 697 do {
698 do { 698 iMid = (iStart + iEnd) / 2;
699 iMid = (iStart + iEnd) / 2; 699 const CHARSET_MAP& cp = g_Codepage2CharsetTable[iMid];
700 const CHARSET_MAP & cp = g_Codepage2CharsetTable[iMid]; 700 if (codepage == cp.codepage) {
701 if (codepage == cp.codepage) { 701 return cp.charset;
702 return cp.charset; 702 } else if (codepage < cp.codepage) {
703 } else if (codepage < cp.codepage) { 703 iEnd = iMid - 1;
704 iEnd = iMid - 1; 704 } else {
705 } else { 705 iStart = iMid + 1;
706 iStart = iMid + 1; 706 }
707 } 707 } while (iStart <= iEnd);
708 } while (iStart <= iEnd); 708 return 1;
709 return 1; 709 }
710 } 710 FX_DWORD _GetCodePageRangeFromCharset(int charset) {
711 FX_DWORD _GetCodePageRangeFromCharset(int charset) 711 if (charset == FXFONT_EASTEUROPE_CHARSET) {
712 { 712 return 1 << 1;
713 if (charset == FXFONT_EASTEUROPE_CHARSET) { 713 }
714 return 1 << 1; 714 if (charset == FXFONT_GREEK_CHARSET) {
715 } 715 return 1 << 3;
716 if (charset == FXFONT_GREEK_CHARSET) { 716 }
717 return 1 << 3; 717 if (charset == FXFONT_TURKISH_CHARSET) {
718 } 718 return 1 << 4;
719 if (charset == FXFONT_TURKISH_CHARSET) { 719 }
720 return 1 << 4; 720 if (charset == FXFONT_HEBREW_CHARSET) {
721 } 721 return 1 << 5;
722 if (charset == FXFONT_HEBREW_CHARSET) { 722 }
723 return 1 << 5; 723 if (charset == FXFONT_ARABIC_CHARSET) {
724 } 724 return 1 << 6;
725 if (charset == FXFONT_ARABIC_CHARSET) { 725 }
726 return 1 << 6; 726 if (charset == FXFONT_BALTIC_CHARSET) {
727 } 727 return 1 << 7;
728 if (charset == FXFONT_BALTIC_CHARSET) { 728 }
729 return 1 << 7; 729 if (charset == FXFONT_THAI_CHARSET) {
730 } 730 return 1 << 16;
731 if (charset == FXFONT_THAI_CHARSET) { 731 }
732 return 1 << 16; 732 if (charset == FXFONT_SHIFTJIS_CHARSET) {
733 } 733 return 1 << 17;
734 if (charset == FXFONT_SHIFTJIS_CHARSET) { 734 }
735 return 1 << 17; 735 if (charset == FXFONT_GB2312_CHARSET) {
736 } 736 return 1 << 18;
737 if (charset == FXFONT_GB2312_CHARSET) { 737 }
738 return 1 << 18; 738 if (charset == FXFONT_CHINESEBIG5_CHARSET) {
739 } 739 return 1 << 20;
740 if (charset == FXFONT_CHINESEBIG5_CHARSET) { 740 }
741 return 1 << 20; 741 if (charset == FXFONT_HANGEUL_CHARSET) {
742 } 742 return 1 << 19;
743 if (charset == FXFONT_HANGEUL_CHARSET) { 743 }
744 return 1 << 19; 744 if (charset == FXFONT_SYMBOL_CHARSET) {
745 } 745 return 1 << 31;
746 if (charset == FXFONT_SYMBOL_CHARSET) { 746 }
747 return 1 << 31; 747 return 1 << 21;
748 } 748 }
749 return 1 << 21; 749 static int CP2CharSet(int cp) {
750 } 750 if (cp == 932) {
751 static int CP2CharSet(int cp) 751 return FXFONT_SHIFTJIS_CHARSET;
752 { 752 } else if (cp == 936) {
753 if(cp == 932) { 753 return FXFONT_GB2312_CHARSET;
754 return FXFONT_SHIFTJIS_CHARSET; 754 } else if (cp == 949) {
755 } else if(cp == 936) { 755 return FXFONT_HANGEUL_CHARSET;
756 return FXFONT_GB2312_CHARSET; 756 } else if (cp == 950) {
757 } else if(cp == 949) { 757 return FXFONT_CHINESEBIG5_CHARSET;
758 return FXFONT_HANGEUL_CHARSET; 758 }
759 } else if(cp == 950) { 759 return FXFONT_DEFAULT_CHARSET;
760 return FXFONT_CHINESEBIG5_CHARSET; 760 }
761 } 761 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont,
762 return FXFONT_DEFAULT_CHARSET; 762 int iBaseFont,
763 } 763 int italic_angle,
764 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, int iBaseF ont, int italic_angle, int weight, int picthfamily) 764 int weight,
765 { 765 int picthfamily) {
766 if (iBaseFont < 12) { 766 if (iBaseFont < 12) {
767 if (m_FoxitFaces[iBaseFont]) { 767 if (m_FoxitFaces[iBaseFont]) {
768 return m_FoxitFaces[iBaseFont]; 768 return m_FoxitFaces[iBaseFont];
769 }
770 FX_LPCBYTE pFontData = NULL;
771 FX_DWORD size = 0;
772 if (m_pFontMgr->GetStandardFont(pFontData, size, iBaseFont)) {
773 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
774 return m_FoxitFaces[iBaseFont];
775 }
776 }
777 pSubstFont->m_SubstFlags |= FXFONT_SUBST_MM;
778 pSubstFont->m_ItalicAngle = italic_angle;
779 if (weight) {
780 pSubstFont->m_Weight = weight;
781 }
782 if (picthfamily & FXFONT_FF_ROMAN) {
783 pSubstFont->m_Weight = pSubstFont->m_Weight * 4 / 5;
784 pSubstFont->m_Family = "Chrome Serif";
785 if (m_MMFaces[1]) {
786 return m_MMFaces[1];
787 }
788 FX_LPCBYTE pFontData = NULL;
789 FX_DWORD size;
790 m_pFontMgr->GetStandardFont(pFontData, size, 14);
791 m_MMFaces[1] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
792 return m_MMFaces[1];
793 }
794 pSubstFont->m_Family = "Chrome Sans";
795 if (m_MMFaces[0]) {
796 return m_MMFaces[0];
797 } 769 }
798 FX_LPCBYTE pFontData = NULL; 770 FX_LPCBYTE pFontData = NULL;
799 FX_DWORD size = 0; 771 FX_DWORD size = 0;
800 m_pFontMgr->GetStandardFont(pFontData, size, 15); 772 if (m_pFontMgr->GetStandardFont(pFontData, size, iBaseFont)) {
801 m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0); 773 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
774 return m_FoxitFaces[iBaseFont];
775 }
776 }
777 pSubstFont->m_SubstFlags |= FXFONT_SUBST_MM;
778 pSubstFont->m_ItalicAngle = italic_angle;
779 if (weight) {
780 pSubstFont->m_Weight = weight;
781 }
782 if (picthfamily & FXFONT_FF_ROMAN) {
783 pSubstFont->m_Weight = pSubstFont->m_Weight * 4 / 5;
784 pSubstFont->m_Family = "Chrome Serif";
785 if (m_MMFaces[1]) {
786 return m_MMFaces[1];
787 }
788 FX_LPCBYTE pFontData = NULL;
789 FX_DWORD size;
790 m_pFontMgr->GetStandardFont(pFontData, size, 14);
791 m_MMFaces[1] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
792 return m_MMFaces[1];
793 }
794 pSubstFont->m_Family = "Chrome Sans";
795 if (m_MMFaces[0]) {
802 return m_MMFaces[0]; 796 return m_MMFaces[0];
797 }
798 FX_LPCBYTE pFontData = NULL;
799 FX_DWORD size = 0;
800 m_pFontMgr->GetStandardFont(pFontData, size, 15);
801 m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
802 return m_MMFaces[0];
803 } 803 }
804 const struct _AltFontFamily { 804 const struct _AltFontFamily {
805 FX_LPCSTR m_pFontName; 805 FX_LPCSTR m_pFontName;
806 FX_LPCSTR m_pFontFamily; 806 FX_LPCSTR m_pFontFamily;
807 } 807 } g_AltFontFamilies[] = {
808 g_AltFontFamilies[] = { 808 { "AGaramondPro", "Adobe Garamond Pro" },
809 {"AGaramondPro", "Adobe Garamond Pro"}, 809 { "BankGothicBT-Medium", "BankGothic Md BT" },
810 {"BankGothicBT-Medium", "BankGothic Md BT"}, 810 { "ForteMT", "Forte" },
811 {"ForteMT", "Forte"}, 811 };
812 };
813 extern "C" { 812 extern "C" {
814 static int compareFontFamilyString(const void* key, const void* element) 813 static int compareFontFamilyString(const void* key, const void* element) {
815 { 814 CFX_ByteString str_key((FX_LPCSTR)key);
816 CFX_ByteString str_key((FX_LPCSTR)key); 815 if (str_key.Find(((_AltFontFamily*)element)->m_pFontName) != -1) {
817 if (str_key.Find(((_AltFontFamily*)element)->m_pFontName) != -1) { 816 return 0;
818 return 0; 817 }
819 } 818 return FXSYS_stricmp((FX_LPCSTR)key, ((_AltFontFamily*)element)->m_pFontName);
820 return FXSYS_stricmp((FX_LPCSTR)key, ((_AltFontFamily*)element)->m_pFont Name); 819 }
821 } 820 }
822 } 821 #define FX_FONT_STYLE_None 0x00
823 #define FX_FONT_STYLE_None» » 0x00 822 #define FX_FONT_STYLE_Bold 0x01
824 #define FX_FONT_STYLE_Bold» » 0x01 823 #define FX_FONT_STYLE_Italic 0x02
825 #define FX_FONT_STYLE_Italic» 0x02 824 #define FX_FONT_STYLE_BoldBold 0x04
826 #define FX_FONT_STYLE_BoldBold» 0x04 825 static CFX_ByteString _GetFontFamily(CFX_ByteString fontName, int nStyle) {
827 static CFX_ByteString _GetFontFamily(CFX_ByteString fontName, int nStyle) 826 if (fontName.Find("Script") >= 0) {
828 { 827 if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold) {
829 if (fontName.Find("Script") >= 0) { 828 fontName = "ScriptMTBold";
830 if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold) { 829 } else if (fontName.Find("Palace") >= 0) {
831 fontName = "ScriptMTBold"; 830 fontName = "PalaceScriptMT";
832 } else if (fontName.Find("Palace") >= 0) { 831 } else if (fontName.Find("French") >= 0) {
833 fontName = "PalaceScriptMT"; 832 fontName = "FrenchScriptMT";
834 } else if (fontName.Find("French") >= 0) { 833 } else if (fontName.Find("FreeStyle") >= 0) {
835 fontName = "FrenchScriptMT"; 834 fontName = "FreeStyleScript";
836 } else if (fontName.Find("FreeStyle") >= 0) { 835 }
837 fontName = "FreeStyleScript"; 836 return fontName;
838 } 837 }
839 return fontName; 838 _AltFontFamily* found = (_AltFontFamily*)FXSYS_bsearch(
840 } 839 (FX_LPCSTR)fontName,
841 _AltFontFamily* found = (_AltFontFamily*)FXSYS_bsearch((FX_LPCSTR)fontName, g_AltFontFamilies, 840 g_AltFontFamilies,
842 sizeof g_AltFontFamilies / sizeof (_AltFontFamily), sizeof (_AltFontFamily), compareFontFamilyString); 841 sizeof g_AltFontFamilies / sizeof(_AltFontFamily),
843 if (found == NULL) { 842 sizeof(_AltFontFamily),
844 return fontName; 843 compareFontFamilyString);
845 } 844 if (found == NULL) {
846 return found->m_pFontFamily; 845 return fontName;
846 }
847 return found->m_pFontFamily;
847 }; 848 };
848 typedef struct _FX_FontStyle { 849 typedef struct _FX_FontStyle {
849 FX_LPCSTR style; 850 FX_LPCSTR style;
850 FX_INT32 len; 851 FX_INT32 len;
851 } FX_FontStyle; 852 } FX_FontStyle;
852 const FX_FontStyle g_FontStyles[] = { 853 const FX_FontStyle g_FontStyles[] = {
853 { "Bold", 4 }, 854 { "Bold", 4 },
854 { "Italic", 6 }, 855 { "Italic", 6 },
855 { "BoldItalic", 10 }, 856 { "BoldItalic", 10 },
856 { "Reg", 3 }, 857 { "Reg", 3 },
857 { "Regular", 7 }, 858 { "Regular", 7 },
858 }; 859 };
859 CFX_ByteString ParseStyle(FX_LPCSTR pStyle, int iLen, int iIndex) 860 CFX_ByteString ParseStyle(FX_LPCSTR pStyle, int iLen, int iIndex) {
860 { 861 CFX_ByteTextBuf buf;
861 CFX_ByteTextBuf buf; 862 if (!iLen || iLen <= iIndex) {
862 if (!iLen || iLen <= iIndex) {
863 return buf.GetByteString();
864 }
865 while (iIndex < iLen) {
866 if (pStyle[iIndex] == ',') {
867 break;
868 }
869 buf.AppendChar(pStyle[iIndex]);
870 ++iIndex;
871 }
872 return buf.GetByteString(); 863 return buf.GetByteString();
873 } 864 }
874 FX_INT32 GetStyleType(const CFX_ByteString &bsStyle, FX_BOOL bRevert) 865 while (iIndex < iLen) {
875 { 866 if (pStyle[iIndex] == ',') {
876 FX_INT32 iLen = bsStyle.GetLength(); 867 break;
877 if (!iLen) { 868 }
878 return -1; 869 buf.AppendChar(pStyle[iIndex]);
879 } 870 ++iIndex;
880 int iSize = sizeof(g_FontStyles) / sizeof(FX_FontStyle); 871 }
881 const FX_FontStyle *pStyle = NULL; 872 return buf.GetByteString();
882 for (int i = iSize - 1; i >= 0; --i) { 873 }
883 pStyle = g_FontStyles + i; 874 FX_INT32 GetStyleType(const CFX_ByteString& bsStyle, FX_BOOL bRevert) {
884 if (!pStyle || pStyle->len > iLen) { 875 FX_INT32 iLen = bsStyle.GetLength();
885 continue; 876 if (!iLen) {
886 } 877 return -1;
887 if (!bRevert) { 878 }
888 if (bsStyle.Left(pStyle->len).Compare(pStyle->style) == 0) { 879 int iSize = sizeof(g_FontStyles) / sizeof(FX_FontStyle);
889 return i; 880 const FX_FontStyle* pStyle = NULL;
890 } 881 for (int i = iSize - 1; i >= 0; --i) {
882 pStyle = g_FontStyles + i;
883 if (!pStyle || pStyle->len > iLen) {
884 continue;
885 }
886 if (!bRevert) {
887 if (bsStyle.Left(pStyle->len).Compare(pStyle->style) == 0) {
888 return i;
889 }
890 } else {
891 if (bsStyle.Right(pStyle->len).Compare(pStyle->style) == 0) {
892 return i;
893 }
894 }
895 }
896 return -1;
897 }
898 FX_BOOL CheckSupportThirdPartFont(CFX_ByteString name, int& PitchFamily) {
899 if (name == FX_BSTRC("MyriadPro")) {
900 PitchFamily &= ~FXFONT_FF_ROMAN;
901 return TRUE;
902 }
903 return FALSE;
904 }
905 FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
906 FX_BOOL bTrueType,
907 FX_DWORD flags,
908 int weight,
909 int italic_angle,
910 int WindowCP,
911 CFX_SubstFont* pSubstFont) {
912 if (!(flags & FXFONT_USEEXTERNATTR)) {
913 weight = FXFONT_FW_NORMAL;
914 italic_angle = 0;
915 }
916 CFX_ByteString SubstName = name;
917 SubstName.Remove(0x20);
918 if (bTrueType) {
919 if (name[0] == '@') {
920 SubstName = name.Mid(1);
921 }
922 }
923 _PDF_GetStandardFontName(SubstName);
924 if (SubstName == FX_BSTRC("Symbol") && !bTrueType) {
925 pSubstFont->m_Family = "Chrome Symbol";
926 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET;
927 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
928 if (m_FoxitFaces[12]) {
929 return m_FoxitFaces[12];
930 }
931 FX_LPCBYTE pFontData = NULL;
932 FX_DWORD size = 0;
933 m_pFontMgr->GetStandardFont(pFontData, size, 12);
934 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
935 return m_FoxitFaces[12];
936 }
937 if (SubstName == FX_BSTRC("ZapfDingbats")) {
938 pSubstFont->m_Family = "Chrome Dingbats";
939 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET;
940 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
941 if (m_FoxitFaces[13]) {
942 return m_FoxitFaces[13];
943 }
944 FX_LPCBYTE pFontData = NULL;
945 FX_DWORD size = 0;
946 m_pFontMgr->GetStandardFont(pFontData, size, 13);
947 m_FoxitFaces[13] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
948 return m_FoxitFaces[13];
949 }
950 int iBaseFont = 0;
951 CFX_ByteString family, style;
952 FX_BOOL bHasComma = FALSE;
953 FX_BOOL bHasHypen = FALSE;
954 int find = SubstName.Find(FX_BSTRC(","), 0);
955 if (find >= 0) {
956 family = SubstName.Left(find);
957 _PDF_GetStandardFontName(family);
958 style = SubstName.Mid(find + 1);
959 bHasComma = TRUE;
960 } else {
961 family = SubstName;
962 }
963 for (; iBaseFont < 12; iBaseFont++)
964 if (family == CFX_ByteStringC(g_Base14FontNames[iBaseFont])) {
965 break;
966 }
967 int PitchFamily = 0;
968 FX_BOOL bItalic = FALSE;
969 FX_DWORD nStyle = 0;
970 FX_BOOL bStyleAvail = FALSE;
971 if (iBaseFont < 12) {
972 family = g_Base14FontNames[iBaseFont];
973 if ((iBaseFont % 4) == 1 || (iBaseFont % 4) == 2) {
974 nStyle |= FX_FONT_STYLE_Bold;
975 }
976 if ((iBaseFont % 4) / 2) {
977 nStyle |= FX_FONT_STYLE_Italic;
978 }
979 if (iBaseFont < 4) {
980 PitchFamily |= FXFONT_FF_FIXEDPITCH;
981 }
982 if (iBaseFont >= 8) {
983 PitchFamily |= FXFONT_FF_ROMAN;
984 }
985 } else {
986 if (!bHasComma) {
987 find = family.ReverseFind('-');
988 if (find >= 0) {
989 style = family.Mid(find + 1);
990 family = family.Left(find);
991 bHasHypen = TRUE;
992 }
993 }
994 if (!bHasHypen) {
995 int nLen = family.GetLength();
996 FX_INT32 nRet = GetStyleType(family, TRUE);
997 if (nRet > -1) {
998 family = family.Left(nLen - g_FontStyles[nRet].len);
999 if (nRet == 0) {
1000 nStyle |= FX_FONT_STYLE_Bold;
1001 }
1002 if (nRet == 1) {
1003 nStyle |= FX_FONT_STYLE_Italic;
1004 }
1005 if (nRet == 2) {
1006 nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic);
1007 }
1008 }
1009 }
1010 if (flags & FXFONT_SERIF) {
1011 PitchFamily |= FXFONT_FF_ROMAN;
1012 }
1013 if (flags & FXFONT_SCRIPT) {
1014 PitchFamily |= FXFONT_FF_SCRIPT;
1015 }
1016 if (flags & FXFONT_FIXED_PITCH) {
1017 PitchFamily |= FXFONT_FF_FIXEDPITCH;
1018 }
1019 }
1020 if (!style.IsEmpty()) {
1021 int nLen = style.GetLength();
1022 FX_LPCSTR pStyle = style;
1023 int i = 0;
1024 FX_BOOL bFirstItem = TRUE;
1025 CFX_ByteString buf;
1026 while (i < nLen) {
1027 buf = ParseStyle(pStyle, nLen, i);
1028 FX_INT32 nRet = GetStyleType(buf, FALSE);
1029 if ((i && !bStyleAvail) || (!i && nRet < 0)) {
1030 family = SubstName;
1031 iBaseFont = 12;
1032 break;
1033 } else if (nRet >= 0) {
1034 bStyleAvail = TRUE;
1035 }
1036 if (nRet == 0) {
1037 if (nStyle & FX_FONT_STYLE_Bold) {
1038 nStyle |= FX_FONT_STYLE_BoldBold;
891 } else { 1039 } else {
892 if (bsStyle.Right(pStyle->len).Compare(pStyle->style) == 0) { 1040 nStyle |= FX_FONT_STYLE_Bold;
893 return i; 1041 }
894 } 1042 bFirstItem = FALSE;
895 } 1043 }
896 } 1044 if (nRet == 1) {
897 return -1; 1045 if (bFirstItem) {
898 } 1046 nStyle |= FX_FONT_STYLE_Italic;
899 FX_BOOL CheckSupportThirdPartFont(CFX_ByteString name, int &PitchFamily) 1047 } else {
900 { 1048 family = SubstName;
901 if (name == FX_BSTRC("MyriadPro")) { 1049 iBaseFont = 12;
902 PitchFamily &= ~FXFONT_FF_ROMAN; 1050 }
903 return TRUE; 1051 break;
904 } 1052 }
905 return FALSE; 1053 if (nRet == 2) {
906 } 1054 nStyle |= FX_FONT_STYLE_Italic;
907 FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name, FX_BOOL bTru eType, FX_DWORD flags, 1055 if (nStyle & FX_FONT_STYLE_Bold) {
908 int weight, int italic_angle, int Window CP, CFX_SubstFont* pSubstFont) 1056 nStyle |= FX_FONT_STYLE_BoldBold;
909 { 1057 } else {
910 if (!(flags & FXFONT_USEEXTERNATTR)) { 1058 nStyle |= FX_FONT_STYLE_Bold;
911 weight = FXFONT_FW_NORMAL; 1059 }
912 italic_angle = 0; 1060 bFirstItem = FALSE;
913 } 1061 }
914 CFX_ByteString SubstName = name; 1062 i += buf.GetLength() + 1;
915 SubstName.Remove(0x20); 1063 }
916 if (bTrueType) { 1064 }
917 if (name[0] == '@') { 1065 weight = weight ? weight : FXFONT_FW_NORMAL;
918 SubstName = name.Mid(1); 1066 int old_weight = weight;
919 } 1067 if (nStyle) {
920 } 1068 weight =
921 _PDF_GetStandardFontName(SubstName); 1069 nStyle & FX_FONT_STYLE_BoldBold
922 if (SubstName == FX_BSTRC("Symbol") && !bTrueType) { 1070 ? 900
923 pSubstFont->m_Family = "Chrome Symbol"; 1071 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL);
924 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; 1072 }
1073 if (nStyle & FX_FONT_STYLE_Italic) {
1074 bItalic = TRUE;
1075 }
1076 FX_BOOL bCJK = FALSE;
1077 FX_BOOL bExact = FALSE;
1078 int Charset = FXFONT_ANSI_CHARSET;
1079 if (WindowCP) {
1080 Charset = _GetCharsetFromCodePage(WindowCP);
1081 } else if (iBaseFont == 12 && (flags & FXFONT_SYMBOLIC)) {
1082 Charset = FXFONT_SYMBOL_CHARSET;
1083 }
1084 if (Charset == FXFONT_SHIFTJIS_CHARSET || Charset == FXFONT_GB2312_CHARSET ||
1085 Charset == FXFONT_HANGEUL_CHARSET ||
1086 Charset == FXFONT_CHINESEBIG5_CHARSET) {
1087 bCJK = TRUE;
1088 }
1089 if (m_pFontInfo == NULL) {
1090 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
1091 return UseInternalSubst(
1092 pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily);
1093 }
1094 family = _GetFontFamily(family, nStyle);
1095 CFX_ByteString match = MatchInstalledFonts(_TT_NormalizeName(family));
1096 if (match.IsEmpty() && family != SubstName &&
1097 (!bHasComma && (!bHasHypen || (bHasHypen && !bStyleAvail)))) {
1098 match = MatchInstalledFonts(_TT_NormalizeName(SubstName));
1099 }
1100 if (match.IsEmpty() && iBaseFont >= 12) {
1101 if (!bCJK) {
1102 if (!CheckSupportThirdPartFont(family, PitchFamily)) {
1103 if (italic_angle != 0) {
1104 bItalic = TRUE;
1105 } else {
1106 bItalic = FALSE;
1107 }
1108 weight = old_weight;
1109 }
1110 } else {
1111 pSubstFont->m_bSubstOfCJK = TRUE;
1112 if (nStyle) {
1113 pSubstFont->m_WeightCJK = weight;
1114 } else {
1115 pSubstFont->m_WeightCJK = FXFONT_FW_NORMAL;
1116 }
1117 if (nStyle & FX_FONT_STYLE_Italic) {
1118 pSubstFont->m_bItlicCJK = TRUE;
1119 }
1120 }
1121 } else {
1122 italic_angle = 0;
1123 weight =
1124 nStyle & FX_FONT_STYLE_BoldBold
1125 ? 900
1126 : (nStyle & FX_FONT_STYLE_Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL);
1127 }
1128 if (!match.IsEmpty() || iBaseFont < 12) {
1129 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT;
1130 if (!match.IsEmpty()) {
1131 family = match;
1132 }
1133 if (iBaseFont < 12) {
1134 if (nStyle && !(iBaseFont % 4)) {
1135 if ((nStyle & 0x3) == 1) {
1136 iBaseFont += 1;
1137 }
1138 if ((nStyle & 0x3) == 2) {
1139 iBaseFont += 3;
1140 }
1141 if ((nStyle & 0x3) == 3) {
1142 iBaseFont += 2;
1143 }
1144 }
1145 if (m_pFontMgr->m_ExternalFonts[iBaseFont].m_pFontData) {
1146 if (m_FoxitFaces[iBaseFont]) {
1147 return m_FoxitFaces[iBaseFont];
1148 }
1149 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(
1150 m_pFontMgr->m_ExternalFonts[iBaseFont].m_pFontData,
1151 m_pFontMgr->m_ExternalFonts[iBaseFont].m_dwSize,
1152 0);
1153 if (m_FoxitFaces[iBaseFont]) {
1154 return m_FoxitFaces[iBaseFont];
1155 }
1156 } else {
1157 family = g_Base14FontNames[iBaseFont];
1158 }
1159 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
1160 }
1161 } else {
1162 if (flags & FXFONT_ITALIC) {
1163 bItalic = TRUE;
1164 }
1165 }
1166 bExact = !match.IsEmpty();
1167 void* hFont = m_pFontInfo->MapFont(
1168 weight, bItalic, Charset, PitchFamily, family, bExact);
1169 if (bExact) {
1170 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT;
1171 }
1172 if (hFont == NULL) {
1173 if (bCJK) {
1174 if (italic_angle != 0) {
1175 bItalic = TRUE;
1176 } else {
1177 bItalic = FALSE;
1178 }
1179 weight = old_weight;
1180 }
1181 if (!match.IsEmpty()) {
1182 hFont = m_pFontInfo->GetFont(match);
1183 if (hFont == NULL) {
1184 return UseInternalSubst(
1185 pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily);
1186 }
1187 } else {
1188 if (Charset == FXFONT_SYMBOL_CHARSET) {
1189 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \
1190 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_
1191 if (SubstName == FX_BSTRC("Symbol")) {
1192 pSubstFont->m_Family = "Chrome Symbol";
1193 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
1194 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET;
1195 if (m_FoxitFaces[12]) {
1196 return m_FoxitFaces[12];
1197 }
1198 FX_LPCBYTE pFontData = NULL;
1199 FX_DWORD size = 0;
1200 m_pFontMgr->GetStandardFont(pFontData, size, 12);
1201 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
1202 return m_FoxitFaces[12];
1203 } else {
1204 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL;
1205 return FindSubstFont(family,
1206 bTrueType,
1207 flags & ~FXFONT_SYMBOLIC,
1208 weight,
1209 italic_angle,
1210 0,
1211 pSubstFont);
1212 }
1213 #else
1214 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL;
1215 return FindSubstFont(family,
1216 bTrueType,
1217 flags & ~FXFONT_SYMBOLIC,
1218 weight,
1219 italic_angle,
1220 0,
1221 pSubstFont);
1222 #endif
1223 }
1224 if (Charset == FXFONT_ANSI_CHARSET) {
925 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; 1225 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
926 if (m_FoxitFaces[12]) { 1226 return UseInternalSubst(
927 return m_FoxitFaces[12]; 1227 pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily);
928 } 1228 }
929 FX_LPCBYTE pFontData = NULL; 1229 int index = m_CharsetArray.Find(Charset);
930 FX_DWORD size = 0; 1230 if (index < 0) {
931 m_pFontMgr->GetStandardFont(pFontData, size, 12); 1231 return UseInternalSubst(
932 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); 1232 pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily);
933 return m_FoxitFaces[12]; 1233 } else {
934 } 1234 hFont = m_pFontInfo->GetFont(m_FaceArray[index]);
935 if (SubstName == FX_BSTRC("ZapfDingbats")) { 1235 }
936 pSubstFont->m_Family = "Chrome Dingbats"; 1236 }
937 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; 1237 }
938 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; 1238 pSubstFont->m_ExtHandle = m_pFontInfo->RetainFont(hFont);
939 if (m_FoxitFaces[13]) { 1239 if (hFont == NULL) {
940 return m_FoxitFaces[13]; 1240 return NULL;
941 } 1241 }
942 FX_LPCBYTE pFontData = NULL; 1242 m_pFontInfo->GetFaceName(hFont, SubstName);
943 FX_DWORD size = 0; 1243 if (Charset == FXFONT_DEFAULT_CHARSET) {
944 m_pFontMgr->GetStandardFont(pFontData, size, 13); 1244 m_pFontInfo->GetFontCharset(hFont, Charset);
945 m_FoxitFaces[13] = m_pFontMgr->GetFixedFace(pFontData, size, 0); 1245 }
946 return m_FoxitFaces[13]; 1246 FX_DWORD ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, NULL, 0);
947 } 1247 FX_DWORD font_size = m_pFontInfo->GetFontData(hFont, 0, NULL, 0);
948 int iBaseFont = 0; 1248 if (font_size == 0 && ttc_size == 0) {
949 CFX_ByteString family, style; 1249 m_pFontInfo->DeleteFont(hFont);
950 FX_BOOL bHasComma = FALSE; 1250 return NULL;
951 FX_BOOL bHasHypen = FALSE; 1251 }
952 int find = SubstName.Find(FX_BSTRC(","), 0); 1252 FXFT_Face face = NULL;
953 if (find >= 0) { 1253 if (ttc_size) {
954 family = SubstName.Left(find); 1254 FX_BYTE temp[1024];
955 _PDF_GetStandardFontName(family); 1255 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024);
956 style = SubstName.Mid(find + 1); 1256 FX_DWORD checksum = 0;
957 bHasComma = TRUE; 1257 for (int i = 0; i < 256; i++) {
958 } else { 1258 checksum += ((FX_DWORD*)temp)[i];
959 family = SubstName; 1259 }
960 } 1260 FX_LPBYTE pFontData;
961 for (; iBaseFont < 12; iBaseFont ++) 1261 face = m_pFontMgr->GetCachedTTCFace(
962 if (family == CFX_ByteStringC(g_Base14FontNames[iBaseFont])) { 1262 ttc_size, checksum, ttc_size - font_size, pFontData);
963 break; 1263 if (face == NULL) {
964 } 1264 pFontData = FX_Alloc(FX_BYTE, ttc_size);
965 int PitchFamily = 0; 1265 if (pFontData) {
966 FX_BOOL bItalic = FALSE; 1266 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size);
967 FX_DWORD nStyle = 0; 1267 face = m_pFontMgr->AddCachedTTCFace(
968 FX_BOOL bStyleAvail = FALSE; 1268 ttc_size, checksum, pFontData, ttc_size, ttc_size - font_size);
969 if (iBaseFont < 12) { 1269 }
970 family = g_Base14FontNames[iBaseFont]; 1270 }
971 if ((iBaseFont % 4) == 1 || (iBaseFont % 4) == 2) { 1271 } else {
972 nStyle |= FX_FONT_STYLE_Bold; 1272 FX_LPBYTE pFontData;
973 } 1273 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData);
974 if ((iBaseFont % 4) / 2) { 1274 if (face == NULL) {
975 nStyle |= FX_FONT_STYLE_Italic; 1275 pFontData = FX_Alloc(FX_BYTE, font_size);
976 } 1276 if (!pFontData) {
977 if (iBaseFont < 4) {
978 PitchFamily |= FXFONT_FF_FIXEDPITCH;
979 }
980 if (iBaseFont >= 8) {
981 PitchFamily |= FXFONT_FF_ROMAN;
982 }
983 } else {
984 if (!bHasComma) {
985 find = family.ReverseFind('-');
986 if (find >= 0) {
987 style = family.Mid(find + 1);
988 family = family.Left(find);
989 bHasHypen = TRUE;
990 }
991 }
992 if (!bHasHypen) {
993 int nLen = family.GetLength();
994 FX_INT32 nRet = GetStyleType(family, TRUE);
995 if (nRet > -1) {
996 family = family.Left(nLen - g_FontStyles[nRet].len);
997 if (nRet == 0) {
998 nStyle |= FX_FONT_STYLE_Bold;
999 }
1000 if (nRet == 1) {
1001 nStyle |= FX_FONT_STYLE_Italic;
1002 }
1003 if (nRet == 2) {
1004 nStyle |= (FX_FONT_STYLE_Bold | FX_FONT_STYLE_Italic);
1005 }
1006 }
1007 }
1008 if (flags & FXFONT_SERIF) {
1009 PitchFamily |= FXFONT_FF_ROMAN;
1010 }
1011 if (flags & FXFONT_SCRIPT) {
1012 PitchFamily |= FXFONT_FF_SCRIPT;
1013 }
1014 if (flags & FXFONT_FIXED_PITCH) {
1015 PitchFamily |= FXFONT_FF_FIXEDPITCH;
1016 }
1017 }
1018 if (!style.IsEmpty()) {
1019 int nLen = style.GetLength();
1020 FX_LPCSTR pStyle = style;
1021 int i = 0;
1022 FX_BOOL bFirstItem = TRUE;
1023 CFX_ByteString buf;
1024 while (i < nLen) {
1025 buf = ParseStyle(pStyle, nLen, i);
1026 FX_INT32 nRet = GetStyleType(buf, FALSE);
1027 if ((i && !bStyleAvail) || (!i && nRet < 0)) {
1028 family = SubstName;
1029 iBaseFont = 12;
1030 break;
1031 } else if (nRet >= 0) {
1032 bStyleAvail = TRUE;
1033 }
1034 if (nRet == 0) {
1035 if (nStyle & FX_FONT_STYLE_Bold) {
1036 nStyle |= FX_FONT_STYLE_BoldBold;
1037 } else {
1038 nStyle |= FX_FONT_STYLE_Bold;
1039 }
1040 bFirstItem = FALSE;
1041 }
1042 if (nRet == 1) {
1043 if (bFirstItem) {
1044 nStyle |= FX_FONT_STYLE_Italic;
1045 } else {
1046 family = SubstName;
1047 iBaseFont = 12;
1048 }
1049 break;
1050 }
1051 if (nRet == 2) {
1052 nStyle |= FX_FONT_STYLE_Italic;
1053 if (nStyle & FX_FONT_STYLE_Bold) {
1054 nStyle |= FX_FONT_STYLE_BoldBold;
1055 } else {
1056 nStyle |= FX_FONT_STYLE_Bold;
1057 }
1058 bFirstItem = FALSE;
1059 }
1060 i += buf.GetLength() + 1;
1061 }
1062 }
1063 weight = weight ? weight : FXFONT_FW_NORMAL;
1064 int old_weight = weight;
1065 if (nStyle) {
1066 weight = nStyle & FX_FONT_STYLE_BoldBold ? 900 : (nStyle & FX_FONT_STYLE _Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL);
1067 }
1068 if (nStyle & FX_FONT_STYLE_Italic) {
1069 bItalic = TRUE;
1070 }
1071 FX_BOOL bCJK = FALSE;
1072 FX_BOOL bExact = FALSE;
1073 int Charset = FXFONT_ANSI_CHARSET;
1074 if (WindowCP) {
1075 Charset = _GetCharsetFromCodePage(WindowCP);
1076 } else if (iBaseFont == 12 && (flags & FXFONT_SYMBOLIC)) {
1077 Charset = FXFONT_SYMBOL_CHARSET;
1078 }
1079 if (Charset == FXFONT_SHIFTJIS_CHARSET || Charset == FXFONT_GB2312_CHARSET | |
1080 Charset == FXFONT_HANGEUL_CHARSET || Charset == FXFONT_CHINESEBIG5_C HARSET) {
1081 bCJK = TRUE;
1082 }
1083 if (m_pFontInfo == NULL) {
1084 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
1085 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight, PitchFamily);
1086 }
1087 family = _GetFontFamily(family, nStyle);
1088 CFX_ByteString match = MatchInstalledFonts(_TT_NormalizeName(family));
1089 if (match.IsEmpty() && family != SubstName && (!bHasComma && (!bHasHypen || (bHasHypen && !bStyleAvail)))) {
1090 match = MatchInstalledFonts(_TT_NormalizeName(SubstName));
1091 }
1092 if (match.IsEmpty() && iBaseFont >= 12) {
1093 if (!bCJK) {
1094 if (!CheckSupportThirdPartFont(family, PitchFamily)) {
1095 if (italic_angle != 0) {
1096 bItalic = TRUE;
1097 } else {
1098 bItalic = FALSE;
1099 }
1100 weight = old_weight;
1101 }
1102 } else {
1103 pSubstFont->m_bSubstOfCJK = TRUE;
1104 if (nStyle) {
1105 pSubstFont->m_WeightCJK = weight;
1106 } else {
1107 pSubstFont->m_WeightCJK = FXFONT_FW_NORMAL;
1108 }
1109 if (nStyle & FX_FONT_STYLE_Italic) {
1110 pSubstFont->m_bItlicCJK = TRUE;
1111 }
1112 }
1113 } else {
1114 italic_angle = 0;
1115 weight = nStyle & FX_FONT_STYLE_BoldBold ? 900 : (nStyle & FX_FONT_STYLE _Bold ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL);
1116 }
1117 if (!match.IsEmpty() || iBaseFont < 12) {
1118 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT;
1119 if (!match.IsEmpty()) {
1120 family = match;
1121 }
1122 if (iBaseFont < 12) {
1123 if (nStyle && !(iBaseFont % 4)) {
1124 if ((nStyle & 0x3) == 1) {
1125 iBaseFont += 1;
1126 }
1127 if ((nStyle & 0x3) == 2) {
1128 iBaseFont += 3;
1129 }
1130 if ((nStyle & 0x3) == 3) {
1131 iBaseFont += 2;
1132 }
1133 }
1134 if (m_pFontMgr->m_ExternalFonts[iBaseFont].m_pFontData) {
1135 if (m_FoxitFaces[iBaseFont]) {
1136 return m_FoxitFaces[iBaseFont];
1137 }
1138 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(m_pFontMgr->m _ExternalFonts[iBaseFont].m_pFontData,
1139 m_pFontMgr->m_ExternalFonts[iBaseFont] .m_dwSize, 0);
1140 if (m_FoxitFaces[iBaseFont]) {
1141 return m_FoxitFaces[iBaseFont];
1142 }
1143 } else {
1144 family = g_Base14FontNames[iBaseFont];
1145 }
1146 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
1147 }
1148 } else {
1149 if (flags & FXFONT_ITALIC) {
1150 bItalic = TRUE;
1151 }
1152 }
1153 bExact = !match.IsEmpty();
1154 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, fa mily, bExact);
1155 if (bExact) {
1156 pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT;
1157 }
1158 if (hFont == NULL) {
1159 if (bCJK) {
1160 if (italic_angle != 0) {
1161 bItalic = TRUE;
1162 } else {
1163 bItalic = FALSE;
1164 }
1165 weight = old_weight;
1166 }
1167 if (!match.IsEmpty()) {
1168 hFont = m_pFontInfo->GetFont(match);
1169 if (hFont == NULL) {
1170 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old _weight, PitchFamily);
1171 }
1172 } else {
1173 if (Charset == FXFONT_SYMBOL_CHARSET) {
1174 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || _FXM_PLATFORM_ == _FXM_PLATFORM_ ANDROID_
1175 if (SubstName == FX_BSTRC("Symbol")) {
1176 pSubstFont->m_Family = "Chrome Symbol";
1177 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
1178 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET;
1179 if (m_FoxitFaces[12]) {
1180 return m_FoxitFaces[12];
1181 }
1182 FX_LPCBYTE pFontData = NULL;
1183 FX_DWORD size = 0;
1184 m_pFontMgr->GetStandardFont(pFontData, size, 12);
1185 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0);
1186 return m_FoxitFaces[12];
1187 } else {
1188 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL;
1189 return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMB OLIC, weight, italic_angle, 0, pSubstFont);
1190 }
1191 #else
1192 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL;
1193 return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMBOLIC , weight, italic_angle, 0, pSubstFont);
1194 #endif
1195 }
1196 if (Charset == FXFONT_ANSI_CHARSET) {
1197 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
1198 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old _weight, PitchFamily);
1199 }
1200 int index = m_CharsetArray.Find(Charset);
1201 if (index < 0) {
1202 return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old _weight, PitchFamily);
1203 } else {
1204 hFont = m_pFontInfo->GetFont(m_FaceArray[index]);
1205 }
1206 }
1207 }
1208 pSubstFont->m_ExtHandle = m_pFontInfo->RetainFont(hFont);
1209 if (hFont == NULL) {
1210 return NULL;
1211 }
1212 m_pFontInfo->GetFaceName(hFont, SubstName);
1213 if (Charset == FXFONT_DEFAULT_CHARSET) {
1214 m_pFontInfo->GetFontCharset(hFont, Charset);
1215 }
1216 FX_DWORD ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, NULL, 0);
1217 FX_DWORD font_size = m_pFontInfo->GetFontData(hFont, 0, NULL, 0);
1218 if(font_size == 0 && ttc_size == 0) {
1219 m_pFontInfo->DeleteFont(hFont); 1277 m_pFontInfo->DeleteFont(hFont);
1220 return NULL; 1278 return NULL;
1221 } 1279 }
1222 FXFT_Face face = NULL; 1280 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size);
1223 if (ttc_size) { 1281 face = m_pFontMgr->AddCachedFace(SubstName,
1224 FX_BYTE temp[1024]; 1282 weight,
1225 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024); 1283 bItalic,
1226 FX_DWORD checksum = 0; 1284 pFontData,
1227 for (int i = 0; i < 256; i ++) { 1285 font_size,
1228 checksum += ((FX_DWORD*)temp)[i]; 1286 m_pFontInfo->GetFaceIndex(hFont));
1229 } 1287 }
1230 FX_LPBYTE pFontData; 1288 }
1231 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_ size, pFontData); 1289 if (face == NULL) {
1232 if (face == NULL) { 1290 m_pFontInfo->DeleteFont(hFont);
1233 pFontData = FX_Alloc(FX_BYTE, ttc_size); 1291 return NULL;
1234 if (pFontData) { 1292 }
1235 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size) ; 1293 pSubstFont->m_Family = SubstName;
1236 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontDat a, ttc_size, 1294 pSubstFont->m_Charset = Charset;
1237 ttc_size - font_size); 1295 FX_BOOL bNeedUpdateWeight = FALSE;
1238 } 1296 if (FXFT_Is_Face_Bold(face)) {
1239 } 1297 if (weight == FXFONT_FW_BOLD) {
1298 bNeedUpdateWeight = FALSE;
1240 } else { 1299 } else {
1241 FX_LPBYTE pFontData; 1300 bNeedUpdateWeight = TRUE;
1242 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); 1301 }
1243 if (face == NULL) { 1302 } else {
1244 pFontData = FX_Alloc(FX_BYTE, font_size); 1303 if (weight == FXFONT_FW_NORMAL) {
1245 if (!pFontData) { 1304 bNeedUpdateWeight = FALSE;
1246 m_pFontInfo->DeleteFont(hFont);
1247 return NULL;
1248 }
1249 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size);
1250 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontDa ta, font_size, m_pFontInfo->GetFaceIndex(hFont));
1251 }
1252 }
1253 if (face == NULL) {
1254 m_pFontInfo->DeleteFont(hFont);
1255 return NULL;
1256 }
1257 pSubstFont->m_Family = SubstName;
1258 pSubstFont->m_Charset = Charset;
1259 FX_BOOL bNeedUpdateWeight = FALSE;
1260 if (FXFT_Is_Face_Bold(face)) {
1261 if (weight == FXFONT_FW_BOLD) {
1262 bNeedUpdateWeight = FALSE;
1263 } else {
1264 bNeedUpdateWeight = TRUE;
1265 }
1266 } else { 1305 } else {
1267 if (weight == FXFONT_FW_NORMAL) { 1306 bNeedUpdateWeight = TRUE;
1268 bNeedUpdateWeight = FALSE; 1307 }
1269 } else { 1308 }
1270 bNeedUpdateWeight = TRUE; 1309 if (bNeedUpdateWeight) {
1271 } 1310 pSubstFont->m_Weight = weight;
1272 } 1311 }
1273 if (bNeedUpdateWeight) { 1312 if (bItalic && !FXFT_Is_Face_Italic(face)) {
1274 pSubstFont->m_Weight = weight; 1313 if (italic_angle == 0) {
1275 } 1314 italic_angle = -12;
1276 if (bItalic && !FXFT_Is_Face_Italic(face)) { 1315 } else if (FXSYS_abs(italic_angle) < 5) {
1277 if (italic_angle == 0) { 1316 italic_angle = 0;
1278 italic_angle = -12; 1317 }
1279 } else if (FXSYS_abs(italic_angle) < 5) { 1318 pSubstFont->m_ItalicAngle = italic_angle;
1280 italic_angle = 0; 1319 }
1281 } 1320 m_pFontInfo->DeleteFont(hFont);
1282 pSubstFont->m_ItalicAngle = italic_angle; 1321 return face;
1283 }
1284 m_pFontInfo->DeleteFont(hFont);
1285 return face;
1286 } 1322 }
1287 extern "C" { 1323 extern "C" {
1288 unsigned long _FTStreamRead(FXFT_Stream stream, unsigned long offset, 1324 unsigned long _FTStreamRead(FXFT_Stream stream,
1289 unsigned char* buffer, unsigned long count); 1325 unsigned long offset,
1290 void _FTStreamClose(FXFT_Stream stream); 1326 unsigned char* buffer,
1327 unsigned long count);
1328 void _FTStreamClose(FXFT_Stream stream);
1291 }; 1329 };
1292 CFontFileFaceInfo::CFontFileFaceInfo() 1330 CFontFileFaceInfo::CFontFileFaceInfo() {
1293 { 1331 m_pFile = NULL;
1294 m_pFile = NULL; 1332 m_Face = NULL;
1295 m_Face = NULL; 1333 m_Charsets = 0;
1296 m_Charsets = 0; 1334 m_FileSize = 0;
1297 m_FileSize = 0; 1335 m_FontOffset = 0;
1298 m_FontOffset = 0; 1336 m_Weight = 0;
1299 m_Weight = 0; 1337 m_bItalic = FALSE;
1300 m_bItalic = FALSE; 1338 m_PitchFamily = 0;
1301 m_PitchFamily = 0; 1339 }
1302 } 1340 CFontFileFaceInfo::~CFontFileFaceInfo() {
1303 CFontFileFaceInfo::~CFontFileFaceInfo() 1341 if (m_Face) {
1304 { 1342 FXFT_Done_Face(m_Face);
1305 if (m_Face) { 1343 }
1306 FXFT_Done_Face(m_Face); 1344 m_Face = NULL;
1307 } 1345 }
1308 m_Face = NULL; 1346 extern FX_BOOL _LoadFile(FXFT_Library library,
1309 } 1347 FXFT_Face* Face,
1310 extern FX_BOOL _LoadFile(FXFT_Library library, FXFT_Face* Face, IFX_FileRead* pF ile, FXFT_Stream* stream); 1348 IFX_FileRead* pFile,
1349 FXFT_Stream* stream);
1311 #if defined(_FPDFAPI_MINI_) || _FX_OS_ == _FX_ANDROID_ 1350 #if defined(_FPDFAPI_MINI_) || _FX_OS_ == _FX_ANDROID_
1312 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault() 1351 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault() {
1313 { 1352 return NULL;
1314 return NULL;
1315 } 1353 }
1316 #endif 1354 #endif
1317 #if !defined(_FPDFAPI_MINI_) 1355 #if !defined(_FPDFAPI_MINI_)
1318 CFX_FolderFontInfo::CFX_FolderFontInfo() 1356 CFX_FolderFontInfo::CFX_FolderFontInfo() {
1319 { 1357 }
1320 } 1358 CFX_FolderFontInfo::~CFX_FolderFontInfo() {
1321 CFX_FolderFontInfo::~CFX_FolderFontInfo() 1359 FX_POSITION pos = m_FontList.GetStartPosition();
1322 { 1360 while (pos) {
1323 FX_POSITION pos = m_FontList.GetStartPosition(); 1361 CFX_ByteString key;
1324 while (pos) { 1362 FX_LPVOID value;
1325 CFX_ByteString key; 1363 m_FontList.GetNextAssoc(pos, key, value);
1326 FX_LPVOID value; 1364 delete (CFontFaceInfo*)value;
1327 m_FontList.GetNextAssoc(pos, key, value); 1365 }
1328 delete (CFontFaceInfo*)value; 1366 }
1329 } 1367 void CFX_FolderFontInfo::AddPath(FX_BSTR path) {
1330 } 1368 m_PathList.Add(path);
1331 void CFX_FolderFontInfo::AddPath(FX_BSTR path) 1369 }
1332 { 1370 void CFX_FolderFontInfo::Release() {
1333 m_PathList.Add(path); 1371 delete this;
1334 } 1372 }
1335 void CFX_FolderFontInfo::Release() 1373 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) {
1336 { 1374 m_pMapper = pMapper;
1337 delete this; 1375 for (int i = 0; i < m_PathList.GetSize(); i++) {
1338 } 1376 ScanPath(m_PathList[i]);
1339 FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) 1377 }
1340 { 1378 return TRUE;
1341 m_pMapper = pMapper; 1379 }
1342 for (int i = 0; i < m_PathList.GetSize(); i ++) { 1380 void CFX_FolderFontInfo::ScanPath(CFX_ByteString& path) {
1343 ScanPath(m_PathList[i]); 1381 void* handle = FX_OpenFolder(path);
1344 } 1382 if (handle == NULL) {
1345 return TRUE; 1383 return;
1346 } 1384 }
1347 void CFX_FolderFontInfo::ScanPath(CFX_ByteString& path) 1385 CFX_ByteString filename;
1348 { 1386 FX_BOOL bFolder;
1349 void* handle = FX_OpenFolder(path); 1387 while (FX_GetNextFile(handle, filename, bFolder)) {
1350 if (handle == NULL) { 1388 if (bFolder) {
1351 return; 1389 if (filename == "." || filename == "..") {
1352 } 1390 continue;
1353 CFX_ByteString filename; 1391 }
1354 FX_BOOL bFolder; 1392 } else {
1355 while (FX_GetNextFile(handle, filename, bFolder)) { 1393 CFX_ByteString ext = filename.Right(4);
1356 if (bFolder) { 1394 ext.MakeUpper();
1357 if (filename == "." || filename == "..") { 1395 if (ext != ".TTF" && ext != ".OTF" && ext != ".TTC") {
1358 continue; 1396 continue;
1359 } 1397 }
1360 } else { 1398 }
1361 CFX_ByteString ext = filename.Right(4); 1399 CFX_ByteString fullpath = path;
1362 ext.MakeUpper(); 1400 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
1363 if (ext != ".TTF" && ext != ".OTF" && ext != ".TTC") { 1401 fullpath += "\\";
1364 continue;
1365 }
1366 }
1367 CFX_ByteString fullpath = path;
1368 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
1369 fullpath += "\\";
1370 #else 1402 #else
1371 fullpath += "/"; 1403 fullpath += "/";
1372 #endif 1404 #endif
1373 fullpath += filename; 1405 fullpath += filename;
1374 if (bFolder) { 1406 if (bFolder) {
1375 ScanPath(fullpath); 1407 ScanPath(fullpath);
1376 } else { 1408 } else {
1377 ScanFile(fullpath); 1409 ScanFile(fullpath);
1378 } 1410 }
1379 } 1411 }
1380 FX_CloseFolder(handle); 1412 FX_CloseFolder(handle);
1381 } 1413 }
1382 void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path) 1414 void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path) {
1383 { 1415 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb");
1384 FXSYS_FILE* pFile = FXSYS_fopen(path, "rb"); 1416 if (pFile == NULL) {
1417 return;
1418 }
1419 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END);
1420 FX_DWORD filesize = FXSYS_ftell(pFile);
1421 FX_BYTE buffer[16];
1422 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET);
1423 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile);
1424 if (GET_TT_LONG(buffer) == 0x74746366) {
1425 FX_DWORD nFaces = GET_TT_LONG(buffer + 8);
1426 FX_LPBYTE offsets = FX_Alloc(FX_BYTE, nFaces * 4);
1427 if (!offsets) {
1428 FXSYS_fclose(pFile);
1429 return;
1430 }
1431 readCnt = FXSYS_fread(offsets, nFaces * 4, 1, pFile);
1432 for (FX_DWORD i = 0; i < nFaces; i++) {
1433 FX_LPBYTE p = offsets + i * 4;
1434 ReportFace(path, pFile, filesize, GET_TT_LONG(p));
1435 }
1436 FX_Free(offsets);
1437 } else {
1438 ReportFace(path, pFile, filesize, 0);
1439 }
1440 FXSYS_fclose(pFile);
1441 }
1442 void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path,
1443 FXSYS_FILE* pFile,
1444 FX_DWORD filesize,
1445 FX_DWORD offset) {
1446 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
1447 char buffer[16];
1448 if (!FXSYS_fread(buffer, 12, 1, pFile)) {
1449 return;
1450 }
1451 FX_DWORD nTables = GET_TT_SHORT(buffer + 4);
1452 CFX_ByteString tables = _FPDF_ReadStringFromFile(pFile, nTables * 16);
1453 if (tables.IsEmpty()) {
1454 return;
1455 }
1456 CFX_ByteString names =
1457 _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x6e616d65);
1458 CFX_ByteString facename = _FPDF_GetNameFromTT(names, 1);
1459 CFX_ByteString style = _FPDF_GetNameFromTT(names, 2);
1460 if (style != "Regular") {
1461 facename += " " + style;
1462 }
1463 FX_LPVOID p;
1464 if (m_FontList.Lookup(facename, p)) {
1465 return;
1466 }
1467 CFontFaceInfo* pInfo = FX_NEW CFontFaceInfo;
1468 if (!pInfo) {
1469 return;
1470 }
1471 pInfo->m_FilePath = path;
1472 pInfo->m_FaceName = facename;
1473 pInfo->m_FontTables = tables;
1474 pInfo->m_FontOffset = offset;
1475 pInfo->m_FileSize = filesize;
1476 pInfo->m_Charsets = 0;
1477 CFX_ByteString os2 =
1478 _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x4f532f32);
1479 if (os2.GetLength() >= 86) {
1480 FX_LPCBYTE p = (FX_LPCBYTE)os2 + 78;
1481 FX_DWORD codepages = GET_TT_LONG(p);
1482 if (codepages & (1 << 17)) {
1483 m_pMapper->AddInstalledFont(facename, FXFONT_SHIFTJIS_CHARSET);
1484 pInfo->m_Charsets |= CHARSET_FLAG_SHIFTJIS;
1485 }
1486 if (codepages & (1 << 18)) {
1487 m_pMapper->AddInstalledFont(facename, FXFONT_GB2312_CHARSET);
1488 pInfo->m_Charsets |= CHARSET_FLAG_GB;
1489 }
1490 if (codepages & (1 << 20)) {
1491 m_pMapper->AddInstalledFont(facename, FXFONT_CHINESEBIG5_CHARSET);
1492 pInfo->m_Charsets |= CHARSET_FLAG_BIG5;
1493 }
1494 if ((codepages & (1 << 19)) || (codepages & (1 << 21))) {
1495 m_pMapper->AddInstalledFont(facename, FXFONT_HANGEUL_CHARSET);
1496 pInfo->m_Charsets |= CHARSET_FLAG_KOREAN;
1497 }
1498 if (codepages & (1 << 31)) {
1499 m_pMapper->AddInstalledFont(facename, FXFONT_SYMBOL_CHARSET);
1500 pInfo->m_Charsets |= CHARSET_FLAG_SYMBOL;
1501 }
1502 }
1503 m_pMapper->AddInstalledFont(facename, FXFONT_ANSI_CHARSET);
1504 pInfo->m_Charsets |= CHARSET_FLAG_ANSI;
1505 pInfo->m_Styles = 0;
1506 if (style.Find(FX_BSTRC("Bold")) > -1) {
1507 pInfo->m_Styles |= FXFONT_BOLD;
1508 }
1509 if (style.Find(FX_BSTRC("Italic")) > -1 ||
1510 style.Find(FX_BSTRC("Oblique")) > -1) {
1511 pInfo->m_Styles |= FXFONT_ITALIC;
1512 }
1513 if (facename.Find(FX_BSTRC("Serif")) > -1) {
1514 pInfo->m_Styles |= FXFONT_SERIF;
1515 }
1516 m_FontList.SetAt(facename, pInfo);
1517 }
1518 void* CFX_FolderFontInfo::MapFont(int weight,
1519 FX_BOOL bItalic,
1520 int charset,
1521 int pitch_family,
1522 FX_LPCSTR family,
1523 FX_BOOL& bExact) {
1524 return NULL;
1525 }
1526 void* CFX_FolderFontInfo::GetFont(FX_LPCSTR face) {
1527 FX_LPVOID p;
1528 if (!m_FontList.Lookup(face, p)) {
1529 return NULL;
1530 }
1531 return p;
1532 }
1533 FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont,
1534 FX_DWORD table,
1535 FX_LPBYTE buffer,
1536 FX_DWORD size) {
1537 if (hFont == NULL) {
1538 return 0;
1539 }
1540 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont;
1541 FXSYS_FILE* pFile = NULL;
1542 if (size > 0) {
1543 pFile = FXSYS_fopen(pFont->m_FilePath, "rb");
1385 if (pFile == NULL) { 1544 if (pFile == NULL) {
1386 return; 1545 return 0;
1387 } 1546 }
1388 FXSYS_fseek(pFile, 0, FXSYS_SEEK_END); 1547 }
1389 FX_DWORD filesize = FXSYS_ftell(pFile); 1548 FX_DWORD datasize = 0;
1390 FX_BYTE buffer[16]; 1549 FX_DWORD offset;
1391 FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET); 1550 if (table == 0) {
1392 size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile); 1551 datasize = pFont->m_FontOffset ? 0 : pFont->m_FileSize;
1393 if (GET_TT_LONG(buffer) == 0x74746366) { 1552 offset = 0;
1394 FX_DWORD nFaces = GET_TT_LONG(buffer + 8); 1553 } else if (table == 0x74746366) {
1395 FX_LPBYTE offsets = FX_Alloc(FX_BYTE, nFaces * 4); 1554 datasize = pFont->m_FontOffset ? pFont->m_FileSize : 0;
1396 if (!offsets) { 1555 offset = 0;
1397 FXSYS_fclose(pFile); 1556 } else {
1398 return; 1557 FX_DWORD nTables = pFont->m_FontTables.GetLength() / 16;
1399 } 1558 for (FX_DWORD i = 0; i < nTables; i++) {
1400 readCnt = FXSYS_fread(offsets, nFaces * 4, 1, pFile); 1559 FX_LPCBYTE p = (FX_LPCBYTE)pFont->m_FontTables + i * 16;
1401 for (FX_DWORD i = 0; i < nFaces; i ++) { 1560 if (GET_TT_LONG(p) == table) {
1402 FX_LPBYTE p = offsets + i * 4; 1561 offset = GET_TT_LONG(p + 8);
1403 ReportFace(path, pFile, filesize, GET_TT_LONG(p)); 1562 datasize = GET_TT_LONG(p + 12);
1404 } 1563 }
1405 FX_Free(offsets); 1564 }
1406 } else { 1565 }
1407 ReportFace(path, pFile, filesize, 0); 1566 if (datasize && size >= datasize && pFile) {
1408 } 1567 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
1568 FXSYS_fread(buffer, datasize, 1, pFile);
1569 }
1570 if (pFile) {
1409 FXSYS_fclose(pFile); 1571 FXSYS_fclose(pFile);
1410 } 1572 }
1411 void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, FXSYS_FILE* pFile, FX_ DWORD filesize, FX_DWORD offset) 1573 return datasize;
1412 { 1574 }
1413 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); 1575 void CFX_FolderFontInfo::DeleteFont(void* hFont) {
1414 char buffer[16]; 1576 }
1415 if (!FXSYS_fread(buffer, 12, 1, pFile)) { 1577 FX_BOOL CFX_FolderFontInfo::GetFaceName(void* hFont, CFX_ByteString& name) {
1416 return; 1578 if (hFont == NULL) {
1417 }
1418 FX_DWORD nTables = GET_TT_SHORT(buffer + 4);
1419 CFX_ByteString tables = _FPDF_ReadStringFromFile(pFile, nTables * 16);
1420 if (tables.IsEmpty()) {
1421 return;
1422 }
1423 CFX_ByteString names = _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x6e616 d65);
1424 CFX_ByteString facename = _FPDF_GetNameFromTT(names, 1);
1425 CFX_ByteString style = _FPDF_GetNameFromTT(names, 2);
1426 if (style != "Regular") {
1427 facename += " " + style;
1428 }
1429 FX_LPVOID p;
1430 if (m_FontList.Lookup(facename, p)) {
1431 return;
1432 }
1433 CFontFaceInfo* pInfo = FX_NEW CFontFaceInfo;
1434 if (!pInfo) {
1435 return;
1436 }
1437 pInfo->m_FilePath = path;
1438 pInfo->m_FaceName = facename;
1439 pInfo->m_FontTables = tables;
1440 pInfo->m_FontOffset = offset;
1441 pInfo->m_FileSize = filesize;
1442 pInfo->m_Charsets = 0;
1443 CFX_ByteString os2 = _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x4f532f3 2);
1444 if (os2.GetLength() >= 86) {
1445 FX_LPCBYTE p = (FX_LPCBYTE)os2 + 78;
1446 FX_DWORD codepages = GET_TT_LONG(p);
1447 if (codepages & (1 << 17)) {
1448 m_pMapper->AddInstalledFont(facename, FXFONT_SHIFTJIS_CHARSET);
1449 pInfo->m_Charsets |= CHARSET_FLAG_SHIFTJIS;
1450 }
1451 if (codepages & (1 << 18)) {
1452 m_pMapper->AddInstalledFont(facename, FXFONT_GB2312_CHARSET);
1453 pInfo->m_Charsets |= CHARSET_FLAG_GB;
1454 }
1455 if (codepages & (1 << 20)) {
1456 m_pMapper->AddInstalledFont(facename, FXFONT_CHINESEBIG5_CHARSET);
1457 pInfo->m_Charsets |= CHARSET_FLAG_BIG5;
1458 }
1459 if ((codepages & (1 << 19)) || (codepages & (1 << 21))) {
1460 m_pMapper->AddInstalledFont(facename, FXFONT_HANGEUL_CHARSET);
1461 pInfo->m_Charsets |= CHARSET_FLAG_KOREAN;
1462 }
1463 if (codepages & (1 << 31)) {
1464 m_pMapper->AddInstalledFont(facename, FXFONT_SYMBOL_CHARSET);
1465 pInfo->m_Charsets |= CHARSET_FLAG_SYMBOL;
1466 }
1467 }
1468 m_pMapper->AddInstalledFont(facename, FXFONT_ANSI_CHARSET);
1469 pInfo->m_Charsets |= CHARSET_FLAG_ANSI;
1470 pInfo->m_Styles = 0;
1471 if (style.Find(FX_BSTRC("Bold")) > -1) {
1472 pInfo->m_Styles |= FXFONT_BOLD;
1473 }
1474 if (style.Find(FX_BSTRC("Italic")) > -1 || style.Find(FX_BSTRC("Oblique")) > -1) {
1475 pInfo->m_Styles |= FXFONT_ITALIC;
1476 }
1477 if (facename.Find(FX_BSTRC("Serif")) > -1) {
1478 pInfo->m_Styles |= FXFONT_SERIF;
1479 }
1480 m_FontList.SetAt(facename, pInfo);
1481 }
1482 void* CFX_FolderFontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int pitch_family, FX_LPCSTR family, FX_BOOL& bExact)
1483 {
1484 return NULL;
1485 }
1486 void* CFX_FolderFontInfo::GetFont(FX_LPCSTR face)
1487 {
1488 FX_LPVOID p;
1489 if (!m_FontList.Lookup(face, p)) {
1490 return NULL;
1491 }
1492 return p;
1493 }
1494 FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffer, FX_DWORD size)
1495 {
1496 if (hFont == NULL) {
1497 return 0;
1498 }
1499 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont;
1500 FXSYS_FILE* pFile = NULL;
1501 if (size > 0) {
1502 pFile = FXSYS_fopen(pFont->m_FilePath, "rb");
1503 if (pFile == NULL) {
1504 return 0;
1505 }
1506 }
1507 FX_DWORD datasize = 0;
1508 FX_DWORD offset;
1509 if (table == 0)» {
1510 datasize = pFont->m_FontOffset ? 0 : pFont->m_FileSize;
1511 offset = 0;
1512 } else if (table == 0x74746366)» {
1513 datasize = pFont->m_FontOffset ? pFont->m_FileSize : 0;
1514 offset = 0;
1515 } else {
1516 FX_DWORD nTables = pFont->m_FontTables.GetLength() / 16;
1517 for (FX_DWORD i = 0; i < nTables; i ++) {
1518 FX_LPCBYTE p = (FX_LPCBYTE)pFont->m_FontTables + i * 16;
1519 if (GET_TT_LONG(p) == table) {
1520 offset = GET_TT_LONG(p + 8);
1521 datasize = GET_TT_LONG(p + 12);
1522 }
1523 }
1524 }
1525 if (datasize && size >= datasize && pFile) {
1526 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
1527 FXSYS_fread(buffer, datasize, 1, pFile);
1528 }
1529 if (pFile) {
1530 FXSYS_fclose(pFile);
1531 }
1532 return datasize;
1533 }
1534 void CFX_FolderFontInfo::DeleteFont(void* hFont)
1535 {
1536 }
1537 FX_BOOL CFX_FolderFontInfo::GetFaceName(void* hFont, CFX_ByteString& name)
1538 {
1539 if (hFont == NULL) {
1540 return FALSE;
1541 }
1542 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont;
1543 name = pFont->m_FaceName;
1544 return TRUE;
1545 }
1546 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset)
1547 {
1548 return FALSE; 1579 return FALSE;
1580 }
1581 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont;
1582 name = pFont->m_FaceName;
1583 return TRUE;
1584 }
1585 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) {
1586 return FALSE;
1549 } 1587 }
1550 #endif 1588 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698