blob: 42beab7d21e5ae45902b6a5e0b3f3bc6d013e5b7 [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"
dsinclairc7a73492016-04-05 12:01:42 -070013#include "core/fpdfdoc/include/ipvt_fontmap.h"
dan sinclair89e904b2016-03-23 19:29:15 -040014#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015
Lei Zhang1b976642016-01-08 14:24:37 -080016namespace {
17
18const char kDefaultFontName[] = "Helvetica";
19
20const char* const g_sDEStandardFontName[] = {"Courier",
21 "Courier-Bold",
22 "Courier-BoldOblique",
23 "Courier-Oblique",
24 "Helvetica",
25 "Helvetica-Bold",
26 "Helvetica-BoldOblique",
27 "Helvetica-Oblique",
28 "Times-Roman",
29 "Times-Bold",
30 "Times-Italic",
31 "Times-BoldItalic",
32 "Symbol",
33 "ZapfDingbats"};
34
35} // namespace
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler)
38 : m_pPDFDoc(NULL), m_pSystemHandler(pSystemHandler) {
Lei Zhang96660d62015-12-14 18:27:25 -080039 ASSERT(m_pSystemHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040}
41
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042CPWL_FontMap::~CPWL_FontMap() {
43 delete m_pPDFDoc;
44 m_pPDFDoc = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 Empty();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047}
48
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler) {
50 m_pSystemHandler = pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051}
52
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053CPDF_Document* CPWL_FontMap::GetDocument() {
54 if (!m_pPDFDoc) {
55 if (CPDF_ModuleMgr::Get()) {
Tom Sepezae51c812015-08-05 12:34:06 -070056 m_pPDFDoc = new CPDF_Document;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 m_pPDFDoc->CreateNewDoc();
58 }
59 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061 return m_pPDFDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062}
63
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) {
65 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
66 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
67 return pData->pFont;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070068 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072}
73
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
75 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
76 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
77 return pData->sFontName;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070078 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 return "";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082}
83
Tom Sepez62a70f92016-03-21 15:00:20 -070084FX_BOOL CPWL_FontMap::KnowWord(int32_t nFontIndex, uint16_t word) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) {
86 if (m_aData.GetAt(nFontIndex)) {
87 return CharCodeFromUnicode(nFontIndex, word) >= 0;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070088 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092}
93
Tom Sepez62a70f92016-03-21 15:00:20 -070094int32_t CPWL_FontMap::GetWordFontIndex(uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095 int32_t nCharset,
96 int32_t nFontIndex) {
97 if (nFontIndex > 0) {
98 if (KnowWord(nFontIndex, word))
99 return nFontIndex;
100 } else {
101 if (const CPWL_FontMap_Data* pData = GetFontMapData(0)) {
102 if (nCharset == DEFAULT_CHARSET || pData->nCharset == SYMBOL_CHARSET ||
103 nCharset == pData->nCharset) {
104 if (KnowWord(0, word))
105 return 0;
106 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700107 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 int32_t nNewFontIndex =
111 GetFontIndex(GetNativeFontName(nCharset), nCharset, TRUE);
112 if (nNewFontIndex >= 0) {
113 if (KnowWord(nNewFontIndex, word))
114 return nNewFontIndex;
115 }
116 nNewFontIndex = GetFontIndex("Arial Unicode MS", DEFAULT_CHARSET, FALSE);
117 if (nNewFontIndex >= 0) {
118 if (KnowWord(nNewFontIndex, word))
119 return nNewFontIndex;
120 }
121 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122}
123
Tom Sepez62a70f92016-03-21 15:00:20 -0700124int32_t CPWL_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) {
126 if (pData->pFont) {
127 if (pData->pFont->IsUnicodeCompatible()) {
128 int nCharCode = pData->pFont->CharCodeFromUnicode(word);
129 pData->pFont->GlyphFromCharCode(nCharCode);
130 return nCharCode;
131 }
132 if (word < 0xFF)
133 return word;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700134 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 }
136 return -1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137}
138
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139CFX_ByteString CPWL_FontMap::GetNativeFontName(int32_t nCharset) {
140 // searching native font is slow, so we must save time
141 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++) {
142 if (CPWL_FontMap_Native* pData = m_aNativeFont.GetAt(i)) {
143 if (pData->nCharset == nCharset)
144 return pData->sFontName;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700145 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700147
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 CFX_ByteString sNew = GetNativeFont(nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700149
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150 if (!sNew.IsEmpty()) {
151 CPWL_FontMap_Native* pNewData = new CPWL_FontMap_Native;
152 pNewData->nCharset = nCharset;
153 pNewData->sFontName = sNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 m_aNativeFont.Add(pNewData);
156 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700157
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700158 return sNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159}
160
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161void CPWL_FontMap::Empty() {
162 {
163 for (int32_t i = 0, sz = m_aData.GetSize(); i < sz; i++)
164 delete m_aData.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 m_aData.RemoveAll();
167 }
168 {
169 for (int32_t i = 0, sz = m_aNativeFont.GetSize(); i < sz; i++)
170 delete m_aNativeFont.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 m_aNativeFont.RemoveAll();
173 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700174}
175
Lei Zhangfcfa3b82015-12-24 21:07:28 -0800176void CPWL_FontMap::Initialize() {
Lei Zhang1b976642016-01-08 14:24:37 -0800177 GetFontIndex(kDefaultFontName, ANSI_CHARSET, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178}
Lei Zhang60f507b2015-06-13 00:41:00 -0700179
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180FX_BOOL CPWL_FontMap::IsStandardFont(const CFX_ByteString& sFontName) {
Wei Li89409932016-03-28 10:33:33 -0700181 for (size_t i = 0; i < FX_ArraySize(g_sDEStandardFontName); ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 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
Tom Sepez62a70f92016-03-21 15:00:20 -0700224int32_t CPWL_FontMap::GetPWLFontIndex(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 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
Tom Sepez62a70f92016-03-21 15:00:20 -0700439int32_t CPWL_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 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}