Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp

Issue 1701073002: Split CPDF_PageObjectHolder off from CPDF_PageObjectList (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: m_pPage can never be null, remove checks. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "core/include/fpdfapi/fpdf_module.h" 9 #include "core/include/fpdfapi/fpdf_module.h"
10 #include "core/include/fpdfapi/fpdf_page.h" 10 #include "core/include/fpdfapi/fpdf_page.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 } 108 }
109 return false; 109 return false;
110 } 110 }
111 111
112 CPDF_StreamContentParser::CPDF_StreamContentParser( 112 CPDF_StreamContentParser::CPDF_StreamContentParser(
113 CPDF_Document* pDocument, 113 CPDF_Document* pDocument,
114 CPDF_Dictionary* pPageResources, 114 CPDF_Dictionary* pPageResources,
115 CPDF_Dictionary* pParentResources, 115 CPDF_Dictionary* pParentResources,
116 CFX_Matrix* pmtContentToUser, 116 CFX_Matrix* pmtContentToUser,
117 CPDF_PageObjectList* pObjList, 117 CPDF_PageObjectHolder* pObjHolder,
118 CPDF_Dictionary* pResources, 118 CPDF_Dictionary* pResources,
119 CPDF_Rect* pBBox, 119 CPDF_Rect* pBBox,
120 CPDF_ParseOptions* pOptions, 120 CPDF_ParseOptions* pOptions,
121 CPDF_AllStates* pStates, 121 CPDF_AllStates* pStates,
122 int level) 122 int level)
123 : m_pDocument(pDocument), 123 : m_pDocument(pDocument),
124 m_pPageResources(pPageResources), 124 m_pPageResources(pPageResources),
125 m_pParentResources(pParentResources), 125 m_pParentResources(pParentResources),
126 m_pResources(pResources), 126 m_pResources(pResources),
127 m_pObjectList(pObjList), 127 m_pObjectHolder(pObjHolder),
128 m_Level(level), 128 m_Level(level),
129 m_ParamStartPos(0), 129 m_ParamStartPos(0),
130 m_ParamCount(0), 130 m_ParamCount(0),
131 m_pCurStates(new CPDF_AllStates), 131 m_pCurStates(new CPDF_AllStates),
132 m_pLastTextObject(nullptr), 132 m_pLastTextObject(nullptr),
133 m_DefFontSize(0), 133 m_DefFontSize(0),
134 m_pPathPoints(nullptr), 134 m_pPathPoints(nullptr),
135 m_PathPointCount(0), 135 m_PathPointCount(0),
136 m_PathAllocSize(0), 136 m_PathAllocSize(0),
137 m_PathCurrentX(0.0f), 137 m_PathCurrentX(0.0f),
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 CFX_ByteStringC type = pXObject->GetDict() 731 CFX_ByteStringC type = pXObject->GetDict()
732 ? pXObject->GetDict()->GetConstStringBy("Subtype") 732 ? pXObject->GetDict()->GetConstStringBy("Subtype")
733 : CFX_ByteStringC(); 733 : CFX_ByteStringC();
734 if (type == "Image") { 734 if (type == "Image") {
735 if (m_Options.m_bTextOnly) { 735 if (m_Options.m_bTextOnly) {
736 return; 736 return;
737 } 737 }
738 CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE); 738 CPDF_ImageObject* pObj = AddImage(pXObject, NULL, FALSE);
739 m_LastImageName = name; 739 m_LastImageName = name;
740 m_pLastImage = pObj->m_pImage; 740 m_pLastImage = pObj->m_pImage;
741 if (!m_pObjectList->HasImageMask()) 741 if (!m_pObjectHolder->HasImageMask())
742 m_pObjectList->SetHasImageMask(m_pLastImage->IsMask()); 742 m_pObjectHolder->SetHasImageMask(m_pLastImage->IsMask());
743 } else if (type == "Form") { 743 } else if (type == "Form") {
744 AddForm(pXObject); 744 AddForm(pXObject);
745 } else { 745 } else {
746 return; 746 return;
747 } 747 }
748 } 748 }
749 749
750 void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { 750 void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) {
751 if (!m_Options.m_bSeparateForm) { 751 if (!m_Options.m_bSeparateForm) {
752 CPDF_Dictionary* pResources = pStream->GetDict()->GetDictBy("Resources"); 752 CPDF_Dictionary* pResources = pStream->GetDict()->GetDictBy("Resources");
753 CFX_Matrix form_matrix = pStream->GetDict()->GetMatrixBy("Matrix"); 753 CFX_Matrix form_matrix = pStream->GetDict()->GetMatrixBy("Matrix");
754 form_matrix.Concat(m_pCurStates->m_CTM); 754 form_matrix.Concat(m_pCurStates->m_CTM);
755 CPDF_Array* pBBox = pStream->GetDict()->GetArrayBy("BBox"); 755 CPDF_Array* pBBox = pStream->GetDict()->GetArrayBy("BBox");
756 CFX_FloatRect form_bbox; 756 CFX_FloatRect form_bbox;
757 CPDF_Path ClipPath; 757 CPDF_Path ClipPath;
758 if (pBBox) { 758 if (pBBox) {
759 form_bbox = pStream->GetDict()->GetRectBy("BBox"); 759 form_bbox = pStream->GetDict()->GetRectBy("BBox");
760 ClipPath.New(); 760 ClipPath.New();
761 ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right, 761 ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right,
762 form_bbox.top); 762 form_bbox.top);
763 ClipPath.Transform(&form_matrix); 763 ClipPath.Transform(&form_matrix);
764 form_bbox.Transform(&form_matrix); 764 form_bbox.Transform(&form_matrix);
765 } 765 }
766 CPDF_StreamContentParser parser(m_pDocument, m_pPageResources, m_pResources, 766 CPDF_StreamContentParser parser(m_pDocument, m_pPageResources, m_pResources,
767 &m_mtContentToUser, m_pObjectList, 767 &m_mtContentToUser, m_pObjectHolder,
768 pResources, &form_bbox, &m_Options, 768 pResources, &form_bbox, &m_Options,
769 m_pCurStates.get(), m_Level + 1); 769 m_pCurStates.get(), m_Level + 1);
770 parser.m_pCurStates->m_CTM = form_matrix; 770 parser.m_pCurStates->m_CTM = form_matrix;
771 if (ClipPath.NotNull()) { 771 if (ClipPath.NotNull()) {
772 parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING, 772 parser.m_pCurStates->m_ClipPath.AppendPath(ClipPath, FXFILL_WINDING,
773 TRUE); 773 TRUE);
774 } 774 }
775 CPDF_StreamAcc stream; 775 CPDF_StreamAcc stream;
776 stream.LoadAllData(pStream, FALSE); 776 stream.LoadAllData(pStream, FALSE);
777 if (stream.GetSize() == 0) { 777 if (stream.GetSize() == 0) {
778 return; 778 return;
779 } 779 }
780 parser.Parse(stream.GetData(), stream.GetSize(), 0); 780 parser.Parse(stream.GetData(), stream.GetSize(), 0);
781 return; 781 return;
782 } 782 }
783 CPDF_FormObject* pFormObj = new CPDF_FormObject; 783 CPDF_FormObject* pFormObj = new CPDF_FormObject;
784 pFormObj->m_pForm = 784 pFormObj->m_pForm =
785 new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources); 785 new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources);
786 pFormObj->m_FormMatrix = m_pCurStates->m_CTM; 786 pFormObj->m_FormMatrix = m_pCurStates->m_CTM;
787 pFormObj->m_FormMatrix.Concat(m_mtContentToUser); 787 pFormObj->m_FormMatrix.Concat(m_mtContentToUser);
788 CPDF_AllStates status; 788 CPDF_AllStates status;
789 status.m_GeneralState = m_pCurStates->m_GeneralState; 789 status.m_GeneralState = m_pCurStates->m_GeneralState;
790 status.m_GraphState = m_pCurStates->m_GraphState; 790 status.m_GraphState = m_pCurStates->m_GraphState;
791 status.m_ColorState = m_pCurStates->m_ColorState; 791 status.m_ColorState = m_pCurStates->m_ColorState;
792 status.m_TextState = m_pCurStates->m_TextState; 792 status.m_TextState = m_pCurStates->m_TextState;
793 pFormObj->m_pForm->ParseContent(&status, NULL, NULL, &m_Options, m_Level + 1); 793 pFormObj->m_pForm->ParseContent(&status, NULL, NULL, &m_Options, m_Level + 1);
794 if (!m_pObjectList->BackgroundAlphaNeeded() && 794 if (!m_pObjectHolder->BackgroundAlphaNeeded() &&
795 pFormObj->m_pForm->BackgroundAlphaNeeded()) { 795 pFormObj->m_pForm->BackgroundAlphaNeeded()) {
796 m_pObjectList->SetBackgroundAlphaNeeded(TRUE); 796 m_pObjectHolder->SetBackgroundAlphaNeeded(TRUE);
797 } 797 }
798 pFormObj->CalcBoundingBox(); 798 pFormObj->CalcBoundingBox();
799 SetGraphicStates(pFormObj, TRUE, TRUE, TRUE); 799 SetGraphicStates(pFormObj, TRUE, TRUE, TRUE);
800 m_pObjectList->AddTail(pFormObj); 800 m_pObjectHolder->GetPageObjectList()->AddTail(pFormObj);
801 } 801 }
802 802
803 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, 803 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream,
804 CPDF_Image* pImage, 804 CPDF_Image* pImage,
805 FX_BOOL bInline) { 805 FX_BOOL bInline) {
806 if (!pStream && !pImage) { 806 if (!pStream && !pImage) {
807 return NULL; 807 return NULL;
808 } 808 }
809 CFX_Matrix ImageMatrix; 809 CFX_Matrix ImageMatrix;
810 ImageMatrix.Copy(m_pCurStates->m_CTM); 810 ImageMatrix.Copy(m_pCurStates->m_CTM);
811 ImageMatrix.Concat(m_mtContentToUser); 811 ImageMatrix.Concat(m_mtContentToUser);
812 CPDF_ImageObject* pImageObj = new CPDF_ImageObject; 812 CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
813 if (pImage) { 813 if (pImage) {
814 pImageObj->m_pImage = 814 pImageObj->m_pImage =
815 m_pDocument->GetPageData()->GetImage(pImage->GetStream()); 815 m_pDocument->GetPageData()->GetImage(pImage->GetStream());
816 } else if (pStream->GetObjNum()) { 816 } else if (pStream->GetObjNum()) {
817 pImageObj->m_pImage = m_pDocument->LoadImageF(pStream); 817 pImageObj->m_pImage = m_pDocument->LoadImageF(pStream);
818 } else { 818 } else {
819 pImageObj->m_pImage = new CPDF_Image(m_pDocument); 819 pImageObj->m_pImage = new CPDF_Image(m_pDocument);
820 pImageObj->m_pImage->LoadImageF(pStream, bInline); 820 pImageObj->m_pImage->LoadImageF(pStream, bInline);
821 } 821 }
822 SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE); 822 SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE);
823 pImageObj->m_Matrix = ImageMatrix; 823 pImageObj->m_Matrix = ImageMatrix;
824 pImageObj->CalcBoundingBox(); 824 pImageObj->CalcBoundingBox();
825 m_pObjectList->AddTail(pImageObj); 825 m_pObjectHolder->GetPageObjectList()->AddTail(pImageObj);
826 return pImageObj; 826 return pImageObj;
827 } 827 }
828 828
829 void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {} 829 void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {}
830 830
831 void CPDF_StreamContentParser::Handle_EndImage() {} 831 void CPDF_StreamContentParser::Handle_EndImage() {}
832 832
833 void CPDF_StreamContentParser::Handle_EndMarkedContent() { 833 void CPDF_StreamContentParser::Handle_EndMarkedContent() {
834 if (!m_Options.m_bMarkedContent) { 834 if (!m_Options.m_bMarkedContent) {
835 return; 835 return;
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 if (pShading->IsMeshShading()) { 1204 if (pShading->IsMeshShading()) {
1205 bbox.Intersect(GetShadingBBox(ToStream(pShading->m_pShadingObj), 1205 bbox.Intersect(GetShadingBBox(ToStream(pShading->m_pShadingObj),
1206 pShading->m_ShadingType, &pObj->m_Matrix, 1206 pShading->m_ShadingType, &pObj->m_Matrix,
1207 pShading->m_pFunctions, pShading->m_nFuncs, 1207 pShading->m_pFunctions, pShading->m_nFuncs,
1208 pShading->m_pCS)); 1208 pShading->m_pCS));
1209 } 1209 }
1210 pObj->m_Left = bbox.left; 1210 pObj->m_Left = bbox.left;
1211 pObj->m_Right = bbox.right; 1211 pObj->m_Right = bbox.right;
1212 pObj->m_Top = bbox.top; 1212 pObj->m_Top = bbox.top;
1213 pObj->m_Bottom = bbox.bottom; 1213 pObj->m_Bottom = bbox.bottom;
1214 m_pObjectList->AddTail(pObj); 1214 m_pObjectHolder->GetPageObjectList()->AddTail(pObj);
1215 } 1215 }
1216 1216
1217 void CPDF_StreamContentParser::Handle_SetCharSpace() { 1217 void CPDF_StreamContentParser::Handle_SetCharSpace() {
1218 m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(0); 1218 m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(0);
1219 } 1219 }
1220 1220
1221 void CPDF_StreamContentParser::Handle_MoveTextPoint() { 1221 void CPDF_StreamContentParser::Handle_MoveTextPoint() {
1222 m_pCurStates->m_TextLineX += GetNumber(1); 1222 m_pCurStates->m_TextLineX += GetNumber(1);
1223 m_pCurStates->m_TextLineY += GetNumber(0); 1223 m_pCurStates->m_TextLineY += GetNumber(0);
1224 m_pCurStates->m_TextX = m_pCurStates->m_TextLineX; 1224 m_pCurStates->m_TextX = m_pCurStates->m_TextLineX;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 FX_FLOAT x_advance, y_advance; 1382 FX_FLOAT x_advance, y_advance;
1383 pText->CalcPositionData(&x_advance, &y_advance, m_pCurStates->m_TextHorzScale, 1383 pText->CalcPositionData(&x_advance, &y_advance, m_pCurStates->m_TextHorzScale,
1384 m_Level); 1384 m_Level);
1385 m_pCurStates->m_TextX += x_advance; 1385 m_pCurStates->m_TextX += x_advance;
1386 m_pCurStates->m_TextY += y_advance; 1386 m_pCurStates->m_TextY += y_advance;
1387 if (textmode > 3) { 1387 if (textmode > 3) {
1388 CPDF_TextObject* pCopy = new CPDF_TextObject; 1388 CPDF_TextObject* pCopy = new CPDF_TextObject;
1389 pCopy->Copy(pText); 1389 pCopy->Copy(pText);
1390 m_ClipTextList.Add(pCopy); 1390 m_ClipTextList.Add(pCopy);
1391 } 1391 }
1392 m_pObjectList->AddTail(pText); 1392 m_pObjectHolder->GetPageObjectList()->AddTail(pText);
1393 if (pKerning && pKerning[nsegs - 1] != 0) { 1393 if (pKerning && pKerning[nsegs - 1] != 0) {
1394 if (!pFont->IsVertWriting()) { 1394 if (!pFont->IsVertWriting()) {
1395 m_pCurStates->m_TextX -= 1395 m_pCurStates->m_TextX -=
1396 FXSYS_Mul(pKerning[nsegs - 1], 1396 FXSYS_Mul(pKerning[nsegs - 1],
1397 m_pCurStates->m_TextState.GetFontSize()) / 1397 m_pCurStates->m_TextState.GetFontSize()) /
1398 1000; 1398 1000;
1399 } else { 1399 } else {
1400 m_pCurStates->m_TextY -= 1400 m_pCurStates->m_TextY -=
1401 FXSYS_Mul(pKerning[nsegs - 1], 1401 FXSYS_Mul(pKerning[nsegs - 1],
1402 m_pCurStates->m_TextState.GetFontSize()) / 1402 m_pCurStates->m_TextState.GetFontSize()) /
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 CFX_Matrix matrix = m_pCurStates->m_CTM; 1617 CFX_Matrix matrix = m_pCurStates->m_CTM;
1618 matrix.Concat(m_mtContentToUser); 1618 matrix.Concat(m_mtContentToUser);
1619 if (bStroke || FillType) { 1619 if (bStroke || FillType) {
1620 CPDF_PathObject* pPathObj = new CPDF_PathObject; 1620 CPDF_PathObject* pPathObj = new CPDF_PathObject;
1621 pPathObj->m_bStroke = bStroke; 1621 pPathObj->m_bStroke = bStroke;
1622 pPathObj->m_FillType = FillType; 1622 pPathObj->m_FillType = FillType;
1623 pPathObj->m_Path = Path; 1623 pPathObj->m_Path = Path;
1624 pPathObj->m_Matrix = matrix; 1624 pPathObj->m_Matrix = matrix;
1625 SetGraphicStates(pPathObj, TRUE, FALSE, TRUE); 1625 SetGraphicStates(pPathObj, TRUE, FALSE, TRUE);
1626 pPathObj->CalcBoundingBox(); 1626 pPathObj->CalcBoundingBox();
1627 m_pObjectList->AddTail(pPathObj); 1627 m_pObjectHolder->GetPageObjectList()->AddTail(pPathObj);
1628 } 1628 }
1629 if (PathClipType) { 1629 if (PathClipType) {
1630 if (!matrix.IsIdentity()) { 1630 if (!matrix.IsIdentity()) {
1631 Path.Transform(&matrix); 1631 Path.Transform(&matrix);
1632 matrix.SetIdentity(); 1632 matrix.SetIdentity();
1633 } 1633 }
1634 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE); 1634 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE);
1635 } 1635 }
1636 } 1636 }
1637 1637
1638 FX_DWORD CPDF_StreamContentParser::Parse(const uint8_t* pData, 1638 FX_DWORD CPDF_StreamContentParser::Parse(const uint8_t* pData,
1639 FX_DWORD dwSize, 1639 FX_DWORD dwSize,
1640 FX_DWORD max_cost) { 1640 FX_DWORD max_cost) {
1641 if (m_Level > _FPDF_MAX_FORM_LEVEL_) { 1641 if (m_Level > _FPDF_MAX_FORM_LEVEL_) {
1642 return dwSize; 1642 return dwSize;
1643 } 1643 }
1644 FX_DWORD InitObjCount = m_pObjectList->CountObjects(); 1644 FX_DWORD InitObjCount = m_pObjectHolder->GetPageObjectList()->GetCount();
1645 CPDF_StreamParser syntax(pData, dwSize); 1645 CPDF_StreamParser syntax(pData, dwSize);
1646 CPDF_StreamParserAutoClearer auto_clearer(&m_pSyntax, &syntax); 1646 CPDF_StreamParserAutoClearer auto_clearer(&m_pSyntax, &syntax);
1647 m_CompatCount = 0; 1647 m_CompatCount = 0;
1648 while (1) { 1648 while (1) {
1649 FX_DWORD cost = m_pObjectList->CountObjects() - InitObjCount; 1649 FX_DWORD cost =
1650 m_pObjectHolder->GetPageObjectList()->GetCount() - InitObjCount;
1650 if (max_cost && cost >= max_cost) { 1651 if (max_cost && cost >= max_cost) {
1651 break; 1652 break;
1652 } 1653 }
1653 switch (syntax.ParseNextElement()) { 1654 switch (syntax.ParseNextElement()) {
1654 case CPDF_StreamParser::EndOfData: 1655 case CPDF_StreamParser::EndOfData:
1655 return m_pSyntax->GetPos(); 1656 return m_pSyntax->GetPos();
1656 case CPDF_StreamParser::Keyword: 1657 case CPDF_StreamParser::Keyword:
1657 OnOperator((char*)syntax.GetWordBuf()); 1658 OnOperator((char*)syntax.GetWordBuf());
1658 ClearAllParams(); 1659 ClearAllParams();
1659 break; 1660 break;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 } else { 1814 } else {
1814 PDF_ReplaceAbbr(pElement); 1815 PDF_ReplaceAbbr(pElement);
1815 } 1816 }
1816 } 1817 }
1817 break; 1818 break;
1818 } 1819 }
1819 default: 1820 default:
1820 break; 1821 break;
1821 } 1822 }
1822 } 1823 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698