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

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

Issue 2301263003: Make CPDF_ClipPath have a CPDF_ClipPathData rather than inheriting (Closed)
Patch Set: safe bool while we're at it Created 4 years, 3 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
« no previous file with comments | « BUILD.gn ('k') | core/fpdfapi/fpdf_page/cpdf_clippathdata.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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/fpdfapi/fpdf_page/include/cpdf_clippath.h" 7 #include "core/fpdfapi/fpdf_page/include/cpdf_clippath.h"
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "core/fpdfapi/fpdf_page/include/cpdf_path.h"
11 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" 12 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
12 #include "third_party/base/stl_util.h" 13 #include "third_party/base/stl_util.h"
13 14
14 #define FPDF_CLIPPATH_MAX_TEXTS 1024 15 #define FPDF_CLIPPATH_MAX_TEXTS 1024
15 16
17 CPDF_ClipPath::CPDF_ClipPath() {}
18
19 CPDF_ClipPath::CPDF_ClipPath(const CPDF_ClipPath& that) : m_Ref(that.m_Ref) {}
20
21 CPDF_ClipPath::~CPDF_ClipPath() {}
22
16 uint32_t CPDF_ClipPath::GetPathCount() const { 23 uint32_t CPDF_ClipPath::GetPathCount() const {
17 return pdfium::CollectionSize<uint32_t>(GetObject()->m_PathAndTypeList); 24 return pdfium::CollectionSize<uint32_t>(m_Ref.GetObject()->m_PathAndTypeList);
18 } 25 }
19 26
20 CPDF_Path CPDF_ClipPath::GetPath(size_t i) const { 27 CPDF_Path CPDF_ClipPath::GetPath(size_t i) const {
21 return GetObject()->m_PathAndTypeList[i].first; 28 return m_Ref.GetObject()->m_PathAndTypeList[i].first;
22 } 29 }
23 30
24 uint8_t CPDF_ClipPath::GetClipType(size_t i) const { 31 uint8_t CPDF_ClipPath::GetClipType(size_t i) const {
25 return GetObject()->m_PathAndTypeList[i].second; 32 return m_Ref.GetObject()->m_PathAndTypeList[i].second;
26 } 33 }
27 34
28 uint32_t CPDF_ClipPath::GetTextCount() const { 35 uint32_t CPDF_ClipPath::GetTextCount() const {
29 return pdfium::CollectionSize<uint32_t>(GetObject()->m_TextList); 36 return pdfium::CollectionSize<uint32_t>(m_Ref.GetObject()->m_TextList);
30 } 37 }
31 38
32 CPDF_TextObject* CPDF_ClipPath::GetText(size_t i) const { 39 CPDF_TextObject* CPDF_ClipPath::GetText(size_t i) const {
33 return GetObject()->m_TextList[i].get(); 40 return m_Ref.GetObject()->m_TextList[i].get();
34 } 41 }
35 42
36 CFX_FloatRect CPDF_ClipPath::GetClipBox() const { 43 CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
37 CFX_FloatRect rect; 44 CFX_FloatRect rect;
38 FX_BOOL bStarted = FALSE; 45 FX_BOOL bStarted = FALSE;
39 int count = GetPathCount(); 46 int count = GetPathCount();
40 if (count) { 47 if (count) {
41 rect = GetPath(0).GetBoundingBox(); 48 rect = GetPath(0).GetBoundingBox();
42 for (int i = 1; i < count; i++) { 49 for (int i = 1; i < count; i++) {
43 CFX_FloatRect path_rect = GetPath(i).GetBoundingBox(); 50 CFX_FloatRect path_rect = GetPath(i).GetBoundingBox();
(...skipping 22 matching lines...) Expand all
66 } else { 73 } else {
67 layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr))); 74 layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr)));
68 } 75 }
69 } 76 }
70 } 77 }
71 } 78 }
72 return rect; 79 return rect;
73 } 80 }
74 81
75 void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) { 82 void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) {
76 CPDF_ClipPathData* pData = GetPrivateCopy(); 83 PathData* pData = m_Ref.GetPrivateCopy();
77 if (!pData->m_PathAndTypeList.empty() && bAutoMerge) { 84 if (!pData->m_PathAndTypeList.empty() && bAutoMerge) {
78 const CPDF_Path& old_path = pData->m_PathAndTypeList.back().first; 85 const CPDF_Path& old_path = pData->m_PathAndTypeList.back().first;
79 if (old_path.IsRect()) { 86 if (old_path.IsRect()) {
80 CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0), 87 CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0),
81 old_path.GetPointX(2), old_path.GetPointY(2)); 88 old_path.GetPointX(2), old_path.GetPointY(2));
82 CFX_FloatRect new_rect = path.GetBoundingBox(); 89 CFX_FloatRect new_rect = path.GetBoundingBox();
83 if (old_rect.Contains(new_rect)) 90 if (old_rect.Contains(new_rect))
84 pData->m_PathAndTypeList.pop_back(); 91 pData->m_PathAndTypeList.pop_back();
85 } 92 }
86 } 93 }
87 pData->m_PathAndTypeList.push_back(std::make_pair(path, type)); 94 pData->m_PathAndTypeList.push_back(std::make_pair(path, type));
88 } 95 }
89 96
90 void CPDF_ClipPath::AppendTexts( 97 void CPDF_ClipPath::AppendTexts(
91 std::vector<std::unique_ptr<CPDF_TextObject>>* pTexts) { 98 std::vector<std::unique_ptr<CPDF_TextObject>>* pTexts) {
92 CPDF_ClipPathData* pData = GetPrivateCopy(); 99 PathData* pData = m_Ref.GetPrivateCopy();
93 if (pData->m_TextList.size() + pTexts->size() <= FPDF_CLIPPATH_MAX_TEXTS) { 100 if (pData->m_TextList.size() + pTexts->size() <= FPDF_CLIPPATH_MAX_TEXTS) {
94 for (size_t i = 0; i < pTexts->size(); i++) 101 for (size_t i = 0; i < pTexts->size(); i++)
95 pData->m_TextList.push_back(std::move((*pTexts)[i])); 102 pData->m_TextList.push_back(std::move((*pTexts)[i]));
96 pData->m_TextList.push_back(std::unique_ptr<CPDF_TextObject>()); 103 pData->m_TextList.push_back(std::unique_ptr<CPDF_TextObject>());
97 } 104 }
98 pTexts->clear(); 105 pTexts->clear();
99 } 106 }
100 107
101 void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) { 108 void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) {
102 CPDF_ClipPathData* pData = GetPrivateCopy(); 109 PathData* pData = m_Ref.GetPrivateCopy();
103 for (auto& obj : pData->m_PathAndTypeList) 110 for (auto& obj : pData->m_PathAndTypeList)
104 obj.first.Transform(&matrix); 111 obj.first.Transform(&matrix);
105 for (auto& text : pData->m_TextList) { 112 for (auto& text : pData->m_TextList) {
106 if (text) 113 if (text)
107 text->Transform(matrix); 114 text->Transform(matrix);
108 } 115 }
109 } 116 }
117
118 CPDF_ClipPath::PathData::PathData() {}
119
120 CPDF_ClipPath::PathData::PathData(const PathData& that) {
121 m_PathAndTypeList = that.m_PathAndTypeList;
122
123 m_TextList.resize(that.m_TextList.size());
124 for (size_t i = 0; i < that.m_TextList.size(); ++i) {
125 if (that.m_TextList[i])
126 m_TextList[i].reset(that.m_TextList[i]->Clone());
127 }
128 }
129
130 CPDF_ClipPath::PathData::~PathData() {}
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | core/fpdfapi/fpdf_page/cpdf_clippathdata.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698