summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_page/cpdf_clippath.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-09-02 17:34:21 -0700
committerCommit bot <commit-bot@chromium.org>2016-09-02 17:34:21 -0700
commitd21f22e2c07d61bf15ee3af91869901adb6f0cde (patch)
tree5277acb7de48541f5a39f57f3017a69b3ecfcec3 /core/fpdfapi/fpdf_page/cpdf_clippath.cpp
parent6296f2d501e2749d98e890ed722f923ee584c9ca (diff)
downloadpdfium-d21f22e2c07d61bf15ee3af91869901adb6f0cde.tar.xz
Make CPDF_ClipPath have a CPDF_ClipPathData rather than inheriting.
Make Data private to the ClipPath class which manages it transparently for its callers. This prevents the callers from having to remember to make a copy before dirtying the shared data, since the operations that modify state will do this under the covers for us. Review-Url: https://codereview.chromium.org/2301263003
Diffstat (limited to 'core/fpdfapi/fpdf_page/cpdf_clippath.cpp')
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_clippath.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_clippath.cpp b/core/fpdfapi/fpdf_page/cpdf_clippath.cpp
index e820260131..51ff593a5a 100644
--- a/core/fpdfapi/fpdf_page/cpdf_clippath.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_clippath.cpp
@@ -8,29 +8,36 @@
#include <utility>
+#include "core/fpdfapi/fpdf_page/include/cpdf_path.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
#include "third_party/base/stl_util.h"
#define FPDF_CLIPPATH_MAX_TEXTS 1024
+CPDF_ClipPath::CPDF_ClipPath() {}
+
+CPDF_ClipPath::CPDF_ClipPath(const CPDF_ClipPath& that) : m_Ref(that.m_Ref) {}
+
+CPDF_ClipPath::~CPDF_ClipPath() {}
+
uint32_t CPDF_ClipPath::GetPathCount() const {
- return pdfium::CollectionSize<uint32_t>(GetObject()->m_PathAndTypeList);
+ return pdfium::CollectionSize<uint32_t>(m_Ref.GetObject()->m_PathAndTypeList);
}
CPDF_Path CPDF_ClipPath::GetPath(size_t i) const {
- return GetObject()->m_PathAndTypeList[i].first;
+ return m_Ref.GetObject()->m_PathAndTypeList[i].first;
}
uint8_t CPDF_ClipPath::GetClipType(size_t i) const {
- return GetObject()->m_PathAndTypeList[i].second;
+ return m_Ref.GetObject()->m_PathAndTypeList[i].second;
}
uint32_t CPDF_ClipPath::GetTextCount() const {
- return pdfium::CollectionSize<uint32_t>(GetObject()->m_TextList);
+ return pdfium::CollectionSize<uint32_t>(m_Ref.GetObject()->m_TextList);
}
CPDF_TextObject* CPDF_ClipPath::GetText(size_t i) const {
- return GetObject()->m_TextList[i].get();
+ return m_Ref.GetObject()->m_TextList[i].get();
}
CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
@@ -73,7 +80,7 @@ CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
}
void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) {
- CPDF_ClipPathData* pData = GetPrivateCopy();
+ PathData* pData = m_Ref.GetPrivateCopy();
if (!pData->m_PathAndTypeList.empty() && bAutoMerge) {
const CPDF_Path& old_path = pData->m_PathAndTypeList.back().first;
if (old_path.IsRect()) {
@@ -89,7 +96,7 @@ void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) {
void CPDF_ClipPath::AppendTexts(
std::vector<std::unique_ptr<CPDF_TextObject>>* pTexts) {
- CPDF_ClipPathData* pData = GetPrivateCopy();
+ PathData* pData = m_Ref.GetPrivateCopy();
if (pData->m_TextList.size() + pTexts->size() <= FPDF_CLIPPATH_MAX_TEXTS) {
for (size_t i = 0; i < pTexts->size(); i++)
pData->m_TextList.push_back(std::move((*pTexts)[i]));
@@ -99,7 +106,7 @@ void CPDF_ClipPath::AppendTexts(
}
void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) {
- CPDF_ClipPathData* pData = GetPrivateCopy();
+ PathData* pData = m_Ref.GetPrivateCopy();
for (auto& obj : pData->m_PathAndTypeList)
obj.first.Transform(&matrix);
for (auto& text : pData->m_TextList) {
@@ -107,3 +114,17 @@ void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) {
text->Transform(matrix);
}
}
+
+CPDF_ClipPath::PathData::PathData() {}
+
+CPDF_ClipPath::PathData::PathData(const PathData& that) {
+ m_PathAndTypeList = that.m_PathAndTypeList;
+
+ m_TextList.resize(that.m_TextList.size());
+ for (size_t i = 0; i < that.m_TextList.size(); ++i) {
+ if (that.m_TextList[i])
+ m_TextList[i].reset(that.m_TextList[i]->Clone());
+ }
+}
+
+CPDF_ClipPath::PathData::~PathData() {}