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

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

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

Powered by Google App Engine
This is Rietveld 408576698