blob: 3f149e7193ae0af559696ebfc04743fedefbe312 [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
dan sinclair89e904b2016-03-23 19:29:15 -04007#include "fpdfsdk/pdfwindow/PWL_FontMap.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
dan sinclair61b2fc72016-03-23 19:21:44 -04009#include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
10#include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -040011#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
12#include "core/fpdfapi/include/cpdf_modulemgr.h"
dan sinclair89e904b2016-03-23 19:29:15 -040013#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014
Lei Zhang1b976642016-01-08 14:24:37 -080015namespace {
16
17const char kDefaultFontName[] = "Helvetica";
18
19const char* const g_sDEStandardFontName[] = {"Courier",
20 "Courier-Bold",
21 "Courier-BoldOblique",
22 "Courier-Oblique",
23 "Helvetica",
24 "Helvetica-Bold",
25 "Helvetica-BoldOblique",
26 "Helvetica-Oblique",
27 "Times-Roman",
28 "Times-Bold",
29 "Times-Italic",
30 "Times-BoldItalic",
31 "Symbol",
32 "ZapfDingbats"};
33
34} // namespace
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler)
37 : m_pPDFDoc(NULL), m_pSystemHandler(pSystemHandler) {
Lei Zhang96660d62015-12-14 18:27:25 -080038 ASSERT(m_pSystemHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039}
40
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041CPWL_FontMap::~CPWL_FontMap() {
42 delete m_pPDFDoc;
43 m_pPDFDoc = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 Empty();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046}
47
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler) {
49 m_pSystemHandler = pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050}
51
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052CPDF_Document* CPWL_FontMap::GetDocument() {
53 if (!m_pPDFDoc) {
54 if (CPDF_ModuleMgr::Get()) {
Tom Sepezae51c812015-08-05 12:34:06 -070055 m_pPDFDoc = new CPDF_Document;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 m_pPDFDoc->CreateNewDoc();
57 }
58 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060 return m_pPDFDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070061}
62
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) {
64 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
65 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
66 return pData->pFont;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070067 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071}
72
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
74 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
75 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
76 return pData->sFontName;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070077 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070079
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081}
82
Tom Sepez62a70f92016-03-21 15:00:20 -070083FX_BOOL CPWL_FontMap::KnowWord(int32_t nFontIndex, uint16_t word) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
85 if (m_aData.GetAt(nFontIndex)) {
86 return CharCodeFromUnicode(nFontIndex, word) >= 0;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070087 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070091}
92
Tom Sepez62a70f92016-03-21 15:00:20 -070093int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 int32_t nCharset,
95 int32_t nFontIndex) {
96 if (nFontIndex > 0) {
97 if (KnowWord(nFontIndex, word))
98 return nFontIndex;
99 } else {
100 if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) {
101 if (nCharset == DEFAULT_CHARSET || pData->nCharset == SYMBOL_CHARSET ||
102 nCharset == pData->nCharset) {
103 if (KnowWord(0, word))
104 return 0;
105 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700106 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700108
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109 int32_t nNewFontIndex =
110 GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE);
111 if (nNewFontIndex >= 0) {
112 if (KnowWord(nNewFontIndex, word))
113 return nNewFontIndex;
114 }
115 nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE);
116 if (nNewFontIndex >= 0) {
117 if (KnowWord(nNewFontIndex, word))
118 return nNewFontIndex;
119 }
120 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121}
122
Tom Sepez62a70f92016-03-21 15:00:20 -0700123int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
125 if (pData->pFont) {
126 if (pData->pFont->IsUnicodeCompatible()) {
127 int nCharCode = pData->pFont->CharCodeFromUnicode(word);
128 pData->pFont->GlyphFromCharCode(nCharCode);
129 return nCharCode;
130 }
131 if (word < 0xFF)
132 return word;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700133 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134 }
135 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136}
137
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset) {
139 // searching native font is slow, so we must save time
140 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++) {
141 if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i)) {
142 if (pData->nCharset == nCharset)
143 return pData->sFontName;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700144 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700146
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147 CFX_ByteString sNew = GetNativeFont(nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 if (!sNew.IsEmpty()) {
150 CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native;
151 pNewData->nCharset = nCharset;
152 pNewData->sFontName = sNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 m_aNativeFont.Add(pNewData);
155 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 return sNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700158}
159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160void CPWL_FontMap::Empty() {
161 {
162 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++)
163 delete m_aData.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 m_aData.RemoveAll();
166 }
167 {
168 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++)
169 delete m_aNativeFont.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700170
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 m_aNativeFont.RemoveAll();
172 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700173}
174
Lei Zhangfcfa3b82015-12-24 21:07:28 -0800175void CPWL_FontMap::Initialize() {
Lei Zhang1b976642016-01-08 14:24:37 -0800176 GetFontIndex(kDefaultFontName, ANSI_CHARSET, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700177}
Lei Zhang60f507b2015-06-13 00:41:00 -0700178
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) {
Wei Li89409932016-03-28 10:33:33 -0700180 for (size_t i = 0; i < FX_ArraySize(g_sDEStandardFontName); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 if (sFontName == g_sDEStandardFontName[i])
182 return TRUE;
183 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700186}
187
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188int32_t CPWL_FontMap::FindFont(const CFX_ByteString& sFontName,
189 int32_t nCharset) {
190 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++) {
191 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) {
192 if (nCharset == DEFAULT_CHARSET || nCharset == pData->nCharset) {
193 if (sFontName.IsEmpty() || pData->sFontName == sFontName)
194 return i;
195 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700196 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700198
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 return -1;
200}
201
202int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName,
203 int32_t nCharset,
204 FX_BOOL bFind) {
205 int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset);
206 if (nFontIndex >= 0)
207 return nFontIndex;
208
209 CFX_ByteString sAlias;
210 CPDF_Font* pFont = NULL;
211 if (bFind)
212 pFont = FindFontSameCharset(sAlias, nCharset);
213
214 if (!pFont) {
215 CFX_ByteString sTemp = sFontName;
216 pFont = AddFontToDocument(GetDocument(), sTemp, nCharset);
217 sAlias = EncodeFontAlias(sTemp, nCharset);
218 }
219 AddedFont(pFont, sAlias);
220 return AddFontData(pFont, sAlias, nCharset);
221}
222
Tom Sepez62a70f92016-03-21 15:00:20 -0700223int32_t CPWL_FontMap::GetPWLFontIndex(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 int32_t nFind = -1;
225
226 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++) {
227 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) {
228 if (pData->nCharset == nCharset) {
229 nFind = i;
230 break;
231 }
232 }
233 }
234
235 CPDF_Font* pNewFont = GetPDFFont(nFind);
236
237 if (!pNewFont)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700238 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset);
241 AddedFont(pNewFont, sAlias);
242
243 return AddFontData(pNewFont, sAlias, nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244}
245
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias,
247 int32_t nCharset) {
248 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700249}
250
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251int32_t CPWL_FontMap::AddFontData(CPDF_Font* pFont,
252 const CFX_ByteString& sFontAlias,
253 int32_t nCharset) {
254 CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data;
255 pNewData->pFont = pFont;
256 pNewData->sFontName = sFontAlias;
257 pNewData->nCharset = nCharset;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700258
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259 m_aData.Add(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 return m_aData.GetSize() - 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262}
263
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264void CPWL_FontMap::AddedFont(CPDF_Font* pFont,
265 const CFX_ByteString& sFontAlias) {}
266
267CFX_ByteString CPWL_FontMap::GetFontName(int32_t nFontIndex) {
268 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
269 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
270 return pData->sFontName;
271 }
272 }
273
274 return "";
275}
276
277CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) {
278 if (nCharset == DEFAULT_CHARSET)
279 nCharset = GetNativeCharset();
280
281 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset);
282 if (m_pSystemHandler) {
283 if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName))
284 return sFontName;
285
286 sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset);
287 }
288 return sFontName;
289}
290
291CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc,
292 CFX_ByteString& sFontName,
293 uint8_t nCharset) {
294 if (IsStandardFont(sFontName))
295 return AddStandardFont(pDoc, sFontName);
296
297 return AddSystemFont(pDoc, sFontName, nCharset);
298}
299
300CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc,
301 CFX_ByteString& sFontName) {
302 if (!pDoc)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700303 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304
305 CPDF_Font* pFont = NULL;
306
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800307 if (sFontName == "ZapfDingbats") {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700308 pFont = pDoc->AddStandardFont(sFontName, NULL);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800309 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI);
311 pFont = pDoc->AddStandardFont(sFontName, &fe);
312 }
313
314 return pFont;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700315}
316
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc,
318 CFX_ByteString& sFontName,
319 uint8_t nCharset) {
320 if (!pDoc)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700321 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322
323 if (sFontName.IsEmpty())
324 sFontName = GetNativeFont(nCharset);
325 if (nCharset == DEFAULT_CHARSET)
326 nCharset = GetNativeCharset();
327
328 if (m_pSystemHandler)
329 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName,
330 nCharset);
331
332 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700333}
334
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName,
336 int32_t nCharset) {
337 CFX_ByteString sPostfix;
338 sPostfix.Format("_%02X", nCharset);
339 return EncodeFontAlias(sFontName) + sPostfix;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700340}
341
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) {
343 CFX_ByteString sRet = sFontName;
344 sRet.Remove(' ');
345 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700346}
347
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348int32_t CPWL_FontMap::GetFontMapCount() const {
349 return m_aData.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700350}
351
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const {
353 if (nIndex >= 0 && nIndex < m_aData.GetSize()) {
354 return m_aData.GetAt(nIndex);
355 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700358}
359
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360int32_t CPWL_FontMap::GetNativeCharset() {
361 uint8_t nCharset = ANSI_CHARSET;
362 int32_t iCodePage = FXSYS_GetACP();
363 switch (iCodePage) {
364 case 932: // Japan
365 nCharset = SHIFTJIS_CHARSET;
366 break;
367 case 936: // Chinese (PRC, Singapore)
368 nCharset = GB2312_CHARSET;
369 break;
370 case 950: // Chinese (Taiwan; Hong Kong SAR, PRC)
371 nCharset = GB2312_CHARSET;
372 break;
373 case 1252: // Windows 3.1 Latin 1 (US, Western Europe)
374 nCharset = ANSI_CHARSET;
375 break;
376 case 874: // Thai
377 nCharset = THAI_CHARSET;
378 break;
379 case 949: // Korean
380 nCharset = HANGUL_CHARSET;
381 break;
382 case 1200: // Unicode (BMP of ISO 10646)
383 nCharset = ANSI_CHARSET;
384 break;
385 case 1250: // Windows 3.1 Eastern European
386 nCharset = EASTEUROPE_CHARSET;
387 break;
388 case 1251: // Windows 3.1 Cyrillic
389 nCharset = RUSSIAN_CHARSET;
390 break;
391 case 1253: // Windows 3.1 Greek
392 nCharset = GREEK_CHARSET;
393 break;
394 case 1254: // Windows 3.1 Turkish
395 nCharset = TURKISH_CHARSET;
396 break;
397 case 1255: // Hebrew
398 nCharset = HEBREW_CHARSET;
399 break;
400 case 1256: // Arabic
401 nCharset = ARABIC_CHARSET;
402 break;
403 case 1257: // Baltic
404 nCharset = BALTIC_CHARSET;
405 break;
406 case 1258: // Vietnamese
407 nCharset = VIETNAMESE_CHARSET;
408 break;
409 case 1361: // Korean(Johab)
410 nCharset = JOHAB_CHARSET;
411 break;
412 }
413 return nCharset;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700414}
415
416const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 {ANSI_CHARSET, "Helvetica"}, {GB2312_CHARSET, "SimSun"},
418 {CHINESEBIG5_CHARSET, "MingLiU"}, {SHIFTJIS_CHARSET, "MS Gothic"},
419 {HANGUL_CHARSET, "Batang"}, {RUSSIAN_CHARSET, "Arial"},
420#if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \
421 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
422 {EASTEUROPE_CHARSET, "Arial"},
Bo Xudbd4c062014-05-29 11:32:56 -0700423#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424 {EASTEUROPE_CHARSET, "Tahoma"},
Bo Xudbd4c062014-05-29 11:32:56 -0700425#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426 {ARABIC_CHARSET, "Arial"}, {-1, NULL}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700427
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) {
429 int i = 0;
430 while (defaultTTFMap[i].charset != -1) {
431 if (nCharset == defaultTTFMap[i].charset)
432 return defaultTTFMap[i].fontname;
433 ++i;
434 }
435 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700436}
437
Tom Sepez62a70f92016-03-21 15:00:20 -0700438int32_t CPWL_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 if (m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet()))
440 return m_pSystemHandler->GetCharSet();
441 // to avoid CJK Font to show ASCII
442 if (word < 0x7F)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700443 return ANSI_CHARSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 // follow the old charset
445 if (nOldCharset != DEFAULT_CHARSET)
446 return nOldCharset;
447
448 // find new charset
449 if ((word >= 0x4E00 && word <= 0x9FA5) ||
450 (word >= 0xE7C7 && word <= 0xE7F3) ||
451 (word >= 0x3000 && word <= 0x303F) ||
452 (word >= 0x2000 && word <= 0x206F)) {
453 return GB2312_CHARSET;
454 }
455
456 if (((word >= 0x3040) && (word <= 0x309F)) ||
457 ((word >= 0x30A0) && (word <= 0x30FF)) ||
458 ((word >= 0x31F0) && (word <= 0x31FF)) ||
459 ((word >= 0xFF00) && (word <= 0xFFEF))) {
460 return SHIFTJIS_CHARSET;
461 }
462
463 if (((word >= 0xAC00) && (word <= 0xD7AF)) ||
464 ((word >= 0x1100) && (word <= 0x11FF)) ||
465 ((word >= 0x3130) && (word <= 0x318F))) {
466 return HANGUL_CHARSET;
467 }
468
469 if (word >= 0x0E00 && word <= 0x0E7F)
470 return THAI_CHARSET;
471
472 if ((word >= 0x0370 && word <= 0x03FF) || (word >= 0x1F00 && word <= 0x1FFF))
473 return GREEK_CHARSET;
474
475 if ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
476 return ARABIC_CHARSET;
477
478 if (word >= 0x0590 && word <= 0x05FF)
479 return HEBREW_CHARSET;
480
481 if (word >= 0x0400 && word <= 0x04FF)
482 return RUSSIAN_CHARSET;
483
484 if (word >= 0x0100 && word <= 0x024F)
485 return EASTEUROPE_CHARSET;
486
487 if (word >= 0x1E00 && word <= 0x1EFF)
488 return VIETNAMESE_CHARSET;
489
490 return ANSI_CHARSET;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700491}
492
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493CPWL_DocFontMap::CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler,
494 CPDF_Document* pAttachedDoc)
495 : CPWL_FontMap(pSystemHandler), m_pAttachedDoc(pAttachedDoc) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700496
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497CPWL_DocFontMap::~CPWL_DocFontMap() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700498
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499CPDF_Document* CPWL_DocFontMap::GetDocument() {
500 return m_pAttachedDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700501}