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 
35 {
36 public:
42  struct PathData
43  {
45  PathData(char type, Vec2f const &x=Vec2f(), Vec2f const &x1=Vec2f(), Vec2f const &x2=Vec2f())
46  : m_type(type)
47  , m_x(x)
48  , m_x1(x1)
49  , m_x2(x2)
50  , m_r()
51  , m_rotate(0)
52  , m_largeAngle(false)
53  , m_sweep(false)
54  {
55  }
57  void translate(Vec2f const &delta);
59  void scale(Vec2f const &factor);
61  void rotate(float angle, Vec2f const &delta);
63  void transform(WPSTransformation const &matrix, float rotation);
65  bool get(librevenge::RVNGPropertyList &pList, Vec2f const &orig) const;
67  friend std::ostream &operator<<(std::ostream &o, PathData const &path);
69  int cmp(PathData const &a) const;
71  char m_type;
81  float m_rotate;
85  bool m_sweep;
86  };
87 
91  , m_bdBox()
92  , m_formBox()
93  , m_cornerWidth(0,0)
94  , m_arcAngles(0,0)
95  , m_vertices()
96  , m_path()
97  , m_extra("")
98  {
99  }
100  WPSGraphicShape(WPSGraphicShape const &)=default;
101  WPSGraphicShape(WPSGraphicShape &&)=default;
102  WPSGraphicShape &operator=(WPSGraphicShape const &)=default;
107  static WPSGraphicShape line(Vec2f const &orign, Vec2f const &dest);
109  static WPSGraphicShape rectangle(WPSBox2f const &box, Vec2f const &corners=Vec2f(0,0))
110  {
111  WPSGraphicShape res;
112  res.m_type=Rectangle;
113  res.m_bdBox=res.m_formBox=box;
114  res.m_cornerWidth=corners;
115  return res;
116  }
118  static WPSGraphicShape circle(WPSBox2f const &box)
119  {
120  WPSGraphicShape res;
121  res.m_type=Circle;
122  res.m_bdBox=res.m_formBox=box;
123  return res;
124  }
126  static WPSGraphicShape arc(WPSBox2f const &box, WPSBox2f const &circleWPSBox, Vec2f const &angles)
127  {
128  WPSGraphicShape res;
129  res.m_type=Arc;
130  res.m_bdBox=box;
131  res.m_formBox=circleWPSBox;
132  res.m_arcAngles=angles;
133  return res;
134  }
136  static WPSGraphicShape pie(WPSBox2f const &box, WPSBox2f const &circleWPSBox, Vec2f const &angles)
137  {
138  WPSGraphicShape res;
139  res.m_type=Pie;
140  res.m_bdBox=box;
141  res.m_formBox=circleWPSBox;
142  res.m_arcAngles=angles;
143  return res;
144  }
146  static WPSGraphicShape polygon(WPSBox2f const &box)
147  {
148  WPSGraphicShape res;
149  res.m_type=Polygon;
150  res.m_bdBox=box;
151  return res;
152  }
154  static WPSGraphicShape polyline(WPSBox2f const &box)
155  {
156  WPSGraphicShape res;
157  res.m_type=Polyline;
158  res.m_bdBox=box;
159  return res;
160  }
162  static WPSGraphicShape path(WPSBox2f const &box)
163  {
164  WPSGraphicShape res;
165  res.m_type=Path;
166  res.m_bdBox=box;
167  return res;
168  }
169 
171  void translate(Vec2f const &delta);
173  void scale(Vec2f const &factor);
177  WPSGraphicShape rotate(float angle, Vec2f const &center) const;
179  WPSGraphicShape transform(WPSTransformation const &matrix) const;
181  Type getType() const
182  {
183  return m_type;
184  }
187  {
188  return m_bdBox;
189  }
191  Command addTo(Vec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const;
193  friend std::ostream &operator<<(std::ostream &o, WPSGraphicShape const &sh);
195  int cmp(WPSGraphicShape const &a) const;
196 protected:
198  std::vector<PathData> getPath(bool forTransformation) const;
199 public:
211  std::vector<Vec2f> m_vertices;
213  std::vector<PathData> m_path;
215  std::string m_extra;
216 };
217 #endif
218 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPSGraphicShape::m_vertices
std::vector< Vec2f > m_vertices
the list of vertices for lines or polygons
Definition: WPSGraphicShape.h:211
WPSGraphicShape::m_bdBox
WPSBox2f m_bdBox
the shape bdbox
Definition: WPSGraphicShape.h:203
WPSBox2::center
Vec2< T > center() const
the box center
Definition: libwps_internal.h:759
WPSGraphicShape::Polygon
@ Polygon
Definition: WPSGraphicShape.h:38
WPSGraphicShape::rectangle
static WPSGraphicShape rectangle(WPSBox2f const &box, Vec2f const &corners=Vec2f(0, 0))
static constructor to create a rectangle
Definition: WPSGraphicShape.h:109
WPSGraphicShape::getType
Type getType() const
returns the type corresponding to a shape
Definition: WPSGraphicShape.h:181
WPSTransformation
a transformation which stored the first row of a 3x3 perspective matrix
Definition: libwps_internal.h:1130
WPSBox2f
WPSBox2< float > WPSBox2f
WPSBox2 of float.
Definition: libwps_internal.h:890
WPSGraphicShape::PathData::m_r
Vec2f m_r
the radius ( A command)
Definition: WPSGraphicShape.h:79
WPSGraphicShape::PathData::PathData
PathData(char type, Vec2f const &x=Vec2f(), Vec2f const &x1=Vec2f(), Vec2f const &x2=Vec2f())
constructor
Definition: WPSGraphicShape.h:45
WPSGraphicShape::Type
Type
an enum used to define the shape type
Definition: WPSGraphicShape.h:38
WPSGraphicShape::PathData
a simple path component
Definition: WPSGraphicShape.h:42
WPSGraphicShape::operator=
WPSGraphicShape & operator=(WPSGraphicShape const &)=default
M_PI
#define M_PI
Definition: libwps_internal.h:43
WPSGraphicShape::Line
@ Line
Definition: WPSGraphicShape.h:38
WPSGraphicShape::PathData::scale
void scale(Vec2f const &factor)
scale all the coordinate by a factor
Definition: WPSGraphicShape.cpp:91
Vec2::cmp
int cmp(Vec2< T > const &p) const
a comparison function: which first compares x then y
Definition: libwps_internal.h:647
WPSGraphicShape::circle
static WPSGraphicShape circle(WPSBox2f const &box)
static constructor to create a circle
Definition: WPSGraphicShape.h:118
WPSBox2::min
const Vec2< T > & min() const
the minimum 2D point (in x and in y)
Definition: libwps_internal.h:725
WPSGraphicShape::C_Path
@ C_Path
Definition: WPSGraphicShape.h:40
WPSGraphicShape::m_extra
std::string m_extra
extra data
Definition: WPSGraphicShape.h:215
WPSGraphicShape::PathData::transform
void transform(WPSTransformation const &matrix, float rotation)
multiply all the coordinate by a matrix
Definition: WPSGraphicShape.cpp:126
WPSGraphicShape::PathData::m_x1
Vec2f m_x1
x1 value
Definition: WPSGraphicShape.h:75
WPSGraphicShape::addTo
Command addTo(Vec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const
updates the propList to send to an interface
Definition: WPSGraphicShape.cpp:396
WPSGraphicShape::C_Polygon
@ C_Polygon
Definition: WPSGraphicShape.h:40
WPSGraphicShape
a structure used to define a picture shape
Definition: WPSGraphicShape.h:34
WPSGraphicShape::WPSGraphicShape
WPSGraphicShape()
constructor
Definition: WPSGraphicShape.h:89
WPSGraphicShape::Command
Command
an enum used to define the interface command
Definition: WPSGraphicShape.h:40
Vec2f
Vec2< float > Vec2f
Vec2 of float.
Definition: libwps_internal.h:704
WPSGraphicShape::PathData::cmp
int cmp(PathData const &a) const
comparison function
Definition: WPSGraphicShape.cpp:188
operator<<
std::ostream & operator<<(std::ostream &o, WPSGraphicShape::PathData const &path)
Definition: WPSGraphicShape.cpp:41
Vec2< float >
WPS_DEBUG_MSG
#define WPS_DEBUG_MSG(M)
Definition: libwps_internal.h:134
WPSGraphicShape::PathData::m_sweep
bool m_sweep
sweep value ( A command)
Definition: WPSGraphicShape.h:85
WPSGraphicShape::PathData::m_x2
Vec2f m_x2
x2 value
Definition: WPSGraphicShape.h:77
WPS_FALLTHROUGH
#define WPS_FALLTHROUGH
fall through attributes
Definition: libwps_internal.h:82
WPSGraphicShape::Path
@ Path
Definition: WPSGraphicShape.h:38
Vec2::x
T x() const
first element
Definition: libwps_internal.h:542
WPSGraphicShape::C_Polyline
@ C_Polyline
Definition: WPSGraphicShape.h:40
WPSGraphicShape::Rectangle
@ Rectangle
Definition: WPSGraphicShape.h:38
WPSGraphicShape::C_Rectangle
@ C_Rectangle
Definition: WPSGraphicShape.h:40
WPSGraphicShape::polyline
static WPSGraphicShape polyline(WPSBox2f const &box)
static constructor to create a polyline
Definition: WPSGraphicShape.h:154
WPSGraphicShape::C_Ellipse
@ C_Ellipse
Definition: WPSGraphicShape.h:40
WPSGraphicShape::m_formBox
WPSBox2f m_formBox
the internal shape bdbox ( used for arc, circle to store the circle bdbox )
Definition: WPSGraphicShape.h:205
WPSGraphicShape::PathData::translate
void translate(Vec2f const &delta)
translate all the coordinate by delta
Definition: WPSGraphicShape.cpp:78
WPSGraphicShape::m_cornerWidth
Vec2f m_cornerWidth
the rectangle round corner
Definition: WPSGraphicShape.h:207
WPSGraphicShape::ShapeUnknown
@ ShapeUnknown
Definition: WPSGraphicShape.h:38
WPSGraphicShape::cmp
int cmp(WPSGraphicShape const &a) const
compare two shapes
Definition: WPSGraphicShape.cpp:286
WPSGraphicShape::PathData::rotate
void rotate(float angle, Vec2f const &delta)
rotate all the coordinate by angle (origin rotation) then translate coordinate
Definition: WPSGraphicShape.cpp:104
WPSGraphicShape::pie
static WPSGraphicShape pie(WPSBox2f const &box, WPSBox2f const &circleWPSBox, Vec2f const &angles)
static constructor to create a pie
Definition: WPSGraphicShape.h:136
WPSGraphicShape::PathData::m_largeAngle
bool m_largeAngle
large angle ( A command)
Definition: WPSGraphicShape.h:83
WPSGraphicShape::Arc
@ Arc
Definition: WPSGraphicShape.h:38
WPSBox2::max
const Vec2< T > & max() const
the maximum 2D point (in x and in y)
Definition: libwps_internal.h:730
WPSGraphicShape::C_Bad
@ C_Bad
Definition: WPSGraphicShape.h:40
WPSGraphicShape::rotate
WPSGraphicShape rotate(float angle, Vec2f const &center) const
return a new shape corresponding to a rotation from center.
Definition: WPSGraphicShape.cpp:340
WPSGraphicShape::PathData::m_x
Vec2f m_x
the main x value
Definition: WPSGraphicShape.h:73
WPSGraphicShape::line
static WPSGraphicShape line(Vec2f const &orign, Vec2f const &dest)
static constructor to create a line
Definition: WPSGraphicShape.cpp:212
WPSTransformation::isIdentity
bool isIdentity() const
returns true if the matrix is an identity matrix
Definition: libwps_internal.h:1145
WPSGraphicShape::getBdBox
WPSBox2f getBdBox() const
returns the basic bdbox
Definition: WPSGraphicShape.h:186
WPSGraphicShape::m_path
std::vector< PathData > m_path
the list of path component
Definition: WPSGraphicShape.h:213
WPSGraphicShape::translate
void translate(Vec2f const &delta)
translate all the coordinate by delta
Definition: WPSGraphicShape.cpp:315
WPSTransformation::decompose
bool decompose(float &rotation, Vec2f &shearing, WPSTransformation &transform, Vec2f const &center) const
try to decompose the matrix in a rotation + scaling/translation matrix.
Definition: libwps_internal.cpp:899
WPSGraphicShape::arc
static WPSGraphicShape arc(WPSBox2f const &box, WPSBox2f const &circleWPSBox, Vec2f const &angles)
static constructor to create a arc
Definition: WPSGraphicShape.h:126
WPSGraphicShape::scale
void scale(Vec2f const &factor)
rescale all the coordinate
Definition: WPSGraphicShape.cpp:327
WPSGraphicShape::m_type
Type m_type
the type
Definition: WPSGraphicShape.h:201
WPSGraphicShape::Pie
@ Pie
Definition: WPSGraphicShape.h:38
WPSGraphicShape::transform
WPSGraphicShape transform(WPSTransformation const &matrix) const
returns a new shape corresponding to a matrix transformation
Definition: WPSGraphicShape.cpp:364
WPSGraphicShape::PathData::get
bool get(librevenge::RVNGPropertyList &pList, Vec2f const &orig) const
update the property list to correspond to a command
Definition: WPSGraphicShape.cpp:144
WPSBox2::size
Vec2< T > size() const
the box size
Definition: libwps_internal.h:754
libwps_internal.h
WPSGraphicShape::m_arcAngles
Vec2f m_arcAngles
the start and end value which defines an arc
Definition: WPSGraphicShape.h:209
WPSGraphicShape.h
WPSBox2::cmp
int cmp(WPSBox2< T > const &p) const
comparison function : fist sorts min by Y,X values then max extremity
Definition: libwps_internal.h:850
WPSBox2< float >
WPSBox2::getUnion
WPSBox2< T > getUnion(WPSBox2< T > const &box) const
returns the union between this and box
Definition: libwps_internal.h:813
WPSGraphicShape::Polyline
@ Polyline
Definition: WPSGraphicShape.h:38
WPSGraphicShape::getPath
std::vector< PathData > getPath(bool forTransformation) const
return a path corresponding to the shape
Definition: WPSGraphicShape.cpp:542
WPSGraphicShape::PathData::m_rotate
float m_rotate
the rotate ( A command)
Definition: WPSGraphicShape.h:81
WPSGraphicShape::PathData::m_type
char m_type
the type: M, L, ...
Definition: WPSGraphicShape.h:71
WPSGraphicShape::path
static WPSGraphicShape path(WPSBox2f const &box)
static constructor to create a path
Definition: WPSGraphicShape.h:162
WPSGraphicShape::PathData::operator<<
friend std::ostream & operator<<(std::ostream &o, PathData const &path)
a print operator
Definition: WPSGraphicShape.cpp:41
Vec2::y
T y() const
second element
Definition: libwps_internal.h:547
WPSGraphicShape::polygon
static WPSGraphicShape polygon(WPSBox2f const &box)
static constructor to create a polygon
Definition: WPSGraphicShape.h:146
WPSGraphicShape::~WPSGraphicShape
~WPSGraphicShape()
destructor
Definition: WPSGraphicShape.h:105
WPSGraphicShape::Circle
@ Circle
Definition: WPSGraphicShape.h:38
WPSGraphicShape::operator<<
friend std::ostream & operator<<(std::ostream &o, WPSGraphicShape const &sh)
a print operator
Definition: WPSGraphicShape.cpp:231

Generated on Wed Dec 7 2022 07:30:48 for libwps by doxygen 1.8.17