MWAWGraphicShape.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3/* libmwaw
4* Version: MPL 2.0 / LGPLv2+
5*
6* The contents of this file are subject to the Mozilla Public License Version
7* 2.0 (the "License"); you may not use this file except in compliance with
8* the License or as specified alternatively below. You may obtain a copy of
9* the License at http://www.mozilla.org/MPL/
10*
11* Software distributed under the License is distributed on an "AS IS" basis,
12* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13* for the specific language governing rights and limitations under the
14* License.
15*
16* Major Contributor(s):
17* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20* Copyright (C) 2006, 2007 Andrew Ziem
21* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22*
23*
24* All Rights Reserved.
25*
26* For minor contributions see the git repository.
27*
28* Alternatively, the contents of this file may be used under the terms of
29* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30* in which case the provisions of the LGPLv2+ are applicable
31* instead of those above.
32*/
33#ifndef MWAW_GRAPHIC_SHAPE
34# define MWAW_GRAPHIC_SHAPE
35# include <ostream>
36# include <string>
37# include <vector>
38
39# include "librevenge/librevenge.h"
40# include "libmwaw_internal.hxx"
41
43
46{
47public:
53 struct PathData {
55 explicit PathData(char type, MWAWVec2f const &x=MWAWVec2f(), MWAWVec2f const &x1=MWAWVec2f(), MWAWVec2f const &x2=MWAWVec2f())
56 : m_type(type)
57 , m_x(x)
58 , m_x1(x1)
59 , m_x2(x2)
60 , m_r()
61 , m_rotate(0)
62 , m_largeAngle(false)
63 , m_sweep(false)
64 {
65 }
67 void translate(MWAWVec2f const &delta);
69 void scale(MWAWVec2f const &factor);
71 void rotate(float angle, MWAWVec2f const &delta);
73 void transform(MWAWTransformation const &matrix, float rotation);
75 bool get(librevenge::RVNGPropertyList &pList, MWAWVec2f const &orig) const;
77 friend std::ostream &operator<<(std::ostream &o, PathData const &path);
79 int cmp(PathData const &a) const;
81 char m_type;
91 float m_rotate;
95 bool m_sweep;
96 };
97
101 , m_bdBox()
102 , m_formBox()
103 , m_cornerWidth(0,0)
104 , m_arcAngles(0,0)
105 , m_vertices()
106 , m_path()
107 , m_extra("")
108 {
109 }
116 static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest);
118 static MWAWGraphicShape measure(MWAWVec2f const &orign, MWAWVec2f const &dest);
120 static MWAWGraphicShape rectangle(MWAWBox2f const &box, MWAWVec2f const &corners=MWAWVec2f(0,0))
121 {
123 res.m_type=Rectangle;
124 res.m_bdBox=res.m_formBox=box;
125 res.m_cornerWidth=corners;
126 return res;
127 }
130 {
132 res.m_type=Circle;
133 res.m_bdBox=res.m_formBox=box;
134 return res;
135 }
137 static MWAWGraphicShape arc(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
138 {
140 res.m_type=Arc;
141 res.m_bdBox=box;
142 res.m_formBox=circleBox;
143 res.m_arcAngles=angles;
144 return res;
145 }
147 static MWAWGraphicShape pie(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
148 {
150 res.m_type=Pie;
151 res.m_bdBox=box;
152 res.m_formBox=circleBox;
153 res.m_arcAngles=angles;
154 return res;
155 }
158 {
160 res.m_type=Polyline;
161 res.m_bdBox=box;
162 return res;
163 }
166 {
168 res.m_type=Polygon;
169 res.m_bdBox=box;
170 return res;
171 }
173 static MWAWGraphicShape path(MWAWBox2f const &box)
174 {
176 res.m_type=Path;
177 res.m_bdBox=box;
178 return res;
179 }
180
182 void translate(MWAWVec2f const &delta);
184 void scale(MWAWVec2f const &factor);
188 MWAWGraphicShape rotate(float angle, MWAWVec2f const &center) const;
190 MWAWGraphicShape transform(MWAWTransformation const &matrix) const;
192 Type getType() const
193 {
194 return m_type;
195 }
198 {
199 return m_bdBox;
200 }
202 MWAWBox2f getBdBox(MWAWGraphicStyle const &style, bool moveToO=false) const;
204 Command addTo(MWAWVec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const;
206 bool addPathTo(MWAWVec2f const &orig, librevenge::RVNGPropertyListVector &propList) const;
208 friend std::ostream &operator<<(std::ostream &o, MWAWGraphicShape const &sh);
210 int cmp(MWAWGraphicShape const &a) const;
211
212 // -----------------------------
213 // low level
214 // -----------------------------
215
217 std::vector<PathData> getPath(bool forTransformation) const;
219 static std::vector<PathData> offsetVertices(std::vector<PathData> const &path, float offset, MWAWBox2f &finalBox);
220public:
232 std::vector<MWAWVec2f> m_vertices;
234 std::vector<PathData> m_path;
236 std::string m_extra;
237};
238#endif
239// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
a structure used to define a picture shape
Definition: MWAWGraphicShape.hxx:46
MWAWBox2f m_formBox
the internal shape bdbox ( used for arc, circle to store the circle bdbox )
Definition: MWAWGraphicShape.hxx:226
MWAWGraphicShape & operator=(MWAWGraphicShape const &)=default
MWAWVec2f m_arcAngles
the start and end value which defines an arc
Definition: MWAWGraphicShape.hxx:230
int cmp(MWAWGraphicShape const &a) const
compare two shapes
Definition: MWAWGraphicShape.cxx:314
static MWAWGraphicShape polygon(MWAWBox2f const &box)
static constructor to create a polygon
Definition: MWAWGraphicShape.hxx:165
std::vector< MWAWVec2f > m_vertices
the list of vertices for lines or polygons
Definition: MWAWGraphicShape.hxx:232
MWAWGraphicShape()
constructor
Definition: MWAWGraphicShape.hxx:99
static MWAWGraphicShape arc(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
static constructor to create a arc
Definition: MWAWGraphicShape.hxx:137
static MWAWGraphicShape pie(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
static constructor to create a pie
Definition: MWAWGraphicShape.hxx:147
MWAWGraphicShape & operator=(MWAWGraphicShape &&)=default
static MWAWGraphicShape rectangle(MWAWBox2f const &box, MWAWVec2f const &corners=MWAWVec2f(0, 0))
static constructor to create a rectangle
Definition: MWAWGraphicShape.hxx:120
static MWAWGraphicShape polyline(MWAWBox2f const &box)
static constructor to create a polyline
Definition: MWAWGraphicShape.hxx:157
Command addTo(MWAWVec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const
updates the propList to send to an interface
Definition: MWAWGraphicShape.cxx:458
void scale(MWAWVec2f const &factor)
rescale all the coordinate
Definition: MWAWGraphicShape.cxx:368
std::vector< PathData > getPath(bool forTransformation) const
return a path corresponding to the shape
Definition: MWAWGraphicShape.cxx:597
static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest)
static constructor to create a line
Definition: MWAWGraphicShape.cxx:228
bool addPathTo(MWAWVec2f const &orig, librevenge::RVNGPropertyListVector &propList) const
adds the shape path to a propListVector
Definition: MWAWGraphicShape.cxx:434
Type
an enum used to define the shape type
Definition: MWAWGraphicShape.hxx:49
@ Pie
Definition: MWAWGraphicShape.hxx:49
@ Path
Definition: MWAWGraphicShape.hxx:49
@ ShapeUnknown
Definition: MWAWGraphicShape.hxx:49
@ Line
Definition: MWAWGraphicShape.hxx:49
@ Measure
Definition: MWAWGraphicShape.hxx:49
@ Rectangle
Definition: MWAWGraphicShape.hxx:49
@ Circle
Definition: MWAWGraphicShape.hxx:49
@ Polyline
Definition: MWAWGraphicShape.hxx:49
@ Polygon
Definition: MWAWGraphicShape.hxx:49
@ Arc
Definition: MWAWGraphicShape.hxx:49
MWAWVec2f m_cornerWidth
the rectangle round corner
Definition: MWAWGraphicShape.hxx:228
void translate(MWAWVec2f const &delta)
translate all the coordinate by delta
Definition: MWAWGraphicShape.cxx:356
static MWAWGraphicShape path(MWAWBox2f const &box)
static constructor to create a path
Definition: MWAWGraphicShape.hxx:173
Type m_type
the type
Definition: MWAWGraphicShape.hxx:222
MWAWBox2f m_bdBox
the shape bdbox
Definition: MWAWGraphicShape.hxx:224
static std::vector< PathData > offsetVertices(std::vector< PathData > const &path, float offset, MWAWBox2f &finalBox)
try to decal each path point by an offset (using their normal)
Definition: MWAWGraphicShape.cxx:759
Type getType() const
returns the type corresponding to a shape
Definition: MWAWGraphicShape.hxx:192
Command
an enum used to define the interface command
Definition: MWAWGraphicShape.hxx:51
@ C_Rectangle
Definition: MWAWGraphicShape.hxx:51
@ C_Bad
Definition: MWAWGraphicShape.hxx:51
@ C_Polygon
Definition: MWAWGraphicShape.hxx:51
@ C_Ellipse
Definition: MWAWGraphicShape.hxx:51
@ C_Polyline
Definition: MWAWGraphicShape.hxx:51
@ C_Path
Definition: MWAWGraphicShape.hxx:51
std::vector< PathData > m_path
the list of path component
Definition: MWAWGraphicShape.hxx:234
MWAWGraphicShape rotate(float angle, MWAWVec2f const &center) const
return a new shape corresponding to a rotation from center.
Definition: MWAWGraphicShape.cxx:381
std::string m_extra
extra data
Definition: MWAWGraphicShape.hxx:236
static MWAWGraphicShape measure(MWAWVec2f const &orign, MWAWVec2f const &dest)
static constructor to create a measure
Definition: MWAWGraphicShape.cxx:246
friend std::ostream & operator<<(std::ostream &o, MWAWGraphicShape const &sh)
a print operator
Definition: MWAWGraphicShape.cxx:253
MWAWBox2f getBdBox() const
returns the basic bdbox
Definition: MWAWGraphicShape.hxx:197
MWAWGraphicShape(MWAWGraphicShape const &)=default
static MWAWGraphicShape circle(MWAWBox2f const &box)
static constructor to create a circle
Definition: MWAWGraphicShape.hxx:129
MWAWGraphicShape transform(MWAWTransformation const &matrix) const
returns a new shape corresponding to a matrix transformation
Definition: MWAWGraphicShape.cxx:404
~MWAWGraphicShape()
destructor
Definition: MWAWGraphicShape.cxx:224
a structure used to define a picture style
Definition: MWAWGraphicStyle.hxx:48
a transformation which stored the first row of a 3x3 perspective matrix
Definition: libmwaw_internal.hxx:1199
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition: libmwaw_internal.hxx:842
a simple path component
Definition: MWAWGraphicShape.hxx:53
friend std::ostream & operator<<(std::ostream &o, PathData const &path)
a print operator
Definition: MWAWGraphicShape.cxx:59
float m_rotate
the rotate ( A command)
Definition: MWAWGraphicShape.hxx:91
char m_type
the type: M, L, ...
Definition: MWAWGraphicShape.hxx:81
bool get(librevenge::RVNGPropertyList &pList, MWAWVec2f const &orig) const
update the property list to correspond to a command
Definition: MWAWGraphicShape.cxx:159
void rotate(float angle, MWAWVec2f const &delta)
rotate all the coordinate by angle (origin rotation) then translate coordinate
Definition: MWAWGraphicShape.cxx:121
void translate(MWAWVec2f const &delta)
translate all the coordinate by delta
Definition: MWAWGraphicShape.cxx:95
void scale(MWAWVec2f const &factor)
scale all the coordinate by a factor
Definition: MWAWGraphicShape.cxx:108
bool m_sweep
sweep value ( A command)
Definition: MWAWGraphicShape.hxx:95
int cmp(PathData const &a) const
comparison function
Definition: MWAWGraphicShape.cxx:200
void transform(MWAWTransformation const &matrix, float rotation)
multiply all the coordinate by a matrix
Definition: MWAWGraphicShape.cxx:142
bool m_largeAngle
large angle ( A command)
Definition: MWAWGraphicShape.hxx:93
MWAWVec2f m_r
the radius ( A command)
Definition: MWAWGraphicShape.hxx:89
MWAWVec2f m_x1
x1 value
Definition: MWAWGraphicShape.hxx:85
MWAWVec2f m_x
the main x value
Definition: MWAWGraphicShape.hxx:83
MWAWVec2f m_x2
x2 value
Definition: MWAWGraphicShape.hxx:87
PathData(char type, MWAWVec2f const &x=MWAWVec2f(), MWAWVec2f const &x1=MWAWVec2f(), MWAWVec2f const &x2=MWAWVec2f())
constructor
Definition: MWAWGraphicShape.hxx:55

Generated on Thu Jan 19 2023 00:00:00 for libmwaw by doxygen 1.9.6