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

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

Issue 1519693002: Merge to XFA: Remove CFX_AffineMatrix/CPDF_Matrix (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: XFA-specific changes Created 5 years 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 "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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 ((CPDF_TextObject*)this)->RecalcPositionData(); 58 ((CPDF_TextObject*)this)->RecalcPositionData();
59 break; 59 break;
60 case PDFPAGE_PATH: 60 case PDFPAGE_PATH:
61 ((CPDF_PathObject*)this)->CalcBoundingBox(); 61 ((CPDF_PathObject*)this)->CalcBoundingBox();
62 break; 62 break;
63 case PDFPAGE_SHADING: 63 case PDFPAGE_SHADING:
64 ((CPDF_ShadingObject*)this)->CalcBoundingBox(); 64 ((CPDF_ShadingObject*)this)->CalcBoundingBox();
65 break; 65 break;
66 } 66 }
67 } 67 }
68 void CPDF_PageObject::TransformClipPath(CFX_AffineMatrix& matrix) { 68 void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) {
69 if (m_ClipPath.IsNull()) { 69 if (m_ClipPath.IsNull()) {
70 return; 70 return;
71 } 71 }
72 m_ClipPath.GetModify(); 72 m_ClipPath.GetModify();
73 m_ClipPath.Transform(matrix); 73 m_ClipPath.Transform(matrix);
74 } 74 }
75 void CPDF_PageObject::TransformGeneralState(CFX_AffineMatrix& matrix) { 75 void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) {
76 if (m_GeneralState.IsNull()) { 76 if (m_GeneralState.IsNull()) {
77 return; 77 return;
78 } 78 }
79 CPDF_GeneralStateData* pGS = m_GeneralState.GetModify(); 79 CPDF_GeneralStateData* pGS = m_GeneralState.GetModify();
80 pGS->m_Matrix.Concat(matrix); 80 pGS->m_Matrix.Concat(matrix);
81 } 81 }
82 FX_RECT CPDF_PageObject::GetBBox(const CFX_AffineMatrix* pMatrix) const { 82 FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const {
83 CFX_FloatRect rect(m_Left, m_Bottom, m_Right, m_Top); 83 CFX_FloatRect rect(m_Left, m_Bottom, m_Right, m_Top);
84 if (pMatrix) { 84 if (pMatrix) {
85 pMatrix->TransformRect(rect); 85 pMatrix->TransformRect(rect);
86 } 86 }
87 return rect.GetOutterRect(); 87 return rect.GetOutterRect();
88 } 88 }
89 89
90 CPDF_TextObject::CPDF_TextObject() 90 CPDF_TextObject::CPDF_TextObject()
91 : m_PosX(0), 91 : m_PosX(0),
92 m_PosY(0), 92 m_PosY(0),
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 for (int i = 0; i < m_nChars - 1; ++i) { 202 for (int i = 0; i < m_nChars - 1; ++i) {
203 m_pCharPos[i] = pSrcObj->m_pCharPos[i]; 203 m_pCharPos[i] = pSrcObj->m_pCharPos[i];
204 } 204 }
205 } else { 205 } else {
206 m_pCharCodes = pSrcObj->m_pCharCodes; 206 m_pCharCodes = pSrcObj->m_pCharCodes;
207 } 207 }
208 m_PosX = pSrcObj->m_PosX; 208 m_PosX = pSrcObj->m_PosX;
209 m_PosY = pSrcObj->m_PosY; 209 m_PosY = pSrcObj->m_PosY;
210 } 210 }
211 211
212 void CPDF_TextObject::GetTextMatrix(CFX_AffineMatrix* pMatrix) const { 212 void CPDF_TextObject::GetTextMatrix(CFX_Matrix* pMatrix) const {
213 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); 213 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix();
214 pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3], 214 pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3],
215 m_PosX, m_PosY); 215 m_PosX, m_PosY);
216 } 216 }
217 217
218 void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs, 218 void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs,
219 FX_FLOAT* pKerning, 219 FX_FLOAT* pKerning,
220 int nsegs) { 220 int nsegs) {
221 if (m_nChars > 1) { 221 if (m_nChars > 1) {
222 FX_Free(m_pCharCodes); 222 FX_Free(m_pCharCodes);
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } else { 502 } else {
503 if (pTextAdvanceX) { 503 if (pTextAdvanceX) {
504 *pTextAdvanceX = FXSYS_Mul(curpos, horz_scale); 504 *pTextAdvanceX = FXSYS_Mul(curpos, horz_scale);
505 } 505 }
506 if (pTextAdvanceY) { 506 if (pTextAdvanceY) {
507 *pTextAdvanceY = 0; 507 *pTextAdvanceY = 0;
508 } 508 }
509 min_y = min_y * fontsize / 1000; 509 min_y = min_y * fontsize / 1000;
510 max_y = max_y * fontsize / 1000; 510 max_y = max_y * fontsize / 1000;
511 } 511 }
512 CFX_AffineMatrix matrix; 512 CFX_Matrix matrix;
513 GetTextMatrix(&matrix); 513 GetTextMatrix(&matrix);
514 m_Left = min_x; 514 m_Left = min_x;
515 m_Right = max_x; 515 m_Right = max_x;
516 m_Bottom = min_y; 516 m_Bottom = min_y;
517 m_Top = max_y; 517 m_Top = max_y;
518 matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); 518 matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
519 int textmode = m_TextState.GetObject()->m_TextMode; 519 int textmode = m_TextState.GetObject()->m_TextMode;
520 if (textmode == 1 || textmode == 2 || textmode == 5 || textmode == 6) { 520 if (textmode == 1 || textmode == 2 || textmode == 5 || textmode == 6) {
521 FX_FLOAT half_width = m_GraphState.GetObject()->m_LineWidth / 2; 521 FX_FLOAT half_width = m_GraphState.GetObject()->m_LineWidth / 2;
522 m_Left -= half_width; 522 m_Left -= half_width;
(...skipping 23 matching lines...) Expand all
546 FX_WORD CID = pCIDFont->CIDFromCharCode(charcode); 546 FX_WORD CID = pCIDFont->CIDFromCharCode(charcode);
547 charwidth = pCIDFont->GetVertWidth(CID) * fontsize / 1000; 547 charwidth = pCIDFont->GetVertWidth(CID) * fontsize / 1000;
548 } else { 548 } else {
549 charwidth = pFont->GetCharWidthF(charcode) * fontsize / 1000; 549 charwidth = pFont->GetCharWidthF(charcode) * fontsize / 1000;
550 } 550 }
551 pPosArray[index] = pPosArray[index - 1] + charwidth; 551 pPosArray[index] = pPosArray[index - 1] + charwidth;
552 index++; 552 index++;
553 } 553 }
554 } 554 }
555 555
556 void CPDF_TextObject::Transform(const CFX_AffineMatrix& matrix) { 556 void CPDF_TextObject::Transform(const CFX_Matrix& matrix) {
557 m_TextState.GetModify(); 557 m_TextState.GetModify();
558 CFX_AffineMatrix text_matrix; 558 CFX_Matrix text_matrix;
559 GetTextMatrix(&text_matrix); 559 GetTextMatrix(&text_matrix);
560 text_matrix.Concat(matrix); 560 text_matrix.Concat(matrix);
561 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix(); 561 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix();
562 pTextMatrix[0] = text_matrix.GetA(); 562 pTextMatrix[0] = text_matrix.GetA();
563 pTextMatrix[1] = text_matrix.GetC(); 563 pTextMatrix[1] = text_matrix.GetC();
564 pTextMatrix[2] = text_matrix.GetB(); 564 pTextMatrix[2] = text_matrix.GetB();
565 pTextMatrix[3] = text_matrix.GetD(); 565 pTextMatrix[3] = text_matrix.GetD();
566 m_PosX = text_matrix.GetE(); 566 m_PosX = text_matrix.GetE();
567 m_PosY = text_matrix.GetF(); 567 m_PosY = text_matrix.GetF();
568 CalcPositionData(nullptr, nullptr, 0); 568 CalcPositionData(nullptr, nullptr, 0);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 CPDF_ShadingObject* pSrcObj = (CPDF_ShadingObject*)pSrc; 616 CPDF_ShadingObject* pSrcObj = (CPDF_ShadingObject*)pSrc;
617 m_pShading = pSrcObj->m_pShading; 617 m_pShading = pSrcObj->m_pShading;
618 if (m_pShading && m_pShading->m_pDocument) { 618 if (m_pShading && m_pShading->m_pDocument) {
619 CPDF_DocPageData* pDocPageData = m_pShading->m_pDocument->GetPageData(); 619 CPDF_DocPageData* pDocPageData = m_pShading->m_pDocument->GetPageData();
620 m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern( 620 m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern(
621 m_pShading->m_pShadingObj, m_pShading->m_bShadingObj, 621 m_pShading->m_pShadingObj, m_pShading->m_bShadingObj,
622 &m_pShading->m_ParentMatrix); 622 &m_pShading->m_ParentMatrix);
623 } 623 }
624 m_Matrix = pSrcObj->m_Matrix; 624 m_Matrix = pSrcObj->m_Matrix;
625 } 625 }
626 void CPDF_ShadingObject::Transform(const CFX_AffineMatrix& matrix) { 626 void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) {
627 if (!m_ClipPath.IsNull()) { 627 if (!m_ClipPath.IsNull()) {
628 m_ClipPath.GetModify(); 628 m_ClipPath.GetModify();
629 m_ClipPath.Transform(matrix); 629 m_ClipPath.Transform(matrix);
630 } 630 }
631 m_Matrix.Concat(matrix); 631 m_Matrix.Concat(matrix);
632 if (!m_ClipPath.IsNull()) { 632 if (!m_ClipPath.IsNull()) {
633 CalcBoundingBox(); 633 CalcBoundingBox();
634 } else { 634 } else {
635 matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom); 635 matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
636 } 636 }
637 } 637 }
638 void CPDF_ShadingObject::CalcBoundingBox() { 638 void CPDF_ShadingObject::CalcBoundingBox() {
639 if (m_ClipPath.IsNull()) { 639 if (m_ClipPath.IsNull()) {
640 return; 640 return;
641 } 641 }
642 CFX_FloatRect rect = m_ClipPath.GetClipBox(); 642 CFX_FloatRect rect = m_ClipPath.GetClipBox();
643 m_Left = rect.left; 643 m_Left = rect.left;
644 m_Bottom = rect.bottom; 644 m_Bottom = rect.bottom;
645 m_Right = rect.right; 645 m_Right = rect.right;
646 m_Top = rect.top; 646 m_Top = rect.top;
647 } 647 }
648 CPDF_FormObject::~CPDF_FormObject() { 648 CPDF_FormObject::~CPDF_FormObject() {
649 delete m_pForm; 649 delete m_pForm;
650 } 650 }
651 void CPDF_FormObject::Transform(const CFX_AffineMatrix& matrix) { 651 void CPDF_FormObject::Transform(const CFX_Matrix& matrix) {
652 m_FormMatrix.Concat(matrix); 652 m_FormMatrix.Concat(matrix);
653 CalcBoundingBox(); 653 CalcBoundingBox();
654 } 654 }
655 void CPDF_FormObject::CopyData(const CPDF_PageObject* pSrc) { 655 void CPDF_FormObject::CopyData(const CPDF_PageObject* pSrc) {
656 const CPDF_FormObject* pSrcObj = (const CPDF_FormObject*)pSrc; 656 const CPDF_FormObject* pSrcObj = (const CPDF_FormObject*)pSrc;
657 delete m_pForm; 657 delete m_pForm;
658 m_pForm = pSrcObj->m_pForm->Clone(); 658 m_pForm = pSrcObj->m_pForm->Clone();
659 m_FormMatrix = pSrcObj->m_FormMatrix; 659 m_FormMatrix = pSrcObj->m_FormMatrix;
660 } 660 }
661 void CPDF_FormObject::CalcBoundingBox() { 661 void CPDF_FormObject::CalcBoundingBox() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 } 718 }
719 return -1; 719 return -1;
720 } 720 }
721 CPDF_PageObject* CPDF_PageObjects::GetObjectByIndex(int index) const { 721 CPDF_PageObject* CPDF_PageObjects::GetObjectByIndex(int index) const {
722 FX_POSITION pos = m_ObjectList.FindIndex(index); 722 FX_POSITION pos = m_ObjectList.FindIndex(index);
723 if (pos == NULL) { 723 if (pos == NULL) {
724 return NULL; 724 return NULL;
725 } 725 }
726 return (CPDF_PageObject*)m_ObjectList.GetAt(pos); 726 return (CPDF_PageObject*)m_ObjectList.GetAt(pos);
727 } 727 }
728 void CPDF_PageObjects::Transform(const CFX_AffineMatrix& matrix) { 728 void CPDF_PageObjects::Transform(const CFX_Matrix& matrix) {
729 FX_POSITION pos = m_ObjectList.GetHeadPosition(); 729 FX_POSITION pos = m_ObjectList.GetHeadPosition();
730 while (pos) { 730 while (pos) {
731 CPDF_PageObject* pObj = (CPDF_PageObject*)m_ObjectList.GetNext(pos); 731 CPDF_PageObject* pObj = (CPDF_PageObject*)m_ObjectList.GetNext(pos);
732 pObj->Transform(matrix); 732 pObj->Transform(matrix);
733 } 733 }
734 } 734 }
735 CFX_FloatRect CPDF_PageObjects::CalcBoundingBox() const { 735 CFX_FloatRect CPDF_PageObjects::CalcBoundingBox() const {
736 if (m_ObjectList.GetCount() == 0) { 736 if (m_ObjectList.GetCount() == 0) {
737 return CFX_FloatRect(0, 0, 0, 0); 737 return CFX_FloatRect(0, 0, 0, 0);
738 } 738 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 m_pResources = pParentResources; 916 m_pResources = pParentResources;
917 } 917 }
918 if (m_pResources == NULL) { 918 if (m_pResources == NULL) {
919 m_pResources = pPageResources; 919 m_pResources = pPageResources;
920 } 920 }
921 m_Transparency = 0; 921 m_Transparency = 0;
922 LoadTransInfo(); 922 LoadTransInfo();
923 } 923 }
924 CPDF_Form::~CPDF_Form() {} 924 CPDF_Form::~CPDF_Form() {}
925 void CPDF_Form::StartParse(CPDF_AllStates* pGraphicStates, 925 void CPDF_Form::StartParse(CPDF_AllStates* pGraphicStates,
926 CFX_AffineMatrix* pParentMatrix, 926 CFX_Matrix* pParentMatrix,
927 CPDF_Type3Char* pType3Char, 927 CPDF_Type3Char* pType3Char,
928 CPDF_ParseOptions* pOptions, 928 CPDF_ParseOptions* pOptions,
929 int level) { 929 int level) {
930 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { 930 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) {
931 return; 931 return;
932 } 932 }
933 m_pParser = new CPDF_ContentParser; 933 m_pParser = new CPDF_ContentParser;
934 m_pParser->Start(this, pGraphicStates, pParentMatrix, pType3Char, pOptions, 934 m_pParser->Start(this, pGraphicStates, pParentMatrix, pType3Char, pOptions,
935 level); 935 level);
936 m_ParseState = CONTENT_PARSING; 936 m_ParseState = CONTENT_PARSING;
937 } 937 }
938 void CPDF_Form::ParseContent(CPDF_AllStates* pGraphicStates, 938 void CPDF_Form::ParseContent(CPDF_AllStates* pGraphicStates,
939 CFX_AffineMatrix* pParentMatrix, 939 CFX_Matrix* pParentMatrix,
940 CPDF_Type3Char* pType3Char, 940 CPDF_Type3Char* pType3Char,
941 CPDF_ParseOptions* pOptions, 941 CPDF_ParseOptions* pOptions,
942 int level) { 942 int level) {
943 StartParse(pGraphicStates, pParentMatrix, pType3Char, pOptions, level); 943 StartParse(pGraphicStates, pParentMatrix, pType3Char, pOptions, level);
944 ContinueParse(NULL); 944 ContinueParse(NULL);
945 } 945 }
946 CPDF_Form* CPDF_Form::Clone() const { 946 CPDF_Form* CPDF_Form::Clone() const {
947 CPDF_Form* pClone = 947 CPDF_Form* pClone =
948 new CPDF_Form(m_pDocument, m_pPageResources, m_pFormStream, m_pResources); 948 new CPDF_Form(m_pDocument, m_pPageResources, m_pFormStream, m_pResources);
949 FX_POSITION pos = m_ObjectList.GetHeadPosition(); 949 FX_POSITION pos = m_ObjectList.GetHeadPosition();
950 while (pos) { 950 while (pos) {
951 CPDF_PageObject* pObj = (CPDF_PageObject*)m_ObjectList.GetNext(pos); 951 CPDF_PageObject* pObj = (CPDF_PageObject*)m_ObjectList.GetNext(pos);
952 pClone->m_ObjectList.AddTail(pObj->Clone()); 952 pClone->m_ObjectList.AddTail(pObj->Clone());
953 } 953 }
954 return pClone; 954 return pClone;
955 } 955 }
956 void CPDF_Page::GetDisplayMatrix(CFX_AffineMatrix& matrix, 956 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix,
957 int xPos, 957 int xPos,
958 int yPos, 958 int yPos,
959 int xSize, 959 int xSize,
960 int ySize, 960 int ySize,
961 int iRotate) const { 961 int iRotate) const {
962 if (m_PageWidth == 0 || m_PageHeight == 0) { 962 if (m_PageWidth == 0 || m_PageHeight == 0) {
963 return; 963 return;
964 } 964 }
965 CFX_AffineMatrix display_matrix; 965 CFX_Matrix display_matrix;
966 int x0, y0, x1, y1, x2, y2; 966 int x0, y0, x1, y1, x2, y2;
967 iRotate %= 4; 967 iRotate %= 4;
968 switch (iRotate) { 968 switch (iRotate) {
969 case 0: 969 case 0:
970 x0 = xPos; 970 x0 = xPos;
971 y0 = yPos + ySize; 971 y0 = yPos + ySize;
972 x1 = xPos; 972 x1 = xPos;
973 y1 = yPos; 973 y1 = yPos;
974 x2 = xPos + xSize; 974 x2 = xPos + xSize;
975 y2 = yPos + ySize; 975 y2 = yPos + ySize;
(...skipping 30 matching lines...) Expand all
1006 (FX_FLOAT)y0); 1006 (FX_FLOAT)y0);
1007 matrix = m_PageMatrix; 1007 matrix = m_PageMatrix;
1008 matrix.Concat(display_matrix); 1008 matrix.Concat(display_matrix);
1009 } 1009 }
1010 CPDF_ParseOptions::CPDF_ParseOptions() { 1010 CPDF_ParseOptions::CPDF_ParseOptions() {
1011 m_bTextOnly = FALSE; 1011 m_bTextOnly = FALSE;
1012 m_bMarkedContent = TRUE; 1012 m_bMarkedContent = TRUE;
1013 m_bSeparateForm = TRUE; 1013 m_bSeparateForm = TRUE;
1014 m_bDecodeInlineImage = FALSE; 1014 m_bDecodeInlineImage = FALSE;
1015 } 1015 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698