blob: cd65c383ffb4ce83e4fe42181a06172bcd413d31 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhang60f507b2015-06-13 00:41:00 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangbde53d22015-11-12 22:21:30 -08007#include "fpdfsdk/include/pdfwindow/PDFWindow.h"
8#include "fpdfsdk/include/pdfwindow/PWL_FontMap.h"
9#include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070010
Nico Weber9d8ec5a2015-08-04 13:00:21 -070011#define DEFAULT_FONT_NAME "Helvetica"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012
13/* ------------------------------ CPWL_FontMap ------------------------------ */
14
Nico Weber9d8ec5a2015-08-04 13:00:21 -070015CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler)
16 : m_pPDFDoc(NULL), m_pSystemHandler(pSystemHandler) {
17 ASSERT(m_pSystemHandler != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018}
19
Nico Weber9d8ec5a2015-08-04 13:00:21 -070020CPWL_FontMap::~CPWL_FontMap() {
21 delete m_pPDFDoc;
22 m_pPDFDoc = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024 Empty();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025}
26
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler) {
28 m_pSystemHandler = pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070029}
30
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031CPDF_Document* CPWL_FontMap::GetDocument() {
32 if (!m_pPDFDoc) {
33 if (CPDF_ModuleMgr::Get()) {
Tom Sepezae51c812015-08-05 12:34:06 -070034 m_pPDFDoc = new CPDF_Document;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035 m_pPDFDoc->CreateNewDoc();
36 }
37 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039 return m_pPDFDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040}
41
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) {
43 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
44 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
45 return pData->pFont;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070046 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070048
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050}
51
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
53 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
54 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
55 return pData->sFontName;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070056 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060}
61
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062FX_BOOL CPWL_FontMap::KnowWord(int32_t nFontIndex, FX_WORD word) {
63 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
64 if (m_aData.GetAt(nFontIndex)) {
65 return CharCodeFromUnicode(nFontIndex, word) >= 0;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070066 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070}
71
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072int32_t CPWL_FontMap::GetWordFontIndex(FX_WORD word,
73 int32_t nCharset,
74 int32_t nFontIndex) {
75 if (nFontIndex > 0) {
76 if (KnowWord(nFontIndex, word))
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 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -070085 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 int32_t nNewFontIndex =
89 GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE);
90 if (nNewFontIndex >= 0) {
91 if (KnowWord(nNewFontIndex, word))
92 return nNewFontIndex;
93 }
94 nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE);
95 if (nNewFontIndex >= 0) {
96 if (KnowWord(nNewFontIndex, word))
97 return nNewFontIndex;
98 }
99 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100}
101
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, FX_WORD word) {
103 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
104 if (pData->pFont) {
105 if (pData->pFont->IsUnicodeCompatible()) {
106 int nCharCode = pData->pFont->CharCodeFromUnicode(word);
107 pData->pFont->GlyphFromCharCode(nCharCode);
108 return nCharCode;
109 }
110 if (word < 0xFF)
111 return word;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700112 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 }
114 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700115}
116
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset) {
118 // searching native font is slow, so we must save time
119 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++) {
120 if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i)) {
121 if (pData->nCharset == nCharset)
122 return pData->sFontName;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700123 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 CFX_ByteString sNew = GetNativeFont(nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700127
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128 if (!sNew.IsEmpty()) {
129 CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native;
130 pNewData->nCharset = nCharset;
131 pNewData->sFontName = sNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 m_aNativeFont.Add(pNewData);
134 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700136 return sNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137}
138
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139void CPWL_FontMap::Empty() {
140 {
141 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++)
142 delete m_aData.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 m_aData.RemoveAll();
145 }
146 {
147 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++)
148 delete m_aNativeFont.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700149
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150 m_aNativeFont.RemoveAll();
151 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700152}
153
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154void CPWL_FontMap::Initial(const FX_CHAR* fontname) {
155 CFX_ByteString sFontName = fontname;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 if (sFontName.IsEmpty())
158 sFontName = DEFAULT_FONT_NAME;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 GetFontIndex(sFontName, ANSI_CHARSET, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700161}
Lei Zhang60f507b2015-06-13 00:41:00 -0700162
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163/*
164List of currently supported standard fonts:
165Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique
166Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique
167Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
168Symbol, ZapfDingbats
169*/
170
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171const char* g_sDEStandardFontName[] = {"Courier",
172 "Courier-Bold",
173 "Courier-BoldOblique",
174 "Courier-Oblique",
175 "Helvetica",
176 "Helvetica-Bold",
177 "Helvetica-BoldOblique",
178 "Helvetica-Oblique",
179 "Times-Roman",
180 "Times-Bold",
181 "Times-Italic",
182 "Times-BoldItalic",
183 "Symbol",
184 "ZapfDingbats"};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700185
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186FX_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 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700191
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700193}
194
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195int32_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 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700203 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700205
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 return -1;
207}
208
209int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName,
210 int32_t nCharset,
211 FX_BOOL bFind) {
212 int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset);
213 if (nFontIndex >= 0)
214 return nFontIndex;
215
216 CFX_ByteString sAlias;
217 CPDF_Font* pFont = NULL;
218 if (bFind)
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
230int32_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 }
239 }
240 }
241
242 CPDF_Font* pNewFont = GetPDFFont(nFind);
243
244 if (!pNewFont)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700245 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246
247 /*
248 if (CPDF_Font* pFont = GetPDFFont(nFind))
249 {
250 PWLFont.AddWordToFontDict(pFontDict, word);
251 }
252 */
253
254 CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset);
255 AddedFont(pNewFont, sAlias);
256
257 return AddFontData(pNewFont, sAlias, nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700258}
259
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias,
261 int32_t nCharset) {
262 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700263}
264
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265int32_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;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700272
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273 m_aData.Add(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700274
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 return m_aData.GetSize() - 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700276}
277
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278void CPWL_FontMap::AddedFont(CPDF_Font* pFont,
279 const CFX_ByteString& sFontAlias) {}
280
281CFX_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;
285 }
286 }
287
288 return "";
289}
290
291CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) {
292 if (nCharset == DEFAULT_CHARSET)
293 nCharset = GetNativeCharset();
294
295 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset);
296 if (m_pSystemHandler) {
297 if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName))
298 return sFontName;
299
300 sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset);
301 }
302 return sFontName;
303}
304
305CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc,
306 CFX_ByteString& sFontName,
307 uint8_t nCharset) {
308 if (IsStandardFont(sFontName))
309 return AddStandardFont(pDoc, sFontName);
310
311 return AddSystemFont(pDoc, sFontName, nCharset);
312}
313
314CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc,
315 CFX_ByteString& sFontName) {
316 if (!pDoc)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700317 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318
319 CPDF_Font* pFont = NULL;
320
321 if (sFontName == "ZapfDingbats")
322 pFont = pDoc->AddStandardFont(sFontName, NULL);
323 else {
324 CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI);
325 pFont = pDoc->AddStandardFont(sFontName, &fe);
326 }
327
328 return pFont;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700329}
330
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc,
332 CFX_ByteString& sFontName,
333 uint8_t nCharset) {
334 if (!pDoc)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700335 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336
337 if (sFontName.IsEmpty())
338 sFontName = GetNativeFont(nCharset);
339 if (nCharset == DEFAULT_CHARSET)
340 nCharset = GetNativeCharset();
341
342 if (m_pSystemHandler)
343 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName,
344 nCharset);
345
346 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700347}
348
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName,
350 int32_t nCharset) {
351 CFX_ByteString sPostfix;
352 sPostfix.Format("_%02X", nCharset);
353 return EncodeFontAlias(sFontName) + sPostfix;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700354}
355
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) {
357 CFX_ByteString sRet = sFontName;
358 sRet.Remove(' ');
359 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700360}
361
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362int32_t CPWL_FontMap::GetFontMapCount() const {
363 return m_aData.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700364}
365
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const {
367 if (nIndex >= 0 && nIndex < m_aData.GetSize()) {
368 return m_aData.GetAt(nIndex);
369 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700370
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700372}
373
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374int32_t CPWL_FontMap::GetNativeCharset() {
375 uint8_t nCharset = ANSI_CHARSET;
376 int32_t iCodePage = FXSYS_GetACP();
377 switch (iCodePage) {
378 case 932: // Japan
379 nCharset = SHIFTJIS_CHARSET;
380 break;
381 case 936: // Chinese (PRC, Singapore)
382 nCharset = GB2312_CHARSET;
383 break;
384 case 950: // Chinese (Taiwan; Hong Kong SAR, PRC)
385 nCharset = GB2312_CHARSET;
386 break;
387 case 1252: // Windows 3.1 Latin 1 (US, Western Europe)
388 nCharset = ANSI_CHARSET;
389 break;
390 case 874: // Thai
391 nCharset = THAI_CHARSET;
392 break;
393 case 949: // Korean
394 nCharset = HANGUL_CHARSET;
395 break;
396 case 1200: // Unicode (BMP of ISO 10646)
397 nCharset = ANSI_CHARSET;
398 break;
399 case 1250: // Windows 3.1 Eastern European
400 nCharset = EASTEUROPE_CHARSET;
401 break;
402 case 1251: // Windows 3.1 Cyrillic
403 nCharset = RUSSIAN_CHARSET;
404 break;
405 case 1253: // Windows 3.1 Greek
406 nCharset = GREEK_CHARSET;
407 break;
408 case 1254: // Windows 3.1 Turkish
409 nCharset = TURKISH_CHARSET;
410 break;
411 case 1255: // Hebrew
412 nCharset = HEBREW_CHARSET;
413 break;
414 case 1256: // Arabic
415 nCharset = ARABIC_CHARSET;
416 break;
417 case 1257: // Baltic
418 nCharset = BALTIC_CHARSET;
419 break;
420 case 1258: // Vietnamese
421 nCharset = VIETNAMESE_CHARSET;
422 break;
423 case 1361: // Korean(Johab)
424 nCharset = JOHAB_CHARSET;
425 break;
426 }
427 return nCharset;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700428}
429
430const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 {ANSI_CHARSET, "Helvetica"}, {GB2312_CHARSET, "SimSun"},
432 {CHINESEBIG5_CHARSET, "MingLiU"}, {SHIFTJIS_CHARSET, "MS Gothic"},
433 {HANGUL_CHARSET, "Batang"}, {RUSSIAN_CHARSET, "Arial"},
434#if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \
435 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
436 {EASTEUROPE_CHARSET, "Arial"},
Bo Xudbd4c062014-05-29 11:32:56 -0700437#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438 {EASTEUROPE_CHARSET, "Tahoma"},
Bo Xudbd4c062014-05-29 11:32:56 -0700439#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 {ARABIC_CHARSET, "Arial"}, {-1, NULL}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700441
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) {
443 int i = 0;
444 while (defaultTTFMap[i].charset != -1) {
445 if (nCharset == defaultTTFMap[i].charset)
446 return defaultTTFMap[i].fontname;
447 ++i;
448 }
449 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700450}
451
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452int32_t CPWL_FontMap::CharSetFromUnicode(FX_WORD word, int32_t nOldCharset) {
453 if (m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet()))
454 return m_pSystemHandler->GetCharSet();
455 // to avoid CJK Font to show ASCII
456 if (word < 0x7F)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700457 return ANSI_CHARSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 // 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;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700505}
506
507/* ------------------------ CPWL_DocFontMap ------------------------ */
508
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509CPWL_DocFontMap::CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler,
510 CPDF_Document* pAttachedDoc)
511 : CPWL_FontMap(pSystemHandler), m_pAttachedDoc(pAttachedDoc) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700512
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513CPWL_DocFontMap::~CPWL_DocFontMap() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700514
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515CPDF_Document* CPWL_DocFontMap::GetDocument() {
516 return m_pAttachedDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700517}