OLD | NEW |
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 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 { | |
105 return 0; | 104 return 0; |
106 } | |
107 } | 105 } |
108 } | 106 } |
109 } | 107 } |
110 | 108 |
111 » int32_t nNewFontIndex = -1; | 109 » int32_t nNewFontIndex = GetFontIndex(GetNativeFontName(nCharset), nChars
et, TRUE); |
112 | |
113 » nNewFontIndex = GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE
); | |
114 if (nNewFontIndex >= 0) | 110 if (nNewFontIndex >= 0) |
115 { | 111 { |
116 if (KnowWord(nNewFontIndex, word)) | 112 if (KnowWord(nNewFontIndex, word)) |
117 return nNewFontIndex; | 113 return nNewFontIndex; |
118 } | 114 } |
119 | |
120 nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE)
; | 115 nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE)
; |
121 if (nNewFontIndex >= 0) | 116 if (nNewFontIndex >= 0) |
122 { | 117 { |
123 if (KnowWord(nNewFontIndex, word)) | 118 if (KnowWord(nNewFontIndex, word)) |
124 » » return nNewFontIndex; | 119 return nNewFontIndex; |
125 } | 120 } |
126 | |
127 return -1; | 121 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->CharCodeFromUnicod
e(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) | |
145 » » » » » return word; | |
146 » » » } | |
147 } | 138 } |
148 } | 139 } |
149 | |
150 return -1; | 140 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 { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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), nCha
rset); |
250 » if (nFontIndex >= 0) return nFontIndex; | 240 » if (nFontIndex >= 0) |
251 | 241 return nFontIndex; |
252 //» nFontIndex = FindFont("", nCharset); | |
253 //» if (nFontIndex >= 0) return nFontIndex; | |
254 | 242 |
255 CFX_ByteString sAlias; | 243 CFX_ByteString sAlias; |
256 CPDF_Font* pFont = NULL; | 244 CPDF_Font* pFont = NULL; |
257 | |
258 if (bFind) | 245 if (bFind) |
259 pFont = FindFontSameCharset(sAlias, nCharset); | 246 pFont = FindFontSameCharset(sAlias, nCharset); |
260 | 247 |
261 if (!pFont) | 248 if (!pFont) |
262 { | 249 { |
263 CFX_ByteString sTemp = sFontName; | 250 CFX_ByteString sTemp = sFontName; |
264 pFont = AddFontToDocument(GetDocument(), sTemp, nCharset); | 251 pFont = AddFontToDocument(GetDocument(), sTemp, nCharset); |
265 | 252 sAlias = EncodeFontAlias(sTemp, nCharset); |
266 » » /* | |
267 » » if (FindFont(sAlias)) | |
268 » » { | |
269 » » » sAlias = EncodeFontAlias(sTemp, nCharset); | |
270 » » } | |
271 » » else | |
272 » » */ | |
273 » » { | |
274 » » » sAlias = EncodeFontAlias(sTemp, nCharset); | |
275 » » } | |
276 } | 253 } |
277 | |
278 AddedFont(pFont, sAlias); | 254 AddedFont(pFont, sAlias); |
279 | |
280 return AddFontData(pFont, sAlias, nCharset); | 255 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)) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; | |
353 | 327 |
354 if (nCharset == DEFAULT_CHARSET) | 328 if (nCharset == DEFAULT_CHARSET) |
355 nCharset = GetNativeCharset(); | 329 nCharset = GetNativeCharset(); |
356 | 330 |
357 » sFontName = GetDefaultFontByCharset(nCharset); | 331 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset); |
358 | |
359 if (m_pSystemHandler) | 332 if (m_pSystemHandler) |
360 { | 333 { |
361 if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName
)) | 334 if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName
)) |
362 return sFontName; | 335 return sFontName; |
363 | 336 |
364 sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset); | 337 sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset); |
365 } | 338 } |
366 | |
367 return sFontName; | 339 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); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |