1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "xfa/fxgraphics/cfx_path.h"
#include "core/fxge/cfx_pathdata.h"
#include "third_party/base/ptr_util.h"
#include "xfa/fxgraphics/cfx_path_generator.h"
CFX_Path::CFX_Path() {}
FWL_Error CFX_Path::Create() {
if (m_generator)
return FWL_Error::PropertyInvalid;
m_generator = pdfium::MakeUnique<CFX_PathGenerator>();
return FWL_Error::Succeeded;
}
CFX_Path::~CFX_Path() {}
FWL_Error CFX_Path::MoveTo(const CFX_PointF& point) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
m_generator->MoveTo(point);
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::LineTo(const CFX_PointF& point) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
m_generator->LineTo(point);
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::BezierTo(const CFX_PointF& c1,
const CFX_PointF& c2,
const CFX_PointF& to) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
m_generator->BezierTo(c1, c2, to);
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::ArcTo(const CFX_PointF& pos,
const CFX_SizeF& size,
FX_FLOAT startAngle,
FX_FLOAT sweepAngle) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
CFX_SizeF newSize = size / 2.0f;
m_generator->ArcTo(CFX_PointF(pos.x + newSize.width, pos.y + newSize.height),
newSize, startAngle, sweepAngle);
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::Close() {
if (!m_generator)
return FWL_Error::PropertyInvalid;
m_generator->Close();
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::AddLine(const CFX_PointF& p1, const CFX_PointF& p2) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
m_generator->AddLine(p1, p2);
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::AddBezier(const CFX_PointF& p1,
const CFX_PointF& c1,
const CFX_PointF& c2,
const CFX_PointF& p2) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
m_generator->AddBezier(p1, c1, c2, p2);
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::AddRectangle(FX_FLOAT left,
FX_FLOAT top,
FX_FLOAT width,
FX_FLOAT height) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
m_generator->AddRectangle(left, top, left + width, top + height);
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::AddEllipse(const CFX_PointF& pos, const CFX_SizeF& size) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
CFX_SizeF newSize = size / 2.0f;
m_generator->AddEllipse(
CFX_PointF(pos.x + newSize.width, pos.y + newSize.height), newSize);
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::AddEllipse(const CFX_RectF& rect) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
m_generator->AddEllipse(
CFX_PointF(rect.left + rect.Width() / 2, rect.top + rect.Height() / 2),
CFX_SizeF(rect.Width() / 2, rect.Height() / 2));
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::AddArc(const CFX_PointF& pos,
const CFX_SizeF& size,
FX_FLOAT startAngle,
FX_FLOAT sweepAngle) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
CFX_SizeF newSize = size / 2;
m_generator->AddArc(CFX_PointF(pos.x + newSize.width, pos.y + newSize.height),
newSize, startAngle, sweepAngle);
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::AddPie(const CFX_PointF& pos,
const CFX_SizeF& size,
FX_FLOAT startAngle,
FX_FLOAT sweepAngle) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
CFX_SizeF newSize = size / 2;
m_generator->AddPie(CFX_PointF(pos.x + newSize.width, pos.y + newSize.height),
newSize, startAngle, sweepAngle);
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::AddSubpath(CFX_Path* path) {
if (!m_generator)
return FWL_Error::PropertyInvalid;
m_generator->AddPathData(path->GetPathData());
return FWL_Error::Succeeded;
}
FWL_Error CFX_Path::Clear() {
if (!m_generator)
return FWL_Error::PropertyInvalid;
m_generator->GetPathData()->Clear();
return FWL_Error::Succeeded;
}
bool CFX_Path::IsEmpty() const {
if (!m_generator)
return false;
if (m_generator->GetPathData()->GetPoints().empty())
return true;
return false;
}
CFX_PathData* CFX_Path::GetPathData() const {
if (!m_generator)
return nullptr;
return m_generator->GetPathData();
}
|