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 "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 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 std::unique_ptr<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_pObjectHolder->BackgroundAlphaNeeded() && | 794 if (!m_pObjectHolder->BackgroundAlphaNeeded() && |
795 pFormObj->m_pForm->BackgroundAlphaNeeded()) { | 795 pFormObj->m_pForm->BackgroundAlphaNeeded()) { |
796 m_pObjectHolder->SetBackgroundAlphaNeeded(TRUE); | 796 m_pObjectHolder->SetBackgroundAlphaNeeded(TRUE); |
797 } | 797 } |
798 pFormObj->CalcBoundingBox(); | 798 pFormObj->CalcBoundingBox(); |
799 SetGraphicStates(pFormObj, TRUE, TRUE, TRUE); | 799 SetGraphicStates(pFormObj.get(), TRUE, TRUE, TRUE); |
800 m_pObjectHolder->GetPageObjectList()->AddTail(pFormObj); | 800 m_pObjectHolder->GetPageObjectList()->push_back(std::move(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 |
| 813 std::unique_ptr<CPDF_ImageObject> pImageObj(new CPDF_ImageObject); |
813 if (pImage) { | 814 if (pImage) { |
814 pImageObj->m_pImage = | 815 pImageObj->m_pImage = |
815 m_pDocument->GetPageData()->GetImage(pImage->GetStream()); | 816 m_pDocument->GetPageData()->GetImage(pImage->GetStream()); |
816 } else if (pStream->GetObjNum()) { | 817 } else if (pStream->GetObjNum()) { |
817 pImageObj->m_pImage = m_pDocument->LoadImageF(pStream); | 818 pImageObj->m_pImage = m_pDocument->LoadImageF(pStream); |
818 } else { | 819 } else { |
819 pImageObj->m_pImage = new CPDF_Image(m_pDocument); | 820 pImageObj->m_pImage = new CPDF_Image(m_pDocument); |
820 pImageObj->m_pImage->LoadImageF(pStream, bInline); | 821 pImageObj->m_pImage->LoadImageF(pStream, bInline); |
821 } | 822 } |
822 SetGraphicStates(pImageObj, pImageObj->m_pImage->IsMask(), FALSE, FALSE); | 823 SetGraphicStates(pImageObj.get(), pImageObj->m_pImage->IsMask(), FALSE, |
| 824 FALSE); |
823 pImageObj->m_Matrix = ImageMatrix; | 825 pImageObj->m_Matrix = ImageMatrix; |
824 pImageObj->CalcBoundingBox(); | 826 pImageObj->CalcBoundingBox(); |
825 m_pObjectHolder->GetPageObjectList()->AddTail(pImageObj); | 827 CPDF_ImageObject* pRet = pImageObj.get(); |
826 return pImageObj; | 828 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pImageObj)); |
| 829 return pRet; |
827 } | 830 } |
828 | 831 |
829 void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {} | 832 void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {} |
830 | 833 |
831 void CPDF_StreamContentParser::Handle_EndImage() {} | 834 void CPDF_StreamContentParser::Handle_EndImage() {} |
832 | 835 |
833 void CPDF_StreamContentParser::Handle_EndMarkedContent() { | 836 void CPDF_StreamContentParser::Handle_EndMarkedContent() { |
834 if (!m_Options.m_bMarkedContent) { | 837 if (!m_Options.m_bMarkedContent) { |
835 return; | 838 return; |
836 } | 839 } |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 if (pPattern->m_PatternType != CPDF_Pattern::SHADING) { | 1186 if (pPattern->m_PatternType != CPDF_Pattern::SHADING) { |
1184 return; | 1187 return; |
1185 } | 1188 } |
1186 CPDF_ShadingPattern* pShading = static_cast<CPDF_ShadingPattern*>(pPattern); | 1189 CPDF_ShadingPattern* pShading = static_cast<CPDF_ShadingPattern*>(pPattern); |
1187 if (!pShading->m_bShadingObj) { | 1190 if (!pShading->m_bShadingObj) { |
1188 return; | 1191 return; |
1189 } | 1192 } |
1190 if (!pShading->Load()) { | 1193 if (!pShading->Load()) { |
1191 return; | 1194 return; |
1192 } | 1195 } |
1193 CPDF_ShadingObject* pObj = new CPDF_ShadingObject; | 1196 std::unique_ptr<CPDF_ShadingObject> pObj(new CPDF_ShadingObject); |
1194 pObj->m_pShading = pShading; | 1197 pObj->m_pShading = pShading; |
1195 SetGraphicStates(pObj, FALSE, FALSE, FALSE); | 1198 SetGraphicStates(pObj.get(), FALSE, FALSE, FALSE); |
1196 pObj->m_Matrix = m_pCurStates->m_CTM; | 1199 pObj->m_Matrix = m_pCurStates->m_CTM; |
1197 pObj->m_Matrix.Concat(m_mtContentToUser); | 1200 pObj->m_Matrix.Concat(m_mtContentToUser); |
1198 CFX_FloatRect bbox; | 1201 CFX_FloatRect bbox; |
1199 if (!pObj->m_ClipPath.IsNull()) { | 1202 if (!pObj->m_ClipPath.IsNull()) { |
1200 bbox = pObj->m_ClipPath.GetClipBox(); | 1203 bbox = pObj->m_ClipPath.GetClipBox(); |
1201 } else { | 1204 } else { |
1202 bbox = m_BBox; | 1205 bbox = m_BBox; |
1203 } | 1206 } |
1204 if (pShading->IsMeshShading()) { | 1207 if (pShading->IsMeshShading()) { |
1205 bbox.Intersect(GetShadingBBox(ToStream(pShading->m_pShadingObj), | 1208 bbox.Intersect(GetShadingBBox(ToStream(pShading->m_pShadingObj), |
1206 pShading->m_ShadingType, &pObj->m_Matrix, | 1209 pShading->m_ShadingType, &pObj->m_Matrix, |
1207 pShading->m_pFunctions, pShading->m_nFuncs, | 1210 pShading->m_pFunctions, pShading->m_nFuncs, |
1208 pShading->m_pCS)); | 1211 pShading->m_pCS)); |
1209 } | 1212 } |
1210 pObj->m_Left = bbox.left; | 1213 pObj->m_Left = bbox.left; |
1211 pObj->m_Right = bbox.right; | 1214 pObj->m_Right = bbox.right; |
1212 pObj->m_Top = bbox.top; | 1215 pObj->m_Top = bbox.top; |
1213 pObj->m_Bottom = bbox.bottom; | 1216 pObj->m_Bottom = bbox.bottom; |
1214 m_pObjectHolder->GetPageObjectList()->AddTail(pObj); | 1217 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pObj)); |
1215 } | 1218 } |
1216 | 1219 |
1217 void CPDF_StreamContentParser::Handle_SetCharSpace() { | 1220 void CPDF_StreamContentParser::Handle_SetCharSpace() { |
1218 m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(0); | 1221 m_pCurStates->m_TextState.GetModify()->m_CharSpace = GetNumber(0); |
1219 } | 1222 } |
1220 | 1223 |
1221 void CPDF_StreamContentParser::Handle_MoveTextPoint() { | 1224 void CPDF_StreamContentParser::Handle_MoveTextPoint() { |
1222 m_pCurStates->m_TextLineX += GetNumber(1); | 1225 m_pCurStates->m_TextLineX += GetNumber(1); |
1223 m_pCurStates->m_TextLineY += GetNumber(0); | 1226 m_pCurStates->m_TextLineY += GetNumber(0); |
1224 m_pCurStates->m_TextX = m_pCurStates->m_TextLineX; | 1227 m_pCurStates->m_TextX = m_pCurStates->m_TextLineX; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 } | 1361 } |
1359 if (nsegs == 0) { | 1362 if (nsegs == 0) { |
1360 return; | 1363 return; |
1361 } | 1364 } |
1362 int textmode; | 1365 int textmode; |
1363 if (pFont->GetFontType() == PDFFONT_TYPE3) { | 1366 if (pFont->GetFontType() == PDFFONT_TYPE3) { |
1364 textmode = 0; | 1367 textmode = 0; |
1365 } else { | 1368 } else { |
1366 textmode = m_pCurStates->m_TextState.GetObject()->m_TextMode; | 1369 textmode = m_pCurStates->m_TextState.GetObject()->m_TextMode; |
1367 } | 1370 } |
1368 CPDF_TextObject* pText = new CPDF_TextObject; | 1371 { |
1369 m_pLastTextObject = pText; | 1372 std::unique_ptr<CPDF_TextObject> pText(new CPDF_TextObject); |
1370 SetGraphicStates(pText, TRUE, TRUE, TRUE); | 1373 m_pLastTextObject = pText.get(); |
1371 if (textmode && textmode != 3 && textmode != 4 && textmode != 7) { | 1374 SetGraphicStates(m_pLastTextObject, TRUE, TRUE, TRUE); |
1372 FX_FLOAT* pCTM = pText->m_TextState.GetModify()->m_CTM; | 1375 if (textmode && textmode != 3 && textmode != 4 && textmode != 7) { |
1373 pCTM[0] = m_pCurStates->m_CTM.a; | 1376 FX_FLOAT* pCTM = pText->m_TextState.GetModify()->m_CTM; |
1374 pCTM[1] = m_pCurStates->m_CTM.c; | 1377 pCTM[0] = m_pCurStates->m_CTM.a; |
1375 pCTM[2] = m_pCurStates->m_CTM.b; | 1378 pCTM[1] = m_pCurStates->m_CTM.c; |
1376 pCTM[3] = m_pCurStates->m_CTM.d; | 1379 pCTM[2] = m_pCurStates->m_CTM.b; |
| 1380 pCTM[3] = m_pCurStates->m_CTM.d; |
| 1381 } |
| 1382 pText->SetSegments(pStrs, pKerning, nsegs); |
| 1383 pText->m_PosX = m_pCurStates->m_TextX; |
| 1384 pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise; |
| 1385 ConvertTextSpace(pText->m_PosX, pText->m_PosY); |
| 1386 FX_FLOAT x_advance; |
| 1387 FX_FLOAT y_advance; |
| 1388 pText->CalcPositionData(&x_advance, &y_advance, |
| 1389 m_pCurStates->m_TextHorzScale, m_Level); |
| 1390 m_pCurStates->m_TextX += x_advance; |
| 1391 m_pCurStates->m_TextY += y_advance; |
| 1392 if (textmode > 3) { |
| 1393 CPDF_TextObject* pCopy = new CPDF_TextObject; |
| 1394 pCopy->Copy(pText.get()); |
| 1395 m_ClipTextList.Add(pCopy); |
| 1396 } |
| 1397 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pText)); |
1377 } | 1398 } |
1378 pText->SetSegments(pStrs, pKerning, nsegs); | |
1379 pText->m_PosX = m_pCurStates->m_TextX; | |
1380 pText->m_PosY = m_pCurStates->m_TextY + m_pCurStates->m_TextRise; | |
1381 ConvertTextSpace(pText->m_PosX, pText->m_PosY); | |
1382 FX_FLOAT x_advance, y_advance; | |
1383 pText->CalcPositionData(&x_advance, &y_advance, m_pCurStates->m_TextHorzScale, | |
1384 m_Level); | |
1385 m_pCurStates->m_TextX += x_advance; | |
1386 m_pCurStates->m_TextY += y_advance; | |
1387 if (textmode > 3) { | |
1388 CPDF_TextObject* pCopy = new CPDF_TextObject; | |
1389 pCopy->Copy(pText); | |
1390 m_ClipTextList.Add(pCopy); | |
1391 } | |
1392 m_pObjectHolder->GetPageObjectList()->AddTail(pText); | |
1393 if (pKerning && pKerning[nsegs - 1] != 0) { | 1399 if (pKerning && pKerning[nsegs - 1] != 0) { |
1394 if (!pFont->IsVertWriting()) { | 1400 if (!pFont->IsVertWriting()) { |
1395 m_pCurStates->m_TextX -= | 1401 m_pCurStates->m_TextX -= |
1396 FXSYS_Mul(pKerning[nsegs - 1], | 1402 FXSYS_Mul(pKerning[nsegs - 1], |
1397 m_pCurStates->m_TextState.GetFontSize()) / | 1403 m_pCurStates->m_TextState.GetFontSize()) / |
1398 1000; | 1404 1000; |
1399 } else { | 1405 } else { |
1400 m_pCurStates->m_TextY -= | 1406 m_pCurStates->m_TextY -= |
1401 FXSYS_Mul(pKerning[nsegs - 1], | 1407 FXSYS_Mul(pKerning[nsegs - 1], |
1402 m_pCurStates->m_TextState.GetFontSize()) / | 1408 m_pCurStates->m_TextState.GetFontSize()) / |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 PathPointCount--; | 1616 PathPointCount--; |
1611 } | 1617 } |
1612 CPDF_Path Path; | 1618 CPDF_Path Path; |
1613 CFX_PathData* pPathData = Path.New(); | 1619 CFX_PathData* pPathData = Path.New(); |
1614 pPathData->SetPointCount(PathPointCount); | 1620 pPathData->SetPointCount(PathPointCount); |
1615 FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints, | 1621 FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints, |
1616 sizeof(FX_PATHPOINT) * PathPointCount); | 1622 sizeof(FX_PATHPOINT) * PathPointCount); |
1617 CFX_Matrix matrix = m_pCurStates->m_CTM; | 1623 CFX_Matrix matrix = m_pCurStates->m_CTM; |
1618 matrix.Concat(m_mtContentToUser); | 1624 matrix.Concat(m_mtContentToUser); |
1619 if (bStroke || FillType) { | 1625 if (bStroke || FillType) { |
1620 CPDF_PathObject* pPathObj = new CPDF_PathObject; | 1626 std::unique_ptr<CPDF_PathObject> pPathObj(new CPDF_PathObject); |
1621 pPathObj->m_bStroke = bStroke; | 1627 pPathObj->m_bStroke = bStroke; |
1622 pPathObj->m_FillType = FillType; | 1628 pPathObj->m_FillType = FillType; |
1623 pPathObj->m_Path = Path; | 1629 pPathObj->m_Path = Path; |
1624 pPathObj->m_Matrix = matrix; | 1630 pPathObj->m_Matrix = matrix; |
1625 SetGraphicStates(pPathObj, TRUE, FALSE, TRUE); | 1631 SetGraphicStates(pPathObj.get(), TRUE, FALSE, TRUE); |
1626 pPathObj->CalcBoundingBox(); | 1632 pPathObj->CalcBoundingBox(); |
1627 m_pObjectHolder->GetPageObjectList()->AddTail(pPathObj); | 1633 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pPathObj)); |
1628 } | 1634 } |
1629 if (PathClipType) { | 1635 if (PathClipType) { |
1630 if (!matrix.IsIdentity()) { | 1636 if (!matrix.IsIdentity()) { |
1631 Path.Transform(&matrix); | 1637 Path.Transform(&matrix); |
1632 matrix.SetIdentity(); | 1638 matrix.SetIdentity(); |
1633 } | 1639 } |
1634 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE); | 1640 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE); |
1635 } | 1641 } |
1636 } | 1642 } |
1637 | 1643 |
1638 FX_DWORD CPDF_StreamContentParser::Parse(const uint8_t* pData, | 1644 FX_DWORD CPDF_StreamContentParser::Parse(const uint8_t* pData, |
1639 FX_DWORD dwSize, | 1645 FX_DWORD dwSize, |
1640 FX_DWORD max_cost) { | 1646 FX_DWORD max_cost) { |
1641 if (m_Level > _FPDF_MAX_FORM_LEVEL_) { | 1647 if (m_Level > _FPDF_MAX_FORM_LEVEL_) { |
1642 return dwSize; | 1648 return dwSize; |
1643 } | 1649 } |
1644 FX_DWORD InitObjCount = m_pObjectHolder->GetPageObjectList()->GetCount(); | 1650 FX_DWORD InitObjCount = m_pObjectHolder->GetPageObjectList()->size(); |
1645 CPDF_StreamParser syntax(pData, dwSize); | 1651 CPDF_StreamParser syntax(pData, dwSize); |
1646 CPDF_StreamParserAutoClearer auto_clearer(&m_pSyntax, &syntax); | 1652 CPDF_StreamParserAutoClearer auto_clearer(&m_pSyntax, &syntax); |
1647 m_CompatCount = 0; | 1653 m_CompatCount = 0; |
1648 while (1) { | 1654 while (1) { |
1649 FX_DWORD cost = | 1655 FX_DWORD cost = m_pObjectHolder->GetPageObjectList()->size() - InitObjCount; |
1650 m_pObjectHolder->GetPageObjectList()->GetCount() - InitObjCount; | |
1651 if (max_cost && cost >= max_cost) { | 1656 if (max_cost && cost >= max_cost) { |
1652 break; | 1657 break; |
1653 } | 1658 } |
1654 switch (syntax.ParseNextElement()) { | 1659 switch (syntax.ParseNextElement()) { |
1655 case CPDF_StreamParser::EndOfData: | 1660 case CPDF_StreamParser::EndOfData: |
1656 return m_pSyntax->GetPos(); | 1661 return m_pSyntax->GetPos(); |
1657 case CPDF_StreamParser::Keyword: | 1662 case CPDF_StreamParser::Keyword: |
1658 OnOperator((char*)syntax.GetWordBuf()); | 1663 OnOperator((char*)syntax.GetWordBuf()); |
1659 ClearAllParams(); | 1664 ClearAllParams(); |
1660 break; | 1665 break; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1814 } else { | 1819 } else { |
1815 PDF_ReplaceAbbr(pElement); | 1820 PDF_ReplaceAbbr(pElement); |
1816 } | 1821 } |
1817 } | 1822 } |
1818 break; | 1823 break; |
1819 } | 1824 } |
1820 default: | 1825 default: |
1821 break; | 1826 break; |
1822 } | 1827 } |
1823 } | 1828 } |
OLD | NEW |