OLD | NEW |
---|---|
(Empty) | |
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/fpdf_font/include/cpdf_font.h" | |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | |
12 #include "core/fpdfdoc/doc_utils.h" | |
13 | |
14 CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc, | |
15 CPDF_Dictionary* pResDict, | |
16 CPDF_Font* pDefFont, | |
17 const CFX_ByteString& sDefFontAlias) | |
18 : m_pDocument(pDoc), | |
19 m_pResDict(pResDict), | |
20 m_pDefFont(pDefFont), | |
21 m_sDefFontAlias(sDefFontAlias), | |
22 m_pSysFont(nullptr), | |
23 m_sSysFontAlias() {} | |
24 | |
25 CPVT_FontMap::~CPVT_FontMap() {} | |
26 | |
27 void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc, | |
28 CPDF_Dictionary* pResDict, | |
29 CPDF_Font*& pSysFont, | |
30 CFX_ByteString& sSysFontAlias) { | |
31 if (pDoc && pResDict) { | |
Tom Sepez
2016/03/30 17:19:52
nit: prefer early return
dsinclair
2016/03/30 18:41:19
Done.
| |
32 CFX_ByteString sFontAlias; | |
33 CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDictBy("AcroForm"); | |
34 if (CPDF_Font* pPDFFont = | |
35 AddNativeInterFormFont(pFormDict, pDoc, sSysFontAlias)) { | |
36 if (CPDF_Dictionary* pFontList = pResDict->GetDictBy("Font")) { | |
37 if (!pFontList->KeyExist(sSysFontAlias)) { | |
38 pFontList->SetAtReference(sSysFontAlias, pDoc, | |
39 pPDFFont->GetFontDict()); | |
40 } | |
41 } | |
42 pSysFont = pPDFFont; | |
43 } | |
44 } | |
45 } | |
46 | |
47 CPDF_Font* CPVT_FontMap::GetPDFFont(int32_t nFontIndex) { | |
48 switch (nFontIndex) { | |
49 case 0: | |
50 return m_pDefFont; | |
51 case 1: | |
52 if (!m_pSysFont) { | |
53 GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont, | |
54 m_sSysFontAlias); | |
55 } | |
56 return m_pSysFont; | |
57 } | |
58 return nullptr; | |
Tom Sepez
2016/03/30 17:19:52
nit: maybe this becomes default: and there's no ne
dsinclair
2016/03/30 18:41:19
Done.
| |
59 } | |
60 | |
61 CFX_ByteString CPVT_FontMap::GetPDFFontAlias(int32_t nFontIndex) { | |
62 switch (nFontIndex) { | |
63 case 0: | |
64 return m_sDefFontAlias; | |
65 case 1: | |
66 if (!m_pSysFont) { | |
67 GetAnnotSysPDFFont(m_pDocument, m_pResDict, m_pSysFont, | |
68 m_sSysFontAlias); | |
69 } | |
70 return m_sSysFontAlias; | |
Tom Sepez
2016/03/30 17:19:52
ditto
dsinclair
2016/03/30 18:41:19
Done.
| |
71 } | |
72 return ""; | |
73 } | |
OLD | NEW |