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

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

Issue 1709393002: Remove PageObject's m_Type and add As<Type> functions (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments 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 <algorithm> 9 #include <algorithm>
10 10
11 #include "core/include/fpdfapi/fpdf_module.h" 11 #include "core/include/fpdfapi/fpdf_module.h"
12 #include "core/include/fpdfapi/fpdf_page.h" 12 #include "core/include/fpdfapi/fpdf_page.h"
13 #include "third_party/base/stl_util.h" 13 #include "third_party/base/stl_util.h"
14 14
15 CPDF_PageObject* CPDF_PageObject::Create(int type) { 15 CPDF_PageObject* CPDF_PageObject::Create(Type type) {
16 switch (type) { 16 switch (type) {
17 case TEXT: 17 case TEXT:
18 return new CPDF_TextObject; 18 return new CPDF_TextObject;
19 case IMAGE: 19 case IMAGE:
20 return new CPDF_ImageObject; 20 return new CPDF_ImageObject;
21 case PATH: 21 case PATH:
22 return new CPDF_PathObject; 22 return new CPDF_PathObject;
23 case SHADING: 23 case SHADING:
24 return new CPDF_ShadingObject; 24 return new CPDF_ShadingObject;
25 case FORM: 25 case FORM:
26 return new CPDF_FormObject; 26 return new CPDF_FormObject;
27 } 27 }
28 return NULL; 28 return NULL;
29 } 29 }
30 CPDF_PageObject::~CPDF_PageObject() {} 30 CPDF_PageObject::~CPDF_PageObject() {}
31 CPDF_PageObject* CPDF_PageObject::Clone() const { 31 CPDF_PageObject* CPDF_PageObject::Clone() const {
32 CPDF_PageObject* pObj = Create(m_Type); 32 CPDF_PageObject* pObj = Create(GetType());
33 pObj->Copy(this); 33 pObj->Copy(this);
34 return pObj; 34 return pObj;
35 } 35 }
36 void CPDF_PageObject::Copy(const CPDF_PageObject* pSrc) { 36 void CPDF_PageObject::Copy(const CPDF_PageObject* pSrc) {
37 if (m_Type != pSrc->m_Type) { 37 if (GetType() != pSrc->GetType()) {
38 return; 38 return;
39 } 39 }
40 CopyData(pSrc); 40 CopyData(pSrc);
41 CopyStates(*pSrc); 41 CopyStates(*pSrc);
42 m_Left = pSrc->m_Left; 42 m_Left = pSrc->m_Left;
43 m_Right = pSrc->m_Right; 43 m_Right = pSrc->m_Right;
44 m_Top = pSrc->m_Top; 44 m_Top = pSrc->m_Top;
45 m_Bottom = pSrc->m_Bottom; 45 m_Bottom = pSrc->m_Bottom;
46 } 46 }
47 void CPDF_PageObject::AppendClipPath(CPDF_Path path, 47 void CPDF_PageObject::AppendClipPath(CPDF_Path path,
48 int type, 48 int type,
49 FX_BOOL bAutoMerge) { 49 FX_BOOL bAutoMerge) {
50 m_ClipPath.AppendPath(path, type, bAutoMerge); 50 m_ClipPath.AppendPath(path, type, bAutoMerge);
51 } 51 }
52 void CPDF_PageObject::CopyClipPath(CPDF_PageObject* pObj) { 52 void CPDF_PageObject::CopyClipPath(CPDF_PageObject* pObj) {
53 m_ClipPath = pObj->m_ClipPath; 53 m_ClipPath = pObj->m_ClipPath;
54 } 54 }
55 void CPDF_PageObject::RemoveClipPath() { 55 void CPDF_PageObject::RemoveClipPath() {
56 m_ClipPath.SetNull(); 56 m_ClipPath.SetNull();
57 } 57 }
58 void CPDF_PageObject::RecalcBBox() { 58 void CPDF_PageObject::RecalcBBox() {
59 switch (m_Type) { 59 switch (GetType()) {
60 case TEXT: 60 case TEXT:
61 ((CPDF_TextObject*)this)->RecalcPositionData(); 61 ((CPDF_TextObject*)this)->RecalcPositionData();
62 break; 62 break;
63 case PATH: 63 case PATH:
64 ((CPDF_PathObject*)this)->CalcBoundingBox(); 64 ((CPDF_PathObject*)this)->CalcBoundingBox();
65 break; 65 break;
66 case SHADING: 66 case SHADING:
67 ((CPDF_ShadingObject*)this)->CalcBoundingBox(); 67 ((CPDF_ShadingObject*)this)->CalcBoundingBox();
68 break; 68 break;
69 default: 69 default:
(...skipping 16 matching lines...) Expand all
86 } 86 }
87 FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const { 87 FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const {
88 CFX_FloatRect rect(m_Left, m_Bottom, m_Right, m_Top); 88 CFX_FloatRect rect(m_Left, m_Bottom, m_Right, m_Top);
89 if (pMatrix) { 89 if (pMatrix) {
90 pMatrix->TransformRect(rect); 90 pMatrix->TransformRect(rect);
91 } 91 }
92 return rect.GetOutterRect(); 92 return rect.GetOutterRect();
93 } 93 }
94 94
95 CPDF_TextObject::CPDF_TextObject() 95 CPDF_TextObject::CPDF_TextObject()
96 : CPDF_PageObject(TEXT), 96 : m_PosX(0),
97 m_PosX(0),
98 m_PosY(0), 97 m_PosY(0),
99 m_nChars(0), 98 m_nChars(0),
100 m_pCharCodes(nullptr), 99 m_pCharCodes(nullptr),
101 m_pCharPos(nullptr) {} 100 m_pCharPos(nullptr) {}
102 101
103 CPDF_TextObject::~CPDF_TextObject() { 102 CPDF_TextObject::~CPDF_TextObject() {
104 if (m_nChars > 1) { 103 if (m_nChars > 1) {
105 FX_Free(m_pCharCodes); 104 FX_Free(m_pCharCodes);
106 } 105 }
107 FX_Free(m_pCharPos); 106 FX_Free(m_pCharPos);
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 FXSYS_memcpy(m_pCharPos, pCharPos, sizeof(FX_FLOAT) * (nChars - 1)); 603 FXSYS_memcpy(m_pCharPos, pCharPos, sizeof(FX_FLOAT) * (nChars - 1));
605 } 604 }
606 RecalcPositionData(); 605 RecalcPositionData();
607 } 606 }
608 607
609 void CPDF_TextObject::SetTextState(CPDF_TextState TextState) { 608 void CPDF_TextObject::SetTextState(CPDF_TextState TextState) {
610 m_TextState = TextState; 609 m_TextState = TextState;
611 CalcPositionData(nullptr, nullptr, 0); 610 CalcPositionData(nullptr, nullptr, 0);
612 } 611 }
613 612
614 CPDF_ShadingObject::CPDF_ShadingObject() 613 CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {}
615 : CPDF_PageObject(SHADING), m_pShading(nullptr) {}
616 614
617 CPDF_ShadingObject::~CPDF_ShadingObject() {} 615 CPDF_ShadingObject::~CPDF_ShadingObject() {}
618 616
619 void CPDF_ShadingObject::CopyData(const CPDF_PageObject* pSrc) { 617 void CPDF_ShadingObject::CopyData(const CPDF_PageObject* pSrc) {
620 CPDF_ShadingObject* pSrcObj = (CPDF_ShadingObject*)pSrc; 618 CPDF_ShadingObject* pSrcObj = (CPDF_ShadingObject*)pSrc;
621 m_pShading = pSrcObj->m_pShading; 619 m_pShading = pSrcObj->m_pShading;
622 if (m_pShading && m_pShading->m_pDocument) { 620 if (m_pShading && m_pShading->m_pDocument) {
623 CPDF_DocPageData* pDocPageData = m_pShading->m_pDocument->GetPageData(); 621 CPDF_DocPageData* pDocPageData = m_pShading->m_pDocument->GetPageData();
624 m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern( 622 m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern(
625 m_pShading->m_pShadingObj, m_pShading->m_bShadingObj, 623 m_pShading->m_pShadingObj, m_pShading->m_bShadingObj,
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 (FX_FLOAT)y0); 965 (FX_FLOAT)y0);
968 matrix = m_PageMatrix; 966 matrix = m_PageMatrix;
969 matrix.Concat(display_matrix); 967 matrix.Concat(display_matrix);
970 } 968 }
971 CPDF_ParseOptions::CPDF_ParseOptions() { 969 CPDF_ParseOptions::CPDF_ParseOptions() {
972 m_bTextOnly = FALSE; 970 m_bTextOnly = FALSE;
973 m_bMarkedContent = TRUE; 971 m_bMarkedContent = TRUE;
974 m_bSeparateForm = TRUE; 972 m_bSeparateForm = TRUE;
975 m_bDecodeInlineImage = FALSE; 973 m_bDecodeInlineImage = FALSE;
976 } 974 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_edit/fpdf_edit_content.cpp ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698