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 <limits.h> | 9 #include <limits.h> |
10 | 10 |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 return buf.GetByteString(); | 659 return buf.GetByteString(); |
660 } | 660 } |
661 | 661 |
662 bool CPDF_StreamParser::PositionIsInBounds() const { | 662 bool CPDF_StreamParser::PositionIsInBounds() const { |
663 return m_Pos < m_Size; | 663 return m_Pos < m_Size; |
664 } | 664 } |
665 | 665 |
666 CPDF_ContentParser::CPDF_ContentParser() | 666 CPDF_ContentParser::CPDF_ContentParser() |
667 : m_Status(Ready), | 667 : m_Status(Ready), |
668 m_InternalStage(STAGE_GETCONTENT), | 668 m_InternalStage(STAGE_GETCONTENT), |
669 m_pObjects(nullptr), | 669 m_pObjectHolder(nullptr), |
670 m_bForm(false), | 670 m_bForm(false), |
671 m_pType3Char(nullptr), | 671 m_pType3Char(nullptr), |
672 m_pData(nullptr), | 672 m_pData(nullptr), |
673 m_Size(0), | 673 m_Size(0), |
674 m_CurrentOffset(0) {} | 674 m_CurrentOffset(0) {} |
675 | 675 |
676 CPDF_ContentParser::~CPDF_ContentParser() { | 676 CPDF_ContentParser::~CPDF_ContentParser() { |
677 if (!m_pSingleStream) | 677 if (!m_pSingleStream) |
678 FX_Free(m_pData); | 678 FX_Free(m_pData); |
679 } | 679 } |
680 | 680 |
681 void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) { | 681 void CPDF_ContentParser::Start(CPDF_Page* pPage, CPDF_ParseOptions* pOptions) { |
682 if (m_Status != Ready || !pPage || !pPage->m_pDocument || | 682 if (m_Status != Ready || !pPage || !pPage->m_pDocument || |
683 !pPage->m_pFormDict) { | 683 !pPage->m_pFormDict) { |
684 m_Status = Done; | 684 m_Status = Done; |
685 return; | 685 return; |
686 } | 686 } |
687 m_pObjects = pPage; | 687 m_pObjectHolder = pPage; |
688 m_bForm = FALSE; | 688 m_bForm = FALSE; |
689 if (pOptions) { | 689 if (pOptions) { |
690 m_Options = *pOptions; | 690 m_Options = *pOptions; |
691 } | 691 } |
692 m_Status = ToBeContinued; | 692 m_Status = ToBeContinued; |
693 m_InternalStage = STAGE_GETCONTENT; | 693 m_InternalStage = STAGE_GETCONTENT; |
694 m_CurrentOffset = 0; | 694 m_CurrentOffset = 0; |
695 | 695 |
696 CPDF_Object* pContent = pPage->m_pFormDict->GetElementValue("Contents"); | 696 CPDF_Object* pContent = pPage->m_pFormDict->GetElementValue("Contents"); |
697 if (!pContent) { | 697 if (!pContent) { |
(...skipping 15 matching lines...) Expand all Loading... |
713 } | 713 } |
714 } | 714 } |
715 | 715 |
716 void CPDF_ContentParser::Start(CPDF_Form* pForm, | 716 void CPDF_ContentParser::Start(CPDF_Form* pForm, |
717 CPDF_AllStates* pGraphicStates, | 717 CPDF_AllStates* pGraphicStates, |
718 CFX_Matrix* pParentMatrix, | 718 CFX_Matrix* pParentMatrix, |
719 CPDF_Type3Char* pType3Char, | 719 CPDF_Type3Char* pType3Char, |
720 CPDF_ParseOptions* pOptions, | 720 CPDF_ParseOptions* pOptions, |
721 int level) { | 721 int level) { |
722 m_pType3Char = pType3Char; | 722 m_pType3Char = pType3Char; |
723 m_pObjects = pForm; | 723 m_pObjectHolder = pForm; |
724 m_bForm = TRUE; | 724 m_bForm = TRUE; |
725 CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrixBy("Matrix"); | 725 CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrixBy("Matrix"); |
726 if (pGraphicStates) { | 726 if (pGraphicStates) { |
727 form_matrix.Concat(pGraphicStates->m_CTM); | 727 form_matrix.Concat(pGraphicStates->m_CTM); |
728 } | 728 } |
729 CPDF_Array* pBBox = pForm->m_pFormDict->GetArrayBy("BBox"); | 729 CPDF_Array* pBBox = pForm->m_pFormDict->GetArrayBy("BBox"); |
730 CFX_FloatRect form_bbox; | 730 CFX_FloatRect form_bbox; |
731 CPDF_Path ClipPath; | 731 CPDF_Path ClipPath; |
732 if (pBBox) { | 732 if (pBBox) { |
733 form_bbox = pBBox->GetRect(); | 733 form_bbox = pBBox->GetRect(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 m_pData[pos++] = ' '; | 796 m_pData[pos++] = ' '; |
797 } | 797 } |
798 m_StreamArray.clear(); | 798 m_StreamArray.clear(); |
799 } else { | 799 } else { |
800 m_pData = (uint8_t*)m_pSingleStream->GetData(); | 800 m_pData = (uint8_t*)m_pSingleStream->GetData(); |
801 m_Size = m_pSingleStream->GetSize(); | 801 m_Size = m_pSingleStream->GetSize(); |
802 } | 802 } |
803 m_InternalStage = STAGE_PARSE; | 803 m_InternalStage = STAGE_PARSE; |
804 m_CurrentOffset = 0; | 804 m_CurrentOffset = 0; |
805 } else { | 805 } else { |
806 CPDF_Array* pContent = m_pObjects->m_pFormDict->GetArrayBy("Contents"); | 806 CPDF_Array* pContent = |
| 807 m_pObjectHolder->m_pFormDict->GetArrayBy("Contents"); |
807 m_StreamArray[m_CurrentOffset].reset(new CPDF_StreamAcc); | 808 m_StreamArray[m_CurrentOffset].reset(new CPDF_StreamAcc); |
808 CPDF_Stream* pStreamObj = ToStream( | 809 CPDF_Stream* pStreamObj = ToStream( |
809 pContent ? pContent->GetElementValue(m_CurrentOffset) : nullptr); | 810 pContent ? pContent->GetElementValue(m_CurrentOffset) : nullptr); |
810 m_StreamArray[m_CurrentOffset]->LoadAllData(pStreamObj, FALSE); | 811 m_StreamArray[m_CurrentOffset]->LoadAllData(pStreamObj, FALSE); |
811 m_CurrentOffset++; | 812 m_CurrentOffset++; |
812 } | 813 } |
813 } | 814 } |
814 if (m_InternalStage == STAGE_PARSE) { | 815 if (m_InternalStage == STAGE_PARSE) { |
815 if (!m_pParser) { | 816 if (!m_pParser) { |
816 m_pParser.reset(new CPDF_StreamContentParser( | 817 m_pParser.reset(new CPDF_StreamContentParser( |
817 m_pObjects->m_pDocument, m_pObjects->m_pPageResources, nullptr, | 818 m_pObjectHolder->m_pDocument, m_pObjectHolder->m_pPageResources, |
818 nullptr, m_pObjects, m_pObjects->m_pResources, &m_pObjects->m_BBox, | 819 nullptr, nullptr, m_pObjectHolder, m_pObjectHolder->m_pResources, |
819 &m_Options, nullptr, 0)); | 820 &m_pObjectHolder->m_BBox, &m_Options, nullptr, 0)); |
820 m_pParser->GetCurStates()->m_ColorState.GetModify()->Default(); | 821 m_pParser->GetCurStates()->m_ColorState.GetModify()->Default(); |
821 } | 822 } |
822 if (m_CurrentOffset >= m_Size) { | 823 if (m_CurrentOffset >= m_Size) { |
823 m_InternalStage = STAGE_CHECKCLIP; | 824 m_InternalStage = STAGE_CHECKCLIP; |
824 } else { | 825 } else { |
825 m_CurrentOffset += | 826 m_CurrentOffset += |
826 m_pParser->Parse(m_pData + m_CurrentOffset, | 827 m_pParser->Parse(m_pData + m_CurrentOffset, |
827 m_Size - m_CurrentOffset, PARSE_STEP_LIMIT); | 828 m_Size - m_CurrentOffset, PARSE_STEP_LIMIT); |
828 } | 829 } |
829 } | 830 } |
830 if (m_InternalStage == STAGE_CHECKCLIP) { | 831 if (m_InternalStage == STAGE_CHECKCLIP) { |
831 if (m_pType3Char) { | 832 if (m_pType3Char) { |
832 m_pType3Char->m_bColored = m_pParser->IsColored(); | 833 m_pType3Char->m_bColored = m_pParser->IsColored(); |
833 m_pType3Char->m_Width = | 834 m_pType3Char->m_Width = |
834 FXSYS_round(m_pParser->GetType3Data()[0] * 1000); | 835 FXSYS_round(m_pParser->GetType3Data()[0] * 1000); |
835 m_pType3Char->m_BBox.left = | 836 m_pType3Char->m_BBox.left = |
836 FXSYS_round(m_pParser->GetType3Data()[2] * 1000); | 837 FXSYS_round(m_pParser->GetType3Data()[2] * 1000); |
837 m_pType3Char->m_BBox.bottom = | 838 m_pType3Char->m_BBox.bottom = |
838 FXSYS_round(m_pParser->GetType3Data()[3] * 1000); | 839 FXSYS_round(m_pParser->GetType3Data()[3] * 1000); |
839 m_pType3Char->m_BBox.right = | 840 m_pType3Char->m_BBox.right = |
840 FXSYS_round(m_pParser->GetType3Data()[4] * 1000); | 841 FXSYS_round(m_pParser->GetType3Data()[4] * 1000); |
841 m_pType3Char->m_BBox.top = | 842 m_pType3Char->m_BBox.top = |
842 FXSYS_round(m_pParser->GetType3Data()[5] * 1000); | 843 FXSYS_round(m_pParser->GetType3Data()[5] * 1000); |
843 } | 844 } |
844 FX_POSITION pos = m_pObjects->GetPageObjectList()->GetHeadPosition(); | 845 for (auto& pObj : *m_pObjectHolder->GetPageObjectList()) { |
845 while (pos) { | |
846 CPDF_PageObject* pObj = | |
847 m_pObjects->GetPageObjectList()->GetNextObject(pos); | |
848 if (pObj->m_ClipPath.IsNull()) { | 846 if (pObj->m_ClipPath.IsNull()) { |
849 continue; | 847 continue; |
850 } | 848 } |
851 if (pObj->m_ClipPath.GetPathCount() != 1) { | 849 if (pObj->m_ClipPath.GetPathCount() != 1) { |
852 continue; | 850 continue; |
853 } | 851 } |
854 if (pObj->m_ClipPath.GetTextCount()) { | 852 if (pObj->m_ClipPath.GetTextCount()) { |
855 continue; | 853 continue; |
856 } | 854 } |
857 CPDF_Path ClipPath = pObj->m_ClipPath.GetPath(0); | 855 CPDF_Path ClipPath = pObj->m_ClipPath.GetPath(0); |
(...skipping 10 matching lines...) Expand all Loading... |
868 } | 866 } |
869 m_Status = Done; | 867 m_Status = Done; |
870 return; | 868 return; |
871 } | 869 } |
872 steps++; | 870 steps++; |
873 if (pPause && pPause->NeedToPauseNow()) { | 871 if (pPause && pPause->NeedToPauseNow()) { |
874 break; | 872 break; |
875 } | 873 } |
876 } | 874 } |
877 } | 875 } |
OLD | NEW |