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/formfiller/cba_fontmap.h" | 7 #include "fpdfsdk/formfiller/cba_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_page/include/cpdf_page.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
14 #include "fpdfsdk/include/fsdk_baseannot.h" | 14 #include "fpdfsdk/include/fsdk_baseannot.h" |
15 | 15 |
16 CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, | 16 CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, |
17 CFX_SystemHandler* pSystemHandler) | 17 CFX_SystemHandler* pSystemHandler) |
18 : CPWL_FontMap(pSystemHandler), | 18 : CPWL_FontMap(pSystemHandler), |
19 m_pDocument(NULL), | 19 m_pDocument(nullptr), |
20 m_pAnnotDict(NULL), | 20 m_pAnnotDict(nullptr), |
21 m_pDefaultFont(NULL), | 21 m_pDefaultFont(nullptr), |
22 m_sAPType("N") { | 22 m_sAPType("N") { |
23 CPDF_Page* pPage = pAnnot->GetPDFPage(); | 23 CPDF_Page* pPage = pAnnot->GetPDFPage(); |
24 | 24 |
25 m_pDocument = pPage->m_pDocument; | 25 m_pDocument = pPage->m_pDocument; |
26 m_pAnnotDict = pAnnot->GetPDFAnnot()->GetAnnotDict(); | 26 m_pAnnotDict = pAnnot->GetPDFAnnot()->GetAnnotDict(); |
27 Initialize(); | 27 Initialize(); |
28 } | 28 } |
29 | 29 |
30 CBA_FontMap::~CBA_FontMap() {} | 30 CBA_FontMap::~CBA_FontMap() {} |
31 | 31 |
32 void CBA_FontMap::Reset() { | 32 void CBA_FontMap::Reset() { |
33 Empty(); | 33 Empty(); |
34 m_pDefaultFont = NULL; | 34 m_pDefaultFont = nullptr; |
35 m_sDefaultFontName = ""; | 35 m_sDefaultFontName = ""; |
36 } | 36 } |
37 | 37 |
38 void CBA_FontMap::Initialize() { | 38 void CBA_FontMap::Initialize() { |
39 int32_t nCharset = DEFAULT_CHARSET; | 39 int32_t nCharset = DEFAULT_CHARSET; |
40 | 40 |
41 if (!m_pDefaultFont) { | 41 if (!m_pDefaultFont) { |
42 m_pDefaultFont = GetAnnotDefaultFont(m_sDefaultFontName); | 42 m_pDefaultFont = GetAnnotDefaultFont(m_sDefaultFontName); |
43 if (m_pDefaultFont) { | 43 if (m_pDefaultFont) { |
44 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) { | 44 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 nCharset = pSubstFont->m_Charset; | 76 nCharset = pSubstFont->m_Charset; |
77 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); | 77 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); |
78 } | 78 } |
79 | 79 |
80 CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, | 80 CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, |
81 int32_t nCharset) { | 81 int32_t nCharset) { |
82 if (m_pAnnotDict->GetStringBy("Subtype") == "Widget") { | 82 if (m_pAnnotDict->GetStringBy("Subtype") == "Widget") { |
83 CPDF_Document* pDocument = GetDocument(); | 83 CPDF_Document* pDocument = GetDocument(); |
84 CPDF_Dictionary* pRootDict = pDocument->GetRoot(); | 84 CPDF_Dictionary* pRootDict = pDocument->GetRoot(); |
85 if (!pRootDict) | 85 if (!pRootDict) |
86 return NULL; | 86 return nullptr; |
87 | 87 |
88 CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm"); | 88 CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm"); |
89 if (!pAcroFormDict) | 89 if (!pAcroFormDict) |
90 return NULL; | 90 return nullptr; |
91 | 91 |
92 CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"); | 92 CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"); |
93 if (!pDRDict) | 93 if (!pDRDict) |
94 return NULL; | 94 return nullptr; |
95 | 95 |
96 return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); | 96 return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); |
97 } | 97 } |
98 | 98 |
99 return NULL; | 99 return nullptr; |
100 } | 100 } |
101 | 101 |
102 CPDF_Document* CBA_FontMap::GetDocument() { | 102 CPDF_Document* CBA_FontMap::GetDocument() { |
103 return m_pDocument; | 103 return m_pDocument; |
104 } | 104 } |
105 | 105 |
106 CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, | 106 CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, |
107 CFX_ByteString& sFontAlias, | 107 CFX_ByteString& sFontAlias, |
108 int32_t nCharset) { | 108 int32_t nCharset) { |
109 if (!pResDict) | 109 if (!pResDict) |
110 return NULL; | 110 return nullptr; |
111 | 111 |
112 CPDF_Dictionary* pFonts = pResDict->GetDictBy("Font"); | 112 CPDF_Dictionary* pFonts = pResDict->GetDictBy("Font"); |
113 if (!pFonts) | 113 if (!pFonts) |
114 return NULL; | 114 return nullptr; |
115 | 115 |
116 CPDF_Document* pDocument = GetDocument(); | 116 CPDF_Document* pDocument = GetDocument(); |
117 CPDF_Font* pFind = NULL; | 117 CPDF_Font* pFind = nullptr; |
118 for (const auto& it : *pFonts) { | 118 for (const auto& it : *pFonts) { |
119 const CFX_ByteString& csKey = it.first; | 119 const CFX_ByteString& csKey = it.first; |
120 CPDF_Object* pObj = it.second; | 120 CPDF_Object* pObj = it.second; |
121 if (!pObj) | 121 if (!pObj) |
122 continue; | 122 continue; |
123 | 123 |
124 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 124 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
125 if (!pElement) | 125 if (!pElement) |
126 continue; | 126 continue; |
127 if (pElement->GetStringBy("Type") != "Font") | 127 if (pElement->GetStringBy("Type") != "Font") |
(...skipping 30 matching lines...) Expand all Loading... |
158 m_pAnnotDict->SetAt("AP", pAPDict); | 158 m_pAnnotDict->SetAt("AP", pAPDict); |
159 } | 159 } |
160 | 160 |
161 // to avoid checkbox and radiobutton | 161 // to avoid checkbox and radiobutton |
162 CPDF_Object* pObject = pAPDict->GetObjectBy(m_sAPType); | 162 CPDF_Object* pObject = pAPDict->GetObjectBy(m_sAPType); |
163 if (ToDictionary(pObject)) | 163 if (ToDictionary(pObject)) |
164 return; | 164 return; |
165 | 165 |
166 CPDF_Stream* pStream = pAPDict->GetStreamBy(m_sAPType); | 166 CPDF_Stream* pStream = pAPDict->GetStreamBy(m_sAPType); |
167 if (!pStream) { | 167 if (!pStream) { |
168 pStream = new CPDF_Stream(NULL, 0, NULL); | 168 pStream = new CPDF_Stream(nullptr, 0, nullptr); |
169 int32_t objnum = m_pDocument->AddIndirectObject(pStream); | 169 int32_t objnum = m_pDocument->AddIndirectObject(pStream); |
170 pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum); | 170 pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum); |
171 } | 171 } |
172 | 172 |
173 CPDF_Dictionary* pStreamDict = pStream->GetDict(); | 173 CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
174 | 174 |
175 if (!pStreamDict) { | 175 if (!pStreamDict) { |
176 pStreamDict = new CPDF_Dictionary; | 176 pStreamDict = new CPDF_Dictionary; |
177 pStream->InitStream(NULL, 0, pStreamDict); | 177 pStream->InitStream(nullptr, 0, pStreamDict); |
178 } | 178 } |
179 | 179 |
180 if (pStreamDict) { | 180 if (pStreamDict) { |
181 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); | 181 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); |
182 if (!pStreamResList) { | 182 if (!pStreamResList) { |
183 pStreamResList = new CPDF_Dictionary(); | 183 pStreamResList = new CPDF_Dictionary(); |
184 pStreamDict->SetAt("Resources", pStreamResList); | 184 pStreamDict->SetAt("Resources", pStreamResList); |
185 } | 185 } |
186 | 186 |
187 if (pStreamResList) { | 187 if (pStreamResList) { |
188 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); | 188 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font"); |
189 if (!pStreamResFontList) { | 189 if (!pStreamResFontList) { |
190 pStreamResFontList = new CPDF_Dictionary; | 190 pStreamResFontList = new CPDF_Dictionary; |
191 int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); | 191 int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); |
192 pStreamResList->SetAtReference("Font", m_pDocument, objnum); | 192 pStreamResList->SetAtReference("Font", m_pDocument, objnum); |
193 } | 193 } |
194 if (!pStreamResFontList->KeyExist(sAlias)) | 194 if (!pStreamResFontList->KeyExist(sAlias)) |
195 pStreamResFontList->SetAtReference(sAlias, m_pDocument, | 195 pStreamResFontList->SetAtReference(sAlias, m_pDocument, |
196 pFont->GetFontDict()); | 196 pFont->GetFontDict()); |
197 } | 197 } |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { | 201 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { |
202 CPDF_Dictionary* pAcroFormDict = NULL; | 202 CPDF_Dictionary* pAcroFormDict = nullptr; |
203 const bool bWidget = (m_pAnnotDict->GetStringBy("Subtype") == "Widget"); | 203 const bool bWidget = (m_pAnnotDict->GetStringBy("Subtype") == "Widget"); |
204 if (bWidget) { | 204 if (bWidget) { |
205 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) | 205 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) |
206 pAcroFormDict = pRootDict->GetDictBy("AcroForm"); | 206 pAcroFormDict = pRootDict->GetDictBy("AcroForm"); |
207 } | 207 } |
208 | 208 |
209 CFX_ByteString sDA; | 209 CFX_ByteString sDA; |
210 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA"); | 210 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA"); |
211 if (pObj) | 211 if (pObj) |
212 sDA = pObj->GetString(); | 212 sDA = pObj->GetString(); |
213 | 213 |
214 if (bWidget) { | 214 if (bWidget) { |
215 if (sDA.IsEmpty()) { | 215 if (sDA.IsEmpty()) { |
216 pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); | 216 pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); |
217 sDA = pObj ? pObj->GetString() : CFX_ByteString(); | 217 sDA = pObj ? pObj->GetString() : CFX_ByteString(); |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 CPDF_Dictionary* pFontDict = NULL; | 221 CPDF_Dictionary* pFontDict = nullptr; |
222 | 222 |
223 if (!sDA.IsEmpty()) { | 223 if (!sDA.IsEmpty()) { |
224 CPDF_SimpleParser syntax(sDA.AsStringC()); | 224 CPDF_SimpleParser syntax(sDA.AsStringC()); |
225 syntax.FindTagParamFromStart("Tf", 2); | 225 syntax.FindTagParamFromStart("Tf", 2); |
226 CFX_ByteString sFontName(syntax.GetWord()); | 226 CFX_ByteString sFontName(syntax.GetWord()); |
227 sAlias = PDF_NameDecode(sFontName).Mid(1); | 227 sAlias = PDF_NameDecode(sFontName).Mid(1); |
228 | 228 |
229 if (CPDF_Dictionary* pDRDict = m_pAnnotDict->GetDictBy("DR")) | 229 if (CPDF_Dictionary* pDRDict = m_pAnnotDict->GetDictBy("DR")) |
230 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) | 230 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font")) |
231 pFontDict = pDRFontDict->GetDictBy(sAlias); | 231 pFontDict = pDRFontDict->GetDictBy(sAlias); |
(...skipping 20 matching lines...) Expand all Loading... |
252 | 252 |
253 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; | 253 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; |
254 } | 254 } |
255 | 255 |
256 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { | 256 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { |
257 m_sAPType = sAPType; | 257 m_sAPType = sAPType; |
258 | 258 |
259 Reset(); | 259 Reset(); |
260 Initialize(); | 260 Initialize(); |
261 } | 261 } |
OLD | NEW |