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 "../../public/fpdf_ppo.h" | 7 #include "../../public/fpdf_ppo.h" |
8 #include "../../third_party/base/nonstd_unique_ptr.h" | 8 #include "../../third_party/base/nonstd_unique_ptr.h" |
9 #include "../include/fsdk_define.h" | 9 #include "../include/fsdk_define.h" |
10 | 10 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 ++curpage; | 178 ++curpage; |
179 } | 179 } |
180 | 180 |
181 return TRUE; | 181 return TRUE; |
182 } | 182 } |
183 | 183 |
184 CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag( | 184 CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag( |
185 CPDF_Dictionary* pDict, | 185 CPDF_Dictionary* pDict, |
186 CFX_ByteString nSrctag) | 186 CFX_ByteString nSrctag) |
187 { | 187 { |
188 if (!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty()) | 188 if (!pDict || nSrctag.IsEmpty()) |
189 return nullptr; | 189 return nullptr; |
190 if (!pDict->KeyExist("Parent")) | 190 if (!pDict->KeyExist("Parent") || !pDict->KeyExist("Type")) |
191 return nullptr; | 191 return nullptr; |
192 | 192 |
193 CPDF_Object* pType = pDict->GetElement("Type")->GetDirect(); | 193 CPDF_Object* pType = pDict->GetElement("Type")->GetDirect(); |
194 if (!pType || pType->GetType() != PDFOBJ_NAME) | 194 if (!pType || pType->GetType() != PDFOBJ_NAME) |
195 return nullptr; | 195 return nullptr; |
196 if (pType->GetString().Compare("Page")) | 196 if (pType->GetString().Compare("Page")) |
197 return nullptr; | 197 return nullptr; |
198 | 198 |
199 CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect(); | 199 CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect(); |
200 if (!pParent || pParent->GetType() != PDFOBJ_DICTIONARY) | 200 if (!pParent || pParent->GetType() != PDFOBJ_DICTIONARY) |
201 return nullptr; | 201 return nullptr; |
202 | 202 |
203 CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent; | |
204 | |
205 if (pDict->KeyExist((const char*)nSrctag)) | 203 if (pDict->KeyExist((const char*)nSrctag)) |
206 return pDict->GetElement((const char*)nSrctag); | 204 return pDict->GetElement((const char*)nSrctag); |
207 | 205 |
| 206 CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent; |
208 while (pp) { | 207 while (pp) { |
209 if (pp->KeyExist((const char*)nSrctag)) { | 208 if (pp->KeyExist((const char*)nSrctag)) { |
210 return pp->GetElement((const char*)nSrctag); | 209 return pp->GetElement((const char*)nSrctag); |
211 } else if (pp->KeyExist("Parent")) { | 210 } |
212 pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect(); | 211 if (!pp->KeyExist("Parent")) { |
213 if (pp->GetType() == PDFOBJ_NULL) | 212 break; |
214 break; | 213 } |
215 } else { | 214 pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect(); |
| 215 if (pp->GetType() == PDFOBJ_NULL) { |
216 break; | 216 break; |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 return nullptr; | 220 return nullptr; |
221 } | 221 } |
222 | 222 |
223 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, | 223 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, |
224 CPDF_Document* pDoc, | 224 CPDF_Document* pDoc, |
225 ObjectNumberMap* pObjNumberMap) | 225 ObjectNumberMap* pObjNumberMap) |
(...skipping 26 matching lines...) Expand all Loading... |
252 return FALSE; | 252 return FALSE; |
253 } | 253 } |
254 } | 254 } |
255 break; | 255 break; |
256 } | 256 } |
257 case PDFOBJ_ARRAY: { | 257 case PDFOBJ_ARRAY: { |
258 CPDF_Array* pArray = (CPDF_Array*)pObj; | 258 CPDF_Array* pArray = (CPDF_Array*)pObj; |
259 FX_DWORD count = pArray->GetCount(); | 259 FX_DWORD count = pArray->GetCount(); |
260 for (FX_DWORD i = 0; i < count; ++i) { | 260 for (FX_DWORD i = 0; i < count; ++i) { |
261 CPDF_Object* pNextObj = pArray->GetElement(i); | 261 CPDF_Object* pNextObj = pArray->GetElement(i); |
262 if (pNextObj) { | 262 if (!pNextObj) |
263 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) | |
264 return FALSE; | |
265 } else { | |
266 return FALSE; | 263 return FALSE; |
267 } | 264 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) |
| 265 return FALSE; |
268 } | 266 } |
269 break; | 267 break; |
270 } | 268 } |
271 case PDFOBJ_STREAM: { | 269 case PDFOBJ_STREAM: { |
272 CPDF_Stream* pStream = (CPDF_Stream*)pObj; | 270 CPDF_Stream* pStream = (CPDF_Stream*)pObj; |
273 CPDF_Dictionary* pDict = pStream->GetDict(); | 271 CPDF_Dictionary* pDict = pStream->GetDict(); |
274 if (pDict) { | 272 if (pDict) { |
275 if (!UpdateReference(pDict, pDoc, pObjNumberMap)) | 273 if (!UpdateReference(pDict, pDoc, pObjNumberMap)) |
276 return FALSE; | 274 return FALSE; |
277 } else { | 275 } else { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 if (!pClone) | 307 if (!pClone) |
310 return 0; | 308 return 0; |
311 | 309 |
312 if (pClone->GetType() == PDFOBJ_DICTIONARY) { | 310 if (pClone->GetType() == PDFOBJ_DICTIONARY) { |
313 CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone; | 311 CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone; |
314 if (pDictClone->KeyExist("Type")) { | 312 if (pDictClone->KeyExist("Type")) { |
315 CFX_ByteString strType = pDictClone->GetString("Type"); | 313 CFX_ByteString strType = pDictClone->GetString("Type"); |
316 if (!FXSYS_stricmp(strType, "Pages")) { | 314 if (!FXSYS_stricmp(strType, "Pages")) { |
317 pDictClone->Release(); | 315 pDictClone->Release(); |
318 return 4; | 316 return 4; |
319 } else if (!FXSYS_stricmp(strType, "Page")) { | 317 } |
| 318 if (!FXSYS_stricmp(strType, "Page")) { |
320 pDictClone->Release(); | 319 pDictClone->Release(); |
321 return 0; | 320 return 0; |
322 } | 321 } |
323 } | 322 } |
324 } | 323 } |
325 dwNewObjNum = pDoc->AddIndirectObject(pClone); | 324 dwNewObjNum = pDoc->AddIndirectObject(pClone); |
326 (*pObjNumberMap)[dwObjnum] = dwNewObjNum; | 325 (*pObjNumberMap)[dwObjnum] = dwNewObjNum; |
327 | 326 |
328 if (!UpdateReference(pClone, pDoc, pObjNumberMap)) { | 327 if (!UpdateReference(pClone, pDoc, pObjNumberMap)) { |
329 pClone->Release(); | 328 pClone->Release(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 ++nMid; | 365 ++nMid; |
367 int nEnd = cbMidRange.GetLength() - nMid; | 366 int nEnd = cbMidRange.GetLength() - nMid; |
368 if (nEnd == 0) | 367 if (nEnd == 0) |
369 return FALSE; | 368 return FALSE; |
370 | 369 |
371 int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd)); | 370 int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd)); |
372 if (nStartPageNum < 0 || | 371 if (nStartPageNum < 0 || |
373 nStartPageNum >nEndPageNum || | 372 nStartPageNum >nEndPageNum || |
374 nEndPageNum > nCount) { | 373 nEndPageNum > nCount) { |
375 return FALSE; | 374 return FALSE; |
376 } else { | 375 } |
377 for (int i = nStartPageNum; i <= nEndPageNum; ++i) { | 376 for (int i = nStartPageNum; i <= nEndPageNum; ++i) { |
378 pageArray->Add(i); | 377 pageArray->Add(i); |
379 } | |
380 } | 378 } |
381 } | 379 } |
382 nStringFrom = nStringTo + 1; | 380 nStringFrom = nStringTo + 1; |
383 } | 381 } |
384 } | 382 } |
385 return TRUE; | 383 return TRUE; |
386 } | 384 } |
387 | 385 |
388 DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc, | 386 DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc, |
389 FPDF_DOCUMENT src_doc, | 387 FPDF_DOCUMENT src_doc, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 if (!pSrcDict) | 423 if (!pSrcDict) |
426 return FALSE; | 424 return FALSE; |
427 | 425 |
428 CPDF_Document* pDstDoc = (CPDF_Document*)dest_doc; | 426 CPDF_Document* pDstDoc = (CPDF_Document*)dest_doc; |
429 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 427 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
430 if (!pDstDict) | 428 if (!pDstDict) |
431 return FALSE; | 429 return FALSE; |
432 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE)); | 430 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE)); |
433 return TRUE; | 431 return TRUE; |
434 } | 432 } |
OLD | NEW |