| 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 "pageint.h" | 7 #include "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" |
| 11 #include "core/include/fpdfapi/fpdf_serial.h" | 11 #include "core/include/fpdfapi/fpdf_serial.h" |
| 12 | 12 |
| 13 #define REQUIRE_PARAMS(count) \ | 13 #define REQUIRE_PARAMS(count) \ |
| 14 if (m_ParamCount != count) { \ | 14 if (m_ParamCount != count) { \ |
| 15 return; \ | 15 return; \ |
| 16 } | 16 } |
| 17 | 17 |
| 18 CPDF_StreamContentParser::CPDF_StreamContentParser( | 18 CPDF_StreamContentParser::CPDF_StreamContentParser( |
| 19 CPDF_Document* pDocument, | 19 CPDF_Document* pDocument, |
| 20 CPDF_Dictionary* pPageResources, | 20 CPDF_Dictionary* pPageResources, |
| 21 CPDF_Dictionary* pParentResources, | 21 CPDF_Dictionary* pParentResources, |
| 22 CFX_AffineMatrix* pmtContentToUser, | 22 CFX_Matrix* pmtContentToUser, |
| 23 CPDF_PageObjects* pObjList, | 23 CPDF_PageObjects* pObjList, |
| 24 CPDF_Dictionary* pResources, | 24 CPDF_Dictionary* pResources, |
| 25 CPDF_Rect* pBBox, | 25 CPDF_Rect* pBBox, |
| 26 CPDF_ParseOptions* pOptions, | 26 CPDF_ParseOptions* pOptions, |
| 27 CPDF_AllStates* pStates, | 27 CPDF_AllStates* pStates, |
| 28 int level) | 28 int level) |
| 29 : m_pDocument(pDocument), | 29 : m_pDocument(pDocument), |
| 30 m_pPageResources(pPageResources), | 30 m_pPageResources(pPageResources), |
| 31 m_pParentResources(pParentResources), | 31 m_pParentResources(pParentResources), |
| 32 m_pResources(pResources), | 32 m_pResources(pResources), |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 return; | 613 return; |
| 614 } | 614 } |
| 615 AddPathPoint(GetNumber(5), GetNumber(4), FXPT_BEZIERTO); | 615 AddPathPoint(GetNumber(5), GetNumber(4), FXPT_BEZIERTO); |
| 616 AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO); | 616 AddPathPoint(GetNumber(3), GetNumber(2), FXPT_BEZIERTO); |
| 617 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); | 617 AddPathPoint(GetNumber(1), GetNumber(0), FXPT_BEZIERTO); |
| 618 } | 618 } |
| 619 void CPDF_StreamContentParser::Handle_ConcatMatrix() { | 619 void CPDF_StreamContentParser::Handle_ConcatMatrix() { |
| 620 FX_FLOAT a2 = GetNumber16(5), b2 = GetNumber16(4), c2 = GetNumber16(3), | 620 FX_FLOAT a2 = GetNumber16(5), b2 = GetNumber16(4), c2 = GetNumber16(3), |
| 621 d2 = GetNumber16(2); | 621 d2 = GetNumber16(2); |
| 622 FX_FLOAT e2 = GetNumber(1), f2 = GetNumber(0); | 622 FX_FLOAT e2 = GetNumber(1), f2 = GetNumber(0); |
| 623 CFX_AffineMatrix new_matrix(a2, b2, c2, d2, e2, f2); | 623 CFX_Matrix new_matrix(a2, b2, c2, d2, e2, f2); |
| 624 new_matrix.Concat(m_pCurStates->m_CTM); | 624 new_matrix.Concat(m_pCurStates->m_CTM); |
| 625 m_pCurStates->m_CTM = new_matrix; | 625 m_pCurStates->m_CTM = new_matrix; |
| 626 OnChangeTextMatrix(); | 626 OnChangeTextMatrix(); |
| 627 } | 627 } |
| 628 void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() { | 628 void CPDF_StreamContentParser::Handle_SetColorSpace_Fill() { |
| 629 if (m_Options.m_bTextOnly) { | 629 if (m_Options.m_bTextOnly) { |
| 630 return; | 630 return; |
| 631 } | 631 } |
| 632 CFX_ByteString csname = GetString(0); | 632 CFX_ByteString csname = GetString(0); |
| 633 CPDF_ColorSpace* pCS = FindColorSpace(csname); | 633 CPDF_ColorSpace* pCS = FindColorSpace(csname); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 } else if (type == FX_BSTRC("Form")) { | 714 } else if (type == FX_BSTRC("Form")) { |
| 715 AddForm(pXObject); | 715 AddForm(pXObject); |
| 716 } else { | 716 } else { |
| 717 return; | 717 return; |
| 718 } | 718 } |
| 719 } | 719 } |
| 720 void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { | 720 void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { |
| 721 if (!m_Options.m_bSeparateForm) { | 721 if (!m_Options.m_bSeparateForm) { |
| 722 CPDF_Dictionary* pResources = | 722 CPDF_Dictionary* pResources = |
| 723 pStream->GetDict()->GetDict(FX_BSTRC("Resources")); | 723 pStream->GetDict()->GetDict(FX_BSTRC("Resources")); |
| 724 CFX_AffineMatrix form_matrix = | 724 CFX_Matrix form_matrix = pStream->GetDict()->GetMatrix(FX_BSTRC("Matrix")); |
| 725 pStream->GetDict()->GetMatrix(FX_BSTRC("Matrix")); | |
| 726 form_matrix.Concat(m_pCurStates->m_CTM); | 725 form_matrix.Concat(m_pCurStates->m_CTM); |
| 727 CPDF_Array* pBBox = pStream->GetDict()->GetArray(FX_BSTRC("BBox")); | 726 CPDF_Array* pBBox = pStream->GetDict()->GetArray(FX_BSTRC("BBox")); |
| 728 CFX_FloatRect form_bbox; | 727 CFX_FloatRect form_bbox; |
| 729 CPDF_Path ClipPath; | 728 CPDF_Path ClipPath; |
| 730 if (pBBox) { | 729 if (pBBox) { |
| 731 form_bbox = pStream->GetDict()->GetRect(FX_BSTRC("BBox")); | 730 form_bbox = pStream->GetDict()->GetRect(FX_BSTRC("BBox")); |
| 732 ClipPath.New(); | 731 ClipPath.New(); |
| 733 ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right, | 732 ClipPath.AppendRect(form_bbox.left, form_bbox.bottom, form_bbox.right, |
| 734 form_bbox.top); | 733 form_bbox.top); |
| 735 ClipPath.Transform(&form_matrix); | 734 ClipPath.Transform(&form_matrix); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 pFormObj->CalcBoundingBox(); | 769 pFormObj->CalcBoundingBox(); |
| 771 SetGraphicStates(pFormObj, TRUE, TRUE, TRUE); | 770 SetGraphicStates(pFormObj, TRUE, TRUE, TRUE); |
| 772 m_pObjectList->m_ObjectList.AddTail(pFormObj); | 771 m_pObjectList->m_ObjectList.AddTail(pFormObj); |
| 773 } | 772 } |
| 774 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, | 773 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, |
| 775 CPDF_Image* pImage, | 774 CPDF_Image* pImage, |
| 776 FX_BOOL bInline) { | 775 FX_BOOL bInline) { |
| 777 if (pStream == NULL && pImage == NULL) { | 776 if (pStream == NULL && pImage == NULL) { |
| 778 return NULL; | 777 return NULL; |
| 779 } | 778 } |
| 780 CFX_AffineMatrix ImageMatrix; | 779 CFX_Matrix ImageMatrix; |
| 781 ImageMatrix.Copy(m_pCurStates->m_CTM); | 780 ImageMatrix.Copy(m_pCurStates->m_CTM); |
| 782 ImageMatrix.Concat(m_mtContentToUser); | 781 ImageMatrix.Concat(m_mtContentToUser); |
| 783 CPDF_ImageObject* pImageObj = new CPDF_ImageObject; | 782 CPDF_ImageObject* pImageObj = new CPDF_ImageObject; |
| 784 if (pImage) { | 783 if (pImage) { |
| 785 pImageObj->m_pImage = | 784 pImageObj->m_pImage = |
| 786 m_pDocument->GetPageData()->GetImage(pImage->GetStream()); | 785 m_pDocument->GetPageData()->GetImage(pImage->GetStream()); |
| 787 } else if (pStream->GetObjNum()) { | 786 } else if (pStream->GetObjNum()) { |
| 788 pImageObj->m_pImage = m_pDocument->LoadImageF(pStream); | 787 pImageObj->m_pImage = m_pDocument->LoadImageF(pStream); |
| 789 } else { | 788 } else { |
| 790 pImageObj->m_pImage = new CPDF_Image(m_pDocument); | 789 pImageObj->m_pImage = new CPDF_Image(m_pDocument); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 if (pPattern) { | 1085 if (pPattern) { |
| 1087 m_pCurStates->m_ColorState.SetStrokePattern(pPattern, values, nvalues); | 1086 m_pCurStates->m_ColorState.SetStrokePattern(pPattern, values, nvalues); |
| 1088 } | 1087 } |
| 1089 } else { | 1088 } else { |
| 1090 m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nvalues); | 1089 m_pCurStates->m_ColorState.SetStrokeColor(NULL, values, nvalues); |
| 1091 } | 1090 } |
| 1092 FX_Free(values); | 1091 FX_Free(values); |
| 1093 } | 1092 } |
| 1094 CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream, | 1093 CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream, |
| 1095 ShadingType type, | 1094 ShadingType type, |
| 1096 const CFX_AffineMatrix* pMatrix, | 1095 const CFX_Matrix* pMatrix, |
| 1097 CPDF_Function** pFuncs, | 1096 CPDF_Function** pFuncs, |
| 1098 int nFuncs, | 1097 int nFuncs, |
| 1099 CPDF_ColorSpace* pCS); | 1098 CPDF_ColorSpace* pCS); |
| 1100 | 1099 |
| 1101 void CPDF_StreamContentParser::Handle_ShadeFill() { | 1100 void CPDF_StreamContentParser::Handle_ShadeFill() { |
| 1102 if (m_Options.m_bTextOnly) { | 1101 if (m_Options.m_bTextOnly) { |
| 1103 return; | 1102 return; |
| 1104 } | 1103 } |
| 1105 CPDF_Pattern* pPattern = FindPattern(GetString(0), TRUE); | 1104 CPDF_Pattern* pPattern = FindPattern(GetString(0), TRUE); |
| 1106 if (pPattern == NULL) { | 1105 if (pPattern == NULL) { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 void CPDF_StreamContentParser::Handle_SetTextMatrix() { | 1379 void CPDF_StreamContentParser::Handle_SetTextMatrix() { |
| 1381 m_pCurStates->m_TextMatrix.Set(GetNumber16(5), GetNumber16(4), GetNumber16(3), | 1380 m_pCurStates->m_TextMatrix.Set(GetNumber16(5), GetNumber16(4), GetNumber16(3), |
| 1382 GetNumber16(2), GetNumber(1), GetNumber(0)); | 1381 GetNumber16(2), GetNumber(1), GetNumber(0)); |
| 1383 OnChangeTextMatrix(); | 1382 OnChangeTextMatrix(); |
| 1384 m_pCurStates->m_TextX = 0; | 1383 m_pCurStates->m_TextX = 0; |
| 1385 m_pCurStates->m_TextY = 0; | 1384 m_pCurStates->m_TextY = 0; |
| 1386 m_pCurStates->m_TextLineX = 0; | 1385 m_pCurStates->m_TextLineX = 0; |
| 1387 m_pCurStates->m_TextLineY = 0; | 1386 m_pCurStates->m_TextLineY = 0; |
| 1388 } | 1387 } |
| 1389 void CPDF_StreamContentParser::OnChangeTextMatrix() { | 1388 void CPDF_StreamContentParser::OnChangeTextMatrix() { |
| 1390 CFX_AffineMatrix text_matrix(m_pCurStates->m_TextHorzScale, 0.0f, 0.0f, 1.0f, | 1389 CFX_Matrix text_matrix(m_pCurStates->m_TextHorzScale, 0.0f, 0.0f, 1.0f, 0.0f, |
| 1391 0.0f, 0.0f); | 1390 0.0f); |
| 1392 text_matrix.Concat(m_pCurStates->m_TextMatrix); | 1391 text_matrix.Concat(m_pCurStates->m_TextMatrix); |
| 1393 text_matrix.Concat(m_pCurStates->m_CTM); | 1392 text_matrix.Concat(m_pCurStates->m_CTM); |
| 1394 text_matrix.Concat(m_mtContentToUser); | 1393 text_matrix.Concat(m_mtContentToUser); |
| 1395 FX_FLOAT* pTextMatrix = m_pCurStates->m_TextState.GetModify()->m_Matrix; | 1394 FX_FLOAT* pTextMatrix = m_pCurStates->m_TextState.GetModify()->m_Matrix; |
| 1396 pTextMatrix[0] = text_matrix.a; | 1395 pTextMatrix[0] = text_matrix.a; |
| 1397 pTextMatrix[1] = text_matrix.c; | 1396 pTextMatrix[1] = text_matrix.c; |
| 1398 pTextMatrix[2] = text_matrix.b; | 1397 pTextMatrix[2] = text_matrix.b; |
| 1399 pTextMatrix[3] = text_matrix.d; | 1398 pTextMatrix[3] = text_matrix.d; |
| 1400 } | 1399 } |
| 1401 void CPDF_StreamContentParser::Handle_SetTextRenderMode() { | 1400 void CPDF_StreamContentParser::Handle_SetTextRenderMode() { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 } | 1503 } |
| 1505 if (PathPointCount && | 1504 if (PathPointCount && |
| 1506 m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVETO) { | 1505 m_pPathPoints[PathPointCount - 1].m_Flag == FXPT_MOVETO) { |
| 1507 PathPointCount--; | 1506 PathPointCount--; |
| 1508 } | 1507 } |
| 1509 CPDF_Path Path; | 1508 CPDF_Path Path; |
| 1510 CFX_PathData* pPathData = Path.New(); | 1509 CFX_PathData* pPathData = Path.New(); |
| 1511 pPathData->SetPointCount(PathPointCount); | 1510 pPathData->SetPointCount(PathPointCount); |
| 1512 FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints, | 1511 FXSYS_memcpy(pPathData->GetPoints(), m_pPathPoints, |
| 1513 sizeof(FX_PATHPOINT) * PathPointCount); | 1512 sizeof(FX_PATHPOINT) * PathPointCount); |
| 1514 CFX_AffineMatrix matrix = m_pCurStates->m_CTM; | 1513 CFX_Matrix matrix = m_pCurStates->m_CTM; |
| 1515 matrix.Concat(m_mtContentToUser); | 1514 matrix.Concat(m_mtContentToUser); |
| 1516 if (bStroke || FillType) { | 1515 if (bStroke || FillType) { |
| 1517 CPDF_PathObject* pPathObj = new CPDF_PathObject; | 1516 CPDF_PathObject* pPathObj = new CPDF_PathObject; |
| 1518 pPathObj->m_bStroke = bStroke; | 1517 pPathObj->m_bStroke = bStroke; |
| 1519 pPathObj->m_FillType = FillType; | 1518 pPathObj->m_FillType = FillType; |
| 1520 pPathObj->m_Path = Path; | 1519 pPathObj->m_Path = Path; |
| 1521 pPathObj->m_Matrix = matrix; | 1520 pPathObj->m_Matrix = matrix; |
| 1522 SetGraphicStates(pPathObj, TRUE, FALSE, TRUE); | 1521 SetGraphicStates(pPathObj, TRUE, FALSE, TRUE); |
| 1523 pPathObj->CalcBoundingBox(); | 1522 pPathObj->CalcBoundingBox(); |
| 1524 m_pObjectList->m_ObjectList.AddTail(pPathObj); | 1523 m_pObjectList->m_ObjectList.AddTail(pPathObj); |
| 1525 } | 1524 } |
| 1526 if (PathClipType) { | 1525 if (PathClipType) { |
| 1527 if (!matrix.IsIdentity()) { | 1526 if (!matrix.IsIdentity()) { |
| 1528 Path.Transform(&matrix); | 1527 Path.Transform(&matrix); |
| 1529 matrix.SetIdentity(); | 1528 matrix.SetIdentity(); |
| 1530 } | 1529 } |
| 1531 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE); | 1530 m_pCurStates->m_ClipPath.AppendPath(Path, PathClipType, TRUE); |
| 1532 } | 1531 } |
| 1533 } | 1532 } |
| OLD | NEW |