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

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

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

Powered by Google App Engine
This is Rietveld 408576698