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 
46 {
47 public:
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  }
110  MWAWGraphicShape(MWAWGraphicShape const &)=default;
111  MWAWGraphicShape &operator=(MWAWGraphicShape const &)=default;
115  static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest);
117  static MWAWGraphicShape measure(MWAWVec2f const &orign, MWAWVec2f const &dest);
119  static MWAWGraphicShape rectangle(MWAWBox2f const &box, MWAWVec2f const &corners=MWAWVec2f(0,0))
120  {
121  MWAWGraphicShape res;
122  res.m_type=Rectangle;
123  res.m_bdBox=res.m_formBox=box;
124  res.m_cornerWidth=corners;
125  return res;
126  }
128  static MWAWGraphicShape circle(MWAWBox2f const &box)
129  {
130  MWAWGraphicShape res;
131  res.m_type=Circle;
132  res.m_bdBox=res.m_formBox=box;
133  return res;
134  }
136  static MWAWGraphicShape arc(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
137  {
138  MWAWGraphicShape res;
139  res.m_type=Arc;
140  res.m_bdBox=box;
141  res.m_formBox=circleBox;
142  res.m_arcAngles=angles;
143  return res;
144  }
146  static MWAWGraphicShape pie(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
147  {
148  MWAWGraphicShape res;
149  res.m_type=Pie;
150  res.m_bdBox=box;
151  res.m_formBox=circleBox;
152  res.m_arcAngles=angles;
153  return res;
154  }
157  {
158  MWAWGraphicShape res;
159  res.m_type=Polyline;
160  res.m_bdBox=box;
161  return res;
162  }
164  static MWAWGraphicShape polygon(MWAWBox2f const &box)
165  {
166  MWAWGraphicShape res;
167  res.m_type=Polygon;
168  res.m_bdBox=box;
169  return res;
170  }
172  static MWAWGraphicShape path(MWAWBox2f const &box)
173  {
174  MWAWGraphicShape res;
175  res.m_type=Path;
176  res.m_bdBox=box;
177  return res;
178  }
179 
181  void translate(MWAWVec2f const &delta);
183  void scale(MWAWVec2f const &factor);
187  MWAWGraphicShape rotate(float angle, MWAWVec2f const &center) const;
189  MWAWGraphicShape transform(MWAWTransformation const &matrix) const;
191  Type getType() const
192  {
193  return m_type;
194  }
197  {
198  return m_bdBox;
199  }
201  MWAWBox2f getBdBox(MWAWGraphicStyle const &style, bool moveToO=false) const;
203  Command addTo(MWAWVec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const;
205  bool addPathTo(MWAWVec2f const &orig, librevenge::RVNGPropertyListVector &propList) const;
207  friend std::ostream &operator<<(std::ostream &o, MWAWGraphicShape const &sh);
209  int cmp(MWAWGraphicShape const &a) const;
210 protected:
212  std::vector<PathData> getPath(bool forTransformation) const;
213 public:
225  std::vector<MWAWVec2f> m_vertices;
227  std::vector<PathData> m_path;
229  std::string m_extra;
230 };
231 #endif
232 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWGraphicStyle::Arrow::isEmpty
bool isEmpty() const
returns true if there is no arrow
Definition: MWAWGraphicStyle.hxx:123
MWAWGraphicShape::PathData::translate
void translate(MWAWVec2f const &delta)
translate all the coordinate by delta
Definition: MWAWGraphicShape.cxx:95
MWAWGraphicShape::transform
MWAWGraphicShape transform(MWAWTransformation const &matrix) const
returns a new shape corresponding to a matrix transformation
Definition: MWAWGraphicShape.cxx:404
MWAWGraphicShape::cmp
int cmp(MWAWGraphicShape const &a) const
compare two shapes
Definition: MWAWGraphicShape.cxx:314
MWAWGraphicShape::getBdBox
MWAWBox2f getBdBox() const
returns the basic bdbox
Definition: MWAWGraphicShape.hxx:196
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:129
MWAWVec2f
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition: libmwaw_internal.hxx:840
MWAWBox2::max
const MWAWVec2< T > & max() const
the maximum 2D point (in x and in y)
Definition: libmwaw_internal.hxx:1042
MWAWGraphicShape::PathData::PathData
PathData(char type, MWAWVec2f const &x=MWAWVec2f(), MWAWVec2f const &x1=MWAWVec2f(), MWAWVec2f const &x2=MWAWVec2f())
constructor
Definition: MWAWGraphicShape.hxx:55
MWAWGraphicShape::C_Polygon
@ C_Polygon
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::PathData::scale
void scale(MWAWVec2f const &factor)
scale all the coordinate by a factor
Definition: MWAWGraphicShape.cxx:108
MWAWGraphicShape::C_Path
@ C_Path
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:146
MWAWGraphicShape::translate
void translate(MWAWVec2f const &delta)
translate all the coordinate by delta
Definition: MWAWGraphicShape.cxx:356
MWAWGraphicShape::m_path
std::vector< PathData > m_path
the list of path component
Definition: MWAWGraphicShape.hxx:227
MWAWBox2::min
const MWAWVec2< T > & min() const
the minimum 2D point (in x and in y)
Definition: libmwaw_internal.hxx:1037
MWAWGraphicShape
a structure used to define a picture shape
Definition: MWAWGraphicShape.hxx:45
MWAWGraphicShape::line
static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest)
static constructor to create a line
Definition: MWAWGraphicShape.cxx:228
MWAWBox2::extend
void extend(T val)
extends the bdbox by (val, val) keeping the center
Definition: libmwaw_internal.hxx:1120
MWAWGraphicShape::PathData::rotate
void rotate(float angle, MWAWVec2f const &delta)
rotate all the coordinate by angle (origin rotation) then translate coordinate
Definition: MWAWGraphicShape.cxx:121
MWAW_FALLTHROUGH
#define MWAW_FALLTHROUGH
Definition: libmwaw_internal.hxx:118
MWAWGraphicShape::PathData::m_r
MWAWVec2f m_r
the radius ( A command)
Definition: MWAWGraphicShape.hxx:89
MWAWGraphicShape::~MWAWGraphicShape
~MWAWGraphicShape()
destructor
Definition: MWAWGraphicShape.cxx:224
MWAWGraphicStyle
a structure used to define a picture style
Definition: MWAWGraphicStyle.hxx:47
MWAWGraphicShape::m_bdBox
MWAWBox2f m_bdBox
the shape bdbox
Definition: MWAWGraphicShape.hxx:217
MWAWGraphicStyle::hasLine
bool hasLine() const
returns true if the border is defined
Definition: MWAWGraphicStyle.hxx:317
MWAWGraphicShape::measure
static MWAWGraphicShape measure(MWAWVec2f const &orign, MWAWVec2f const &dest)
static constructor to create a measure
Definition: MWAWGraphicShape.cxx:246
MWAWGraphicShape::operator<<
friend std::ostream & operator<<(std::ostream &o, MWAWGraphicShape const &sh)
a print operator
Definition: MWAWGraphicShape.cxx:253
MWAWGraphicShape::PathData::m_largeAngle
bool m_largeAngle
large angle ( A command)
Definition: MWAWGraphicShape.hxx:93
MWAWGraphicShape::circle
static MWAWGraphicShape circle(MWAWBox2f const &box)
static constructor to create a circle
Definition: MWAWGraphicShape.hxx:128
MWAWGraphicShape::PathData::m_sweep
bool m_sweep
sweep value ( A command)
Definition: MWAWGraphicShape.hxx:95
MWAWGraphicShape::getType
Type getType() const
returns the type corresponding to a shape
Definition: MWAWGraphicShape.hxx:191
MWAWGraphicShape::polygon
static MWAWGraphicShape polygon(MWAWBox2f const &box)
static constructor to create a polygon
Definition: MWAWGraphicShape.hxx:164
MWAWGraphicShape::Polygon
@ Polygon
Definition: MWAWGraphicShape.hxx:49
MWAWBox2::getUnion
MWAWBox2< T > getUnion(MWAWBox2< T > const &box) const
returns the union between this and box
Definition: libmwaw_internal.hxx:1127
MWAWGraphicShape::PathData::cmp
int cmp(PathData const &a) const
comparison function
Definition: MWAWGraphicShape.cxx:200
MWAWGraphicShape::Rectangle
@ Rectangle
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::operator=
MWAWGraphicShape & operator=(MWAWGraphicShape const &)=default
MWAWVec2::cmp
int cmp(MWAWVec2< T > const &p) const
a comparison function: which first compares x then y
Definition: libmwaw_internal.hxx:775
MWAWGraphicShape::PathData::m_rotate
float m_rotate
the rotate ( A command)
Definition: MWAWGraphicShape.hxx:91
MWAWGraphicEncoder.hxx
MWAWVec2::y
T y() const
second element
Definition: libmwaw_internal.hxx:671
MWAWGraphicShape::addPathTo
bool addPathTo(MWAWVec2f const &orig, librevenge::RVNGPropertyListVector &propList) const
adds the shape path to a propListVector
Definition: MWAWGraphicShape.cxx:434
libmwaw_internal.hxx
MWAWGraphicStyle::m_lineWidth
float m_lineWidth
the linewidth
Definition: MWAWGraphicStyle.hxx:415
MWAWGraphicShape::C_Bad
@ C_Bad
Definition: MWAWGraphicShape.hxx:51
MWAWVec2::x
T x() const
first element
Definition: libmwaw_internal.hxx:666
MWAWGraphicShape::PathData::m_type
char m_type
the type: M, L, ...
Definition: MWAWGraphicShape.hxx:81
MWAWGraphicShape::PathData::transform
void transform(MWAWTransformation const &matrix, float rotation)
multiply all the coordinate by a matrix
Definition: MWAWGraphicShape.cxx:142
MWAWGraphicShape::m_vertices
std::vector< MWAWVec2f > m_vertices
the list of vertices for lines or polygons
Definition: MWAWGraphicShape.hxx:225
M_PI
#define M_PI
Definition: libmwaw_internal.hxx:52
MWAWGraphicShape::Path
@ Path
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::m_type
Type m_type
the type
Definition: MWAWGraphicShape.hxx:215
MWAWVec2< float >
MWAWGraphicShape::PathData::operator<<
friend std::ostream & operator<<(std::ostream &o, PathData const &path)
a print operator
Definition: MWAWGraphicShape.cxx:59
MWAWGraphicShape.hxx
MWAWGraphicShape::Polyline
@ Polyline
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::rotate
MWAWGraphicShape rotate(float angle, MWAWVec2f const &center) const
return a new shape corresponding to a rotation from center.
Definition: MWAWGraphicShape.cxx:381
MWAWGraphicStyle::m_arrows
Arrow m_arrows[2]
the two arrows corresponding to start and end extremity
Definition: MWAWGraphicStyle.hxx:470
MWAWBox2f
MWAWBox2< float > MWAWBox2f
MWAWBox2 of float.
Definition: libmwaw_internal.hxx:1191
MWAWGraphicShape::C_Polyline
@ C_Polyline
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::Pie
@ Pie
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::PathData::get
bool get(librevenge::RVNGPropertyList &pList, MWAWVec2f const &orig) const
update the property list to correspond to a command
Definition: MWAWGraphicShape.cxx:159
MWAWGraphicShape::m_cornerWidth
MWAWVec2f m_cornerWidth
the rectangle round corner
Definition: MWAWGraphicShape.hxx:221
MWAWGraphicShape::arc
static MWAWGraphicShape arc(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
static constructor to create a arc
Definition: MWAWGraphicShape.hxx:136
MWAWTransformation::decompose
bool decompose(float &rotation, MWAWVec2f &shearing, MWAWTransformation &transform, MWAWVec2f const &center) const
try to decompose the matrix in a rotation + scaling/translation matrix.
Definition: libmwaw_internal.cxx:647
MWAWGraphicShape::Command
Command
an enum used to define the interface command
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::PathData::m_x1
MWAWVec2f m_x1
x1 value
Definition: MWAWGraphicShape.hxx:85
MWAWGraphicShape::Line
@ Line
Definition: MWAWGraphicShape.hxx:49
MWAWBox2::center
MWAWVec2< T > center() const
the box center
Definition: libmwaw_internal.hxx:1070
MWAWGraphicStyle.hxx
MWAWGraphicShape::ShapeUnknown
@ ShapeUnknown
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::PathData::m_x
MWAWVec2f m_x
the main x value
Definition: MWAWGraphicShape.hxx:83
MWAWGraphicShape::C_Ellipse
@ C_Ellipse
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::PathData::m_x2
MWAWVec2f m_x2
x2 value
Definition: MWAWGraphicShape.hxx:87
MWAWGraphicShape::path
static MWAWGraphicShape path(MWAWBox2f const &box)
static constructor to create a path
Definition: MWAWGraphicShape.hxx:172
MWAWGraphicShape::MWAWGraphicShape
MWAWGraphicShape()
constructor
Definition: MWAWGraphicShape.hxx:99
MWAWTransformation::isIdentity
bool isIdentity() const
returns true if the matrix is an identity matrix
Definition: libmwaw_internal.hxx:1207
MWAWTransformation
a transformation which stored the first row of a 3x3 perspective matrix
Definition: libmwaw_internal.hxx:1196
MWAWGraphicShape::Measure
@ Measure
Definition: MWAWGraphicShape.hxx:49
operator<<
std::ostream & operator<<(std::ostream &o, MWAWGraphicShape::PathData const &path)
Definition: MWAWGraphicShape.cxx:59
MWAWGraphicShape::addTo
Command addTo(MWAWVec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const
updates the propList to send to an interface
Definition: MWAWGraphicShape.cxx:458
MWAWBox2::size
MWAWVec2< T > size() const
the box size
Definition: libmwaw_internal.hxx:1065
MWAWGraphicShape::Arc
@ Arc
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::polyline
static MWAWGraphicShape polyline(MWAWBox2f const &box)
static constructor to create a polyline
Definition: MWAWGraphicShape.hxx:156
MWAWGraphicShape::Type
Type
an enum used to define the shape type
Definition: MWAWGraphicShape.hxx:49
MWAWGraphicShape::getPath
std::vector< PathData > getPath(bool forTransformation) const
return a path corresponding to the shape
Definition: MWAWGraphicShape.cxx:597
MWAWGraphicShape::scale
void scale(MWAWVec2f const &factor)
rescale all the coordinate
Definition: MWAWGraphicShape.cxx:368
MWAWGraphicShape::m_arcAngles
MWAWVec2f m_arcAngles
the start and end value which defines an arc
Definition: MWAWGraphicShape.hxx:223
MWAWGraphicShape::Circle
@ Circle
Definition: MWAWGraphicShape.hxx:49
MWAWBox2< float >
MWAWGraphicShape::PathData
a simple path component
Definition: MWAWGraphicShape.hxx:53
MWAWGraphicShape::rectangle
static MWAWGraphicShape rectangle(MWAWBox2f const &box, MWAWVec2f const &corners=MWAWVec2f(0, 0))
static constructor to create a rectangle
Definition: MWAWGraphicShape.hxx:119
MWAWGraphicShape::C_Rectangle
@ C_Rectangle
Definition: MWAWGraphicShape.hxx:51
MWAWGraphicShape::m_extra
std::string m_extra
extra data
Definition: MWAWGraphicShape.hxx:229
MWAWGraphicShape::m_formBox
MWAWBox2f m_formBox
the internal shape bdbox ( used for arc, circle to store the circle bdbox )
Definition: MWAWGraphicShape.hxx:219

Generated on Sat Mar 21 2020 12:28:17 for libmwaw by doxygen 1.8.17