Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_clippath.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "core/fpdfapi/page/cpdf_clippath.h"
8
9#include <utility>
10
11#include "core/fpdfapi/page/cpdf_textobject.h"
12
13CPDF_ClipPath::CPDF_ClipPath() = default;
14
15CPDF_ClipPath::CPDF_ClipPath(const CPDF_ClipPath& that) = default;
16
17CPDF_ClipPath& CPDF_ClipPath::operator=(const CPDF_ClipPath& that) = default;
18
19CPDF_ClipPath::~CPDF_ClipPath() = default;
20
22 return m_Ref.GetObject()->m_PathAndTypeList.size();
23}
24
26 return m_Ref.GetObject()->m_PathAndTypeList[i].first;
27}
28
30 return m_Ref.GetObject()->m_PathAndTypeList[i].second;
31}
32
34 return m_Ref.GetObject()->m_TextList.size();
35}
36
37CPDF_TextObject* CPDF_ClipPath::GetText(size_t i) const {
38 return m_Ref.GetObject()->m_TextList[i].get();
39}
40
42 CFX_FloatRect rect;
43 bool bStarted = false;
44 if (GetPathCount() > 0) {
45 rect = GetPath(0).GetBoundingBox();
46 for (size_t i = 1; i < GetPathCount(); ++i) {
47 CFX_FloatRect path_rect = GetPath(i).GetBoundingBox();
48 rect.Intersect(path_rect);
49 }
50 bStarted = true;
51 }
52
53 CFX_FloatRect layer_rect;
54 bool bLayerStarted = false;
55 for (size_t i = 0; i < GetTextCount(); ++i) {
56 CPDF_TextObject* pTextObj = GetText(i);
57 if (pTextObj) {
58 if (bLayerStarted) {
59 layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox()));
60 } else {
61 layer_rect = CFX_FloatRect(pTextObj->GetBBox());
62 bLayerStarted = true;
63 }
64 } else {
65 if (bStarted) {
66 rect.Intersect(layer_rect);
67 } else {
68 rect = layer_rect;
69 bStarted = true;
70 }
71 bLayerStarted = false;
72 }
73 }
74 return rect;
75}
76
79 PathData* pData = m_Ref.GetPrivateCopy();
80 pData->m_PathAndTypeList.emplace_back(path, type);
81}
82
84 CPDF_Path path,
86 PathData* pData = m_Ref.GetPrivateCopy();
87 if (!pData->m_PathAndTypeList.empty()) {
88 const CPDF_Path& old_path = pData->m_PathAndTypeList.back().first;
89 if (old_path.IsRect()) {
90 CFX_PointF point0 = old_path.GetPoint(0);
91 CFX_PointF point2 = old_path.GetPoint(2);
92 CFX_FloatRect old_rect(point0.x, point0.y, point2.x, point2.y);
93 CFX_FloatRect new_rect = path.GetBoundingBox();
94 if (old_rect.Contains(new_rect))
95 pData->m_PathAndTypeList.pop_back();
96 }
97 }
98 AppendPath(path, type);
99}
100
102 std::vector<std::unique_ptr<CPDF_TextObject>>* pTexts) {
103 constexpr size_t kMaxTextObjects = 1024;
104 PathData* pData = m_Ref.GetPrivateCopy();
105 if (pData->m_TextList.size() + pTexts->size() <= kMaxTextObjects) {
106 for (size_t i = 0; i < pTexts->size(); i++)
107 pData->m_TextList.push_back(std::move((*pTexts)[i]));
108 pData->m_TextList.push_back(nullptr);
109 }
110 pTexts->clear();
111}
112
114 if (*this == that || !that.HasRef())
115 return;
116
117 for (size_t i = 0; i < that.GetPathCount(); ++i)
118 AppendPath(that.GetPath(i), that.GetClipType(i));
119}
120
121void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) {
122 PathData* pData = m_Ref.GetPrivateCopy();
123 for (auto& obj : pData->m_PathAndTypeList)
124 obj.first.Transform(matrix);
125
126 for (auto& text : pData->m_TextList) {
127 if (text)
128 text->Transform(matrix);
129 }
130}
131
132CPDF_ClipPath::PathData::PathData() = default;
133
134CPDF_ClipPath::PathData::PathData(const PathData& that)
135 : m_PathAndTypeList(that.m_PathAndTypeList),
136 m_TextList(that.m_TextList.size()) {
137 for (size_t i = 0; i < that.m_TextList.size(); ++i) {
138 if (that.m_TextList[i])
139 m_TextList[i] = that.m_TextList[i]->Clone();
140 }
141}
142
143CPDF_ClipPath::PathData::~PathData() = default;
144
145RetainPtr<CPDF_ClipPath::PathData> CPDF_ClipPath::PathData::Clone() const {
146 return pdfium::MakeRetain<CPDF_ClipPath::PathData>(*this);
147}
void Intersect(const CFX_FloatRect &other_rect)
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
bool Contains(const CFX_FloatRect &other_rect) const
void Union(const CFX_FloatRect &other_rect)
CFX_FloatRect GetClipBox() const
CPDF_TextObject * GetText(size_t i) const
CPDF_ClipPath & operator=(const CPDF_ClipPath &that)
CPDF_ClipPath(const CPDF_ClipPath &that)
void CopyClipPath(const CPDF_ClipPath &that)
void AppendPathWithAutoMerge(CPDF_Path path, CFX_FillRenderOptions::FillType type)
CFX_FillRenderOptions::FillType GetClipType(size_t i) const
size_t GetTextCount() const
void Transform(const CFX_Matrix &matrix)
bool operator==(const CPDF_ClipPath &that) const
void AppendTexts(std::vector< std::unique_ptr< CPDF_TextObject > > *pTexts)
CPDF_Path GetPath(size_t i) const
size_t GetPathCount() const
void AppendPath(CPDF_Path path, CFX_FillRenderOptions::FillType type)
bool HasRef() const
FX_RECT GetBBox() const
CFX_FloatRect GetBoundingBox() const
Definition cpdf_path.cpp:27
bool IsRect() const
Definition cpdf_path.cpp:37