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

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

Powered by Google App Engine
This is Rietveld 408576698