| 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 CPWL_FontMap::CPWL_FontMap(CFX_SystemHandler* pSystemHandler) | 37 CPWL_FontMap::CPWL_FontMap(CFX_SystemHandler* pSystemHandler) |
| 38 : m_pSystemHandler(pSystemHandler) { | 38 : 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 Empty(); | 43 Empty(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void CPWL_FontMap::SetSystemHandler(CFX_SystemHandler* pSystemHandler) { | |
| 47 m_pSystemHandler = pSystemHandler; | |
| 48 } | |
| 49 | |
| 50 CPDF_Document* CPWL_FontMap::GetDocument() { | 46 CPDF_Document* CPWL_FontMap::GetDocument() { |
| 51 if (!m_pPDFDoc) { | 47 if (!m_pPDFDoc) { |
| 52 if (CPDF_ModuleMgr::Get()) { | 48 if (CPDF_ModuleMgr::Get()) { |
| 53 m_pPDFDoc.reset(new CPDF_Document(nullptr)); | 49 m_pPDFDoc.reset(new CPDF_Document(nullptr)); |
| 54 m_pPDFDoc->CreateNewDoc(); | 50 m_pPDFDoc->CreateNewDoc(); |
| 55 } | 51 } |
| 56 } | 52 } |
| 57 | 53 |
| 58 return m_pPDFDoc.get(); | 54 return m_pPDFDoc.get(); |
| 59 } | 55 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 265 } |
| 270 | 266 |
| 271 return ""; | 267 return ""; |
| 272 } | 268 } |
| 273 | 269 |
| 274 CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) { | 270 CFX_ByteString CPWL_FontMap::GetNativeFont(int32_t nCharset) { |
| 275 if (nCharset == DEFAULT_CHARSET) | 271 if (nCharset == DEFAULT_CHARSET) |
| 276 nCharset = GetNativeCharset(); | 272 nCharset = GetNativeCharset(); |
| 277 | 273 |
| 278 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset); | 274 CFX_ByteString sFontName = GetDefaultFontByCharset(nCharset); |
| 279 if (m_pSystemHandler) { | 275 if (m_pSystemHandler->FindNativeTrueTypeFont(sFontName)) |
| 280 if (m_pSystemHandler->FindNativeTrueTypeFont(sFontName)) | 276 return sFontName; |
| 281 return sFontName; | |
| 282 | 277 |
| 283 sFontName.clear(); | 278 sFontName.clear(); |
| 284 } | |
| 285 return sFontName; | 279 return sFontName; |
| 286 } | 280 } |
| 287 | 281 |
| 288 CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc, | 282 CPDF_Font* CPWL_FontMap::AddFontToDocument(CPDF_Document* pDoc, |
| 289 CFX_ByteString& sFontName, | 283 CFX_ByteString& sFontName, |
| 290 uint8_t nCharset) { | 284 uint8_t nCharset) { |
| 291 if (IsStandardFont(sFontName)) | 285 if (IsStandardFont(sFontName)) |
| 292 return AddStandardFont(pDoc, sFontName); | 286 return AddStandardFont(pDoc, sFontName); |
| 293 | 287 |
| 294 return AddSystemFont(pDoc, sFontName, nCharset); | 288 return AddSystemFont(pDoc, sFontName, nCharset); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 315 CFX_ByteString& sFontName, | 309 CFX_ByteString& sFontName, |
| 316 uint8_t nCharset) { | 310 uint8_t nCharset) { |
| 317 if (!pDoc) | 311 if (!pDoc) |
| 318 return nullptr; | 312 return nullptr; |
| 319 | 313 |
| 320 if (sFontName.IsEmpty()) | 314 if (sFontName.IsEmpty()) |
| 321 sFontName = GetNativeFont(nCharset); | 315 sFontName = GetNativeFont(nCharset); |
| 322 if (nCharset == DEFAULT_CHARSET) | 316 if (nCharset == DEFAULT_CHARSET) |
| 323 nCharset = GetNativeCharset(); | 317 nCharset = GetNativeCharset(); |
| 324 | 318 |
| 325 if (m_pSystemHandler) | 319 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, |
| 326 return m_pSystemHandler->AddNativeTrueTypeFontToPDF(pDoc, sFontName, | 320 nCharset); |
| 327 nCharset); | |
| 328 | |
| 329 return nullptr; | |
| 330 } | 321 } |
| 331 | 322 |
| 332 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, | 323 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName, |
| 333 int32_t nCharset) { | 324 int32_t nCharset) { |
| 334 CFX_ByteString sPostfix; | 325 CFX_ByteString sPostfix; |
| 335 sPostfix.Format("_%02X", nCharset); | 326 sPostfix.Format("_%02X", nCharset); |
| 336 return EncodeFontAlias(sFontName) + sPostfix; | 327 return EncodeFontAlias(sFontName) + sPostfix; |
| 337 } | 328 } |
| 338 | 329 |
| 339 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) { | 330 CFX_ByteString CPWL_FontMap::EncodeFontAlias(const CFX_ByteString& sFontName) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 return RUSSIAN_CHARSET; | 468 return RUSSIAN_CHARSET; |
| 478 | 469 |
| 479 if (word >= 0x0100 && word <= 0x024F) | 470 if (word >= 0x0100 && word <= 0x024F) |
| 480 return EASTEUROPE_CHARSET; | 471 return EASTEUROPE_CHARSET; |
| 481 | 472 |
| 482 if (word >= 0x1E00 && word <= 0x1EFF) | 473 if (word >= 0x1E00 && word <= 0x1EFF) |
| 483 return VIETNAMESE_CHARSET; | 474 return VIETNAMESE_CHARSET; |
| 484 | 475 |
| 485 return ANSI_CHARSET; | 476 return ANSI_CHARSET; |
| 486 } | 477 } |
| 487 | |
| 488 CPWL_DocFontMap::CPWL_DocFontMap(CFX_SystemHandler* pSystemHandler, | |
| 489 CPDF_Document* pAttachedDoc) | |
| 490 : CPWL_FontMap(pSystemHandler), m_pAttachedDoc(pAttachedDoc) {} | |
| 491 | |
| 492 CPWL_DocFontMap::~CPWL_DocFontMap() {} | |
| 493 | |
| 494 CPDF_Document* CPWL_DocFontMap::GetDocument() { | |
| 495 return m_pAttachedDoc; | |
| 496 } | |
| OLD | NEW |