• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/fpdfapi/parser/fpdf_parser_utility.h"
14 #include "core/fpdfdoc/cpdf_interactiveform.h"
15 #include "core/fxcrt/fx_codepage.h"
16 #include "third_party/base/logging.h"
17 
CPVT_FontMap(CPDF_Document * pDoc,CPDF_Dictionary * pResDict,const RetainPtr<CPDF_Font> & pDefFont,const ByteString & sDefFontAlias)18 CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc,
19                            CPDF_Dictionary* pResDict,
20                            const RetainPtr<CPDF_Font>& pDefFont,
21                            const ByteString& sDefFontAlias)
22     : m_pDocument(pDoc),
23       m_pResDict(pResDict),
24       m_pDefFont(pDefFont),
25       m_sDefFontAlias(sDefFontAlias) {}
26 
~CPVT_FontMap()27 CPVT_FontMap::~CPVT_FontMap() {}
28 
29 // static
GetAnnotSysPDFFont(CPDF_Document * pDoc,CPDF_Dictionary * pResDict,ByteString * sSysFontAlias)30 RetainPtr<CPDF_Font> CPVT_FontMap::GetAnnotSysPDFFont(
31     CPDF_Document* pDoc,
32     CPDF_Dictionary* pResDict,
33     ByteString* sSysFontAlias) {
34   if (!pDoc || !pResDict)
35     return nullptr;
36 
37   CPDF_Dictionary* pFormDict = pDoc->GetRoot()->GetDictFor("AcroForm");
38   RetainPtr<CPDF_Font> pPDFFont =
39       AddNativeInteractiveFormFont(pFormDict, pDoc, sSysFontAlias);
40   if (!pPDFFont)
41     return nullptr;
42 
43   CPDF_Dictionary* pFontList = pResDict->GetDictFor("Font");
44   if (ValidateFontResourceDict(pFontList) &&
45       !pFontList->KeyExist(*sSysFontAlias)) {
46     pFontList->SetNewFor<CPDF_Reference>(*sSysFontAlias, pDoc,
47                                          pPDFFont->GetFontDict()->GetObjNum());
48   }
49   return pPDFFont;
50 }
51 
GetPDFFont(int32_t nFontIndex)52 RetainPtr<CPDF_Font> CPVT_FontMap::GetPDFFont(int32_t nFontIndex) {
53   switch (nFontIndex) {
54     case 0:
55       return m_pDefFont;
56     case 1:
57       if (!m_pSysFont) {
58         m_pSysFont = GetAnnotSysPDFFont(m_pDocument.Get(), m_pResDict.Get(),
59                                         &m_sSysFontAlias);
60       }
61       return m_pSysFont;
62     default:
63       return nullptr;
64   }
65 }
66 
GetPDFFontAlias(int32_t nFontIndex)67 ByteString CPVT_FontMap::GetPDFFontAlias(int32_t nFontIndex) {
68   switch (nFontIndex) {
69     case 0:
70       return m_sDefFontAlias;
71     case 1:
72       if (!m_pSysFont) {
73         m_pSysFont = GetAnnotSysPDFFont(m_pDocument.Get(), m_pResDict.Get(),
74                                         &m_sSysFontAlias);
75       }
76       return m_sSysFontAlias;
77     default:
78       return ByteString();
79   }
80 }
81 
GetWordFontIndex(uint16_t word,int32_t charset,int32_t nFontIndex)82 int32_t CPVT_FontMap::GetWordFontIndex(uint16_t word,
83                                        int32_t charset,
84                                        int32_t nFontIndex) {
85   NOTREACHED();
86   return 0;
87 }
88 
CharCodeFromUnicode(int32_t nFontIndex,uint16_t word)89 int32_t CPVT_FontMap::CharCodeFromUnicode(int32_t nFontIndex, uint16_t word) {
90   NOTREACHED();
91   return 0;
92 }
93 
CharSetFromUnicode(uint16_t word,int32_t nOldCharset)94 int32_t CPVT_FontMap::CharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
95   NOTREACHED();
96   return FX_CHARSET_ANSI;
97 }
98