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

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

Issue 2386423004: Move core/fpdfapi/fpdf_page to core/fpdfapi/page (Closed)
Patch Set: Rebase to master Created 4 years, 2 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 | « core/fpdfapi/fpdf_page/cpdf_clippath.h ('k') | core/fpdfapi/fpdf_page/cpdf_color.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 PDFium Authors. All rights reserved.
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/fpdf_page/cpdf_clippath.h"
8
9 #include <utility>
10
11 #include "core/fpdfapi/fpdf_page/cpdf_path.h"
12 #include "core/fpdfapi/fpdf_page/cpdf_textobject.h"
13 #include "third_party/base/stl_util.h"
14
15 #define FPDF_CLIPPATH_MAX_TEXTS 1024
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
23 uint32_t CPDF_ClipPath::GetPathCount() const {
24 return pdfium::CollectionSize<uint32_t>(m_Ref.GetObject()->m_PathAndTypeList);
25 }
26
27 CPDF_Path CPDF_ClipPath::GetPath(size_t i) const {
28 return m_Ref.GetObject()->m_PathAndTypeList[i].first;
29 }
30
31 uint8_t CPDF_ClipPath::GetClipType(size_t i) const {
32 return m_Ref.GetObject()->m_PathAndTypeList[i].second;
33 }
34
35 uint32_t CPDF_ClipPath::GetTextCount() const {
36 return pdfium::CollectionSize<uint32_t>(m_Ref.GetObject()->m_TextList);
37 }
38
39 CPDF_TextObject* CPDF_ClipPath::GetText(size_t i) const {
40 return m_Ref.GetObject()->m_TextList[i].get();
41 }
42
43 CFX_FloatRect CPDF_ClipPath::GetClipBox() const {
44 CFX_FloatRect rect;
45 FX_BOOL bStarted = FALSE;
46 int count = GetPathCount();
47 if (count) {
48 rect = GetPath(0).GetBoundingBox();
49 for (int i = 1; i < count; i++) {
50 CFX_FloatRect path_rect = GetPath(i).GetBoundingBox();
51 rect.Intersect(path_rect);
52 }
53 bStarted = TRUE;
54 }
55 count = GetTextCount();
56 if (count) {
57 CFX_FloatRect layer_rect;
58 FX_BOOL bLayerStarted = FALSE;
59 for (int i = 0; i < count; i++) {
60 CPDF_TextObject* pTextObj = GetText(i);
61 if (!pTextObj) {
62 if (!bStarted) {
63 rect = layer_rect;
64 bStarted = TRUE;
65 } else {
66 rect.Intersect(layer_rect);
67 }
68 bLayerStarted = FALSE;
69 } else {
70 if (!bLayerStarted) {
71 layer_rect = CFX_FloatRect(pTextObj->GetBBox(nullptr));
72 bLayerStarted = TRUE;
73 } else {
74 layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr)));
75 }
76 }
77 }
78 }
79 return rect;
80 }
81
82 void CPDF_ClipPath::AppendPath(CPDF_Path path, uint8_t type, bool bAutoMerge) {
83 PathData* pData = m_Ref.GetPrivateCopy();
84 if (!pData->m_PathAndTypeList.empty() && bAutoMerge) {
85 const CPDF_Path& old_path = pData->m_PathAndTypeList.back().first;
86 if (old_path.IsRect()) {
87 CFX_FloatRect old_rect(old_path.GetPointX(0), old_path.GetPointY(0),
88 old_path.GetPointX(2), old_path.GetPointY(2));
89 CFX_FloatRect new_rect = path.GetBoundingBox();
90 if (old_rect.Contains(new_rect))
91 pData->m_PathAndTypeList.pop_back();
92 }
93 }
94 pData->m_PathAndTypeList.push_back(std::make_pair(path, type));
95 }
96
97 void CPDF_ClipPath::AppendTexts(
98 std::vector<std::unique_ptr<CPDF_TextObject>>* pTexts) {
99 PathData* pData = m_Ref.GetPrivateCopy();
100 if (pData->m_TextList.size() + pTexts->size() <= FPDF_CLIPPATH_MAX_TEXTS) {
101 for (size_t i = 0; i < pTexts->size(); i++)
102 pData->m_TextList.push_back(std::move((*pTexts)[i]));
103 pData->m_TextList.push_back(std::unique_ptr<CPDF_TextObject>());
104 }
105 pTexts->clear();
106 }
107
108 void CPDF_ClipPath::Transform(const CFX_Matrix& matrix) {
109 PathData* pData = m_Ref.GetPrivateCopy();
110 for (auto& obj : pData->m_PathAndTypeList)
111 obj.first.Transform(&matrix);
112 for (auto& text : pData->m_TextList) {
113 if (text)
114 text->Transform(matrix);
115 }
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 | « core/fpdfapi/fpdf_page/cpdf_clippath.h ('k') | core/fpdfapi/fpdf_page/cpdf_color.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698