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
42 class MWAWGraphicStyle;
43
45 class MWAWGraphicShape
46 {
47 public:
49 enum Type { Arc, Circle, Line, Measure, Rectangle, Path, Pie, Polygon, ShapeUnknown };
51 enum Command { C_Ellipse, C_Polyline, C_Rectangle, C_Path, C_Polygon, C_Bad };
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;
83 MWAWVec2f m_x;
85 MWAWVec2f m_x1;
87 MWAWVec2f m_x2;
89 MWAWVec2f m_r;
91 float m_rotate;
93 bool m_largeAngle;
95 bool m_sweep;
96 };
97
99 MWAWGraphicShape()
100 : m_type(ShapeUnknown)
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 }
111 ~MWAWGraphicShape();
113 static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest);
115 static MWAWGraphicShape measure(MWAWVec2f const &orign, MWAWVec2f const &dest);
117 static MWAWGraphicShape rectangle(MWAWBox2f const &box, MWAWVec2f const &corners=MWAWVec2f(0,0))
118 {
119 MWAWGraphicShape res;
120 res.m_type=Rectangle;
121 res.m_bdBox=res.m_formBox=box;
122 res.m_cornerWidth=corners;
123 return res;
124 }
126 static MWAWGraphicShape circle(MWAWBox2f const &box)
127 {
128 MWAWGraphicShape res;
129 res.m_type=Circle;
130 res.m_bdBox=res.m_formBox=box;
131 return res;
132 }
134 static MWAWGraphicShape arc(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
135 {
136 MWAWGraphicShape res;
137 res.m_type=Arc;
138 res.m_bdBox=box;
139 res.m_formBox=circleBox;
140 res.m_arcAngles=angles;
141 return res;
142 }
144 static MWAWGraphicShape pie(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
145 {
146 MWAWGraphicShape res;
147 res.m_type=Pie;
148 res.m_bdBox=box;
149 res.m_formBox=circleBox;
150 res.m_arcAngles=angles;
151 return res;
152 }
154 static MWAWGraphicShape polygon(MWAWBox2f const &box)
155 {
156 MWAWGraphicShape res;
157 res.m_type=Polygon;
158 res.m_bdBox=box;
159 return res;
160 }
162 static MWAWGraphicShape path(MWAWBox2f const &box)
163 {
164 MWAWGraphicShape res;
165 res.m_type=Path;
166 res.m_bdBox=box;
167 return res;
168 }
169
171 void translate(MWAWVec2f const &delta);
173 void scale(MWAWVec2f const &factor);
177 MWAWGraphicShape rotate(float angle, MWAWVec2f const &center) const;
179 MWAWGraphicShape transform(MWAWTransformation const &matrix) const;
181 Type getType() const
182 {
183 return m_type;
184 }
186 MWAWBox2f getBdBox() const
187 {
188 return m_bdBox;
189 }
191 MWAWBox2f getBdBox(MWAWGraphicStyle const &style, bool moveToO=false) const;
193 Command addTo(MWAWVec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const;
195 bool addPathTo(MWAWVec2f const &orig, librevenge::RVNGPropertyListVector &propList) const;
197 friend std::ostream &operator<<(std::ostream &o, MWAWGraphicShape const &sh);
199 int cmp(MWAWGraphicShape const &a) const;
200 protected:
202 std::vector<PathData> getPath(bool forTransformation) const;
203 public:
205 Type m_type;
207 MWAWBox2f m_bdBox;
209 MWAWBox2f m_formBox;
211 MWAWVec2f m_cornerWidth;
213 MWAWVec2f m_arcAngles;
215 std::vector<MWAWVec2f> m_vertices;
217 std::vector<PathData> m_path;
219 std::string m_extra;
220 };
221 #endif
222 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWGraphicShape::circle
static MWAWGraphicShape circle(MWAWBox2f const &box)
static constructor to create a circle
Definition: MWAWGraphicShape.hxx:126
MWAWGraphicShape::getType
Type getType() const
returns the type corresponding to a shape
Definition: MWAWGraphicShape.hxx:181
MWAWGraphicShape::PathData::PathData
PathData(char type, MWAWVec2f const &x=MWAWVec2f(), MWAWVec2f const &x1=MWAWVec2f(), MWAWVec2f const &x2=MWAWVec2f())
constructor
Definition: MWAWGraphicShape.hxx:55
MWAWGraphicShape::m_cornerWidth
MWAWVec2f m_cornerWidth
the rectangle round corner
Definition: MWAWGraphicShape.hxx:211
MWAWGraphicShape::MWAWGraphicShape
MWAWGraphicShape()
constructor
Definition: MWAWGraphicShape.hxx:99
MWAWGraphicShape::Rectangle
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::m_vertices
std::vector< MWAWVec2f > m_vertices
the list of vertices for lines or polygons
Definition: MWAWGraphicShape.hxx:215
libmwaw_internal.hxx
MWAWGraphicShape::PathData::translate
void translate(MWAWVec2f const &delta)
translate all the coordinate by delta
Definition: MWAWGraphicShape.cxx:94
MWAWGraphicShape::getPath
std::vector< PathData > getPath(bool forTransformation) const
return a path corresponding to the shape
Definition: MWAWGraphicShape.cxx:591
MWAWGraphicShape::C_Path
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::PathData::scale
void scale(MWAWVec2f const &factor)
scale all the coordinate by a factor
Definition: MWAWGraphicShape.cxx:107
MWAWGraphicShape::ShapeUnknown
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicStyle
a structure used to define a picture style
Definition: MWAWGraphicStyle.hxx:47
MWAWGraphicShape::arc
static MWAWGraphicShape arc(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
static constructor to create a arc
Definition: MWAWGraphicShape.hxx:134
MWAWGraphicShape::Measure
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::m_arcAngles
MWAWVec2f m_arcAngles
the start and end value which defines an arc
Definition: MWAWGraphicShape.hxx:213
MWAWGraphicShape::Command
Command
an enum used to define the interface command
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::addTo
Command addTo(MWAWVec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const
updates the propList to send to an interface
Definition: MWAWGraphicShape.cxx:453
MWAWGraphicShape::m_formBox
MWAWBox2f m_formBox
the internal shape bdbox ( used for arc, circle to store the circle bdbox )
Definition: MWAWGraphicShape.hxx:209
MWAWGraphicShape::Circle
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::C_Polygon
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::path
static MWAWGraphicShape path(MWAWBox2f const &box)
static constructor to create a path
Definition: MWAWGraphicShape.hxx:162
MWAWGraphicShape::PathData::m_sweep
bool m_sweep
sweep value ( A command)
Definition: MWAWGraphicShape.hxx:95
MWAWGraphicShape::PathData::m_r
MWAWVec2f m_r
the radius ( A command)
Definition: MWAWGraphicShape.hxx:89
MWAWGraphicShape::PathData::m_largeAngle
bool m_largeAngle
large angle ( A command)
Definition: MWAWGraphicShape.hxx:93
MWAWGraphicShape::getBdBox
MWAWBox2f getBdBox() const
returns the basic bdbox
Definition: MWAWGraphicShape.hxx:186
MWAWBox2< float >
MWAWGraphicShape::Type
Type
an enum used to define the shape type
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::PathData::rotate
void rotate(float angle, MWAWVec2f const &delta)
rotate all the coordinate by angle (origin rotation) then translate coordinate
Definition: MWAWGraphicShape.cxx:120
MWAWGraphicShape::rectangle
static MWAWGraphicShape rectangle(MWAWBox2f const &box, MWAWVec2f const &corners=MWAWVec2f(0, 0))
static constructor to create a rectangle
Definition: MWAWGraphicShape.hxx:117
MWAWGraphicShape::Polygon
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::PathData::m_x1
MWAWVec2f m_x1
x1 value
Definition: MWAWGraphicShape.hxx:85
MWAWVec2f
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition: libmwaw_internal.hxx:838
MWAWGraphicShape::PathData::m_rotate
float m_rotate
the rotate ( A command)
Definition: MWAWGraphicShape.hxx:91
MWAWGraphicShape::Arc
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::PathData::m_type
char m_type
the type: M, L, ...
Definition: MWAWGraphicShape.hxx:81
MWAWGraphicShape::PathData::m_x2
MWAWVec2f m_x2
x2 value
Definition: MWAWGraphicShape.hxx:87
MWAWGraphicShape::C_Bad
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::PathData::cmp
int cmp(PathData const &a) const
comparison function
Definition: MWAWGraphicShape.cxx:199
MWAWGraphicShape::PathData::operator<<
friend std::ostream & operator<<(std::ostream &o, PathData const &path)
a print operator
Definition: MWAWGraphicShape.cxx:59
MWAWGraphicShape::PathData::transform
void transform(MWAWTransformation const &matrix, float rotation)
multiply all the coordinate by a matrix
Definition: MWAWGraphicShape.cxx:141
MWAWGraphicShape::m_extra
std::string m_extra
extra data
Definition: MWAWGraphicShape.hxx:219
MWAWGraphicShape::line
static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest)
static constructor to create a line
Definition: MWAWGraphicShape.cxx:227
MWAWGraphicShape::C_Polyline
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::C_Rectangle
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::pie
static MWAWGraphicShape pie(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
static constructor to create a pie
Definition: MWAWGraphicShape.hxx:144
MWAWGraphicShape::Pie
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape
a structure used to define a picture shape
Definition: MWAWGraphicShape.hxx:45
MWAWGraphicShape::polygon
static MWAWGraphicShape polygon(MWAWBox2f const &box)
static constructor to create a polygon
Definition: MWAWGraphicShape.hxx:154
MWAWGraphicShape::~MWAWGraphicShape
~MWAWGraphicShape()
destructor
Definition: MWAWGraphicShape.cxx:223
MWAWGraphicShape::m_path
std::vector< PathData > m_path
the list of path component
Definition: MWAWGraphicShape.hxx:217
MWAWGraphicShape::Path
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::C_Ellipse
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::m_bdBox
MWAWBox2f m_bdBox
the shape bdbox
Definition: MWAWGraphicShape.hxx:207
MWAWGraphicShape::PathData::m_x
MWAWVec2f m_x
the main x value
Definition: MWAWGraphicShape.hxx:83
MWAWGraphicShape::PathData
a simple path component
Definition: MWAWGraphicShape.hxx:53
MWAWTransformation
a transformation which stored the first row of a 3x3 perspective matrix
Definition: libmwaw_internal.hxx:1194
MWAWGraphicShape::measure
static MWAWGraphicShape measure(MWAWVec2f const &orign, MWAWVec2f const &dest)
static constructor to create a measure
Definition: MWAWGraphicShape.cxx:245
MWAWGraphicShape::m_type
Type m_type
the type
Definition: MWAWGraphicShape.hxx:205
MWAWVec2< float >
MWAWGraphicShape::addPathTo
bool addPathTo(MWAWVec2f const &orig, librevenge::RVNGPropertyListVector &propList) const
adds the shape path to a propListVector
Definition: MWAWGraphicShape.cxx:429
MWAWGraphicShape::Line
Definition: MWAWGraphicShape.hxx:49