- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

WPSGraphicShape.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
3 /* libwps
4 * Version: MPL 2.0 / LGPLv2.1+
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 *
10 * Major Contributor(s):
11 * Copyright (C) 2002, 2005 William Lachance (william.lachance@sympatico.ca)
12 * Copyright (C) 2002, 2004 Marc Maurer (uwog@uwog.net)
13 *
14 * For minor contributions see the git repository.
15 *
16 * Alternatively, the contents of this file may be used under the terms
17 * of the GNU Lesser General Public License Version 2.1 or later
18 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19 * applicable instead of those above.
20 *
21 * For further information visit http://libwps.sourceforge.net
22 */
23 #ifndef WPS_GRAPHIC_SHAPE
24 # define WPS_GRAPHIC_SHAPE
25 # include <ostream>
26 # include <string>
27 # include <vector>
28
29 # include "librevenge/librevenge.h"
30
31 # include "libwps_internal.h"
32
34 class WPSGraphicShape
35 {
36 public:
38 enum Type { Arc, Circle, Line, Rectangle, Path, Pie, Polygon, ShapeUnknown };
40 enum Command { C_Ellipse, C_Polyline, C_Rectangle, C_Path, C_Polygon, C_Bad };
42 struct PathData
43 {
45 PathData(char type, Vec2f const &x=Vec2f(), Vec2f const &x1=Vec2f(), Vec2f const &x2=Vec2f()):
46 m_type(type), m_x(x), m_x1(x1), m_x2(x2), m_r(), m_rotate(0), m_largeAngle(false), m_sweep(false)
47 {
48 }
50 void translate(Vec2f const &delta);
52 void scale(Vec2f const &factor);
54 void rotate(float angle, Vec2f const &delta);
56 bool get(librevenge::RVNGPropertyList &pList, Vec2f const &orig) const;
58 friend std::ostream &operator<<(std::ostream &o, PathData const &path);
60 int cmp(PathData const &a) const;
62 char m_type;
64 Vec2f m_x;
66 Vec2f m_x1;
68 Vec2f m_x2;
70 Vec2f m_r;
72 float m_rotate;
74 bool m_largeAngle;
76 bool m_sweep;
77 };
78
80 WPSGraphicShape() : m_type(ShapeUnknown), m_bdBox(), m_formBox(), m_cornerWidth(0,0), m_arcAngles(0,0),
81 m_vertices(), m_path(), m_extra("")
82 {
83 }
85 virtual ~WPSGraphicShape() { }
87 static WPSGraphicShape line(Vec2f const &orign, Vec2f const &dest);
89 static WPSGraphicShape rectangle(Box2f const &box, Vec2f const &corners=Vec2f(0,0))
90 {
91 WPSGraphicShape res;
92 res.m_type=Rectangle;
93 res.m_bdBox=res.m_formBox=box;
94 res.m_cornerWidth=corners;
95 return res;
96 }
98 static WPSGraphicShape circle(Box2f const &box)
99 {
100 WPSGraphicShape res;
101 res.m_type=Circle;
102 res.m_bdBox=res.m_formBox=box;
103 return res;
104 }
106 static WPSGraphicShape arc(Box2f const &box, Box2f const &circleBox, Vec2f const &angles)
107 {
108 WPSGraphicShape res;
109 res.m_type=Arc;
110 res.m_bdBox=box;
111 res.m_formBox=circleBox;
112 res.m_arcAngles=angles;
113 return res;
114 }
116 static WPSGraphicShape pie(Box2f const &box, Box2f const &circleBox, Vec2f const &angles)
117 {
118 WPSGraphicShape res;
119 res.m_type=Pie;
120 res.m_bdBox=box;
121 res.m_formBox=circleBox;
122 res.m_arcAngles=angles;
123 return res;
124 }
126 static WPSGraphicShape polygon(Box2f const &box)
127 {
128 WPSGraphicShape res;
129 res.m_type=Polygon;
130 res.m_bdBox=box;
131 return res;
132 }
134 static WPSGraphicShape path(Box2f const &box)
135 {
136 WPSGraphicShape res;
137 res.m_type=Path;
138 res.m_bdBox=box;
139 return res;
140 }
141
143 void translate(Vec2f const &delta);
145 void scale(Vec2f const &factor);
149 WPSGraphicShape rotate(float angle, Vec2f const &center) const;
151 Type getType() const
152 {
153 return m_type;
154 }
156 Box2f getBdBox() const
157 {
158 return m_bdBox;
159 }
161 Command addTo(Vec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const;
163 friend std::ostream &operator<<(std::ostream &o, WPSGraphicShape const &sh);
165 int cmp(WPSGraphicShape const &a) const;
166 protected:
168 std::vector<PathData> getPath() const;
169 public:
171 Type m_type;
173 Box2f m_bdBox;
175 Box2f m_formBox;
177 Vec2f m_cornerWidth;
179 Vec2f m_arcAngles;
181 std::vector<Vec2f> m_vertices;
183 std::vector<PathData> m_path;
185 std::string m_extra;
186 };
187 #endif
188 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPSGraphicShape::m_cornerWidth
Vec2f m_cornerWidth
the rectangle round corner
Definition: WPSGraphicShape.h:177
Vec2f
Vec2< float > Vec2f
Vec2 of float.
Definition: libwps_internal.h:714
WPSGraphicShape::PathData::m_x1
Vec2f m_x1
x1 value
Definition: WPSGraphicShape.h:66
WPSGraphicShape::Type
Type
an enum used to define the shape type
Definition: WPSGraphicShape.h:38
WPSGraphicShape::addTo
Command addTo(Vec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const
updates the propList to send to an interface
Definition: WPSGraphicShape.cpp:339
WPSGraphicShape::m_bdBox
Box2f m_bdBox
the shape bdbox
Definition: WPSGraphicShape.h:173
WPSGraphicShape::PathData::m_r
Vec2f m_r
the radius ( A command)
Definition: WPSGraphicShape.h:70
WPSGraphicShape::path
static WPSGraphicShape path(Box2f const &box)
static constructor to create a path
Definition: WPSGraphicShape.h:134
WPSGraphicShape::m_path
std::vector< PathData > m_path
the list of path component
Definition: WPSGraphicShape.h:183
WPSGraphicShape::Polygon
Definition: WPSGraphicShape.h:38
WPSGraphicShape::m_vertices
std::vector< Vec2f > m_vertices
the list of vertices for lines or polygons
Definition: WPSGraphicShape.h:181
Box2< float >
WPSGraphicShape::PathData::m_rotate
float m_rotate
the rotate ( A command)
Definition: WPSGraphicShape.h:72
WPSGraphicShape::PathData::translate
void translate(Vec2f const &delta)
translate all the coordinate by delta
Definition: WPSGraphicShape.cpp:77
WPSGraphicShape::PathData::scale
void scale(Vec2f const &factor)
scale all the coordinate by a factor
Definition: WPSGraphicShape.cpp:90
WPSGraphicShape::C_Path
Definition: WPSGraphicShape.h:40
WPSGraphicShape::Arc
Definition: WPSGraphicShape.h:38
WPSGraphicShape::PathData::operator<<
friend std::ostream & operator<<(std::ostream &o, PathData const &path)
a print operator
Definition: WPSGraphicShape.cpp:41
WPSGraphicShape::WPSGraphicShape
WPSGraphicShape()
constructor
Definition: WPSGraphicShape.h:80
WPSGraphicShape::Command
Command
an enum used to define the interface command
Definition: WPSGraphicShape.h:40
WPSGraphicShape::m_extra
std::string m_extra
extra data
Definition: WPSGraphicShape.h:185
WPSGraphicShape::arc
static WPSGraphicShape arc(Box2f const &box, Box2f const &circleBox, Vec2f const &angles)
static constructor to create a arc
Definition: WPSGraphicShape.h:106
WPSGraphicShape::rectangle
static WPSGraphicShape rectangle(Box2f const &box, Vec2f const &corners=Vec2f(0, 0))
static constructor to create a rectangle
Definition: WPSGraphicShape.h:89
WPSGraphicShape::getBdBox
Box2f getBdBox() const
returns the basic bdbox
Definition: WPSGraphicShape.h:156
WPSGraphicShape::getType
Type getType() const
returns the type corresponding to a shape
Definition: WPSGraphicShape.h:151
WPSGraphicShape::PathData::m_sweep
bool m_sweep
sweep value ( A command)
Definition: WPSGraphicShape.h:76
WPSGraphicShape::C_Polygon
Definition: WPSGraphicShape.h:40
WPSGraphicShape
a structure used to define a picture shape
Definition: WPSGraphicShape.h:34
WPSGraphicShape::PathData
a simple path component
Definition: WPSGraphicShape.h:42
libwps_internal.h
WPSGraphicShape::C_Bad
Definition: WPSGraphicShape.h:40
WPSGraphicShape::PathData::rotate
void rotate(float angle, Vec2f const &delta)
rotate all the coordinate by angle (origin rotation) then translate coordinate
Definition: WPSGraphicShape.cpp:103
WPSGraphicShape::Path
Definition: WPSGraphicShape.h:38
WPSGraphicShape::PathData::m_largeAngle
bool m_largeAngle
large angle ( A command)
Definition: WPSGraphicShape.h:74
WPSGraphicShape::~WPSGraphicShape
virtual ~WPSGraphicShape()
virtual destructor
Definition: WPSGraphicShape.h:85
WPSGraphicShape::PathData::m_type
char m_type
the type: M, L, ...
Definition: WPSGraphicShape.h:62
WPSGraphicShape::polygon
static WPSGraphicShape polygon(Box2f const &box)
static constructor to create a polygon
Definition: WPSGraphicShape.h:126
WPSGraphicShape::C_Polyline
Definition: WPSGraphicShape.h:40
WPSGraphicShape::Rectangle
Definition: WPSGraphicShape.h:38
WPSGraphicShape::m_type
Type m_type
the type
Definition: WPSGraphicShape.h:171
WPSGraphicShape::m_formBox
Box2f m_formBox
the internal shape bdbox ( used for arc, circle to store the circle bdbox )
Definition: WPSGraphicShape.h:175
WPSGraphicShape::PathData::m_x
Vec2f m_x
the main x value
Definition: WPSGraphicShape.h:64
WPSGraphicShape::Pie
Definition: WPSGraphicShape.h:38
WPSGraphicShape::ShapeUnknown
Definition: WPSGraphicShape.h:38
WPSGraphicShape::circle
static WPSGraphicShape circle(Box2f const &box)
static constructor to create a circle
Definition: WPSGraphicShape.h:98
WPSGraphicShape::Circle
Definition: WPSGraphicShape.h:38
WPSGraphicShape::PathData::PathData
PathData(char type, Vec2f const &x=Vec2f(), Vec2f const &x1=Vec2f(), Vec2f const &x2=Vec2f())
constructor
Definition: WPSGraphicShape.h:45
WPSGraphicShape::m_arcAngles
Vec2f m_arcAngles
the start and end value which defines an arc
Definition: WPSGraphicShape.h:179
WPSGraphicShape::line
static WPSGraphicShape line(Vec2f const &orign, Vec2f const &dest)
static constructor to create a line
Definition: WPSGraphicShape.cpp:193
WPSGraphicShape::PathData::m_x2
Vec2f m_x2
x2 value
Definition: WPSGraphicShape.h:68
WPSGraphicShape::C_Ellipse
Definition: WPSGraphicShape.h:40
Vec2< float >
WPSGraphicShape::pie
static WPSGraphicShape pie(Box2f const &box, Box2f const &circleBox, Vec2f const &angles)
static constructor to create a pie
Definition: WPSGraphicShape.h:116
WPSGraphicShape::PathData::cmp
int cmp(PathData const &a) const
comparison function
Definition: WPSGraphicShape.cpp:169
WPSGraphicShape::C_Rectangle
Definition: WPSGraphicShape.h:40
WPSGraphicShape::getPath
std::vector< PathData > getPath() const
return a path corresponding to the shape
Definition: WPSGraphicShape.cpp:484
WPSGraphicShape::Line
Definition: WPSGraphicShape.h:38