From d21f22e2c07d61bf15ee3af91869901adb6f0cde Mon Sep 17 00:00:00 2001 From: tsepez Date: Fri, 2 Sep 2016 17:34:21 -0700 Subject: 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 --- core/fpdfapi/fpdf_page/cpdf_clippath.cpp | 37 +++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'core/fpdfapi/fpdf_page/cpdf_clippath.cpp') 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 +#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(GetObject()->m_PathAndTypeList); + return pdfium::CollectionSize(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(GetObject()->m_TextList); + return pdfium::CollectionSize(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>* 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() {} -- cgit v1.2.3