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

Side by Side Diff: fpdfsdk/src/pdfwindow/PWL_FontMap.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 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/pdfwindow/PDFWindow.h" 7 #include "../../include/pdfwindow/PDFWindow.h"
8 #include "../../include/pdfwindow/PWL_Wnd.h" 8 #include "../../include/pdfwindow/PWL_Wnd.h"
9 #include "../../include/pdfwindow/PWL_FontMap.h" 9 #include "../../include/pdfwindow/PWL_FontMap.h"
10 10
11 #define DEFAULT_FONT_NAME "Helvetica" 11 #define DEFAULT_FONT_NAME "Helvetica"
12 12
13 /* ------------------------------ CPWL_FontMap ------------------------------ */ 13 /* ------------------------------ CPWL_FontMap ------------------------------ */
14 14
15 CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler) : 15 CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler)
16 m_pPDFDoc(NULL), 16 : m_pPDFDoc(NULL), m_pSystemHandler(pSystemHandler) {
17 m_pSystemHandler(pSystemHandler) 17 ASSERT(m_pSystemHandler != NULL);
18 {
19 ASSERT(m_pSystemHandler != NULL);
20 } 18 }
21 19
22 CPWL_FontMap::~CPWL_FontMap() 20 CPWL_FontMap::~CPWL_FontMap() {
23 { 21 delete m_pPDFDoc;
24 delete m_pPDFDoc; 22 m_pPDFDoc = NULL;
25 m_pPDFDoc = NULL;
26 23
27 Empty(); 24 Empty();
28 } 25 }
29 26
30 void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler) 27 void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler) {
31 { 28 m_pSystemHandler = pSystemHandler;
32 m_pSystemHandler = pSystemHandler;
33 } 29 }
34 30
35 CPDF_Document* CPWL_FontMap::GetDocument() 31 CPDF_Document* CPWL_FontMap::GetDocument() {
36 { 32 if (!m_pPDFDoc) {
37 if (!m_pPDFDoc) 33 if (CPDF_ModuleMgr::Get()) {
38 { 34 m_pPDFDoc = new CPDF_Document;
39 if (CPDF_ModuleMgr::Get()) 35 m_pPDFDoc->CreateNewDoc();
40 {
41 m_pPDFDoc = new CPDF_Document;
42 m_pPDFDoc->CreateNewDoc();
43 }
44 } 36 }
37 }
45 38
46 return m_pPDFDoc; 39 return m_pPDFDoc;
47 } 40 }
48 41
49 CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) 42 CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) {
50 { 43 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
51 if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) 44 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
52 { 45 return pData->pFont;
53 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
54 {
55 return pData->pFont;
56 }
57 } 46 }
47 }
58 48
59 return NULL; 49 return NULL;
60 } 50 }
61 51
62 CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) 52 CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
63 { 53 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
64 if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) 54 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
65 { 55 return pData->sFontName;
66 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
67 {
68 return pData->sFontName;
69 }
70 } 56 }
57 }
71 58
72 return ""; 59 return "";
73 } 60 }
74 61
75 FX_BOOL CPWL_FontMap::KnowWord(int32_t nFontIndex, FX_WORD word) 62 FX_BOOL CPWL_FontMap::KnowWord(int32_t nFontIndex, FX_WORD word) {
76 { 63 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
77 if (nFontIndex >=0 && nFontIndex < m_aData.GetSize()) 64 if (m_aData.GetAt(nFontIndex)) {
78 { 65 return CharCodeFromUnicode(nFontIndex, word) >= 0;
79 if (m_aData.GetAt(nFontIndex))
80 {
81 return CharCodeFromUnicode(nFontIndex, word) >= 0;
82 }
83 } 66 }
67 }
84 68
85 return FALSE; 69 return FALSE;
86 } 70 }
87 71
88 int32_t CPWL_FontMap::GetWordFontIndex(FX_WORD word, int32_t nCharset, int32_t n FontIndex) 72 int32_t CPWL_FontMap::GetWordFontIndex(FX_WORD word,
89 { 73 int32_t nCharset,
90 if (nFontIndex > 0) 74 int32_t nFontIndex) {
91 { 75 if (nFontIndex > 0) {
92 if (KnowWord(nFontIndex, word)) 76 if (KnowWord(nFontIndex, word))
93 return nFontIndex; 77 return nFontIndex;
78 } else {
79 if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) {
80 if (nCharset == DEFAULT_CHARSET || pData->nCharset == SYMBOL_CHARSET ||
81 nCharset == pData->nCharset) {
82 if (KnowWord(0, word))
83 return 0;
84 }
94 } 85 }
95 else 86 }
96 {
97 if (const CPWL_FontMap_Data* pData = GetFontMapData(0))
98 {
99 if (nCharset == DEFAULT_CHARSET ||
100 pData->nCharset == SYMBOL_CHARSET ||
101 nCharset == pData->nCharset)
102 {
103 if (KnowWord(0, word))
104 return 0;
105 }
106 }
107 }
108 87
109 int32_t nNewFontIndex = GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE); 88 int32_t nNewFontIndex =
110 if (nNewFontIndex >= 0) 89 GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE);
111 { 90 if (nNewFontIndex >= 0) {
112 if (KnowWord(nNewFontIndex, word)) 91 if (KnowWord(nNewFontIndex, word))
113 return nNewFontIndex; 92 return nNewFontIndex;
114 } 93 }
115 nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE); 94 nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE);
116 if (nNewFontIndex >= 0) 95 if (nNewFontIndex >= 0) {
117 { 96 if (KnowWord(nNewFontIndex, word))
118 if (KnowWord(nNewFontIndex, word)) 97 return nNewFontIndex;
119 return nNewFontIndex; 98 }
120 } 99 return -1;
121 return -1;
122 } 100 }
123 101
124 int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, FX_WORD word) 102 int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, FX_WORD word) {
125 { 103 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
126 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) 104 if (pData->pFont) {
127 { 105 if (pData->pFont->IsUnicodeCompatible()) {
128 if (pData->pFont) 106 int nCharCode = pData->pFont->CharCodeFromUnicode(word);
129 { 107 pData->pFont->GlyphFromCharCode(nCharCode);
130 if (pData->pFont->IsUnicodeCompatible()) 108 return nCharCode;
131 { 109 }
132 int nCharCode = pData->pFont->CharCodeFromUnicode(word); 110 if (word < 0xFF)
133 pData->pFont->GlyphFromCharCode(nCharCode); 111 return word;
134 return nCharCode;
135 }
136 if (word < 0xFF)
137 return word;
138 }
139 } 112 }
140 return -1; 113 }
114 return -1;
141 } 115 }
142 116
143 CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset) 117 CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset) {
144 { 118 // searching native font is slow, so we must save time
145 //searching native font is slow, so we must save time 119 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++) {
146 for (int32_t i=0,sz=m_aNativeFont.GetSize(); i<sz; i++) 120 if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i)) {
147 { 121 if (pData->nCharset == nCharset)
148 if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i)) 122 return pData->sFontName;
149 {
150 if (pData->nCharset == nCharset)
151 return pData->sFontName;
152 }
153 } 123 }
124 }
154 125
155 CFX_ByteString sNew = GetNativeFont(nCharset); 126 CFX_ByteString sNew = GetNativeFont(nCharset);
156 127
157 if (!sNew.IsEmpty()) 128 if (!sNew.IsEmpty()) {
158 { 129 CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native;
159 CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native; 130 pNewData->nCharset = nCharset;
160 pNewData->nCharset = nCharset; 131 pNewData->sFontName = sNew;
161 pNewData->sFontName = sNew;
162 132
163 m_aNativeFont.Add(pNewData); 133 m_aNativeFont.Add(pNewData);
164 } 134 }
165 135
166 return sNew; 136 return sNew;
167 } 137 }
168 138
169 void CPWL_FontMap::Empty() 139 void CPWL_FontMap::Empty() {
170 { 140 {
171 { 141 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++)
172 for (int32_t i=0, sz=m_aData.GetSize(); i<sz; i++) 142 delete m_aData.GetAt(i);
173 delete m_aData.GetAt(i);
174 143
175 m_aData.RemoveAll(); 144 m_aData.RemoveAll();
176 } 145 }
177 { 146 {
178 for (int32_t i=0, sz=m_aNativeFont.GetSize(); i<sz; i++) 147 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++)
179 delete m_aNativeFont.GetAt(i); 148 delete m_aNativeFont.GetAt(i);
180 149
181 m_aNativeFont.RemoveAll(); 150 m_aNativeFont.RemoveAll();
182 } 151 }
183 } 152 }
184 153
185 void CPWL_FontMap::Initial(const FX_CHAR* fontname) 154 void CPWL_FontMap::Initial(const FX_CHAR* fontname) {
186 { 155 CFX_ByteString sFontName = fontname;
187 CFX_ByteString sFontName = fontname;
188 156
189 if (sFontName.IsEmpty()) 157 if (sFontName.IsEmpty())
190 sFontName = DEFAULT_FONT_NAME; 158 sFontName = DEFAULT_FONT_NAME;
191 159
192 GetFontIndex(sFontName, ANSI_CHARSET, FALSE); 160 GetFontIndex(sFontName, ANSI_CHARSET, FALSE);
193 } 161 }
194 162
195
196 /* 163 /*
197 List of currently supported standard fonts: 164 List of currently supported standard fonts:
198 Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique 165 Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique
199 Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique 166 Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique
200 Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic 167 Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
201 Symbol, ZapfDingbats 168 Symbol, ZapfDingbats
202 */ 169 */
203 170
204 const char* g_sDEStandardFontName[] = {"Courier", "Courier-Bold", "Courier-BoldO blique", "Courier-Oblique", 171 const char* g_sDEStandardFontName[] = {"Courier",
205 "Helvetica", "Helvetica-Bold", "Helvetica-BoldOblique", "Helvetica-Oblique", 172 "Courier-Bold",
206 "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic", 173 "Courier-BoldOblique",
207 "Symbol", "ZapfDingbats"}; 174 "Courier-Oblique",
208 175 "Helvetica",
209 FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) 176 "Helvetica-Bold",
210 { 177 "Helvetica-BoldOblique",
211 for (int32_t i=0; i<14; i++) 178 "Helvetica-Oblique",
212 { 179 "Times-Roman",
213 if (sFontName == g_sDEStandardFontName[i]) 180 "Times-Bold",
214 return TRUE; 181 "Times-Italic",
182 "Times-BoldItalic",
183 "Symbol",
184 "ZapfDingbats"};
185
186 FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) {
187 for (int32_t i = 0; i < 14; i++) {
188 if (sFontName == g_sDEStandardFontName[i])
189 return TRUE;
190 }
191
192 return FALSE;
193 }
194
195 int32_t CPWL_FontMap::FindFont(const CFX_ByteString& sFontName,
196 int32_t nCharset) {
197 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++) {
198 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) {
199 if (nCharset == DEFAULT_CHARSET || nCharset == pData->nCharset) {
200 if (sFontName.IsEmpty() || pData->sFontName == sFontName)
201 return i;
202 }
215 } 203 }
216 204 }
217 return FALSE; 205
218 } 206 return -1;
219 207 }
220 int32_t CPWL_FontMap::FindFont(const CFX_ByteString& sFontName, int32_t nCharset ) 208
221 { 209 int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName,
222 for (int32_t i=0,sz=m_aData.GetSize(); i<sz; i++) 210 int32_t nCharset,
223 { 211 FX_BOOL bFind) {
224 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) 212 int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset);
225 { 213 if (nFontIndex >= 0)
226 if (nCharset == DEFAULT_CHARSET || nCharset == pData->nCharset) 214 return nFontIndex;
227 { 215
228 if (sFontName.IsEmpty() || pData->sFontName == sFontName) 216 CFX_ByteString sAlias;
229 return i; 217 CPDF_Font* pFont = NULL;
230 } 218 if (bFind)
231 } 219 pFont = FindFontSameCharset(sAlias, nCharset);
220
221 if (!pFont) {
222 CFX_ByteString sTemp = sFontName;
223 pFont = AddFontToDocument(GetDocument(), sTemp, nCharset);
224 sAlias = EncodeFontAlias(sTemp, nCharset);
225 }
226 AddedFont(pFont, sAlias);
227 return AddFontData(pFont, sAlias, nCharset);
228 }
229
230 int32_t CPWL_FontMap::GetPWLFontIndex(FX_WORD word, int32_t nCharset) {
231 int32_t nFind = -1;
232
233 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++) {
234 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) {
235 if (pData->nCharset == nCharset) {
236 nFind = i;
237 break;
238 }
232 } 239 }
233 240 }
241
242 CPDF_Font* pNewFont = GetPDFFont(nFind);
243
244 if (!pNewFont)
234 return -1; 245 return -1;
235 } 246
236 247 /*
237 int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName, int32_t nCha rset, FX_BOOL bFind) 248 if (CPDF_Font* pFont = GetPDFFont(nFind))
238 { 249 {
239 int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset ); 250 PWLFont.AddWordToFontDict(pFontDict, word);
240 if (nFontIndex >= 0) 251 }
241 return nFontIndex; 252 */
242 253
243 CFX_ByteString sAlias; 254 CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset);
244 CPDF_Font* pFont = NULL; 255 AddedFont(pNewFont, sAlias);
245 if (bFind) 256
246 pFont = FindFontSameCharset(sAlias, nCharset); 257 return AddFontData(pNewFont, sAlias, nCharset);
247 258 }
248 if (!pFont) 259
249 { 260 CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias,
250 CFX_ByteString sTemp = sFontName; 261 int32_t nCharset) {
251 pFont = AddFontToDocument(GetDocument(), sTemp, nCharset); 262 return NULL;
252 sAlias = EncodeFontAlias(sTemp, nCharset); 263 }
264
265 int32_t CPWL_FontMap::AddFontData(CPDF_Font* pFont,
266 const CFX_ByteString& sFontAlias,
267 int32_t nCharset) {
268 CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data;
269 pNewData->pFont = pFont;
270 pNewData->sFontName = sFontAlias;
271 pNewData->nCharset = nCharset;
272
273 m_aData.Add(pNewData);
274
275 return m_aData.GetSize() - 1;
276 }
277
278 void CPWL_FontMap::AddedFont(CPDF_Font* pFont,
279 const CFX_ByteString& sFontAlias) {}
280
281 CFX_ByteString CPWL_FontMap::GetFontName(int32_t nFontIndex) {
282 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
283 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
284 return pData->sFontName;
253 } 285 }
254 AddedFont(pFont, sAlias); 286 }
255 return AddFontData(pFont, sAlias, nCharset); 287
256 } 288 return "";
257 289 }
258 int32_t CPWL_FontMap::GetPWLFontIndex(FX_WORD word, int32_t nCharset) 290
259 { 291 CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) {
260 int32_t nFind = -1; 292 if (nCharset == DEFAULT_CHARSET)
261 293 nCharset = GetNativeCharset();
262 for (int32_t i=0,sz=m_aData.GetSize(); i<sz; i++) 294
263 { 295 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset);
264 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) 296 if (m_pSystemHandler) {
265 { 297 if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName))
266 if (pData->nCharset == nCharset) 298 return sFontName;
267 { 299
268 nFind = i; 300 sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset);
269 break; 301 }
270 } 302 return sFontName;
271 } 303 }
272 } 304
273 305 CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc,
274 CPDF_Font* pNewFont = GetPDFFont(nFind); 306 CFX_ByteString& sFontName,
275 307 uint8_t nCharset) {
276 if (!pNewFont) return -1; 308 if (IsStandardFont(sFontName))
277 309 return AddStandardFont(pDoc, sFontName);
278 /* 310
279 if (CPDF_Font* pFont = GetPDFFont(nFind)) 311 return AddSystemFont(pDoc, sFontName, nCharset);
280 { 312 }
281 PWLFont.AddWordToFontDict(pFontDict, word); 313
282 } 314 CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc,
283 */ 315 CFX_ByteString& sFontName) {
284 316 if (!pDoc)
285 CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset);
286 AddedFont(pNewFont, sAlias);
287
288 return AddFontData(pNewFont, sAlias, nCharset);
289 }
290
291 CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, int32_t nCharset)
292 {
293 return NULL; 317 return NULL;
294 } 318
295 319 CPDF_Font* pFont = NULL;
296 int32_t CPWL_FontMap::AddFontData(CPDF_Font* pFont, const CFX_ByteString& sFontA lias, int32_t nCharset) 320
297 { 321 if (sFontName == "ZapfDingbats")
298 CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data; 322 pFont = pDoc->AddStandardFont(sFontName, NULL);
299 pNewData->pFont = pFont; 323 else {
300 pNewData->sFontName = sFontAlias; 324 CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI);
301 pNewData->nCharset = nCharset; 325 pFont = pDoc->AddStandardFont(sFontName, &fe);
302 326 }
303 m_aData.Add(pNewData); 327
304 328 return pFont;
305 return m_aData.GetSize() -1; 329 }
306 } 330
307 331 CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc,
308 void CPWL_FontMap::AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias) 332 CFX_ByteString& sFontName,
309 { 333 uint8_t nCharset) {
310 } 334 if (!pDoc)
311
312 CFX_ByteString CPWL_FontMap::GetFontName(int32_t nFontIndex)
313 {
314 if (nFontIndex >=0 && nFontIndex < m_aData.GetSize())
315 {
316 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex))
317 {
318 return pData->sFontName;
319 }
320 }
321
322 return "";
323 }
324
325 CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset)
326 {
327
328 if (nCharset == DEFAULT_CHARSET)
329 nCharset = GetNativeCharset();
330
331 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset);
332 if (m_pSystemHandler)
333 {
334 if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName))
335 return sFontName;
336
337 sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset);
338 }
339 return sFontName;
340 }
341
342 CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc, CFX_ByteString& sFontName, uint8_t nCharset)
343 {
344 if (IsStandardFont(sFontName))
345 return AddStandardFont(pDoc, sFontName);
346
347 return AddSystemFont(pDoc, sFontName, nCharset);
348 }
349
350 CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc, CFX_ByteString& sF ontName)
351 {
352 if (!pDoc) return NULL;
353
354 CPDF_Font* pFont = NULL;
355
356 if (sFontName == "ZapfDingbats")
357 pFont = pDoc->AddStandardFont(sFontName, NULL);
358 else
359 {
360 CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI);
361 pFont = pDoc->AddStandardFont(sFontName, &fe);
362 }
363
364 return pFont;
365 }
366
367 CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, CFX_ByteString& sFon tName, uint8_t nCharset)
368 {
369 if (!pDoc) return NULL;
370
371 if (sFontName.IsEmpty()) sFontName = GetNativeFont(nCharset);
372 if (nCharset == DEFAULT_CHARSET) nCharset = GetNativeCharset();
373
374 if (m_pSystemHandler)
375 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, nCh arset);
376
377 return NULL; 335 return NULL;
378 } 336
379 337 if (sFontName.IsEmpty())
380 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, in t32_t nCharset) 338 sFontName = GetNativeFont(nCharset);
381 { 339 if (nCharset == DEFAULT_CHARSET)
382 CFX_ByteString sPostfix; 340 nCharset = GetNativeCharset();
383 sPostfix.Format("_%02X", nCharset); 341
384 return EncodeFontAlias(sFontName) + sPostfix; 342 if (m_pSystemHandler)
385 } 343 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName,
386 344 nCharset);
387 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) 345
388 { 346 return NULL;
389 CFX_ByteString sRet = sFontName; 347 }
390 sRet.Remove(' '); 348
391 return sRet; 349 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName,
392 } 350 int32_t nCharset) {
393 351 CFX_ByteString sPostfix;
394 int32_t CPWL_FontMap::GetFontMapCount() const 352 sPostfix.Format("_%02X", nCharset);
395 { 353 return EncodeFontAlias(sFontName) + sPostfix;
396 return m_aData.GetSize(); 354 }
397 } 355
398 356 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) {
399 const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const 357 CFX_ByteString sRet = sFontName;
400 { 358 sRet.Remove(' ');
401 if (nIndex >=0 && nIndex < m_aData.GetSize()) 359 return sRet;
402 { 360 }
403 return m_aData.GetAt(nIndex); 361
404 } 362 int32_t CPWL_FontMap::GetFontMapCount() const {
405 363 return m_aData.GetSize();
406 return NULL; 364 }
407 } 365
408 366 const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const {
409 int32_t CPWL_FontMap::GetNativeCharset() 367 if (nIndex >= 0 && nIndex < m_aData.GetSize()) {
410 { 368 return m_aData.GetAt(nIndex);
411 uint8_t nCharset = ANSI_CHARSET; 369 }
412 int32_t iCodePage = FXSYS_GetACP(); 370
413 switch (iCodePage) 371 return NULL;
414 { 372 }
415 case 932://Japan 373
416 nCharset = SHIFTJIS_CHARSET; 374 int32_t CPWL_FontMap::GetNativeCharset() {
417 break; 375 uint8_t nCharset = ANSI_CHARSET;
418 case 936://Chinese (PRC, Singapore) 376 int32_t iCodePage = FXSYS_GetACP();
419 nCharset = GB2312_CHARSET; 377 switch (iCodePage) {
420 break; 378 case 932: // Japan
421 case 950://Chinese (Taiwan; Hong Kong SAR, PRC) 379 nCharset = SHIFTJIS_CHARSET;
422 nCharset = GB2312_CHARSET; 380 break;
423 break; 381 case 936: // Chinese (PRC, Singapore)
424 case 1252://Windows 3.1 Latin 1 (US, Western Europe) 382 nCharset = GB2312_CHARSET;
425 nCharset = ANSI_CHARSET; 383 break;
426 break; 384 case 950: // Chinese (Taiwan; Hong Kong SAR, PRC)
427 case 874://Thai 385 nCharset = GB2312_CHARSET;
428 nCharset = THAI_CHARSET; 386 break;
429 break; 387 case 1252: // Windows 3.1 Latin 1 (US, Western Europe)
430 case 949://Korean 388 nCharset = ANSI_CHARSET;
431 nCharset = HANGUL_CHARSET; 389 break;
432 break; 390 case 874: // Thai
433 case 1200://Unicode (BMP of ISO 10646) 391 nCharset = THAI_CHARSET;
434 nCharset = ANSI_CHARSET; 392 break;
435 break; 393 case 949: // Korean
436 case 1250://Windows 3.1 Eastern European 394 nCharset = HANGUL_CHARSET;
437 nCharset = EASTEUROPE_CHARSET; 395 break;
438 break; 396 case 1200: // Unicode (BMP of ISO 10646)
439 case 1251://Windows 3.1 Cyrillic 397 nCharset = ANSI_CHARSET;
440 nCharset = RUSSIAN_CHARSET; 398 break;
441 break; 399 case 1250: // Windows 3.1 Eastern European
442 case 1253://Windows 3.1 Greek 400 nCharset = EASTEUROPE_CHARSET;
443 nCharset = GREEK_CHARSET; 401 break;
444 break; 402 case 1251: // Windows 3.1 Cyrillic
445 case 1254://Windows 3.1 Turkish 403 nCharset = RUSSIAN_CHARSET;
446 nCharset = TURKISH_CHARSET; 404 break;
447 break; 405 case 1253: // Windows 3.1 Greek
448 case 1255://Hebrew 406 nCharset = GREEK_CHARSET;
449 nCharset = HEBREW_CHARSET; 407 break;
450 break; 408 case 1254: // Windows 3.1 Turkish
451 case 1256://Arabic 409 nCharset = TURKISH_CHARSET;
452 nCharset = ARABIC_CHARSET; 410 break;
453 break; 411 case 1255: // Hebrew
454 case 1257://Baltic 412 nCharset = HEBREW_CHARSET;
455 nCharset = BALTIC_CHARSET; 413 break;
456 break; 414 case 1256: // Arabic
457 case 1258://Vietnamese 415 nCharset = ARABIC_CHARSET;
458 nCharset = VIETNAMESE_CHARSET; 416 break;
459 break; 417 case 1257: // Baltic
460 case 1361://Korean(Johab) 418 nCharset = BALTIC_CHARSET;
461 nCharset = JOHAB_CHARSET; 419 break;
462 break; 420 case 1258: // Vietnamese
463 } 421 nCharset = VIETNAMESE_CHARSET;
464 return nCharset; 422 break;
423 case 1361: // Korean(Johab)
424 nCharset = JOHAB_CHARSET;
425 break;
426 }
427 return nCharset;
465 } 428 }
466 429
467 const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = { 430 const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
468 { ANSI_CHARSET, "Helvetica" }, 431 {ANSI_CHARSET, "Helvetica"}, {GB2312_CHARSET, "SimSun"},
469 { GB2312_CHARSET, "SimSun" }, 432 {CHINESEBIG5_CHARSET, "MingLiU"}, {SHIFTJIS_CHARSET, "MS Gothic"},
470 { CHINESEBIG5_CHARSET, "MingLiU" }, 433 {HANGUL_CHARSET, "Batang"}, {RUSSIAN_CHARSET, "Arial"},
471 { SHIFTJIS_CHARSET, "MS Gothic" }, 434 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \
472 { HANGUL_CHARSET, "Batang" }, 435 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
473 { RUSSIAN_CHARSET, "Arial" }, 436 {EASTEUROPE_CHARSET, "Arial"},
474 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || _FXM_PLATFORM_ == _FXM_PLATFORM_AP PLE_
475 { EASTEUROPE_CHARSET, "Arial" },
476 #else 437 #else
477 { EASTEUROPE_CHARSET, "Tahoma" }, 438 {EASTEUROPE_CHARSET, "Tahoma"},
478 #endif 439 #endif
479 { ARABIC_CHARSET, "Arial" }, 440 {ARABIC_CHARSET, "Arial"}, {-1, NULL}};
480 { -1, NULL } 441
481 }; 442 CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) {
482 443 int i = 0;
483 CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) 444 while (defaultTTFMap[i].charset != -1) {
484 { 445 if (nCharset == defaultTTFMap[i].charset)
485 int i = 0; 446 return defaultTTFMap[i].fontname;
486 while (defaultTTFMap[i].charset != -1) { 447 ++i;
487 if (nCharset == defaultTTFMap[i].charset) 448 }
488 return defaultTTFMap[i].fontname; 449 return "";
489 ++i; 450 }
490 } 451
491 return ""; 452 int32_t CPWL_FontMap::CharSetFromUnicode(FX_WORD word, int32_t nOldCharset) {
492 } 453 if (m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet()))
493 454 return m_pSystemHandler->GetCharSet();
494 int32_t CPWL_FontMap::CharSetFromUnicode(FX_WORD word, int32_t nOldCharset) 455 // to avoid CJK Font to show ASCII
495 { 456 if (word < 0x7F)
496 if(m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet()))
497 return m_pSystemHandler->GetCharSet();
498 //to avoid CJK Font to show ASCII
499 if (word < 0x7F) return ANSI_CHARSET;
500 //follow the old charset
501 if (nOldCharset != DEFAULT_CHARSET) return nOldCharset;
502
503 //find new charset
504 if ((word >= 0x4E00 && word <= 0x9FA5) ||
505 (word >= 0xE7C7 && word <= 0xE7F3) ||
506 (word >= 0x3000 && word <= 0x303F) ||
507 (word >= 0x2000 && word <= 0x206F))
508 {
509 return GB2312_CHARSET;
510 }
511
512 if (((word >= 0x3040) && (word <= 0x309F)) ||
513 ((word >= 0x30A0) && (word <= 0x30FF)) ||
514 ((word >= 0x31F0) && (word <= 0x31FF)) ||
515 ((word >= 0xFF00) && (word <= 0xFFEF)) )
516 {
517 return SHIFTJIS_CHARSET;
518 }
519
520 if (((word >= 0xAC00) && (word <= 0xD7AF)) ||
521 ((word >= 0x1100) && (word <= 0x11FF)) ||
522 ((word >= 0x3130) && (word <= 0x318F)))
523 {
524 return HANGUL_CHARSET;
525 }
526
527 if (word >= 0x0E00 && word <= 0x0E7F)
528 return THAI_CHARSET;
529
530 if ((word >= 0x0370 && word <= 0x03FF) ||
531 (word >= 0x1F00 && word <= 0x1FFF))
532 return GREEK_CHARSET;
533
534 if ((word >= 0x0600 && word <= 0x06FF) ||
535 (word >= 0xFB50 && word <= 0xFEFC))
536 return ARABIC_CHARSET;
537
538 if (word >= 0x0590 && word <= 0x05FF)
539 return HEBREW_CHARSET;
540
541 if (word >= 0x0400 && word <= 0x04FF)
542 return RUSSIAN_CHARSET;
543
544 if (word >= 0x0100 && word <= 0x024F)
545 return EASTEUROPE_CHARSET;
546
547 if (word >= 0x1E00 && word <= 0x1EFF)
548 return VIETNAMESE_CHARSET;
549
550 return ANSI_CHARSET; 457 return ANSI_CHARSET;
458 // follow the old charset
459 if (nOldCharset != DEFAULT_CHARSET)
460 return nOldCharset;
461
462 // find new charset
463 if ((word >= 0x4E00 && word <= 0x9FA5) ||
464 (word >= 0xE7C7 && word <= 0xE7F3) ||
465 (word >= 0x3000 && word <= 0x303F) ||
466 (word >= 0x2000 && word <= 0x206F)) {
467 return GB2312_CHARSET;
468 }
469
470 if (((word >= 0x3040) && (word <= 0x309F)) ||
471 ((word >= 0x30A0) && (word <= 0x30FF)) ||
472 ((word >= 0x31F0) && (word <= 0x31FF)) ||
473 ((word >= 0xFF00) && (word <= 0xFFEF))) {
474 return SHIFTJIS_CHARSET;
475 }
476
477 if (((word >= 0xAC00) && (word <= 0xD7AF)) ||
478 ((word >= 0x1100) && (word <= 0x11FF)) ||
479 ((word >= 0x3130) && (word <= 0x318F))) {
480 return HANGUL_CHARSET;
481 }
482
483 if (word >= 0x0E00 && word <= 0x0E7F)
484 return THAI_CHARSET;
485
486 if ((word >= 0x0370 && word <= 0x03FF) || (word >= 0x1F00 && word <= 0x1FFF))
487 return GREEK_CHARSET;
488
489 if ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
490 return ARABIC_CHARSET;
491
492 if (word >= 0x0590 && word <= 0x05FF)
493 return HEBREW_CHARSET;
494
495 if (word >= 0x0400 && word <= 0x04FF)
496 return RUSSIAN_CHARSET;
497
498 if (word >= 0x0100 && word <= 0x024F)
499 return EASTEUROPE_CHARSET;
500
501 if (word >= 0x1E00 && word <= 0x1EFF)
502 return VIETNAMESE_CHARSET;
503
504 return ANSI_CHARSET;
551 } 505 }
552 506
553 /* ------------------------ CPWL_DocFontMap ------------------------ */ 507 /* ------------------------ CPWL_DocFontMap ------------------------ */
554 508
555 CPWL_DocFontMap::CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler, CPDF_Documen t* pAttachedDoc) 509 CPWL_DocFontMap::CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler,
556 : CPWL_FontMap(pSystemHandler), 510 CPDF_Document* pAttachedDoc)
557 m_pAttachedDoc(pAttachedDoc) 511 : CPWL_FontMap(pSystemHandler), m_pAttachedDoc(pAttachedDoc) {}
558 { 512
559 } 513 CPWL_DocFontMap::~CPWL_DocFontMap() {}
560 514
561 CPWL_DocFontMap::~CPWL_DocFontMap() 515 CPDF_Document* CPWL_DocFontMap::GetDocument() {
562 { 516 return m_pAttachedDoc;
563 } 517 }
564
565 CPDF_Document* CPWL_DocFontMap::GetDocument()
566 {
567 return m_pAttachedDoc;
568 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698