| 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 "core/fpdfapi/parser/cpdf_document.h" | 7 #include "core/fpdfapi/parser/cpdf_document.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <utility> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "core/fpdfapi/cpdf_modulemgr.h" | 14 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 14 #include "core/fpdfapi/font/cpdf_fontencoding.h" | 15 #include "core/fpdfapi/font/cpdf_fontencoding.h" |
| 15 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 16 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
| 16 #include "core/fpdfapi/page/cpdf_pagemodule.h" | 17 #include "core/fpdfapi/page/cpdf_pagemodule.h" |
| 17 #include "core/fpdfapi/page/pageint.h" | 18 #include "core/fpdfapi/page/pageint.h" |
| 18 #include "core/fpdfapi/parser/cpdf_array.h" | 19 #include "core/fpdfapi/parser/cpdf_array.h" |
| 19 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 20 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 20 #include "core/fpdfapi/parser/cpdf_number.h" | 21 #include "core/fpdfapi/parser/cpdf_number.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 int size = end - start + 1; | 234 int size = end - start + 1; |
| 234 int* widths = FX_Alloc(int, size); | 235 int* widths = FX_Alloc(int, size); |
| 235 int i; | 236 int i; |
| 236 for (i = 0; i < size; i++) { | 237 for (i = 0; i < size; i++) { |
| 237 int glyph_index = pEncoding->GlyphFromCharCode(start + i); | 238 int glyph_index = pEncoding->GlyphFromCharCode(start + i); |
| 238 widths[i] = pFont->GetGlyphWidth(glyph_index); | 239 widths[i] = pFont->GetGlyphWidth(glyph_index); |
| 239 } | 240 } |
| 240 InsertWidthArrayImpl(widths, size, pWidthArray); | 241 InsertWidthArrayImpl(widths, size, pWidthArray); |
| 241 } | 242 } |
| 242 | 243 |
| 243 int InsertDeletePDFPage(CPDF_Document* pDoc, | |
| 244 CPDF_Dictionary* pPages, | |
| 245 int nPagesToGo, | |
| 246 CPDF_Dictionary* pPage, | |
| 247 FX_BOOL bInsert, | |
| 248 std::set<CPDF_Dictionary*>* pVisited) { | |
| 249 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); | |
| 250 if (!pKidList) | |
| 251 return -1; | |
| 252 | |
| 253 for (size_t i = 0; i < pKidList->GetCount(); i++) { | |
| 254 CPDF_Dictionary* pKid = pKidList->GetDictAt(i); | |
| 255 if (pKid->GetStringFor("Type") == "Page") { | |
| 256 if (nPagesToGo == 0) { | |
| 257 if (bInsert) { | |
| 258 pKidList->InsertAt(i, new CPDF_Reference(pDoc, pPage->GetObjNum())); | |
| 259 pPage->SetReferenceFor("Parent", pDoc, pPages->GetObjNum()); | |
| 260 } else { | |
| 261 pKidList->RemoveAt(i); | |
| 262 } | |
| 263 pPages->SetIntegerFor( | |
| 264 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); | |
| 265 return 1; | |
| 266 } | |
| 267 nPagesToGo--; | |
| 268 } else { | |
| 269 int nPages = pKid->GetIntegerFor("Count"); | |
| 270 if (nPagesToGo < nPages) { | |
| 271 if (pdfium::ContainsKey(*pVisited, pKid)) | |
| 272 return -1; | |
| 273 | |
| 274 pdfium::ScopedSetInsertion<CPDF_Dictionary*> insertion(pVisited, pKid); | |
| 275 if (InsertDeletePDFPage(pDoc, pKid, nPagesToGo, pPage, bInsert, | |
| 276 pVisited) < 0) { | |
| 277 return -1; | |
| 278 } | |
| 279 pPages->SetIntegerFor( | |
| 280 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); | |
| 281 return 1; | |
| 282 } | |
| 283 nPagesToGo -= nPages; | |
| 284 } | |
| 285 } | |
| 286 return 0; | |
| 287 } | |
| 288 | |
| 289 int InsertNewPage(CPDF_Document* pDoc, | |
| 290 int iPage, | |
| 291 CPDF_Dictionary* pPageDict, | |
| 292 CFX_ArrayTemplate<uint32_t>& pageList) { | |
| 293 CPDF_Dictionary* pRoot = pDoc->GetRoot(); | |
| 294 CPDF_Dictionary* pPages = pRoot ? pRoot->GetDictFor("Pages") : nullptr; | |
| 295 if (!pPages) | |
| 296 return -1; | |
| 297 | |
| 298 int nPages = pDoc->GetPageCount(); | |
| 299 if (iPage < 0 || iPage > nPages) | |
| 300 return -1; | |
| 301 | |
| 302 if (iPage == nPages) { | |
| 303 CPDF_Array* pPagesList = pPages->GetArrayFor("Kids"); | |
| 304 if (!pPagesList) { | |
| 305 pPagesList = new CPDF_Array; | |
| 306 pPages->SetFor("Kids", pPagesList); | |
| 307 } | |
| 308 pPagesList->Add(new CPDF_Reference(pDoc, pPageDict->GetObjNum())); | |
| 309 pPages->SetIntegerFor("Count", nPages + 1); | |
| 310 pPageDict->SetReferenceFor("Parent", pDoc, pPages->GetObjNum()); | |
| 311 } else { | |
| 312 std::set<CPDF_Dictionary*> stack = {pPages}; | |
| 313 if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, &stack) < 0) | |
| 314 return -1; | |
| 315 } | |
| 316 pageList.InsertAt(iPage, pPageDict->GetObjNum()); | |
| 317 return iPage; | |
| 318 } | |
| 319 | |
| 320 int CountPages(CPDF_Dictionary* pPages, | 244 int CountPages(CPDF_Dictionary* pPages, |
| 321 std::set<CPDF_Dictionary*>* visited_pages) { | 245 std::set<CPDF_Dictionary*>* visited_pages) { |
| 322 int count = pPages->GetIntegerFor("Count"); | 246 int count = pPages->GetIntegerFor("Count"); |
| 323 if (count > 0 && count < FPDF_PAGE_MAX_NUM) | 247 if (count > 0 && count < FPDF_PAGE_MAX_NUM) |
| 324 return count; | 248 return count; |
| 325 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); | 249 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); |
| 326 if (!pKidList) | 250 if (!pKidList) |
| 327 return 0; | 251 return 0; |
| 328 count = 0; | 252 count = 0; |
| 329 for (size_t i = 0; i < pKidList->GetCount(); i++) { | 253 for (size_t i = 0; i < pKidList->GetCount(); i++) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 return pFontDesc; | 330 return pFontDesc; |
| 407 } | 331 } |
| 408 | 332 |
| 409 } // namespace | 333 } // namespace |
| 410 | 334 |
| 411 CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) | 335 CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) |
| 412 : CPDF_IndirectObjectHolder(), | 336 : CPDF_IndirectObjectHolder(), |
| 413 m_pParser(std::move(pParser)), | 337 m_pParser(std::move(pParser)), |
| 414 m_pRootDict(nullptr), | 338 m_pRootDict(nullptr), |
| 415 m_pInfoDict(nullptr), | 339 m_pInfoDict(nullptr), |
| 340 m_iLastPageTraversed(-1), |
| 416 m_bLinearized(false), | 341 m_bLinearized(false), |
| 417 m_iFirstPageNo(0), | 342 m_iFirstPageNo(0), |
| 418 m_dwFirstPageObjNum(0), | 343 m_dwFirstPageObjNum(0), |
| 419 m_pDocPage(new CPDF_DocPageData(this)), | 344 m_pDocPage(new CPDF_DocPageData(this)), |
| 420 m_pDocRender(new CPDF_DocRenderData(this)), | 345 m_pDocRender(new CPDF_DocRenderData(this)), |
| 421 m_pByteStringPool(pdfium::MakeUnique<CFX_ByteStringPool>()) { | 346 m_pByteStringPool(pdfium::MakeUnique<CFX_ByteStringPool>()) { |
| 422 if (pParser) | 347 if (pParser) |
| 423 SetLastObjNum(m_pParser->GetLastObjNum()); | 348 SetLastObjNum(m_pParser->GetLastObjNum()); |
| 424 } | 349 } |
| 425 | 350 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 395 |
| 471 CPDF_Object* pObjNum = pLinearizationParams->GetObjectFor("O"); | 396 CPDF_Object* pObjNum = pLinearizationParams->GetObjectFor("O"); |
| 472 if (ToNumber(pObjNum)) | 397 if (ToNumber(pObjNum)) |
| 473 m_dwFirstPageObjNum = pObjNum->GetInteger(); | 398 m_dwFirstPageObjNum = pObjNum->GetInteger(); |
| 474 } | 399 } |
| 475 | 400 |
| 476 void CPDF_Document::LoadPages() { | 401 void CPDF_Document::LoadPages() { |
| 477 m_PageList.SetSize(RetrievePageCount()); | 402 m_PageList.SetSize(RetrievePageCount()); |
| 478 } | 403 } |
| 479 | 404 |
| 480 CPDF_Dictionary* CPDF_Document::FindPDFPage(CPDF_Dictionary* pPages, | 405 void CPDF_Document::PopAndPropagate() { |
| 481 int iPage, | 406 m_pTreeTraversal.pop(); |
| 482 int nPagesToGo, | 407 if (m_pTreeTraversal.empty()) |
| 483 int level) { | 408 return; |
| 409 std::pair<CPDF_Dictionary*, int>* top = &m_pTreeTraversal.top(); |
| 410 top->second++; |
| 411 if (top->second == |
| 412 static_cast<int>(top->first->GetArrayFor("Kids")->GetCount() - 1)) { |
| 413 PopAndPropagate(); |
| 414 } |
| 415 } |
| 416 |
| 417 CPDF_Dictionary* CPDF_Document::TraversePDFPages(int iPage, int nPagesToGo) { |
| 418 std::pair<CPDF_Dictionary*, int>* lastProc = &m_pTreeTraversal.top(); |
| 419 CPDF_Dictionary* pPages = lastProc->first; |
| 484 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); | 420 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); |
| 485 if (!pKidList) | 421 if (!pKidList) { |
| 486 return nPagesToGo == 0 ? pPages : nullptr; | 422 PopAndPropagate(); |
| 423 if (nPagesToGo != 1) |
| 424 return nullptr; |
| 425 m_PageList.SetAt(iPage, pPages->GetObjNum()); |
| 426 return pPages; |
| 427 } |
| 487 | 428 |
| 488 if (level >= FX_MAX_PAGE_LEVEL) | 429 if (m_pTreeTraversal.size() >= FX_MAX_PAGE_LEVEL) { |
| 430 PopAndPropagate(); |
| 489 return nullptr; | 431 return nullptr; |
| 432 } |
| 490 | 433 |
| 491 for (size_t i = 0; i < pKidList->GetCount(); i++) { | 434 CPDF_Dictionary* page = nullptr; |
| 435 for (size_t i = lastProc->second + 1; i < pKidList->GetCount(); i++) { |
| 492 CPDF_Dictionary* pKid = pKidList->GetDictAt(i); | 436 CPDF_Dictionary* pKid = pKidList->GetDictAt(i); |
| 493 if (!pKid) { | 437 if (!pKid) { |
| 494 nPagesToGo--; | 438 nPagesToGo--; |
| 439 lastProc->second++; |
| 495 continue; | 440 continue; |
| 496 } | 441 } |
| 497 if (pKid == pPages) | 442 if (pKid == pPages) { |
| 443 lastProc->second++; |
| 498 continue; | 444 continue; |
| 445 } |
| 499 if (!pKid->KeyExist("Kids")) { | 446 if (!pKid->KeyExist("Kids")) { |
| 500 if (nPagesToGo == 0) | 447 m_PageList.SetAt(iPage - nPagesToGo + 1, pKid->GetObjNum()); |
| 501 return pKid; | |
| 502 | |
| 503 m_PageList.SetAt(iPage - nPagesToGo, pKid->GetObjNum()); | |
| 504 nPagesToGo--; | 448 nPagesToGo--; |
| 449 lastProc->second++; |
| 450 if (nPagesToGo == 0) { |
| 451 page = pKid; |
| 452 break; |
| 453 } |
| 505 } else { | 454 } else { |
| 506 int nPages = pKid->GetIntegerFor("Count"); | 455 int nPages = pKid->GetIntegerFor("Count"); |
| 507 if (nPagesToGo < nPages) | 456 m_pTreeTraversal.push(std::make_pair(pKid, -1)); |
| 508 return FindPDFPage(pKid, iPage, nPagesToGo, level + 1); | 457 CPDF_Dictionary* pageKid = TraversePDFPages(iPage, nPagesToGo); |
| 509 | 458 if (nPagesToGo <= nPages) { |
| 459 page = pageKid; |
| 460 break; |
| 461 } |
| 510 nPagesToGo -= nPages; | 462 nPagesToGo -= nPages; |
| 511 } | 463 } |
| 512 } | 464 } |
| 513 return nullptr; | 465 if (!m_pTreeTraversal.empty() && lastProc == &m_pTreeTraversal.top() && |
| 466 lastProc->second == static_cast<int>(pKidList->GetCount() - 1)) { |
| 467 PopAndPropagate(); |
| 468 } |
| 469 return page; |
| 514 } | 470 } |
| 515 | 471 |
| 516 CPDF_Dictionary* CPDF_Document::GetPagesDict() const { | 472 CPDF_Dictionary* CPDF_Document::GetPagesDict() const { |
| 517 CPDF_Dictionary* pRoot = GetRoot(); | 473 CPDF_Dictionary* pRoot = GetRoot(); |
| 518 return pRoot ? pRoot->GetDictFor("Pages") : nullptr; | 474 return pRoot ? pRoot->GetDictFor("Pages") : nullptr; |
| 519 } | 475 } |
| 520 | 476 |
| 521 bool CPDF_Document::IsPageLoaded(int iPage) const { | 477 bool CPDF_Document::IsPageLoaded(int iPage) const { |
| 522 return !!m_PageList.GetAt(iPage); | 478 return !!m_PageList.GetAt(iPage); |
| 523 } | 479 } |
| 524 | 480 |
| 525 CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { | 481 CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { |
| 526 if (iPage < 0 || iPage >= m_PageList.GetSize()) | 482 if (iPage < 0 || iPage >= m_PageList.GetSize()) |
| 527 return nullptr; | 483 return nullptr; |
| 528 | 484 |
| 529 if (m_bLinearized && (iPage == m_iFirstPageNo)) { | 485 if (m_bLinearized && (iPage == m_iFirstPageNo)) { |
| 530 if (CPDF_Dictionary* pDict = | 486 if (CPDF_Dictionary* pDict = |
| 531 ToDictionary(GetOrParseIndirectObject(m_dwFirstPageObjNum))) { | 487 ToDictionary(GetOrParseIndirectObject(m_dwFirstPageObjNum))) { |
| 532 return pDict; | 488 return pDict; |
| 533 } | 489 } |
| 534 } | 490 } |
| 535 | 491 |
| 536 int objnum = m_PageList.GetAt(iPage); | 492 int objnum = m_PageList.GetAt(iPage); |
| 537 if (objnum) { | 493 if (!objnum) { |
| 538 if (CPDF_Dictionary* pDict = ToDictionary(GetOrParseIndirectObject(objnum))) | 494 CPDF_Dictionary* pPages = GetPagesDict(); |
| 539 return pDict; | 495 if (!pPages) |
| 496 return nullptr; |
| 497 if (m_pTreeTraversal.empty()) |
| 498 m_pTreeTraversal.push(std::make_pair(pPages, -1)); |
| 499 CPDF_Dictionary* page = |
| 500 TraversePDFPages(iPage, iPage - m_iLastPageTraversed); |
| 501 m_iLastPageTraversed = iPage; |
| 502 return page; |
| 540 } | 503 } |
| 541 | 504 if (CPDF_Dictionary* pDict = ToDictionary(GetOrParseIndirectObject(objnum))) |
| 542 CPDF_Dictionary* pPages = GetPagesDict(); | 505 return pDict; |
| 543 if (!pPages) | 506 return nullptr; |
| 544 return nullptr; | |
| 545 | |
| 546 CPDF_Dictionary* pPage = FindPDFPage(pPages, iPage, iPage, 0); | |
| 547 if (!pPage) | |
| 548 return nullptr; | |
| 549 | |
| 550 m_PageList.SetAt(iPage, pPage->GetObjNum()); | |
| 551 return pPage; | |
| 552 } | 507 } |
| 553 | 508 |
| 554 void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) { | 509 void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) { |
| 555 m_PageList.SetAt(iPage, objNum); | 510 m_PageList.SetAt(iPage, objNum); |
| 556 } | 511 } |
| 557 | 512 |
| 558 int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, | 513 int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode, |
| 559 uint32_t& skip_count, | 514 uint32_t& skip_count, |
| 560 uint32_t objnum, | 515 uint32_t objnum, |
| 561 int& index, | 516 int& index, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 pPages->SetFor("Kids", new CPDF_Array); | 658 pPages->SetFor("Kids", new CPDF_Array); |
| 704 m_pRootDict->SetReferenceFor("Pages", this, AddIndirectObject(pPages)); | 659 m_pRootDict->SetReferenceFor("Pages", this, AddIndirectObject(pPages)); |
| 705 m_pInfoDict = new CPDF_Dictionary(m_pByteStringPool); | 660 m_pInfoDict = new CPDF_Dictionary(m_pByteStringPool); |
| 706 AddIndirectObject(m_pInfoDict); | 661 AddIndirectObject(m_pInfoDict); |
| 707 } | 662 } |
| 708 | 663 |
| 709 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { | 664 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { |
| 710 CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pByteStringPool); | 665 CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pByteStringPool); |
| 711 pDict->SetNameFor("Type", "Page"); | 666 pDict->SetNameFor("Type", "Page"); |
| 712 uint32_t dwObjNum = AddIndirectObject(pDict); | 667 uint32_t dwObjNum = AddIndirectObject(pDict); |
| 713 if (InsertNewPage(this, iPage, pDict, m_PageList) < 0) { | 668 if (InsertNewPage(iPage, pDict, m_PageList) < 0) { |
| 714 ReleaseIndirectObject(dwObjNum); | 669 ReleaseIndirectObject(dwObjNum); |
| 715 return nullptr; | 670 return nullptr; |
| 716 } | 671 } |
| 717 return pDict; | 672 return pDict; |
| 718 } | 673 } |
| 719 | 674 |
| 675 int CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages, |
| 676 int nPagesToGo, |
| 677 CPDF_Dictionary* pPage, |
| 678 FX_BOOL bInsert, |
| 679 std::set<CPDF_Dictionary*>* pVisited) { |
| 680 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); |
| 681 if (!pKidList) |
| 682 return -1; |
| 683 |
| 684 for (size_t i = 0; i < pKidList->GetCount(); i++) { |
| 685 CPDF_Dictionary* pKid = pKidList->GetDictAt(i); |
| 686 if (pKid->GetStringFor("Type") == "Page") { |
| 687 if (nPagesToGo == 0) { |
| 688 if (bInsert) { |
| 689 pKidList->InsertAt(i, new CPDF_Reference(this, pPage->GetObjNum())); |
| 690 pPage->SetReferenceFor("Parent", this, pPages->GetObjNum()); |
| 691 } else { |
| 692 pKidList->RemoveAt(i); |
| 693 } |
| 694 pPages->SetIntegerFor( |
| 695 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); |
| 696 // Tree will change, so reset tree transversal variables |
| 697 m_iLastPageTraversed = -1; |
| 698 m_pTreeTraversal = std::stack<std::pair<CPDF_Dictionary*, int>>(); |
| 699 return 1; |
| 700 } |
| 701 nPagesToGo--; |
| 702 } else { |
| 703 int nPages = pKid->GetIntegerFor("Count"); |
| 704 if (nPagesToGo < nPages) { |
| 705 if (pdfium::ContainsKey(*pVisited, pKid)) |
| 706 return -1; |
| 707 |
| 708 pdfium::ScopedSetInsertion<CPDF_Dictionary*> insertion(pVisited, pKid); |
| 709 if (InsertDeletePDFPage(pKid, nPagesToGo, pPage, bInsert, pVisited) < |
| 710 0) { |
| 711 return -1; |
| 712 } |
| 713 pPages->SetIntegerFor( |
| 714 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); |
| 715 return 1; |
| 716 } |
| 717 nPagesToGo -= nPages; |
| 718 } |
| 719 } |
| 720 return 0; |
| 721 } |
| 722 |
| 723 int CPDF_Document::InsertNewPage(int iPage, |
| 724 CPDF_Dictionary* pPageDict, |
| 725 CFX_ArrayTemplate<uint32_t>& pageList) { |
| 726 CPDF_Dictionary* pRoot = GetRoot(); |
| 727 CPDF_Dictionary* pPages = pRoot ? pRoot->GetDictFor("Pages") : nullptr; |
| 728 if (!pPages) |
| 729 return -1; |
| 730 |
| 731 int nPages = GetPageCount(); |
| 732 if (iPage < 0 || iPage > nPages) |
| 733 return -1; |
| 734 |
| 735 if (iPage == nPages) { |
| 736 CPDF_Array* pPagesList = pPages->GetArrayFor("Kids"); |
| 737 if (!pPagesList) { |
| 738 pPagesList = new CPDF_Array; |
| 739 pPages->SetFor("Kids", pPagesList); |
| 740 } |
| 741 pPagesList->Add(new CPDF_Reference(this, pPageDict->GetObjNum())); |
| 742 pPages->SetIntegerFor("Count", nPages + 1); |
| 743 pPageDict->SetReferenceFor("Parent", this, pPages->GetObjNum()); |
| 744 // Reset tree transversal variables |
| 745 m_iLastPageTraversed = -1; |
| 746 m_pTreeTraversal = std::stack<std::pair<CPDF_Dictionary*, int>>(); |
| 747 } else { |
| 748 std::set<CPDF_Dictionary*> stack = {pPages}; |
| 749 if (InsertDeletePDFPage(pPages, iPage, pPageDict, TRUE, &stack) < 0) |
| 750 return -1; |
| 751 } |
| 752 pageList.InsertAt(iPage, pPageDict->GetObjNum()); |
| 753 return iPage; |
| 754 } |
| 755 |
| 720 void CPDF_Document::DeletePage(int iPage) { | 756 void CPDF_Document::DeletePage(int iPage) { |
| 721 CPDF_Dictionary* pPages = GetPagesDict(); | 757 CPDF_Dictionary* pPages = GetPagesDict(); |
| 722 if (!pPages) | 758 if (!pPages) |
| 723 return; | 759 return; |
| 724 | 760 |
| 725 int nPages = pPages->GetIntegerFor("Count"); | 761 int nPages = pPages->GetIntegerFor("Count"); |
| 726 if (iPage < 0 || iPage >= nPages) | 762 if (iPage < 0 || iPage >= nPages) |
| 727 return; | 763 return; |
| 728 | 764 |
| 729 std::set<CPDF_Dictionary*> stack = {pPages}; | 765 std::set<CPDF_Dictionary*> stack = {pPages}; |
| 730 if (InsertDeletePDFPage(this, pPages, iPage, nullptr, FALSE, &stack) < 0) | 766 if (InsertDeletePDFPage(pPages, iPage, nullptr, FALSE, &stack) < 0) |
| 731 return; | 767 return; |
| 732 | 768 |
| 733 m_PageList.RemoveAt(iPage); | 769 m_PageList.RemoveAt(iPage); |
| 734 } | 770 } |
| 735 | 771 |
| 736 CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font, | 772 CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font, |
| 737 CPDF_FontEncoding* pEncoding) { | 773 CPDF_FontEncoding* pEncoding) { |
| 738 CFX_ByteString name(font); | 774 CFX_ByteString name(font); |
| 739 if (PDF_GetStandardFontName(&name) < 0) | 775 if (PDF_GetStandardFontName(&name) < 0) |
| 740 return nullptr; | 776 return nullptr; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 pBBox, pLogFont->lfWeight / 5); | 1049 pBBox, pLogFont->lfWeight / 5); |
| 1014 pFontDesc->SetIntegerFor("CapHeight", capheight); | 1050 pFontDesc->SetIntegerFor("CapHeight", capheight); |
| 1015 pFontDict->SetReferenceFor("FontDescriptor", this, | 1051 pFontDict->SetReferenceFor("FontDescriptor", this, |
| 1016 AddIndirectObject(pFontDesc)); | 1052 AddIndirectObject(pFontDesc)); |
| 1017 hFont = SelectObject(hDC, hFont); | 1053 hFont = SelectObject(hDC, hFont); |
| 1018 DeleteObject(hFont); | 1054 DeleteObject(hFont); |
| 1019 DeleteDC(hDC); | 1055 DeleteDC(hDC); |
| 1020 return LoadFont(pBaseDict); | 1056 return LoadFont(pBaseDict); |
| 1021 } | 1057 } |
| 1022 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1058 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| OLD | NEW |