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

Side by Side Diff: fpdfsdk/src/fpdfppo.cpp

Issue 1410343003: [Merge to XFA] Revert "Revert "Add type cast definitions for CPDF_Dictionary."" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 2 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 "../../public/fpdf_ppo.h" 7 #include "../../public/fpdf_ppo.h"
8 #include "../include/fsdk_define.h" 8 #include "../include/fsdk_define.h"
9 #include "../include/fpdfxfa/fpdfxfa_doc.h" 9 #include "../include/fpdfxfa/fpdfxfa_doc.h"
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 CFX_ByteString producerstr; 52 CFX_ByteString producerstr;
53 producerstr.Format("PDFium"); 53 producerstr.Format("PDFium");
54 DInfoDict->SetAt("Producer", new CPDF_String(producerstr)); 54 DInfoDict->SetAt("Producer", new CPDF_String(producerstr));
55 55
56 // Set type//////////////////////////////////////////////////////////////// 56 // Set type////////////////////////////////////////////////////////////////
57 CFX_ByteString cbRootType = pNewRoot->GetString("Type", ""); 57 CFX_ByteString cbRootType = pNewRoot->GetString("Type", "");
58 if (cbRootType.Equal("")) { 58 if (cbRootType.Equal("")) {
59 pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); 59 pNewRoot->SetAt("Type", new CPDF_Name("Catalog"));
60 } 60 }
61 61
62 CPDF_Dictionary* pNewPages = 62 CPDF_Dictionary* pNewPages = ToDictionary(
63 (CPDF_Dictionary*)(pNewRoot->GetElement("Pages") 63 pNewRoot->GetElement("Pages") ? pNewRoot->GetElement("Pages")->GetDirect()
dsinclair 2015/10/20 19:18:31 This code differs slightly from master and was mer
64 ? pNewRoot->GetElement("Pages")->GetDirect() 64 : nullptr);
65 : NULL); 65
66 if (!pNewPages) { 66 if (!pNewPages) {
67 pNewPages = new CPDF_Dictionary; 67 pNewPages = new CPDF_Dictionary;
68 FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages); 68 FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages);
69 pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON)); 69 pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON));
70 } 70 }
71 71
72 CFX_ByteString cbPageType = pNewPages->GetString("Type", ""); 72 CFX_ByteString cbPageType = pNewPages->GetString("Type", "");
73 if (cbPageType.Equal("")) { 73 if (cbPageType.Equal("")) {
74 pNewPages->SetAt("Type", new CPDF_Name("Pages")); 74 pNewPages->SetAt("Type", new CPDF_Name("Pages"));
75 } 75 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 CFX_ByteString nSrctag) { 184 CFX_ByteString nSrctag) {
185 if (!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty()) 185 if (!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty())
186 return NULL; 186 return NULL;
187 187
188 CPDF_Object* pType = pDict->GetElement("Type")->GetDirect(); 188 CPDF_Object* pType = pDict->GetElement("Type")->GetDirect();
189 if (!pType || pType->GetType() != PDFOBJ_NAME) 189 if (!pType || pType->GetType() != PDFOBJ_NAME)
190 return NULL; 190 return NULL;
191 191
192 if (pType->GetString().Compare("Page")) 192 if (pType->GetString().Compare("Page"))
193 return NULL; 193 return NULL;
194
195 if (!pDict->KeyExist("Parent")) 194 if (!pDict->KeyExist("Parent"))
dsinclair 2015/10/20 19:18:31 This key check doesn't exist on master and caused
196 return NULL; 195 return NULL;
197 CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect();
198 if (!pParent || pParent->GetType() != PDFOBJ_DICTIONARY)
199 return NULL;
200 196
201 CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent; 197 CPDF_Dictionary* pp = ToDictionary(pDict->GetElement("Parent")->GetDirect());
198 if (!pp)
199 return nullptr;
202 200
203 if (pDict->KeyExist((const char*)nSrctag)) 201 if (pDict->KeyExist((const char*)nSrctag))
204 return pDict->GetElement((const char*)nSrctag); 202 return pDict->GetElement((const char*)nSrctag);
203
205 while (pp) { 204 while (pp) {
206 if (pp->KeyExist((const char*)nSrctag)) 205 if (pp->KeyExist((const char*)nSrctag))
207 return pp->GetElement((const char*)nSrctag); 206 return pp->GetElement((const char*)nSrctag);
208 if (pp->KeyExist("Parent")) { 207 if (pp->KeyExist("Parent")) {
209 pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect(); 208 pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect();
210 if (pp->GetType() == PDFOBJ_NULL) 209 if (pp->GetType() == PDFOBJ_NULL)
211 break; 210 break;
212 } else 211 } else
213 break; 212 break;
214 } 213 }
dsinclair 2015/10/20 19:18:31 This is a bit weird, on master the while ends with
Tom Sepez 2015/10/20 19:49:28 Looks like on master we inverted the if at 207 to
dsinclair 2015/10/20 19:57:16 Done.
215 214
216 return NULL; 215 return nullptr;
217 } 216 }
218 217
219 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, 218 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
220 CPDF_Document* pDoc, 219 CPDF_Document* pDoc,
221 CFX_MapPtrToPtr* pMapPtrToPtr) { 220 CFX_MapPtrToPtr* pMapPtrToPtr) {
222 switch (pObj->GetType()) { 221 switch (pObj->GetType()) {
223 case PDFOBJ_REFERENCE: { 222 case PDFOBJ_REFERENCE: {
224 CPDF_Reference* pReference = (CPDF_Reference*)pObj; 223 CPDF_Reference* pReference = (CPDF_Reference*)pObj;
225 int newobjnum = GetNewObjId(pDoc, pMapPtrToPtr, pReference); 224 int newobjnum = GetNewObjId(pDoc, pMapPtrToPtr, pReference);
226 if (newobjnum == 0) 225 if (newobjnum == 0)
227 return FALSE; 226 return FALSE;
228 pReference->SetRef(pDoc, newobjnum); //, 0); 227 pReference->SetRef(pDoc, newobjnum); //, 0);
229 break; 228 break;
230 } 229 }
231 case PDFOBJ_DICTIONARY: { 230 case PDFOBJ_DICTIONARY: {
232 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; 231 CPDF_Dictionary* pDict = pObj->AsDictionary();
233 232
234 FX_POSITION pos = pDict->GetStartPos(); 233 FX_POSITION pos = pDict->GetStartPos();
235 while (pos) { 234 while (pos) {
236 CFX_ByteString key(""); 235 CFX_ByteString key("");
237 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key); 236 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key);
238 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || 237 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") ||
239 !FXSYS_strcmp(key, "First")) 238 !FXSYS_strcmp(key, "First"))
240 continue; 239 continue;
241 if (pNextObj) { 240 if (pNextObj) {
242 if (!UpdateReference(pNextObj, pDoc, pMapPtrToPtr)) 241 if (!UpdateReference(pNextObj, pDoc, pMapPtrToPtr))
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 CPDF_Object* pDirect = pRef->GetDirect(); 292 CPDF_Object* pDirect = pRef->GetDirect();
294 if (!pDirect) { 293 if (!pDirect) {
295 return 0; 294 return 0;
296 } 295 }
297 296
298 CPDF_Object* pClone = pDirect->Clone(); 297 CPDF_Object* pClone = pDirect->Clone();
299 if (!pClone) { 298 if (!pClone) {
300 return 0; 299 return 0;
301 } 300 }
302 301
303 if (pClone->GetType() == PDFOBJ_DICTIONARY) { 302 if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) {
304 CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone;
305 if (pDictClone->KeyExist("Type")) { 303 if (pDictClone->KeyExist("Type")) {
306 CFX_ByteString strType = pDictClone->GetString("Type"); 304 CFX_ByteString strType = pDictClone->GetString("Type");
307 if (!FXSYS_stricmp(strType, "Pages")) { 305 if (!FXSYS_stricmp(strType, "Pages")) {
308 pDictClone->Release(); 306 pDictClone->Release();
309 return 4; 307 return 4;
310 } else if (!FXSYS_stricmp(strType, "Page")) { 308 } else if (!FXSYS_stricmp(strType, "Page")) {
311 pDictClone->Release(); 309 pDictClone->Release();
312 return 0; 310 return 0;
313 } 311 }
314 } 312 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 if (!pSrcDict) 416 if (!pSrcDict)
419 return FALSE; 417 return FALSE;
420 418
421 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); 419 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot();
422 if (!pDstDict) 420 if (!pDstDict)
423 return FALSE; 421 return FALSE;
424 422
425 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE)); 423 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE));
426 return TRUE; 424 return TRUE;
427 } 425 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698