blob: 1ac55bcb6ebf2d298b50ab21cee122320e965815 [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
Dan Sinclairaa403d32016-03-15 14:57:22 -04009#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
10#include "core/fpdfapi/include/cpdf_modulemgr.h"
Dan Sinclair455a4192016-03-16 09:48:56 -040011#include "core/include/fpdfapi/fpdf_resource.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080012#include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013
Lei Zhang1b976642016-01-08 14:24:37 -080014namespace {
15
16const char kDefaultFontName[] = "Helvetica";
17
18const char* const g_sDEStandardFontName[] = {"Courier",
19 "Courier-Bold",
20 "Courier-BoldOblique",
21 "Courier-Oblique",
22 "Helvetica",
23 "Helvetica-Bold",
24 "Helvetica-BoldOblique",
25 "Helvetica-Oblique",
26 "Times-Roman",
27 "Times-Bold",
28 "Times-Italic",
29 "Times-BoldItalic",
30 "Symbol",
31 "ZapfDingbats"};
32
33} // namespace
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler)
36 : m_pPDFDoc(NULL), m_pSystemHandler(pSystemHandler) {
Lei Zhang96660d62015-12-14 18:27:25 -080037 ASSERT(m_pSystemHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038}
39
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040CPWL_FontMap::~CPWL_FontMap() {
41 delete m_pPDFDoc;
42 m_pPDFDoc = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 Empty();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045}
46
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler) {
48 m_pSystemHandler = pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049}
50
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051CPDF_Document* CPWL_FontMap::GetDocument() {
52 if (!m_pPDFDoc) {
53 if (CPDF_ModuleMgr::Get()) {
Tom Sepezae51c812015-08-05 12:34:06 -070054 m_pPDFDoc = new CPDF_Document;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 m_pPDFDoc->CreateNewDoc();
56 }
57 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 return m_pPDFDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060}
61
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) {
63 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
64 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
65 return pData->pFont;
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 NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070}
71
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
73 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
74 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
75 return pData->sFontName;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070076 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080}
81
Tom Sepez62a70f92016-03-21 15:00:20 -070082FX_BOOL CPWL_FontMap::KnowWord(int32_t nFontIndex, uint16_t word) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
84 if (m_aData.GetAt(nFontIndex)) {
85 return CharCodeFromUnicode(nFontIndex, word) >= 0;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070086 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070088
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090}
91
Tom Sepez62a70f92016-03-21 15:00:20 -070092int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 int32_t nCharset,
94 int32_t nFontIndex) {
95 if (nFontIndex > 0) {
96 if (KnowWord(nFontIndex, word))
97 return nFontIndex;
98 } else {
99 if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) {
100 if (nCharset == DEFAULT_CHARSET || pData->nCharset == SYMBOL_CHARSET ||
101 nCharset == pData->nCharset) {
102 if (KnowWord(0, word))
103 return 0;
104 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700105 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 int32_t nNewFontIndex =
109 GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE);
110 if (nNewFontIndex >= 0) {
111 if (KnowWord(nNewFontIndex, word))
112 return nNewFontIndex;
113 }
114 nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE);
115 if (nNewFontIndex >= 0) {
116 if (KnowWord(nNewFontIndex, word))
117 return nNewFontIndex;
118 }
119 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120}
121
Tom Sepez62a70f92016-03-21 15:00:20 -0700122int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
124 if (pData->pFont) {
125 if (pData->pFont->IsUnicodeCompatible()) {
126 int nCharCode = pData->pFont->CharCodeFromUnicode(word);
127 pData->pFont->GlyphFromCharCode(nCharCode);
128 return nCharCode;
129 }
130 if (word < 0xFF)
131 return word;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700132 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 }
134 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135}
136
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset) {
138 // searching native font is slow, so we must save time
139 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++) {
140 if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i)) {
141 if (pData->nCharset == nCharset)
142 return pData->sFontName;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700143 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 CFX_ByteString sNew = GetNativeFont(nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700147
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 if (!sNew.IsEmpty()) {
149 CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native;
150 pNewData->nCharset = nCharset;
151 pNewData->sFontName = sNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700152
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153 m_aNativeFont.Add(pNewData);
154 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700155
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 return sNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700157}
158
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159void CPWL_FontMap::Empty() {
160 {
161 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++)
162 delete m_aData.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 m_aData.RemoveAll();
165 }
166 {
167 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++)
168 delete m_aNativeFont.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700169
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 m_aNativeFont.RemoveAll();
171 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700172}
173
Lei Zhangfcfa3b82015-12-24 21:07:28 -0800174void CPWL_FontMap::Initialize() {
Lei Zhang1b976642016-01-08 14:24:37 -0800175 GetFontIndex(kDefaultFontName, ANSI_CHARSET, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700176}
Lei Zhang60f507b2015-06-13 00:41:00 -0700177
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) {
Lei Zhang1b976642016-01-08 14:24:37 -0800179 for (int32_t i = 0; i < FX_ArraySize(g_sDEStandardFontName); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 if (sFontName == g_sDEStandardFontName[i])
181 return TRUE;
182 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700183
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700185}
186
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187int32_t CPWL_FontMap::FindFont(const CFX_ByteString& sFontName,
188 int32_t nCharset) {
189 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++) {
190 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) {
191 if (nCharset == DEFAULT_CHARSET || nCharset == pData->nCharset) {
192 if (sFontName.IsEmpty() || pData->sFontName == sFontName)
193 return i;
194 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700195 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700197
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 return -1;
199}
200
201int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName,
202 int32_t nCharset,
203 FX_BOOL bFind) {
204 int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset);
205 if (nFontIndex >= 0)
206 return nFontIndex;
207
208 CFX_ByteString sAlias;
209 CPDF_Font* pFont = NULL;
210 if (bFind)
211 pFont = FindFontSameCharset(sAlias, nCharset);
212
213 if (!pFont) {
214 CFX_ByteString sTemp = sFontName;
215 pFont = AddFontToDocument(GetDocument(), sTemp, nCharset);
216 sAlias = EncodeFontAlias(sTemp, nCharset);
217 }
218 AddedFont(pFont, sAlias);
219 return AddFontData(pFont, sAlias, nCharset);
220}
221
Tom Sepez62a70f92016-03-21 15:00:20 -0700222int32_t CPWL_FontMap::GetPWLFontIndex(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223 int32_t nFind = -1;
224
225 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++) {
226 if (CPWL_FontMap_Data* pData = m_aData.GetAt(i)) {
227 if (pData->nCharset == nCharset) {
228 nFind = i;
229 break;
230 }
231 }
232 }
233
234 CPDF_Font* pNewFont = GetPDFFont(nFind);
235
236 if (!pNewFont)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700237 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239 CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset);
240 AddedFont(pNewFont, sAlias);
241
242 return AddFontData(pNewFont, sAlias, nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243}
244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias,
246 int32_t nCharset) {
247 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700248}
249
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250int32_t CPWL_FontMap::AddFontData(CPDF_Font* pFont,
251 const CFX_ByteString& sFontAlias,
252 int32_t nCharset) {
253 CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data;
254 pNewData->pFont = pFont;
255 pNewData->sFontName = sFontAlias;
256 pNewData->nCharset = nCharset;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700257
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258 m_aData.Add(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700259
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 return m_aData.GetSize() - 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700261}
262
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263void CPWL_FontMap::AddedFont(CPDF_Font* pFont,
264 const CFX_ByteString& sFontAlias) {}
265
266CFX_ByteString CPWL_FontMap::GetFontName(int32_t nFontIndex) {
267 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
268 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
269 return pData->sFontName;
270 }
271 }
272
273 return "";
274}
275
276CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) {
277 if (nCharset == DEFAULT_CHARSET)
278 nCharset = GetNativeCharset();
279
280 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset);
281 if (m_pSystemHandler) {
282 if (m_pSystemHandler->FindNativeTrueTypeFont(nCharset, sFontName))
283 return sFontName;
284
285 sFontName = m_pSystemHandler->GetNativeTrueTypeFont(nCharset);
286 }
287 return sFontName;
288}
289
290CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc,
291 CFX_ByteString& sFontName,
292 uint8_t nCharset) {
293 if (IsStandardFont(sFontName))
294 return AddStandardFont(pDoc, sFontName);
295
296 return AddSystemFont(pDoc, sFontName, nCharset);
297}
298
299CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc,
300 CFX_ByteString& sFontName) {
301 if (!pDoc)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700302 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303
304 CPDF_Font* pFont = NULL;
305
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800306 if (sFontName == "ZapfDingbats") {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 pFont = pDoc->AddStandardFont(sFontName, NULL);
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800308 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI);
310 pFont = pDoc->AddStandardFont(sFontName, &fe);
311 }
312
313 return pFont;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700314}
315
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc,
317 CFX_ByteString& sFontName,
318 uint8_t nCharset) {
319 if (!pDoc)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700320 return NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321
322 if (sFontName.IsEmpty())
323 sFontName = GetNativeFont(nCharset);
324 if (nCharset == DEFAULT_CHARSET)
325 nCharset = GetNativeCharset();
326
327 if (m_pSystemHandler)
328 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName,
329 nCharset);
330
331 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700332}
333
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName,
335 int32_t nCharset) {
336 CFX_ByteString sPostfix;
337 sPostfix.Format("_%02X", nCharset);
338 return EncodeFontAlias(sFontName) + sPostfix;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700339}
340
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) {
342 CFX_ByteString sRet = sFontName;
343 sRet.Remove(' ');
344 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700345}
346
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700347int32_t CPWL_FontMap::GetFontMapCount() const {
348 return m_aData.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700349}
350
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700351const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const {
352 if (nIndex >= 0 && nIndex < m_aData.GetSize()) {
353 return m_aData.GetAt(nIndex);
354 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700355
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700357}
358
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359int32_t CPWL_FontMap::GetNativeCharset() {
360 uint8_t nCharset = ANSI_CHARSET;
361 int32_t iCodePage = FXSYS_GetACP();
362 switch (iCodePage) {
363 case 932: // Japan
364 nCharset = SHIFTJIS_CHARSET;
365 break;
366 case 936: // Chinese (PRC, Singapore)
367 nCharset = GB2312_CHARSET;
368 break;
369 case 950: // Chinese (Taiwan; Hong Kong SAR, PRC)
370 nCharset = GB2312_CHARSET;
371 break;
372 case 1252: // Windows 3.1 Latin 1 (US, Western Europe)
373 nCharset = ANSI_CHARSET;
374 break;
375 case 874: // Thai
376 nCharset = THAI_CHARSET;
377 break;
378 case 949: // Korean
379 nCharset = HANGUL_CHARSET;
380 break;
381 case 1200: // Unicode (BMP of ISO 10646)
382 nCharset = ANSI_CHARSET;
383 break;
384 case 1250: // Windows 3.1 Eastern European
385 nCharset = EASTEUROPE_CHARSET;
386 break;
387 case 1251: // Windows 3.1 Cyrillic
388 nCharset = RUSSIAN_CHARSET;
389 break;
390 case 1253: // Windows 3.1 Greek
391 nCharset = GREEK_CHARSET;
392 break;
393 case 1254: // Windows 3.1 Turkish
394 nCharset = TURKISH_CHARSET;
395 break;
396 case 1255: // Hebrew
397 nCharset = HEBREW_CHARSET;
398 break;
399 case 1256: // Arabic
400 nCharset = ARABIC_CHARSET;
401 break;
402 case 1257: // Baltic
403 nCharset = BALTIC_CHARSET;
404 break;
405 case 1258: // Vietnamese
406 nCharset = VIETNAMESE_CHARSET;
407 break;
408 case 1361: // Korean(Johab)
409 nCharset = JOHAB_CHARSET;
410 break;
411 }
412 return nCharset;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700413}
414
415const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416 {ANSI_CHARSET, "Helvetica"}, {GB2312_CHARSET, "SimSun"},
417 {CHINESEBIG5_CHARSET, "MingLiU"}, {SHIFTJIS_CHARSET, "MS Gothic"},
418 {HANGUL_CHARSET, "Batang"}, {RUSSIAN_CHARSET, "Arial"},
419#if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \
420 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
421 {EASTEUROPE_CHARSET, "Arial"},
Bo Xudbd4c062014-05-29 11:32:56 -0700422#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423 {EASTEUROPE_CHARSET, "Tahoma"},
Bo Xudbd4c062014-05-29 11:32:56 -0700424#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 {ARABIC_CHARSET, "Arial"}, {-1, NULL}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700426
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) {
428 int i = 0;
429 while (defaultTTFMap[i].charset != -1) {
430 if (nCharset == defaultTTFMap[i].charset)
431 return defaultTTFMap[i].fontname;
432 ++i;
433 }
434 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700435}
436
Tom Sepez62a70f92016-03-21 15:00:20 -0700437int32_t CPWL_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438 if (m_pSystemHandler && (-1 != m_pSystemHandler->GetCharSet()))
439 return m_pSystemHandler->GetCharSet();
440 // to avoid CJK Font to show ASCII
441 if (word < 0x7F)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700442 return ANSI_CHARSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443 // follow the old charset
444 if (nOldCharset != DEFAULT_CHARSET)
445 return nOldCharset;
446
447 // find new charset
448 if ((word >= 0x4E00 && word <= 0x9FA5) ||
449 (word >= 0xE7C7 && word <= 0xE7F3) ||
450 (word >= 0x3000 && word <= 0x303F) ||
451 (word >= 0x2000 && word <= 0x206F)) {
452 return GB2312_CHARSET;
453 }
454
455 if (((word >= 0x3040) && (word <= 0x309F)) ||
456 ((word >= 0x30A0) && (word <= 0x30FF)) ||
457 ((word >= 0x31F0) && (word <= 0x31FF)) ||
458 ((word >= 0xFF00) && (word <= 0xFFEF))) {
459 return SHIFTJIS_CHARSET;
460 }
461
462 if (((word >= 0xAC00) && (word <= 0xD7AF)) ||
463 ((word >= 0x1100) && (word <= 0x11FF)) ||
464 ((word >= 0x3130) && (word <= 0x318F))) {
465 return HANGUL_CHARSET;
466 }
467
468 if (word >= 0x0E00 && word <= 0x0E7F)
469 return THAI_CHARSET;
470
471 if ((word >= 0x0370 && word <= 0x03FF) || (word >= 0x1F00 && word <= 0x1FFF))
472 return GREEK_CHARSET;
473
474 if ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
475 return ARABIC_CHARSET;
476
477 if (word >= 0x0590 && word <= 0x05FF)
478 return HEBREW_CHARSET;
479
480 if (word >= 0x0400 && word <= 0x04FF)
481 return RUSSIAN_CHARSET;
482
483 if (word >= 0x0100 && word <= 0x024F)
484 return EASTEUROPE_CHARSET;
485
486 if (word >= 0x1E00 && word <= 0x1EFF)
487 return VIETNAMESE_CHARSET;
488
489 return ANSI_CHARSET;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490}
491
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492CPWL_DocFontMap::CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler,
493 CPDF_Document* pAttachedDoc)
494 : CPWL_FontMap(pSystemHandler), m_pAttachedDoc(pAttachedDoc) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700495
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496CPWL_DocFontMap::~CPWL_DocFontMap() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700497
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498CPDF_Document* CPWL_DocFontMap::GetDocument() {
499 return m_pAttachedDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700500}