blob: e418e8b380e2f5bdb5e98cce6a47ceab9242353f [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/PWL_FontMap.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
9#include "core/include/fpdfapi/fpdf_module.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080010#include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070011
Nico Weber9d8ec5a2015-08-04 13:00:21 -070012#define DEFAULT_FONT_NAME "Helvetica"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013
Nico Weber9d8ec5a2015-08-04 13:00:21 -070014CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler)
15 : m_pPDFDoc(NULL), m_pSystemHandler(pSystemHandler) {
Lei Zhang96660d62015-12-14 18:27:25 -080016 ASSERT(m_pSystemHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017}
18
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019CPWL_FontMap::~CPWL_FontMap() {
20 delete m_pPDFDoc;
21 m_pPDFDoc = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023 Empty();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024}
25
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler) {
27 m_pSystemHandler = pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028}
29
Nico Weber9d8ec5a2015-08-04 13:00:21 -070030CPDF_Document* CPWL_FontMap::GetDocument() {
31 if (!m_pPDFDoc) {
32 if (CPDF_ModuleMgr::Get()) {
Tom Sepezae51c812015-08-05 12:34:06 -070033 m_pPDFDoc = new CPDF_Document;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034 m_pPDFDoc->CreateNewDoc();
35 }
36 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038 return m_pPDFDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039}
40
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) {
42 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
43 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
44 return pData->pFont;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070045 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049}
50
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
52 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
53 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
54 return pData->sFontName;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070055 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059}
60
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061FX_BOOL CPWL_FontMap::KnowWord(int32_t nFontIndex, FX_WORD word) {
62 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
63 if (m_aData.GetAt(nFontIndex)) {
64 return CharCodeFromUnicode(nFontIndex, word) >= 0;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070065 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070067
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069}
70
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071int32_t CPWL_FontMap::GetWordFontIndex(FX_WORD word,
72 int32_t nCharset,
73 int32_t nFontIndex) {
74 if (nFontIndex > 0) {
75 if (KnowWord(nFontIndex, word))
76 return nFontIndex;
77 } else {
78 if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) {
79 if (nCharset == DEFAULT_CHARSET || pData->nCharset == SYMBOL_CHARSET ||
80 nCharset == pData->nCharset) {
81 if (KnowWord(0, word))
82 return 0;
83 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -070084 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 int32_t nNewFontIndex =
88 GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE);
89 if (nNewFontIndex >= 0) {
90 if (KnowWord(nNewFontIndex, word))
91 return nNewFontIndex;
92 }
93 nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE);
94 if (nNewFontIndex >= 0) {
95 if (KnowWord(nNewFontIndex, word))
96 return nNewFontIndex;
97 }
98 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099}
100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, FX_WORD word) {
102 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
103 if (pData->pFont) {
104 if (pData->pFont->IsUnicodeCompatible()) {
105 int nCharCode = pData->pFont->CharCodeFromUnicode(word);
106 pData->pFont->GlyphFromCharCode(nCharCode);
107 return nCharCode;
108 }
109 if (word < 0xFF)
110 return word;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700111 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 }
113 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114}
115
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset) {
117 // searching native font is slow, so we must save time
118 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++) {
119 if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i)) {
120 if (pData->nCharset == nCharset)
121 return pData->sFontName;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700122 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700124
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 CFX_ByteString sNew = GetNativeFont(nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700126
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 if (!sNew.IsEmpty()) {
128 CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native;
129 pNewData->nCharset = nCharset;
130 pNewData->sFontName = sNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700131
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 m_aNativeFont.Add(pNewData);
133 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 return sNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136}
137
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138void CPWL_FontMap::Empty() {
139 {
140 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++)
141 delete m_aData.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700142
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 m_aData.RemoveAll();
144 }
145 {
146 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++)
147 delete m_aNativeFont.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 m_aNativeFont.RemoveAll();
150 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700151}
152
Lei Zhangfcfa3b82015-12-24 21:07:28 -0800153void CPWL_FontMap::Initialize() {
154 GetFontIndex(DEFAULT_FONT_NAME, ANSI_CHARSET, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700155}
Lei Zhang60f507b2015-06-13 00:41:00 -0700156
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700157/*
158List of currently supported standard fonts:
159Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique
160Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique
161Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
162Symbol, ZapfDingbats
163*/
164
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165const char* g_sDEStandardFontName[] = {"Courier",
166 "Courier-Bold",
167 "Courier-BoldOblique",
168 "Courier-Oblique",
169 "Helvetica",
170 "Helvetica-Bold",
171 "Helvetica-BoldOblique",
172 "Helvetica-Oblique",
173 "Times-Roman",
174 "Times-Bold",
175 "Times-Italic",
176 "Times-BoldItalic",
177 "Symbol",
178 "ZapfDingbats"};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) {
181 for (int32_t i = 0; i < 14; i++) {
182 if (sFontName == g_sDEStandardFontName[i])
183 return TRUE;
184 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700185
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700187}
188
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189int32_t CPWL_FontMap::FindFont(const CFX_ByteString& sFontName,
190 int32_t nCharset) {
191 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++) {
192 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) {
193 if (nCharset == DEFAULT_CHARSET || nCharset == pData->nCharset) {
194 if (sFontName.IsEmpty() || pData->sFontName == sFontName)
195 return i;
196 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700197 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 return -1;
201}
202
203int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName,
204 int32_t nCharset,
205 FX_BOOL bFind) {
206 int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset);
207 if (nFontIndex >= 0)
208 return nFontIndex;
209
210 CFX_ByteString sAlias;
211 CPDF_Font* pFont = NULL;
212 if (bFind)
213 pFont = FindFontSameCharset(sAlias, nCharset);
214
215 if (!pFont) {
216 CFX_ByteString sTemp = sFontName;
217 pFont = AddFontToDocument(GetDocument(), sTemp, nCharset);
218 sAlias = EncodeFontAlias(sTemp, nCharset);
219 }
220 AddedFont(pFont, sAlias);
221 return AddFontData(pFont, sAlias, nCharset);
222}
223
224int32_t CPWL_FontMap::GetPWLFontIndex(FX_WORD word, int32_t nCharset) {
225 int32_t nFind = -1;
226
227 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++) {
228 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) {
229 if (pData->nCharset == nCharset) {
230 nFind = i;
231 break;
232 }
233 }
234 }
235
236 CPDF_Font* pNewFont = GetPDFFont(nFind);
237
238 if (!pNewFont)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700239 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700241 CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset);
242 AddedFont(pNewFont, sAlias);
243
244 return AddFontData(pNewFont, sAlias, nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245}
246
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias,
248 int32_t nCharset) {
249 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700250}
251
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252int32_t CPWL_FontMap::AddFontData(CPDF_Font* pFont,
253 const CFX_ByteString& sFontAlias,
254 int32_t nCharset) {
255 CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data;
256 pNewData->pFont = pFont;
257 pNewData->sFontName = sFontAlias;
258 pNewData->nCharset = nCharset;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700259
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 m_aData.Add(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700261
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 return m_aData.GetSize() - 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700263}
264
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265void CPWL_FontMap::AddedFont(CPDF_Font* pFont,
266 const CFX_ByteString& sFontAlias) {}
267
268CFX_ByteString CPWL_FontMap::GetFontName(int32_t nFontIndex) {
269 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
270 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
271 return pData->sFontName;
272 }
273 }
274
275 return "";
276}
277
278CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) {
279 if (nCharset == DEFAULT_CHARSET)
280 nCharset = GetNativeCharset();
281
282 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset);
283 if (m_pSystemHandler) {
284 if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName))
285 return sFontName;
286
287 sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset);
288 }
289 return sFontName;
290}
291
292CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc,
293 CFX_ByteString& sFontName,
294 uint8_t nCharset) {
295 if (IsStandardFont(sFontName))
296 return AddStandardFont(pDoc, sFontName);
297
298 return AddSystemFont(pDoc, sFontName, nCharset);
299}
300
301CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc,
302 CFX_ByteString& sFontName) {
303 if (!pDoc)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700304 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305
306 CPDF_Font* pFont = NULL;
307
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800308 if (sFontName == "ZapfDingbats") {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 pFont = pDoc->AddStandardFont(sFontName, NULL);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800310 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311 CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI);
312 pFont = pDoc->AddStandardFont(sFontName, &fe);
313 }
314
315 return pFont;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700316}
317
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc,
319 CFX_ByteString& sFontName,
320 uint8_t nCharset) {
321 if (!pDoc)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700322 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323
324 if (sFontName.IsEmpty())
325 sFontName = GetNativeFont(nCharset);
326 if (nCharset == DEFAULT_CHARSET)
327 nCharset = GetNativeCharset();
328
329 if (m_pSystemHandler)
330 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName,
331 nCharset);
332
333 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700334}
335
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName,
337 int32_t nCharset) {
338 CFX_ByteString sPostfix;
339 sPostfix.Format("_%02X", nCharset);
340 return EncodeFontAlias(sFontName) + sPostfix;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700341}
342
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) {
344 CFX_ByteString sRet = sFontName;
345 sRet.Remove(' ');
346 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700347}
348
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349int32_t CPWL_FontMap::GetFontMapCount() const {
350 return m_aData.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700351}
352
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const {
354 if (nIndex >= 0 && nIndex < m_aData.GetSize()) {
355 return m_aData.GetAt(nIndex);
356 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700357
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700359}
360
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361int32_t CPWL_FontMap::GetNativeCharset() {
362 uint8_t nCharset = ANSI_CHARSET;
363 int32_t iCodePage = FXSYS_GetACP();
364 switch (iCodePage) {
365 case 932: // Japan
366 nCharset = SHIFTJIS_CHARSET;
367 break;
368 case 936: // Chinese (PRC, Singapore)
369 nCharset = GB2312_CHARSET;
370 break;
371 case 950: // Chinese (Taiwan; Hong Kong SAR, PRC)
372 nCharset = GB2312_CHARSET;
373 break;
374 case 1252: // Windows 3.1 Latin 1 (US, Western Europe)
375 nCharset = ANSI_CHARSET;
376 break;
377 case 874: // Thai
378 nCharset = THAI_CHARSET;
379 break;
380 case 949: // Korean
381 nCharset = HANGUL_CHARSET;
382 break;
383 case 1200: // Unicode (BMP of ISO 10646)
384 nCharset = ANSI_CHARSET;
385 break;
386 case 1250: // Windows 3.1 Eastern European
387 nCharset = EASTEUROPE_CHARSET;
388 break;
389 case 1251: // Windows 3.1 Cyrillic
390 nCharset = RUSSIAN_CHARSET;
391 break;
392 case 1253: // Windows 3.1 Greek
393 nCharset = GREEK_CHARSET;
394 break;
395 case 1254: // Windows 3.1 Turkish
396 nCharset = TURKISH_CHARSET;
397 break;
398 case 1255: // Hebrew
399 nCharset = HEBREW_CHARSET;
400 break;
401 case 1256: // Arabic
402 nCharset = ARABIC_CHARSET;
403 break;
404 case 1257: // Baltic
405 nCharset = BALTIC_CHARSET;
406 break;
407 case 1258: // Vietnamese
408 nCharset = VIETNAMESE_CHARSET;
409 break;
410 case 1361: // Korean(Johab)
411 nCharset = JOHAB_CHARSET;
412 break;
413 }
414 return nCharset;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700415}
416
417const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 {ANSI_CHARSET, "Helvetica"}, {GB2312_CHARSET, "SimSun"},
419 {CHINESEBIG5_CHARSET, "MingLiU"}, {SHIFTJIS_CHARSET, "MS Gothic"},
420 {HANGUL_CHARSET, "Batang"}, {RUSSIAN_CHARSET, "Arial"},
421#if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \
422 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
423 {EASTEUROPE_CHARSET, "Arial"},
Bo Xudbd4c062014-05-29 11:32:56 -0700424#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 {EASTEUROPE_CHARSET, "Tahoma"},
Bo Xudbd4c062014-05-29 11:32:56 -0700426#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 {ARABIC_CHARSET, "Arial"}, {-1, NULL}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700428
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) {
430 int i = 0;
431 while (defaultTTFMap[i].charset != -1) {
432 if (nCharset == defaultTTFMap[i].charset)
433 return defaultTTFMap[i].fontname;
434 ++i;
435 }
436 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700437}
438
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439int32_t CPWL_FontMap::CharSetFromUnicode(FX_WORD word, int32_t nOldCharset) {
440 if (m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet()))
441 return m_pSystemHandler->GetCharSet();
442 // to avoid CJK Font to show ASCII
443 if (word < 0x7F)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700444 return ANSI_CHARSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445 // follow the old charset
446 if (nOldCharset != DEFAULT_CHARSET)
447 return nOldCharset;
448
449 // find new charset
450 if ((word >= 0x4E00 && word <= 0x9FA5) ||
451 (word >= 0xE7C7 && word <= 0xE7F3) ||
452 (word >= 0x3000 && word <= 0x303F) ||
453 (word >= 0x2000 && word <= 0x206F)) {
454 return GB2312_CHARSET;
455 }
456
457 if (((word >= 0x3040) && (word <= 0x309F)) ||
458 ((word >= 0x30A0) && (word <= 0x30FF)) ||
459 ((word >= 0x31F0) && (word <= 0x31FF)) ||
460 ((word >= 0xFF00) && (word <= 0xFFEF))) {
461 return SHIFTJIS_CHARSET;
462 }
463
464 if (((word >= 0xAC00) && (word <= 0xD7AF)) ||
465 ((word >= 0x1100) && (word <= 0x11FF)) ||
466 ((word >= 0x3130) && (word <= 0x318F))) {
467 return HANGUL_CHARSET;
468 }
469
470 if (word >= 0x0E00 && word <= 0x0E7F)
471 return THAI_CHARSET;
472
473 if ((word >= 0x0370 && word <= 0x03FF) || (word >= 0x1F00 && word <= 0x1FFF))
474 return GREEK_CHARSET;
475
476 if ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
477 return ARABIC_CHARSET;
478
479 if (word >= 0x0590 && word <= 0x05FF)
480 return HEBREW_CHARSET;
481
482 if (word >= 0x0400 && word <= 0x04FF)
483 return RUSSIAN_CHARSET;
484
485 if (word >= 0x0100 && word <= 0x024F)
486 return EASTEUROPE_CHARSET;
487
488 if (word >= 0x1E00 && word <= 0x1EFF)
489 return VIETNAMESE_CHARSET;
490
491 return ANSI_CHARSET;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700492}
493
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494CPWL_DocFontMap::CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler,
495 CPDF_Document* pAttachedDoc)
496 : CPWL_FontMap(pSystemHandler), m_pAttachedDoc(pAttachedDoc) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700497
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498CPWL_DocFontMap::~CPWL_DocFontMap() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700499
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500CPDF_Document* CPWL_DocFontMap::GetDocument() {
501 return m_pAttachedDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700502}