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

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

Issue 453133004: clang-format all code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 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
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 "../../include/formfiller/FormFiller.h" 7 #include "../../include/formfiller/FormFiller.h"
8 #include "../../include/formfiller/FFL_CBA_Fontmap.h" 8 #include "../../include/formfiller/FFL_CBA_Fontmap.h"
9 9
10 CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot, IFX_SystemHandler* pSystemHandle r) : 10 CBA_FontMap::CBA_FontMap(CPDFSDK_Annot* pAnnot,
11 CPWL_FontMap(pSystemHandler), 11 IFX_SystemHandler* pSystemHandler)
12 m_pDocument(NULL), 12 : CPWL_FontMap(pSystemHandler),
13 m_pAnnotDict(NULL), 13 m_pDocument(NULL),
14 m_pDefaultFont(NULL), 14 m_pAnnotDict(NULL),
15 m_sAPType("N") 15 m_pDefaultFont(NULL),
16 { 16 m_sAPType("N") {
17 ASSERT(pAnnot != NULL); 17 ASSERT(pAnnot != NULL);
18 18
19 CPDF_Page* pPage = pAnnot->GetPDFPage(); 19 CPDF_Page* pPage = pAnnot->GetPDFPage();
20 20
21 m_pDocument = pPage->m_pDocument; 21 m_pDocument = pPage->m_pDocument;
22 m_pAnnotDict = pAnnot->GetPDFAnnot()->m_pAnnotDict; 22 m_pAnnotDict = pAnnot->GetPDFAnnot()->m_pAnnotDict;
23 } 23 }
24 24
25 CBA_FontMap::CBA_FontMap(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict, 25 CBA_FontMap::CBA_FontMap(CPDF_Document* pDocument,
26 IFX_SystemHandler* pSystemHandl er) : 26 CPDF_Dictionary* pAnnotDict,
27 CPWL_FontMap(pSystemHandler), 27 IFX_SystemHandler* pSystemHandler)
28 m_pDocument(pDocument), 28 : CPWL_FontMap(pSystemHandler),
29 m_pAnnotDict(pAnnotDict), 29 m_pDocument(pDocument),
30 m_pDefaultFont(NULL), 30 m_pAnnotDict(pAnnotDict),
31 m_sAPType("N") 31 m_pDefaultFont(NULL),
32 { 32 m_sAPType("N") {
33 } 33 }
34 34
35 CBA_FontMap::~CBA_FontMap() 35 CBA_FontMap::~CBA_FontMap() {
36 { 36 }
37 } 37
38 38 void CBA_FontMap::Reset() {
39 void CBA_FontMap::Reset() 39 Empty();
40 { 40 m_pDefaultFont = NULL;
41 Empty(); 41 m_sDefaultFontName = "";
42 m_pDefaultFont = NULL; 42 }
43 m_sDefaultFontName = ""; 43
44 } 44 void CBA_FontMap::Initial(FX_LPCSTR fontname) {
45 45 FX_INT32 nCharset = DEFAULT_CHARSET;
46 void CBA_FontMap::Initial(FX_LPCSTR fontname) 46
47 { 47 if (!m_pDefaultFont) {
48 FX_INT32 nCharset = DEFAULT_CHARSET; 48 m_pDefaultFont = GetAnnotDefaultFont(m_sDefaultFontName);
49 49 if (m_pDefaultFont) {
50 if (!m_pDefaultFont) 50 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont())
51 { 51 nCharset = pSubstFont->m_Charset;
52 m_pDefaultFont = GetAnnotDefaultFont(m_sDefaultFontName); 52 else {
53 if (m_pDefaultFont) 53 if (m_sDefaultFontName == "Wingdings" ||
54 { 54 m_sDefaultFontName == "Wingdings2" ||
55 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->Ge tSubstFont()) 55 m_sDefaultFontName == "Wingdings3" ||
56 nCharset = pSubstFont->m_Charset; 56 m_sDefaultFontName == "Webdings")
57 else 57 nCharset = SYMBOL_CHARSET;
58 { 58 else
59 if (m_sDefaultFontName == "Wingdings" || m_sDefa ultFontName == "Wingdings2" || 59 nCharset = ANSI_CHARSET;
60 m_sDefaultFontName == "Wingdings3" || m_ sDefaultFontName == "Webdings") 60 }
61 nCharset = SYMBOL_CHARSET; 61 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset);
62 else 62 AddFontToAnnotDict(m_pDefaultFont, m_sDefaultFontName);
63 nCharset = ANSI_CHARSET; 63 }
64 } 64 }
65 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset ); 65
66 AddFontToAnnotDict(m_pDefaultFont, m_sDefaultFontName); 66 if (nCharset != ANSI_CHARSET)
67 } 67 CPWL_FontMap::Initial(fontname);
68 } 68 }
69 69
70 if (nCharset != ANSI_CHARSET) 70 void CBA_FontMap::SetDefaultFont(CPDF_Font* pFont,
71 CPWL_FontMap::Initial(fontname); 71 const CFX_ByteString& sFontName) {
72 } 72 ASSERT(pFont != NULL);
73 73
74 void CBA_FontMap::SetDefaultFont(CPDF_Font * pFont, const CFX_ByteString & sFont Name) 74 if (m_pDefaultFont)
75 { 75 return;
76 ASSERT(pFont != NULL); 76
77 77 m_pDefaultFont = pFont;
78 if (m_pDefaultFont) return; 78 m_sDefaultFontName = sFontName;
79 79
80 m_pDefaultFont = pFont; 80 // if (m_sDefaultFontName.IsEmpty())
81 m_sDefaultFontName = sFontName; 81 // m_sDefaultFontName = pFont->GetFontTypeName();
82 82
83 // if (m_sDefaultFontName.IsEmpty()) 83 FX_INT32 nCharset = DEFAULT_CHARSET;
84 // m_sDefaultFontName = pFont->GetFontTypeName(); 84 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont())
85 85 nCharset = pSubstFont->m_Charset;
86 FX_INT32 nCharset = DEFAULT_CHARSET; 86 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset);
87 if (const CFX_SubstFont* pSubstFont = m_pDefaultFont->GetSubstFont()) 87 }
88 nCharset = pSubstFont->m_Charset; 88
89 AddFontData(m_pDefaultFont, m_sDefaultFontName, nCharset); 89 CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias,
90 } 90 FX_INT32 nCharset) {
91 91 ASSERT(m_pAnnotDict != NULL);
92 CPDF_Font* CBA_FontMap::FindFontSameCharset(CFX_ByteString& sFontAlias, FX_INT32 nCharset) 92
93 { 93 if (m_pAnnotDict->GetString("Subtype") == "Widget") {
94 ASSERT(m_pAnnotDict != NULL); 94 CPDF_Document* pDocument = GetDocument();
95 95 ASSERT(pDocument != NULL);
96 if (m_pAnnotDict->GetString("Subtype") == "Widget") 96
97 { 97 CPDF_Dictionary* pRootDict = pDocument->GetRoot();
98 CPDF_Document* pDocument = GetDocument(); 98 if (!pRootDict)
99 ASSERT(pDocument != NULL); 99 return NULL;
100 100
101 CPDF_Dictionary * pRootDict = pDocument->GetRoot(); 101 CPDF_Dictionary* pAcroFormDict = pRootDict->GetDict("AcroForm");
102 if (!pRootDict) return NULL; 102 if (!pAcroFormDict)
103 103 return NULL;
104 CPDF_Dictionary* pAcroFormDict = pRootDict->GetDict("AcroForm"); 104
105 if (!pAcroFormDict) return NULL; 105 CPDF_Dictionary* pDRDict = pAcroFormDict->GetDict("DR");
106 106 if (!pDRDict)
107 CPDF_Dictionary * pDRDict = pAcroFormDict->GetDict("DR"); 107 return NULL;
108 if (!pDRDict) return NULL; 108
109 109 return FindResFontSameCharset(pDRDict, sFontAlias, nCharset);
110 return FindResFontSameCharset(pDRDict, sFontAlias, nCharset); 110 }
111 } 111
112 112 return NULL;
113 return NULL; 113 }
114 } 114
115 115 CPDF_Document* CBA_FontMap::GetDocument() {
116 CPDF_Document* CBA_FontMap::GetDocument() 116 return m_pDocument;
117 { 117 }
118 return m_pDocument; 118
119 } 119 CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict,
120 120 CFX_ByteString& sFontAlias,
121 CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict, CFX_By teString& sFontAlias, 121 FX_INT32 nCharset) {
122 FX_INT32 nCharset) 122 if (!pResDict)
123 { 123 return NULL;
124 if (!pResDict) return NULL; 124
125 125 CPDF_Document* pDocument = GetDocument();
126 CPDF_Document* pDocument = GetDocument(); 126 ASSERT(pDocument != NULL);
127 ASSERT(pDocument != NULL); 127
128 128 CPDF_Dictionary* pFonts = pResDict->GetDict("Font");
129 CPDF_Dictionary* pFonts = pResDict->GetDict("Font"); 129 if (pFonts == NULL)
130 if (pFonts == NULL) return NULL; 130 return NULL;
131 131
132 CPDF_Font* pFind = NULL; 132 CPDF_Font* pFind = NULL;
133 133
134 FX_POSITION pos = pFonts->GetStartPos(); 134 FX_POSITION pos = pFonts->GetStartPos();
135 while (pos) 135 while (pos) {
136 { 136 CPDF_Object* pObj = NULL;
137 CPDF_Object* pObj = NULL; 137 CFX_ByteString csKey;
138 CFX_ByteString csKey; 138 pObj = pFonts->GetNextElement(pos, csKey);
139 pObj = pFonts->GetNextElement(pos, csKey); 139 if (pObj == NULL)
140 if (pObj == NULL) continue; 140 continue;
141 141
142 CPDF_Object* pDirect = pObj->GetDirect(); 142 CPDF_Object* pDirect = pObj->GetDirect();
143 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY) continue; 143 if (pDirect == NULL || pDirect->GetType() != PDFOBJ_DICTIONARY)
144 144 continue;
145 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect; 145
146 if (pElement->GetString("Type") != "Font") continue; 146 CPDF_Dictionary* pElement = (CPDF_Dictionary*)pDirect;
147 147 if (pElement->GetString("Type") != "Font")
148 CPDF_Font* pFont = pDocument->LoadFont(pElement); 148 continue;
149 if (pFont == NULL) continue; 149
150 const CFX_SubstFont* pSubst = pFont->GetSubstFont(); 150 CPDF_Font* pFont = pDocument->LoadFont(pElement);
151 if (pSubst == NULL) continue; 151 if (pFont == NULL)
152 if (pSubst->m_Charset == nCharset) 152 continue;
153 { 153 const CFX_SubstFont* pSubst = pFont->GetSubstFont();
154 sFontAlias = csKey; 154 if (pSubst == NULL)
155 pFind = pFont; 155 continue;
156 } 156 if (pSubst->m_Charset == nCharset) {
157 } 157 sFontAlias = csKey;
158 return pFind; 158 pFind = pFont;
159 } 159 }
160 160 }
161 void CBA_FontMap::AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias) 161 return pFind;
162 { 162 }
163 AddFontToAnnotDict(pFont, sFontAlias); 163
164 } 164 void CBA_FontMap::AddedFont(CPDF_Font* pFont,
165 165 const CFX_ByteString& sFontAlias) {
166 void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, const CFX_ByteString& sAl ias) 166 AddFontToAnnotDict(pFont, sFontAlias);
167 { 167 }
168 if (!pFont) return; 168
169 169 void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
170 ASSERT(m_pAnnotDict != NULL); 170 const CFX_ByteString& sAlias) {
171 ASSERT(m_pDocument != NULL); 171 if (!pFont)
172 172 return;
173 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDict("AP"); 173
174 174 ASSERT(m_pAnnotDict != NULL);
175 if (pAPDict == NULL) 175 ASSERT(m_pDocument != NULL);
176 { 176
177 pAPDict = FX_NEW CPDF_Dictionary; 177 CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDict("AP");
178 m_pAnnotDict->SetAt("AP", pAPDict); 178
179 } 179 if (pAPDict == NULL) {
180 180 pAPDict = FX_NEW CPDF_Dictionary;
181 //to avoid checkbox and radiobutton 181 m_pAnnotDict->SetAt("AP", pAPDict);
182 CPDF_Object* pObject = pAPDict->GetElement(m_sAPType); 182 }
183 if (pObject && pObject->GetType() == PDFOBJ_DICTIONARY) 183
184 return; 184 // to avoid checkbox and radiobutton
185 185 CPDF_Object* pObject = pAPDict->GetElement(m_sAPType);
186 CPDF_Stream* pStream = pAPDict->GetStream(m_sAPType); 186 if (pObject && pObject->GetType() == PDFOBJ_DICTIONARY)
187 if (pStream == NULL) 187 return;
188 { 188
189 pStream = FX_NEW CPDF_Stream(NULL, 0, NULL); 189 CPDF_Stream* pStream = pAPDict->GetStream(m_sAPType);
190 FX_INT32 objnum = m_pDocument->AddIndirectObject(pStream); 190 if (pStream == NULL) {
191 pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum); 191 pStream = FX_NEW CPDF_Stream(NULL, 0, NULL);
192 } 192 FX_INT32 objnum = m_pDocument->AddIndirectObject(pStream);
193 193 pAPDict->SetAtReference(m_sAPType, m_pDocument, objnum);
194 CPDF_Dictionary * pStreamDict = pStream->GetDict(); 194 }
195 195
196 if (!pStreamDict) 196 CPDF_Dictionary* pStreamDict = pStream->GetDict();
197 { 197
198 pStreamDict = FX_NEW CPDF_Dictionary; 198 if (!pStreamDict) {
199 pStream->InitStream(NULL, 0, pStreamDict); 199 pStreamDict = FX_NEW CPDF_Dictionary;
200 } 200 pStream->InitStream(NULL, 0, pStreamDict);
201 201 }
202 if (pStreamDict) 202
203 { 203 if (pStreamDict) {
204 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resource s"); 204 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");
205 if (!pStreamResList) 205 if (!pStreamResList) {
206 { 206 pStreamResList = FX_NEW CPDF_Dictionary();
207 pStreamResList = FX_NEW CPDF_Dictionary(); 207 pStreamDict->SetAt("Resources", pStreamResList);
208 pStreamDict->SetAt("Resources", pStreamResList); 208 }
209 } 209
210 210 if (pStreamResList) {
211 if (pStreamResList) 211 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDict("Font");
212 { 212 if (!pStreamResFontList) {
213 CPDF_Dictionary* pStreamResFontList = pStreamResList->Ge tDict("Font"); 213 pStreamResFontList = FX_NEW CPDF_Dictionary;
214 if (!pStreamResFontList) 214 FX_INT32 objnum = m_pDocument->AddIndirectObject(pStreamResFontList);
215 { 215 pStreamResList->SetAtReference("Font", m_pDocument, objnum);
216 pStreamResFontList = FX_NEW CPDF_Dictionary; 216 }
217 FX_INT32 objnum = m_pDocument->AddIndirectObject (pStreamResFontList); 217 if (!pStreamResFontList->KeyExist(sAlias))
218 pStreamResList->SetAtReference("Font", m_pDocume nt, objnum); 218 pStreamResFontList->SetAtReference(
219 } 219 sAlias, m_pDocument, pFont->GetFontDict());
220 if (!pStreamResFontList->KeyExist(sAlias)) 220 }
221 pStreamResFontList->SetAtReference(sAlias, m_pDo cument, pFont->GetFontDict()); 221 }
222 } 222 }
223 } 223
224 } 224 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString& sAlias) {
225 225 ASSERT(m_pAnnotDict != NULL);
226 CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(CFX_ByteString &sAlias) 226 ASSERT(m_pDocument != NULL);
227 { 227
228 ASSERT(m_pAnnotDict != NULL); 228 CPDF_Dictionary* pAcroFormDict = NULL;
229 ASSERT(m_pDocument != NULL); 229
230 230 FX_BOOL bWidget = (m_pAnnotDict->GetString("Subtype") == "Widget");
231 CPDF_Dictionary* pAcroFormDict = NULL; 231
232 232 if (bWidget) {
233 FX_BOOL bWidget = (m_pAnnotDict->GetString("Subtype") == "Widget"); 233 if (CPDF_Dictionary* pRootDict = m_pDocument->GetRoot())
234 234 pAcroFormDict = pRootDict->GetDict("AcroForm");
235 if (bWidget) 235 }
236 { 236
237 if (CPDF_Dictionary * pRootDict = m_pDocument->GetRoot()) 237 CFX_ByteString sDA;
238 pAcroFormDict = pRootDict->GetDict("AcroForm"); 238 CPDF_Object* pObj;
239 } 239 if ((pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA")))
240 240 sDA = pObj->GetString();
241 CFX_ByteString sDA; 241
242 CPDF_Object* pObj; 242 if (bWidget) {
243 if ((pObj = FPDF_GetFieldAttr(m_pAnnotDict, "DA"))) 243 if (sDA.IsEmpty()) {
244 sDA = pObj->GetString(); 244 pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA");
245 245 sDA = pObj ? pObj->GetString() : CFX_ByteString();
246 if (bWidget) 246 }
247 { 247 }
248 if (sDA.IsEmpty()) 248
249 { 249 CPDF_Dictionary* pFontDict = NULL;
250 pObj = FPDF_GetFieldAttr(pAcroFormDict, "DA"); 250
251 sDA = pObj ? pObj->GetString() : CFX_ByteString(); 251 if (!sDA.IsEmpty()) {
252 } 252 CPDF_SimpleParser syntax(sDA);
253 } 253 syntax.FindTagParam("Tf", 2);
254 254 CFX_ByteString sFontName = syntax.GetWord();
255 CPDF_Dictionary * pFontDict = NULL; 255 sAlias = PDF_NameDecode(sFontName).Mid(1);
256 256
257 if (!sDA.IsEmpty()) 257 if (CPDF_Dictionary* pDRDict = m_pAnnotDict->GetDict("DR"))
258 { 258 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDict("Font"))
259 CPDF_SimpleParser syntax(sDA); 259 pFontDict = pDRFontDict->GetDict(sAlias);
260 syntax.FindTagParam("Tf", 2); 260
261 CFX_ByteString sFontName = syntax.GetWord(); 261 if (!pFontDict)
262 sAlias = PDF_NameDecode(sFontName).Mid(1); 262 if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDict("AP"))
263 263 if (CPDF_Dictionary* pNormalDict = pAPDict->GetDict("N"))
264 if (CPDF_Dictionary * pDRDict = m_pAnnotDict->GetDict("DR")) 264 if (CPDF_Dictionary* pNormalResDict =
265 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDict("Fon t")) 265 pNormalDict->GetDict("Resources"))
266 pFontDict = pDRFontDict->GetDict(sAlias); 266 if (CPDF_Dictionary* pResFontDict = pNormalResDict->GetDict("Font"))
267 267 pFontDict = pResFontDict->GetDict(sAlias);
268 if (!pFontDict) 268
269 if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDict("AP ")) 269 if (bWidget) {
270 if (CPDF_Dictionary* pNormalDict = pAPDict->GetD ict("N")) 270 if (!pFontDict) {
271 if (CPDF_Dictionary* pNormalResDict = pN ormalDict->GetDict("Resources")) 271 if (pAcroFormDict) {
272 if (CPDF_Dictionary* pResFontDic t = pNormalResDict->GetDict("Font")) 272 if (CPDF_Dictionary* pDRDict = pAcroFormDict->GetDict("DR"))
273 pFontDict = pResFontDict ->GetDict(sAlias); 273 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDict("Font"))
274 274 pFontDict = pDRFontDict->GetDict(sAlias);
275 if (bWidget) 275 }
276 { 276 }
277 if (!pFontDict) 277 }
278 { 278 }
279 if (pAcroFormDict) 279
280 { 280 if (pFontDict)
281 if (CPDF_Dictionary * pDRDict = pAcroFor mDict->GetDict("DR")) 281 return m_pDocument->LoadFont(pFontDict);
282 if (CPDF_Dictionary* pDRFontDict = pDRDict->GetDict("Font")) 282 else
283 pFontDict = pDRFontDict- >GetDict(sAlias); 283 return NULL;
284 } 284 }
285 } 285
286 } 286 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType) {
287 } 287 m_sAPType = sAPType;
288 288
289 if (pFontDict) 289 Reset();
290 return m_pDocument->LoadFont(pFontDict); 290 Initial();
291 else 291 }
292 return NULL;
293 }
294
295 void CBA_FontMap::SetAPType(const CFX_ByteString& sAPType)
296 {
297 m_sAPType = sAPType;
298
299 Reset();
300 Initial();
301 }
302
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698