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/src/fpdfapi/fpdf_page/pageint.h" | 7 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
8 | 8 |
| 9 #include <algorithm> |
| 10 |
9 #include "core/include/fpdfapi/fpdf_module.h" | 11 #include "core/include/fpdfapi/fpdf_module.h" |
10 #include "core/include/fpdfapi/fpdf_page.h" | 12 #include "core/include/fpdfapi/fpdf_page.h" |
| 13 #include "third_party/base/stl_util.h" |
11 | 14 |
12 CPDF_PageObject* CPDF_PageObject::Create(int type) { | 15 CPDF_PageObject* CPDF_PageObject::Create(int type) { |
13 switch (type) { | 16 switch (type) { |
14 case TEXT: | 17 case TEXT: |
15 return new CPDF_TextObject; | 18 return new CPDF_TextObject; |
16 case IMAGE: | 19 case IMAGE: |
17 return new CPDF_ImageObject; | 20 return new CPDF_ImageObject; |
18 case PATH: | 21 case PATH: |
19 return new CPDF_PathObject; | 22 return new CPDF_PathObject; |
20 case SHADING: | 23 case SHADING: |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 m_FormMatrix = pSrcObj->m_FormMatrix; | 666 m_FormMatrix = pSrcObj->m_FormMatrix; |
664 } | 667 } |
665 void CPDF_FormObject::CalcBoundingBox() { | 668 void CPDF_FormObject::CalcBoundingBox() { |
666 CFX_FloatRect form_rect = m_pForm->CalcBoundingBox(); | 669 CFX_FloatRect form_rect = m_pForm->CalcBoundingBox(); |
667 form_rect.Transform(&m_FormMatrix); | 670 form_rect.Transform(&m_FormMatrix); |
668 m_Left = form_rect.left; | 671 m_Left = form_rect.left; |
669 m_Bottom = form_rect.bottom; | 672 m_Bottom = form_rect.bottom; |
670 m_Right = form_rect.right; | 673 m_Right = form_rect.right; |
671 m_Top = form_rect.top; | 674 m_Top = form_rect.top; |
672 } | 675 } |
| 676 |
| 677 CPDF_PageObject* CPDF_PageObjectList::GetPageObjectByIndex(int index) { |
| 678 if (index < 0 || index >= pdfium::CollectionSize<int>(*this)) |
| 679 return nullptr; |
| 680 int current = 0; |
| 681 for (const auto& pObj : *this) { |
| 682 if (index == current) |
| 683 return pObj.get(); |
| 684 ++current; |
| 685 } |
| 686 return nullptr; |
| 687 } |
| 688 |
673 CPDF_PageObjectHolder::CPDF_PageObjectHolder() | 689 CPDF_PageObjectHolder::CPDF_PageObjectHolder() |
674 : m_pFormDict(nullptr), | 690 : m_pFormDict(nullptr), |
675 m_pFormStream(nullptr), | 691 m_pFormStream(nullptr), |
676 m_pDocument(nullptr), | 692 m_pDocument(nullptr), |
677 m_pPageResources(nullptr), | 693 m_pPageResources(nullptr), |
678 m_pResources(nullptr), | 694 m_pResources(nullptr), |
679 m_Transparency(0), | 695 m_Transparency(0), |
680 m_bBackgroundAlphaNeeded(FALSE), | 696 m_bBackgroundAlphaNeeded(FALSE), |
681 m_bHasImageMask(FALSE), | 697 m_bHasImageMask(FALSE), |
682 m_ParseState(CONTENT_NOT_PARSED), | 698 m_ParseState(CONTENT_NOT_PARSED) {} |
683 m_PageObjectList(128) {} | |
684 | 699 |
685 CPDF_PageObjectHolder::~CPDF_PageObjectHolder() { | |
686 FX_POSITION pos = m_PageObjectList.GetHeadPosition(); | |
687 while (pos) { | |
688 delete m_PageObjectList.GetNextObject(pos); | |
689 } | |
690 } | |
691 void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { | 700 void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) { |
692 if (!m_pParser) { | 701 if (!m_pParser) { |
693 return; | 702 return; |
694 } | 703 } |
695 m_pParser->Continue(pPause); | 704 m_pParser->Continue(pPause); |
696 if (m_pParser->GetStatus() == CPDF_ContentParser::Done) { | 705 if (m_pParser->GetStatus() == CPDF_ContentParser::Done) { |
697 m_ParseState = CONTENT_PARSED; | 706 m_ParseState = CONTENT_PARSED; |
698 m_pParser.reset(); | 707 m_pParser.reset(); |
699 } | 708 } |
700 } | 709 } |
701 FX_POSITION CPDF_PageObjectList::InsertObject(FX_POSITION posInsertAfter, | 710 |
702 CPDF_PageObject* pNewObject) { | 711 void CPDF_PageObjectHolder::Transform(const CFX_Matrix& matrix) { |
703 if (!posInsertAfter) { | 712 for (auto& pObj : m_PageObjectList) |
704 return AddHead(pNewObject); | 713 pObj->Transform(matrix); |
705 } | |
706 return InsertAfter(posInsertAfter, pNewObject); | |
707 } | 714 } |
708 CPDF_PageObject* CPDF_PageObjectList::GetObjectByIndex(int index) const { | 715 |
709 FX_POSITION pos = FindIndex(index); | |
710 return pos ? GetObjectAt(pos) : nullptr; | |
711 } | |
712 void CPDF_PageObjectHolder::Transform(const CFX_Matrix& matrix) { | |
713 FX_POSITION pos = m_PageObjectList.GetHeadPosition(); | |
714 while (pos) { | |
715 m_PageObjectList.GetNextObject(pos)->Transform(matrix); | |
716 } | |
717 } | |
718 CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const { | 716 CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const { |
719 if (m_PageObjectList.GetCount() == 0) { | 717 if (m_PageObjectList.empty()) |
720 return CFX_FloatRect(0, 0, 0, 0); | 718 return CFX_FloatRect(0, 0, 0, 0); |
721 } | 719 |
722 FX_FLOAT left, right, top, bottom; | 720 FX_FLOAT left = 1000000.0f; |
723 left = bottom = 1000000 * 1.0f; | 721 FX_FLOAT right = -1000000.0f; |
724 right = top = -1000000 * 1.0f; | 722 FX_FLOAT bottom = 1000000.0f; |
725 FX_POSITION pos = m_PageObjectList.GetHeadPosition(); | 723 FX_FLOAT top = -1000000.0f; |
726 while (pos) { | 724 for (const auto& pObj : m_PageObjectList) { |
727 CPDF_PageObject* pObj = (CPDF_PageObject*)m_PageObjectList.GetNext(pos); | 725 left = std::min(left, pObj->m_Left); |
728 if (left > pObj->m_Left) { | 726 right = std::max(right, pObj->m_Right); |
729 left = pObj->m_Left; | 727 bottom = std::min(bottom, pObj->m_Bottom); |
730 } | 728 top = std::max(top, pObj->m_Top); |
731 if (right < pObj->m_Right) { | |
732 right = pObj->m_Right; | |
733 } | |
734 if (top < pObj->m_Top) { | |
735 top = pObj->m_Top; | |
736 } | |
737 if (bottom > pObj->m_Bottom) { | |
738 bottom = pObj->m_Bottom; | |
739 } | |
740 } | 729 } |
741 return CFX_FloatRect(left, bottom, right, top); | 730 return CFX_FloatRect(left, bottom, right, top); |
742 } | 731 } |
| 732 |
743 void CPDF_PageObjectHolder::LoadTransInfo() { | 733 void CPDF_PageObjectHolder::LoadTransInfo() { |
744 if (!m_pFormDict) { | 734 if (!m_pFormDict) { |
745 return; | 735 return; |
746 } | 736 } |
747 CPDF_Dictionary* pGroup = m_pFormDict->GetDictBy("Group"); | 737 CPDF_Dictionary* pGroup = m_pFormDict->GetDictBy("Group"); |
748 if (!pGroup) { | 738 if (!pGroup) { |
749 return; | 739 return; |
750 } | 740 } |
751 if (pGroup->GetStringBy("S") != "Transparency") { | 741 if (pGroup->GetStringBy("S") != "Transparency") { |
752 return; | 742 return; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 m_pPageResources = pPageResources; | 872 m_pPageResources = pPageResources; |
883 if (!m_pResources) { | 873 if (!m_pResources) { |
884 m_pResources = pParentResources; | 874 m_pResources = pParentResources; |
885 } | 875 } |
886 if (!m_pResources) { | 876 if (!m_pResources) { |
887 m_pResources = pPageResources; | 877 m_pResources = pPageResources; |
888 } | 878 } |
889 m_Transparency = 0; | 879 m_Transparency = 0; |
890 LoadTransInfo(); | 880 LoadTransInfo(); |
891 } | 881 } |
| 882 |
892 CPDF_Form::~CPDF_Form() {} | 883 CPDF_Form::~CPDF_Form() {} |
| 884 |
893 void CPDF_Form::StartParse(CPDF_AllStates* pGraphicStates, | 885 void CPDF_Form::StartParse(CPDF_AllStates* pGraphicStates, |
894 CFX_Matrix* pParentMatrix, | 886 CFX_Matrix* pParentMatrix, |
895 CPDF_Type3Char* pType3Char, | 887 CPDF_Type3Char* pType3Char, |
896 CPDF_ParseOptions* pOptions, | 888 CPDF_ParseOptions* pOptions, |
897 int level) { | 889 int level) { |
898 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { | 890 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { |
899 return; | 891 return; |
900 } | 892 } |
901 m_pParser.reset(new CPDF_ContentParser); | 893 m_pParser.reset(new CPDF_ContentParser); |
902 m_pParser->Start(this, pGraphicStates, pParentMatrix, pType3Char, pOptions, | 894 m_pParser->Start(this, pGraphicStates, pParentMatrix, pType3Char, pOptions, |
903 level); | 895 level); |
904 m_ParseState = CONTENT_PARSING; | 896 m_ParseState = CONTENT_PARSING; |
905 } | 897 } |
| 898 |
906 void CPDF_Form::ParseContent(CPDF_AllStates* pGraphicStates, | 899 void CPDF_Form::ParseContent(CPDF_AllStates* pGraphicStates, |
907 CFX_Matrix* pParentMatrix, | 900 CFX_Matrix* pParentMatrix, |
908 CPDF_Type3Char* pType3Char, | 901 CPDF_Type3Char* pType3Char, |
909 CPDF_ParseOptions* pOptions, | 902 CPDF_ParseOptions* pOptions, |
910 int level) { | 903 int level) { |
911 StartParse(pGraphicStates, pParentMatrix, pType3Char, pOptions, level); | 904 StartParse(pGraphicStates, pParentMatrix, pType3Char, pOptions, level); |
912 ContinueParse(NULL); | 905 ContinueParse(NULL); |
913 } | 906 } |
| 907 |
914 CPDF_Form* CPDF_Form::Clone() const { | 908 CPDF_Form* CPDF_Form::Clone() const { |
915 CPDF_Form* pClone = | 909 CPDF_Form* pCloneForm = |
916 new CPDF_Form(m_pDocument, m_pPageResources, m_pFormStream, m_pResources); | 910 new CPDF_Form(m_pDocument, m_pPageResources, m_pFormStream, m_pResources); |
917 FX_POSITION pos = m_PageObjectList.GetHeadPosition(); | 911 for (const auto& pObj : m_PageObjectList) |
918 while (pos) { | 912 pCloneForm->m_PageObjectList.emplace_back(pObj->Clone()); |
919 CPDF_PageObject* pObj = (CPDF_PageObject*)m_PageObjectList.GetNext(pos); | 913 |
920 pClone->m_PageObjectList.AddTail(pObj->Clone()); | 914 return pCloneForm; |
921 } | |
922 return pClone; | |
923 } | 915 } |
| 916 |
924 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, | 917 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, |
925 int xPos, | 918 int xPos, |
926 int yPos, | 919 int yPos, |
927 int xSize, | 920 int xSize, |
928 int ySize, | 921 int ySize, |
929 int iRotate) const { | 922 int iRotate) const { |
930 if (m_PageWidth == 0 || m_PageHeight == 0) { | 923 if (m_PageWidth == 0 || m_PageHeight == 0) { |
931 return; | 924 return; |
932 } | 925 } |
933 CFX_Matrix display_matrix; | 926 CFX_Matrix display_matrix; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 (FX_FLOAT)y0); | 967 (FX_FLOAT)y0); |
975 matrix = m_PageMatrix; | 968 matrix = m_PageMatrix; |
976 matrix.Concat(display_matrix); | 969 matrix.Concat(display_matrix); |
977 } | 970 } |
978 CPDF_ParseOptions::CPDF_ParseOptions() { | 971 CPDF_ParseOptions::CPDF_ParseOptions() { |
979 m_bTextOnly = FALSE; | 972 m_bTextOnly = FALSE; |
980 m_bMarkedContent = TRUE; | 973 m_bMarkedContent = TRUE; |
981 m_bSeparateForm = TRUE; | 974 m_bSeparateForm = TRUE; |
982 m_bDecodeInlineImage = FALSE; | 975 m_bDecodeInlineImage = FALSE; |
983 } | 976 } |
OLD | NEW |