1 // Copyright 2016 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. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "core/fpdfdoc/cpvt_fontmap.h" 8 9 #include "core/fpdfapi/font/cpdf_font.h" 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" 11 #include "core/fpdfapi/parser/cpdf_document.h" 12 #include "core/fpdfapi/parser/cpdf_reference.h" 13 #include "core/fpdfdoc/cpdf_interform.h" 14 #include "core/fxcrt/fx_codepage.h" 15 #include "third_party/base/logging.h" 16 17 CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc, 18 CPDF_Dictionary* pResDict, 19 CPDF_Font* pDefFont, 20 const ByteString& sDefFontAlias) 21 : m_pDocument(pDoc), 22 m_pResDict(pResDict), 23 m_pDefFont(pDefFont), 24 m_sDefFontAlias(sDefFontAlias) {} 25 26 CPVT_FontMap::~CPVT_FontMap() {} 27 28 CPDF_Font* CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc, 29 const CPDF_Dictionary* pResDict, 30 ByteString* sSysFontAlias) { 31 if (!pDoc || !pResDict) 32 return nullptr; 33 34 CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDictFor("AcroForm"); 35 CPDF_Font* pPDFFont = AddNativeInterFormFont(pFormDict, pDoc, sSysFontAlias); 36 if (!pPDFFont) 37 return nullptr; 38 39 CPDF_Dictionary* pFontList = pResDict->GetDictFor("Font"); 40 if (pFontList && !pFontList->KeyExist(*sSysFontAlias)) { 41 pFontList->SetNewFor<CPDF_Reference>(*sSysFontAlias, pDoc, 42 pPDFFont->GetFontDict()->GetObjNum()); 43 } 44 return pPDFFont; 45 } 46 47 CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) { 48 switch (nFontIndex) { 49 case 0: 50 return m_pDefFont.Get(); 51 case 1: 52 if (!m_pSysFont) { 53 m_pSysFont = GetAnnotSysPDFFont(m_pDocument.Get(), m_pResDict.Get(), 54 &m_sSysFontAlias); 55 } 56 return m_pSysFont.Get(); 57 default: 58 return nullptr; 59 } 60 } 61 62 ByteString CPVT_FontMap::GetPDFFontAlias(int32_t nFontIndex) { 63 switch (nFontIndex) { 64 case 0: 65 return m_sDefFontAlias; 66 case 1: 67 if (!m_pSysFont) { 68 m_pSysFont = GetAnnotSysPDFFont(m_pDocument.Get(), m_pResDict.Get(), 69 &m_sSysFontAlias); 70 } 71 return m_sSysFontAlias; 72 default: 73 return ByteString(); 74 } 75 } 76 77 int32_t CPVT_FontMap::GetWordFontIndex(uint16_t word, 78 int32_t charset, 79 int32_t nFontIndex) { 80 NOTREACHED(); 81 return 0; 82 } 83 84 int32_t CPVT_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) { 85 NOTREACHED(); 86 return 0; 87 } 88 89 int32_t CPVT_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) { 90 NOTREACHED(); 91 return FX_CHARSET_ANSI; 92 } 93