Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: fpdfsdk/src/formfiller/FFL_CBA_Fontmap.cpp

Issue 1644633003: Member function name refactoring (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfdoc/doc_viewerPreferences.cpp ('k') | fpdfsdk/src/fpdf_ext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/include/formfiller/FFL_CBA_Fontmap.h" 7 #include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h"
8 8
9 #include "core/include/fpdfapi/fpdf_page.h" 9 #include "core/include/fpdfapi/fpdf_page.h"
10 #include "fpdfsdk/include/fsdk_baseannot.h" 10 #include "fpdfsdk/include/fsdk_baseannot.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 int32_t nCharset = DEFAULT_CHARSET; 70 int32_t nCharset = DEFAULT_CHARSET;
71 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) 71 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont())
72 nCharset = pSubstFont->m_Charset; 72 nCharset = pSubstFont->m_Charset;
73 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); 73 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset);
74 } 74 }
75 75
76 CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, 76 CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias,
77 int32_t nCharset) { 77 int32_t nCharset) {
78 ASSERT(m_pAnnotDict != NULL); 78 ASSERT(m_pAnnotDict != NULL);
79 79
80 if (m_pAnnotDict->GetString("Subtype") == "Widget") { 80 if (m_pAnnotDict->GetStringBy("Subtype") == "Widget") {
81 CPDF_Document* pDocument = GetDocument(); 81 CPDF_Document* pDocument = GetDocument();
82 ASSERT(pDocument != NULL); 82 ASSERT(pDocument != NULL);
83 83
84 CPDF_Dictionary* pRootDict = pDocument->GetRoot(); 84 CPDF_Dictionary* pRootDict = pDocument->GetRoot();
85 if (!pRootDict) 85 if (!pRootDict)
86 return NULL; 86 return NULL;
87 87
88 CPDF_Dictionary* pAcroFormDict = pRootDict->GetDict("AcroForm"); 88 CPDF_Dictionary* pAcroFormDict = pRootDict->GetDictBy("AcroForm");
89 if (!pAcroFormDict) 89 if (!pAcroFormDict)
90 return NULL; 90 return NULL;
91 91
92 CPDF_Dictionary* pDRDict = pAcroFormDict->GetDict("DR"); 92 CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR");
93 if (!pDRDict) 93 if (!pDRDict)
94 return NULL; 94 return NULL;
95 95
96 return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); 96 return FindResFontSameCharset(pDRDict, sFontAlias, nCharset);
97 } 97 }
98 98
99 return NULL; 99 return NULL;
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 NULL;
111 111
112 CPDF_Document* pDocument = GetDocument(); 112 CPDF_Document* pDocument = GetDocument();
113 ASSERT(pDocument != NULL); 113 ASSERT(pDocument != NULL);
114 114
115 CPDF_Dictionary* pFonts = pResDict->GetDict("Font"); 115 CPDF_Dictionary* pFonts = pResDict->GetDictBy("Font");
116 if (!pFonts) 116 if (!pFonts)
117 return NULL; 117 return NULL;
118 118
119 CPDF_Font* pFind = NULL; 119 CPDF_Font* pFind = NULL;
120 120
121 for (const auto& it : *pFonts) { 121 for (const auto& it : *pFonts) {
122 const CFX_ByteString& csKey = it.first; 122 const CFX_ByteString& csKey = it.first;
123 CPDF_Object* pObj = it.second; 123 CPDF_Object* pObj = it.second;
124 if (!pObj) 124 if (!pObj)
125 continue; 125 continue;
126 126
127 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); 127 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
128 if (!pElement) 128 if (!pElement)
129 continue; 129 continue;
130 if (pElement->GetString("Type") != "Font") 130 if (pElement->GetStringBy("Type") != "Font")
131 continue; 131 continue;
132 132
133 CPDF_Font* pFont = pDocument->LoadFont(pElement); 133 CPDF_Font* pFont = pDocument->LoadFont(pElement);
134 if (!pFont) 134 if (!pFont)
135 continue; 135 continue;
136 const CFX_SubstFont* pSubst = pFont->GetSubstFont(); 136 const CFX_SubstFont* pSubst = pFont->GetSubstFont();
137 if (!pSubst) 137 if (!pSubst)
138 continue; 138 continue;
139 if (pSubst->m_Charset == nCharset) { 139 if (pSubst->m_Charset == nCharset) {
140 sFontAlias = csKey; 140 sFontAlias = csKey;
141 pFind = pFont; 141 pFind = pFont;
142 } 142 }
143 } 143 }
144 return pFind; 144 return pFind;
145 } 145 }
146 146
147 void CBA_FontMap::AddedFont(CPDF_Font* pFont, 147 void CBA_FontMap::AddedFont(CPDF_Font* pFont,
148 const CFX_ByteString& sFontAlias) { 148 const CFX_ByteString& sFontAlias) {
149 AddFontToAnnotDict(pFont, sFontAlias); 149 AddFontToAnnotDict(pFont, sFontAlias);
150 } 150 }
151 151
152 void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, 152 void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
153 const CFX_ByteString& sAlias) { 153 const CFX_ByteString& sAlias) {
154 if (!pFont) 154 if (!pFont)
155 return; 155 return;
156 156
157 ASSERT(m_pAnnotDict != NULL); 157 ASSERT(m_pAnnotDict != NULL);
158 ASSERT(m_pDocument != NULL); 158 ASSERT(m_pDocument != NULL);
159 159
160 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDict("AP"); 160 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP");
161 161
162 if (!pAPDict) { 162 if (!pAPDict) {
163 pAPDict = new CPDF_Dictionary; 163 pAPDict = new CPDF_Dictionary;
164 m_pAnnotDict->SetAt("AP", pAPDict); 164 m_pAnnotDict->SetAt("AP", pAPDict);
165 } 165 }
166 166
167 // to avoid checkbox and radiobutton 167 // to avoid checkbox and radiobutton
168 CPDF_Object* pObject = pAPDict->GetElement(m_sAPType); 168 CPDF_Object* pObject = pAPDict->GetElement(m_sAPType);
169 if (ToDictionary(pObject)) 169 if (ToDictionary(pObject))
170 return; 170 return;
171 171
172 CPDF_Stream* pStream = pAPDict->GetStream(m_sAPType); 172 CPDF_Stream* pStream = pAPDict->GetStreamBy(m_sAPType);
173 if (!pStream) { 173 if (!pStream) {
174 pStream = new CPDF_Stream(NULL, 0, NULL); 174 pStream = new CPDF_Stream(NULL, 0, NULL);
175 int32_t objnum = m_pDocument->AddIndirectObject(pStream); 175 int32_t objnum = m_pDocument->AddIndirectObject(pStream);
176 pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum); 176 pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum);
177 } 177 }
178 178
179 CPDF_Dictionary* pStreamDict = pStream->GetDict(); 179 CPDF_Dictionary* pStreamDict = pStream->GetDict();
180 180
181 if (!pStreamDict) { 181 if (!pStreamDict) {
182 pStreamDict = new CPDF_Dictionary; 182 pStreamDict = new CPDF_Dictionary;
183 pStream->InitStream(NULL, 0, pStreamDict); 183 pStream->InitStream(NULL, 0, pStreamDict);
184 } 184 }
185 185
186 if (pStreamDict) { 186 if (pStreamDict) {
187 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); 187 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources");
188 if (!pStreamResList) { 188 if (!pStreamResList) {
189 pStreamResList = new CPDF_Dictionary(); 189 pStreamResList = new CPDF_Dictionary();
190 pStreamDict->SetAt("Resources", pStreamResList); 190 pStreamDict->SetAt("Resources", pStreamResList);
191 } 191 }
192 192
193 if (pStreamResList) { 193 if (pStreamResList) {
194 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font"); 194 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictBy("Font");
195 if (!pStreamResFontList) { 195 if (!pStreamResFontList) {
196 pStreamResFontList = new CPDF_Dictionary; 196 pStreamResFontList = new CPDF_Dictionary;
197 int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList); 197 int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList);
198 pStreamResList->SetAtReference("Font", m_pDocument, objnum); 198 pStreamResList->SetAtReference("Font", m_pDocument, objnum);
199 } 199 }
200 if (!pStreamResFontList->KeyExist(sAlias)) 200 if (!pStreamResFontList->KeyExist(sAlias))
201 pStreamResFontList->SetAtReference(sAlias, m_pDocument, 201 pStreamResFontList->SetAtReference(sAlias, m_pDocument,
202 pFont->GetFontDict()); 202 pFont->GetFontDict());
203 } 203 }
204 } 204 }
205 } 205 }
206 206
207 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) { 207 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) {
208 ASSERT(m_pAnnotDict != NULL); 208 ASSERT(m_pAnnotDict != NULL);
209 ASSERT(m_pDocument != NULL); 209 ASSERT(m_pDocument != NULL);
210 210
211 CPDF_Dictionary* pAcroFormDict = NULL; 211 CPDF_Dictionary* pAcroFormDict = NULL;
212 212
213 FX_BOOL bWidget = (m_pAnnotDict->GetString("Subtype") == "Widget"); 213 FX_BOOL bWidget = (m_pAnnotDict->GetStringBy("Subtype") == "Widget");
214 214
215 if (bWidget) { 215 if (bWidget) {
216 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot()) 216 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot())
217 pAcroFormDict = pRootDict->GetDict("AcroForm"); 217 pAcroFormDict = pRootDict->GetDictBy("AcroForm");
218 } 218 }
219 219
220 CFX_ByteString sDA; 220 CFX_ByteString sDA;
221 CPDF_Object* pObj; 221 CPDF_Object* pObj;
222 if ((pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA"))) 222 if ((pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA")))
223 sDA = pObj->GetString(); 223 sDA = pObj->GetString();
224 224
225 if (bWidget) { 225 if (bWidget) {
226 if (sDA.IsEmpty()) { 226 if (sDA.IsEmpty()) {
227 pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); 227 pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA");
228 sDA = pObj ? pObj->GetString() : CFX_ByteString(); 228 sDA = pObj ? pObj->GetString() : CFX_ByteString();
229 } 229 }
230 } 230 }
231 231
232 CPDF_Dictionary* pFontDict = NULL; 232 CPDF_Dictionary* pFontDict = NULL;
233 233
234 if (!sDA.IsEmpty()) { 234 if (!sDA.IsEmpty()) {
235 CPDF_SimpleParser syntax(sDA); 235 CPDF_SimpleParser syntax(sDA);
236 syntax.FindTagParam("Tf", 2); 236 syntax.FindTagParam("Tf", 2);
237 CFX_ByteString sFontName = syntax.GetWord(); 237 CFX_ByteString sFontName = syntax.GetWord();
238 sAlias = PDF_NameDecode(sFontName).Mid(1); 238 sAlias = PDF_NameDecode(sFontName).Mid(1);
239 239
240 if (CPDF_Dictionary* pDRDict = m_pAnnotDict->GetDict("DR")) 240 if (CPDF_Dictionary* pDRDict = m_pAnnotDict->GetDictBy("DR"))
241 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDict("Font")) 241 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font"))
242 pFontDict = pDRFontDict->GetDict(sAlias); 242 pFontDict = pDRFontDict->GetDictBy(sAlias);
243 243
244 if (!pFontDict) 244 if (!pFontDict)
245 if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDict("AP")) 245 if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictBy("AP"))
246 if (CPDF_Dictionary* pNormalDict = pAPDict->GetDict("N")) 246 if (CPDF_Dictionary* pNormalDict = pAPDict->GetDictBy("N"))
247 if (CPDF_Dictionary* pNormalResDict = 247 if (CPDF_Dictionary* pNormalResDict =
248 pNormalDict->GetDict("Resources")) 248 pNormalDict->GetDictBy("Resources"))
249 if (CPDF_Dictionary* pResFontDict = pNormalResDict->GetDict("Font")) 249 if (CPDF_Dictionary* pResFontDict =
250 pFontDict = pResFontDict->GetDict(sAlias); 250 pNormalResDict->GetDictBy("Font"))
251 pFontDict = pResFontDict->GetDictBy(sAlias);
251 252
252 if (bWidget) { 253 if (bWidget) {
253 if (!pFontDict) { 254 if (!pFontDict) {
254 if (pAcroFormDict) { 255 if (pAcroFormDict) {
255 if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDict("DR")) 256 if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDictBy("DR"))
256 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDict("Font")) 257 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDictBy("Font"))
257 pFontDict = pDRFontDict->GetDict(sAlias); 258 pFontDict = pDRFontDict->GetDictBy(sAlias);
258 } 259 }
259 } 260 }
260 } 261 }
261 } 262 }
262 263
263 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr; 264 return pFontDict ? m_pDocument->LoadFont(pFontDict) : nullptr;
264 } 265 }
265 266
266 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) { 267 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) {
267 m_sAPType = sAPType; 268 m_sAPType = sAPType;
268 269
269 Reset(); 270 Reset();
270 Initialize(); 271 Initialize();
271 } 272 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_viewerPreferences.cpp ('k') | fpdfsdk/src/fpdf_ext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698