| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/pdfwindow/PWL_FontMap.h" | 7 #include "fpdfsdk/pdfwindow/PWL_FontMap.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" | 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 "Times-Roman", | 28 "Times-Roman", |
| 29 "Times-Bold", | 29 "Times-Bold", |
| 30 "Times-Italic", | 30 "Times-Italic", |
| 31 "Times-BoldItalic", | 31 "Times-BoldItalic", |
| 32 "Symbol", | 32 "Symbol", |
| 33 "ZapfDingbats"}; | 33 "ZapfDingbats"}; |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 CPWL_FontMap::CPWL_FontMap(CFX_SystemHandler* pSystemHandler) | 37 CPWL_FontMap::CPWL_FontMap(CFX_SystemHandler* pSystemHandler) |
| 38 : m_pPDFDoc(NULL), m_pSystemHandler(pSystemHandler) { | 38 : m_pPDFDoc(nullptr), m_pSystemHandler(pSystemHandler) { |
| 39 ASSERT(m_pSystemHandler); | 39 ASSERT(m_pSystemHandler); |
| 40 } | 40 } |
| 41 | 41 |
| 42 CPWL_FontMap::~CPWL_FontMap() { | 42 CPWL_FontMap::~CPWL_FontMap() { |
| 43 delete m_pPDFDoc; | 43 delete m_pPDFDoc; |
| 44 m_pPDFDoc = NULL; | 44 m_pPDFDoc = nullptr; |
| 45 | 45 |
| 46 Empty(); | 46 Empty(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void CPWL_FontMap::SetSystemHandler(CFX_SystemHandler* pSystemHandler) { | 49 void CPWL_FontMap::SetSystemHandler(CFX_SystemHandler* pSystemHandler) { |
| 50 m_pSystemHandler = pSystemHandler; | 50 m_pSystemHandler = pSystemHandler; |
| 51 } | 51 } |
| 52 | 52 |
| 53 CPDF_Document* CPWL_FontMap::GetDocument() { | 53 CPDF_Document* CPWL_FontMap::GetDocument() { |
| 54 if (!m_pPDFDoc) { | 54 if (!m_pPDFDoc) { |
| 55 if (CPDF_ModuleMgr::Get()) { | 55 if (CPDF_ModuleMgr::Get()) { |
| 56 m_pPDFDoc = new CPDF_Document(nullptr); | 56 m_pPDFDoc = new CPDF_Document(nullptr); |
| 57 m_pPDFDoc->CreateNewDoc(); | 57 m_pPDFDoc->CreateNewDoc(); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 return m_pPDFDoc; | 61 return m_pPDFDoc; |
| 62 } | 62 } |
| 63 | 63 |
| 64 CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) { | 64 CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) { |
| 65 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) { | 65 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) { |
| 66 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) { | 66 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) { |
| 67 return pData->pFont; | 67 return pData->pFont; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 return NULL; | 71 return nullptr; |
| 72 } | 72 } |
| 73 | 73 |
| 74 CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) { | 74 CFX_ByteString CPWL_FontMap::GetPDFFontAlias(int32_t nFontIndex) { |
| 75 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) { | 75 if (nFontIndex >= 0 && nFontIndex < m_aData.GetSize()) { |
| 76 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) { | 76 if (CPWL_FontMap_Data* pData = m_aData.GetAt(nFontIndex)) { |
| 77 return pData->sFontName; | 77 return pData->sFontName; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 return ""; | 81 return ""; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 201 } |
| 202 | 202 |
| 203 int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName, | 203 int32_t CPWL_FontMap::GetFontIndex(const CFX_ByteString& sFontName, |
| 204 int32_t nCharset, | 204 int32_t nCharset, |
| 205 FX_BOOL bFind) { | 205 FX_BOOL bFind) { |
| 206 int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset); | 206 int32_t nFontIndex = FindFont(EncodeFontAlias(sFontName, nCharset), nCharset); |
| 207 if (nFontIndex >= 0) | 207 if (nFontIndex >= 0) |
| 208 return nFontIndex; | 208 return nFontIndex; |
| 209 | 209 |
| 210 CFX_ByteString sAlias; | 210 CFX_ByteString sAlias; |
| 211 CPDF_Font* pFont = NULL; | 211 CPDF_Font* pFont = nullptr; |
| 212 if (bFind) | 212 if (bFind) |
| 213 pFont = FindFontSameCharset(sAlias, nCharset); | 213 pFont = FindFontSameCharset(sAlias, nCharset); |
| 214 | 214 |
| 215 if (!pFont) { | 215 if (!pFont) { |
| 216 CFX_ByteString sTemp = sFontName; | 216 CFX_ByteString sTemp = sFontName; |
| 217 pFont = AddFontToDocument(GetDocument(), sTemp, nCharset); | 217 pFont = AddFontToDocument(GetDocument(), sTemp, nCharset); |
| 218 sAlias = EncodeFontAlias(sTemp, nCharset); | 218 sAlias = EncodeFontAlias(sTemp, nCharset); |
| 219 } | 219 } |
| 220 AddedFont(pFont, sAlias); | 220 AddedFont(pFont, sAlias); |
| 221 return AddFontData(pFont, sAlias, nCharset); | 221 return AddFontData(pFont, sAlias, nCharset); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 239 return -1; | 239 return -1; |
| 240 | 240 |
| 241 CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset); | 241 CFX_ByteString sAlias = EncodeFontAlias("Arial_Chrome", nCharset); |
| 242 AddedFont(pNewFont, sAlias); | 242 AddedFont(pNewFont, sAlias); |
| 243 | 243 |
| 244 return AddFontData(pNewFont, sAlias, nCharset); | 244 return AddFontData(pNewFont, sAlias, nCharset); |
| 245 } | 245 } |
| 246 | 246 |
| 247 CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, | 247 CPDF_Font* CPWL_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, |
| 248 int32_t nCharset) { | 248 int32_t nCharset) { |
| 249 return NULL; | 249 return nullptr; |
| 250 } | 250 } |
| 251 | 251 |
| 252 int32_t CPWL_FontMap::AddFontData(CPDF_Font* pFont, | 252 int32_t CPWL_FontMap::AddFontData(CPDF_Font* pFont, |
| 253 const CFX_ByteString& sFontAlias, | 253 const CFX_ByteString& sFontAlias, |
| 254 int32_t nCharset) { | 254 int32_t nCharset) { |
| 255 CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data; | 255 CPWL_FontMap_Data* pNewData = new CPWL_FontMap_Data; |
| 256 pNewData->pFont = pFont; | 256 pNewData->pFont = pFont; |
| 257 pNewData->sFontName = sFontAlias; | 257 pNewData->sFontName = sFontAlias; |
| 258 pNewData->nCharset = nCharset; | 258 pNewData->nCharset = nCharset; |
| 259 | 259 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 uint8_t nCharset) { | 294 uint8_t nCharset) { |
| 295 if (IsStandardFont(sFontName)) | 295 if (IsStandardFont(sFontName)) |
| 296 return AddStandardFont(pDoc, sFontName); | 296 return AddStandardFont(pDoc, sFontName); |
| 297 | 297 |
| 298 return AddSystemFont(pDoc, sFontName, nCharset); | 298 return AddSystemFont(pDoc, sFontName, nCharset); |
| 299 } | 299 } |
| 300 | 300 |
| 301 CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc, | 301 CPDF_Font* CPWL_FontMap::AddStandardFont(CPDF_Document* pDoc, |
| 302 CFX_ByteString& sFontName) { | 302 CFX_ByteString& sFontName) { |
| 303 if (!pDoc) | 303 if (!pDoc) |
| 304 return NULL; | 304 return nullptr; |
| 305 | 305 |
| 306 CPDF_Font* pFont = NULL; | 306 CPDF_Font* pFont = nullptr; |
| 307 | 307 |
| 308 if (sFontName == "ZapfDingbats") { | 308 if (sFontName == "ZapfDingbats") { |
| 309 pFont = pDoc->AddStandardFont(sFontName.c_str(), NULL); | 309 pFont = pDoc->AddStandardFont(sFontName.c_str(), nullptr); |
| 310 } else { | 310 } else { |
| 311 CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI); | 311 CPDF_FontEncoding fe(PDFFONT_ENCODING_WINANSI); |
| 312 pFont = pDoc->AddStandardFont(sFontName.c_str(), &fe); | 312 pFont = pDoc->AddStandardFont(sFontName.c_str(), &fe); |
| 313 } | 313 } |
| 314 | 314 |
| 315 return pFont; | 315 return pFont; |
| 316 } | 316 } |
| 317 | 317 |
| 318 CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, | 318 CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, |
| 319 CFX_ByteString& sFontName, | 319 CFX_ByteString& sFontName, |
| 320 uint8_t nCharset) { | 320 uint8_t nCharset) { |
| 321 if (!pDoc) | 321 if (!pDoc) |
| 322 return NULL; | 322 return nullptr; |
| 323 | 323 |
| 324 if (sFontName.IsEmpty()) | 324 if (sFontName.IsEmpty()) |
| 325 sFontName = GetNativeFont(nCharset); | 325 sFontName = GetNativeFont(nCharset); |
| 326 if (nCharset == DEFAULT_CHARSET) | 326 if (nCharset == DEFAULT_CHARSET) |
| 327 nCharset = GetNativeCharset(); | 327 nCharset = GetNativeCharset(); |
| 328 | 328 |
| 329 if (m_pSystemHandler) | 329 if (m_pSystemHandler) |
| 330 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, | 330 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, |
| 331 nCharset); | 331 nCharset); |
| 332 | 332 |
| 333 return NULL; | 333 return nullptr; |
| 334 } | 334 } |
| 335 | 335 |
| 336 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, | 336 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, |
| 337 int32_t nCharset) { | 337 int32_t nCharset) { |
| 338 CFX_ByteString sPostfix; | 338 CFX_ByteString sPostfix; |
| 339 sPostfix.Format("_%02X", nCharset); | 339 sPostfix.Format("_%02X", nCharset); |
| 340 return EncodeFontAlias(sFontName) + sPostfix; | 340 return EncodeFontAlias(sFontName) + sPostfix; |
| 341 } | 341 } |
| 342 | 342 |
| 343 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) { | 343 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) { |
| 344 CFX_ByteString sRet = sFontName; | 344 CFX_ByteString sRet = sFontName; |
| 345 sRet.Remove(' '); | 345 sRet.Remove(' '); |
| 346 return sRet; | 346 return sRet; |
| 347 } | 347 } |
| 348 | 348 |
| 349 int32_t CPWL_FontMap::GetFontMapCount() const { | 349 int32_t CPWL_FontMap::GetFontMapCount() const { |
| 350 return m_aData.GetSize(); | 350 return m_aData.GetSize(); |
| 351 } | 351 } |
| 352 | 352 |
| 353 const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const { | 353 const CPWL_FontMap_Data* CPWL_FontMap::GetFontMapData(int32_t nIndex) const { |
| 354 if (nIndex >= 0 && nIndex < m_aData.GetSize()) { | 354 if (nIndex >= 0 && nIndex < m_aData.GetSize()) { |
| 355 return m_aData.GetAt(nIndex); | 355 return m_aData.GetAt(nIndex); |
| 356 } | 356 } |
| 357 | 357 |
| 358 return NULL; | 358 return nullptr; |
| 359 } | 359 } |
| 360 | 360 |
| 361 int32_t CPWL_FontMap::GetNativeCharset() { | 361 int32_t CPWL_FontMap::GetNativeCharset() { |
| 362 uint8_t nCharset = ANSI_CHARSET; | 362 uint8_t nCharset = ANSI_CHARSET; |
| 363 int32_t iCodePage = FXSYS_GetACP(); | 363 int32_t iCodePage = FXSYS_GetACP(); |
| 364 switch (iCodePage) { | 364 switch (iCodePage) { |
| 365 case 932: // Japan | 365 case 932: // Japan |
| 366 nCharset = SHIFTJIS_CHARSET; | 366 nCharset = SHIFTJIS_CHARSET; |
| 367 break; | 367 break; |
| 368 case 936: // Chinese (PRC, Singapore) | 368 case 936: // Chinese (PRC, Singapore) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = { | 417 const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = { |
| 418 {ANSI_CHARSET, "Helvetica"}, {GB2312_CHARSET, "SimSun"}, | 418 {ANSI_CHARSET, "Helvetica"}, {GB2312_CHARSET, "SimSun"}, |
| 419 {CHINESEBIG5_CHARSET, "MingLiU"}, {SHIFTJIS_CHARSET, "MS Gothic"}, | 419 {CHINESEBIG5_CHARSET, "MingLiU"}, {SHIFTJIS_CHARSET, "MS Gothic"}, |
| 420 {HANGUL_CHARSET, "Batang"}, {RUSSIAN_CHARSET, "Arial"}, | 420 {HANGUL_CHARSET, "Batang"}, {RUSSIAN_CHARSET, "Arial"}, |
| 421 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ | 421 #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ |
| 422 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 422 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 423 {EASTEUROPE_CHARSET, "Arial"}, | 423 {EASTEUROPE_CHARSET, "Arial"}, |
| 424 #else | 424 #else |
| 425 {EASTEUROPE_CHARSET, "Tahoma"}, | 425 {EASTEUROPE_CHARSET, "Tahoma"}, |
| 426 #endif | 426 #endif |
| 427 {ARABIC_CHARSET, "Arial"}, {-1, NULL}}; | 427 {ARABIC_CHARSET, "Arial"}, {-1, nullptr}}; |
| 428 | 428 |
| 429 CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) { | 429 CFX_ByteString CPWL_FontMap::GetDefaultFontByCharset(int32_t nCharset) { |
| 430 int i = 0; | 430 int i = 0; |
| 431 while (defaultTTFMap[i].charset != -1) { | 431 while (defaultTTFMap[i].charset != -1) { |
| 432 if (nCharset == defaultTTFMap[i].charset) | 432 if (nCharset == defaultTTFMap[i].charset) |
| 433 return defaultTTFMap[i].fontname; | 433 return defaultTTFMap[i].fontname; |
| 434 ++i; | 434 ++i; |
| 435 } | 435 } |
| 436 return ""; | 436 return ""; |
| 437 } | 437 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 493 |
| 494 CPWL_DocFontMap::CPWL_DocFontMap(CFX_SystemHandler* pSystemHandler, | 494 CPWL_DocFontMap::CPWL_DocFontMap(CFX_SystemHandler* pSystemHandler, |
| 495 CPDF_Document* pAttachedDoc) | 495 CPDF_Document* pAttachedDoc) |
| 496 : CPWL_FontMap(pSystemHandler), m_pAttachedDoc(pAttachedDoc) {} | 496 : CPWL_FontMap(pSystemHandler), m_pAttachedDoc(pAttachedDoc) {} |
| 497 | 497 |
| 498 CPWL_DocFontMap::~CPWL_DocFontMap() {} | 498 CPWL_DocFontMap::~CPWL_DocFontMap() {} |
| 499 | 499 |
| 500 CPDF_Document* CPWL_DocFontMap::GetDocument() { | 500 CPDF_Document* CPWL_DocFontMap::GetDocument() { |
| 501 return m_pAttachedDoc; | 501 return m_pAttachedDoc; |
| 502 } | 502 } |
| OLD | NEW |