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
CPVT_FontMap(CPDF_Document * pDoc,CPDF_Dictionary * pResDict,CPDF_Font * pDefFont,const CFX_ByteString & sDefFontAlias)15 CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc,
16 CPDF_Dictionary* pResDict,
17 CPDF_Font* pDefFont,
18 const CFX_ByteString& sDefFontAlias)
19 : m_pDocument(pDoc),
20 m_pResDict(pResDict),
21 m_pDefFont(pDefFont),
22 m_sDefFontAlias(sDefFontAlias),
23 m_pSysFont(nullptr),
24 m_sSysFontAlias() {}
25
~CPVT_FontMap()26 CPVT_FontMap::~CPVT_FontMap() {}
27
GetAnnotSysPDFFont(CPDF_Document * pDoc,const CPDF_Dictionary * pResDict,CPDF_Font * & pSysFont,CFX_ByteString & sSysFontAlias)28 void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc,
29 const CPDF_Dictionary* pResDict,
30 CPDF_Font*& pSysFont,
31 CFX_ByteString& sSysFontAlias) {
32 if (!pDoc || !pResDict)
33 return;
34
35 CFX_ByteString sFontAlias;
36 CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDictFor("AcroForm");
37 CPDF_Font* pPDFFont = AddNativeInterFormFont(pFormDict, pDoc, sSysFontAlias);
38 if (!pPDFFont)
39 return;
40
41 CPDF_Dictionary* pFontList = pResDict->GetDictFor("Font");
42 if (pFontList && !pFontList->KeyExist(sSysFontAlias)) {
43 pFontList->SetNewFor<CPDF_Reference>(sSysFontAlias, pDoc,
44 pPDFFont->GetFontDict()->GetObjNum());
45 }
46 pSysFont = pPDFFont;
47 }
48
GetPDFFont(int32_t nFontIndex)49 CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) {
50 switch (nFontIndex) {
51 case 0:
52 return m_pDefFont;
53 case 1:
54 if (!m_pSysFont) {
55 GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont,
56 m_sSysFontAlias);
57 }
58 return m_pSysFont;
59 default:
60 return nullptr;
61 }
62 }
63
GetPDFFontAlias(int32_t nFontIndex)64 CFX_ByteString CPVT_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
65 switch (nFontIndex) {
66 case 0:
67 return m_sDefFontAlias;
68 case 1:
69 if (!m_pSysFont) {
70 GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont,
71 m_sSysFontAlias);
72 }
73 return m_sSysFontAlias;
74 default:
75 return "";
76 }
77 }
78
GetWordFontIndex(uint16_t word,int32_t charset,int32_t nFontIndex)79 int32_t CPVT_FontMap::GetWordFontIndex(uint16_t word,
80 int32_t charset,
81 int32_t nFontIndex) {
82 ASSERT(false);
83 return 0;
84 }
85
CharCodeFromUnicode(int32_t nFontIndex,uint16_t word)86 int32_t CPVT_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) {
87 ASSERT(false);
88 return 0;
89 }
90
CharSetFromUnicode(uint16_t word,int32_t nOldCharset)91 int32_t CPVT_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
92 ASSERT(false);
93 return FXFONT_ANSI_CHARSET;
94 }
95