| 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 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 CPDF_Object* pType = pDict->GetObjectBy("Type")->GetDirect(); | 184 CPDF_Object* pType = pDict->GetObjectBy("Type")->GetDirect(); |
| 185 if (!ToName(pType)) | 185 if (!ToName(pType)) |
| 186 return nullptr; | 186 return nullptr; |
| 187 if (pType->GetString().Compare("Page")) | 187 if (pType->GetString().Compare("Page")) |
| 188 return nullptr; | 188 return nullptr; |
| 189 | 189 |
| 190 CPDF_Dictionary* pp = ToDictionary(pDict->GetObjectBy("Parent")->GetDirect()); | 190 CPDF_Dictionary* pp = ToDictionary(pDict->GetObjectBy("Parent")->GetDirect()); |
| 191 if (!pp) | 191 if (!pp) |
| 192 return nullptr; | 192 return nullptr; |
| 193 | 193 |
| 194 if (pDict->KeyExist((const char*)nSrctag)) | 194 if (pDict->KeyExist(nSrctag.AsStringC())) |
| 195 return pDict->GetObjectBy((const char*)nSrctag); | 195 return pDict->GetObjectBy(nSrctag.AsStringC()); |
| 196 | 196 |
| 197 while (pp) { | 197 while (pp) { |
| 198 if (pp->KeyExist((const char*)nSrctag)) | 198 if (pp->KeyExist(nSrctag.AsStringC())) |
| 199 return pp->GetObjectBy((const char*)nSrctag); | 199 return pp->GetObjectBy(nSrctag.AsStringC()); |
| 200 if (!pp->KeyExist("Parent")) | 200 if (!pp->KeyExist("Parent")) |
| 201 break; | 201 break; |
| 202 pp = ToDictionary(pp->GetObjectBy("Parent")->GetDirect()); | 202 pp = ToDictionary(pp->GetObjectBy("Parent")->GetDirect()); |
| 203 } | 203 } |
| 204 return nullptr; | 204 return nullptr; |
| 205 } | 205 } |
| 206 | 206 |
| 207 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, | 207 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj, |
| 208 CPDF_Document* pDoc, | 208 CPDF_Document* pDoc, |
| 209 ObjectNumberMap* pObjNumberMap) { | 209 ObjectNumberMap* pObjNumberMap) { |
| 210 switch (pObj->GetType()) { | 210 switch (pObj->GetType()) { |
| 211 case CPDF_Object::REFERENCE: { | 211 case CPDF_Object::REFERENCE: { |
| 212 CPDF_Reference* pReference = pObj->AsReference(); | 212 CPDF_Reference* pReference = pObj->AsReference(); |
| 213 uint32_t newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); | 213 uint32_t newobjnum = GetNewObjId(pDoc, pObjNumberMap, pReference); |
| 214 if (newobjnum == 0) | 214 if (newobjnum == 0) |
| 215 return FALSE; | 215 return FALSE; |
| 216 pReference->SetRef(pDoc, newobjnum); | 216 pReference->SetRef(pDoc, newobjnum); |
| 217 break; | 217 break; |
| 218 } | 218 } |
| 219 case CPDF_Object::DICTIONARY: { | 219 case CPDF_Object::DICTIONARY: { |
| 220 CPDF_Dictionary* pDict = pObj->AsDictionary(); | 220 CPDF_Dictionary* pDict = pObj->AsDictionary(); |
| 221 auto it = pDict->begin(); | 221 auto it = pDict->begin(); |
| 222 while (it != pDict->end()) { | 222 while (it != pDict->end()) { |
| 223 const CFX_ByteString& key = it->first; | 223 const CFX_ByteString& key = it->first; |
| 224 CPDF_Object* pNextObj = it->second; | 224 CPDF_Object* pNextObj = it->second; |
| 225 ++it; | 225 ++it; |
| 226 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") || | 226 if (!FXSYS_strcmp(key.c_str(), "Parent") || |
| 227 !FXSYS_strcmp(key, "First")) { | 227 !FXSYS_strcmp(key.c_str(), "Prev") || |
| 228 !FXSYS_strcmp(key.c_str(), "First")) { |
| 228 continue; | 229 continue; |
| 229 } | 230 } |
| 230 if (pNextObj) { | 231 if (pNextObj) { |
| 231 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) | 232 if (!UpdateReference(pNextObj, pDoc, pObjNumberMap)) |
| 232 pDict->RemoveAt(key.AsStringC()); | 233 pDict->RemoveAt(key.AsStringC()); |
| 233 } else { | 234 } else { |
| 234 return FALSE; | 235 return FALSE; |
| 235 } | 236 } |
| 236 } | 237 } |
| 237 break; | 238 break; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 if (!pDirect) | 284 if (!pDirect) |
| 284 return 0; | 285 return 0; |
| 285 | 286 |
| 286 CPDF_Object* pClone = pDirect->Clone(); | 287 CPDF_Object* pClone = pDirect->Clone(); |
| 287 if (!pClone) | 288 if (!pClone) |
| 288 return 0; | 289 return 0; |
| 289 | 290 |
| 290 if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) { | 291 if (CPDF_Dictionary* pDictClone = pClone->AsDictionary()) { |
| 291 if (pDictClone->KeyExist("Type")) { | 292 if (pDictClone->KeyExist("Type")) { |
| 292 CFX_ByteString strType = pDictClone->GetStringBy("Type"); | 293 CFX_ByteString strType = pDictClone->GetStringBy("Type"); |
| 293 if (!FXSYS_stricmp(strType, "Pages")) { | 294 if (!FXSYS_stricmp(strType.c_str(), "Pages")) { |
| 294 pDictClone->Release(); | 295 pDictClone->Release(); |
| 295 return 4; | 296 return 4; |
| 296 } | 297 } |
| 297 if (!FXSYS_stricmp(strType, "Page")) { | 298 if (!FXSYS_stricmp(strType.c_str(), "Page")) { |
| 298 pDictClone->Release(); | 299 pDictClone->Release(); |
| 299 return 0; | 300 return 0; |
| 300 } | 301 } |
| 301 } | 302 } |
| 302 } | 303 } |
| 303 dwNewObjNum = pDoc->AddIndirectObject(pClone); | 304 dwNewObjNum = pDoc->AddIndirectObject(pClone); |
| 304 (*pObjNumberMap)[dwObjnum] = dwNewObjNum; | 305 (*pObjNumberMap)[dwObjnum] = dwNewObjNum; |
| 305 if (!UpdateReference(pClone, pDoc, pObjNumberMap)) { | 306 if (!UpdateReference(pClone, pDoc, pObjNumberMap)) { |
| 306 pClone->Release(); | 307 pClone->Release(); |
| 307 return 0; | 308 return 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 323 CFX_ByteString cbMidRange; | 324 CFX_ByteString cbMidRange; |
| 324 int nStringFrom = 0; | 325 int nStringFrom = 0; |
| 325 int nStringTo = 0; | 326 int nStringTo = 0; |
| 326 while (nStringTo < nLength) { | 327 while (nStringTo < nLength) { |
| 327 nStringTo = rangstring.Find(',', nStringFrom); | 328 nStringTo = rangstring.Find(',', nStringFrom); |
| 328 if (nStringTo == -1) | 329 if (nStringTo == -1) |
| 329 nStringTo = nLength; | 330 nStringTo = nLength; |
| 330 cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom); | 331 cbMidRange = rangstring.Mid(nStringFrom, nStringTo - nStringFrom); |
| 331 int nMid = cbMidRange.Find('-'); | 332 int nMid = cbMidRange.Find('-'); |
| 332 if (nMid == -1) { | 333 if (nMid == -1) { |
| 333 long lPageNum = atol(cbMidRange); | 334 long lPageNum = atol(cbMidRange.c_str()); |
| 334 if (lPageNum <= 0 || lPageNum > nCount) | 335 if (lPageNum <= 0 || lPageNum > nCount) |
| 335 return FALSE; | 336 return FALSE; |
| 336 pageArray->push_back((uint16_t)lPageNum); | 337 pageArray->push_back((uint16_t)lPageNum); |
| 337 } else { | 338 } else { |
| 338 int nStartPageNum = atol(cbMidRange.Mid(0, nMid)); | 339 int nStartPageNum = atol(cbMidRange.Mid(0, nMid).c_str()); |
| 339 if (nStartPageNum == 0) | 340 if (nStartPageNum == 0) |
| 340 return FALSE; | 341 return FALSE; |
| 341 | 342 |
| 342 ++nMid; | 343 ++nMid; |
| 343 int nEnd = cbMidRange.GetLength() - nMid; | 344 int nEnd = cbMidRange.GetLength() - nMid; |
| 344 if (nEnd == 0) | 345 if (nEnd == 0) |
| 345 return FALSE; | 346 return FALSE; |
| 346 | 347 |
| 347 int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd)); | 348 int nEndPageNum = atol(cbMidRange.Mid(nMid, nEnd).c_str()); |
| 348 if (nStartPageNum < 0 || nStartPageNum > nEndPageNum || | 349 if (nStartPageNum < 0 || nStartPageNum > nEndPageNum || |
| 349 nEndPageNum > nCount) { | 350 nEndPageNum > nCount) { |
| 350 return FALSE; | 351 return FALSE; |
| 351 } | 352 } |
| 352 for (int i = nStartPageNum; i <= nEndPageNum; ++i) { | 353 for (int i = nStartPageNum; i <= nEndPageNum; ++i) { |
| 353 pageArray->push_back(i); | 354 pageArray->push_back(i); |
| 354 } | 355 } |
| 355 } | 356 } |
| 356 nStringFrom = nStringTo + 1; | 357 nStringFrom = nStringTo + 1; |
| 357 } | 358 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 if (!pSrcDict) | 403 if (!pSrcDict) |
| 403 return FALSE; | 404 return FALSE; |
| 404 | 405 |
| 405 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); | 406 CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); |
| 406 if (!pDstDict) | 407 if (!pDstDict) |
| 407 return FALSE; | 408 return FALSE; |
| 408 | 409 |
| 409 pDstDict->SetAt("ViewerPreferences", pSrcDict->Clone(TRUE)); | 410 pDstDict->SetAt("ViewerPreferences", pSrcDict->Clone(TRUE)); |
| 410 return TRUE; | 411 return TRUE; |
| 411 } | 412 } |
| OLD | NEW |