MWAWGraphicShape.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
#ifndef MWAW_GRAPHIC_SHAPE
# define MWAW_GRAPHIC_SHAPE
# include <ostream>
# include <string>
# include <vector>
# include "librevenge/librevenge.h"
# include "libmwaw_internal.hxx"
class MWAWGraphicStyle;
class MWAWGraphicShape
{
public:
enum Type { Arc, Circle, Line, Measure, Rectangle, Path, Pie, Polygon, Polyline, ShapeUnknown };
enum Command { C_Ellipse, C_Polyline, C_Rectangle, C_Path, C_Polygon, C_Bad };
struct PathData {
explicit PathData(char type, MWAWVec2f const &x=MWAWVec2f(), MWAWVec2f const &x1=MWAWVec2f(), MWAWVec2f const &x2=MWAWVec2f())
: m_type(type)
, m_x(x)
, m_x1(x1)
, m_x2(x2)
, m_r()
, m_rotate(0)
, m_largeAngle(false)
, m_sweep(false)
{
}
void translate(MWAWVec2f const &delta);
void scale(MWAWVec2f const &factor);
void rotate(float angle, MWAWVec2f const &delta);
void transform(MWAWTransformation const &matrix, float rotation);
bool get(librevenge::RVNGPropertyList &pList, MWAWVec2f const &orig) const;
friend std::ostream &operator<<(std::ostream &o, PathData const &path);
int cmp(PathData const &a) const;
char m_type;
MWAWVec2f m_x;
MWAWVec2f m_x1;
MWAWVec2f m_x2;
MWAWVec2f m_r;
float m_rotate;
bool m_largeAngle;
bool m_sweep;
};
MWAWGraphicShape()
: m_type(ShapeUnknown)
, m_bdBox()
, m_formBox()
, m_cornerWidth(0,0)
, m_arcAngles(0,0)
, m_vertices()
, m_path()
, m_extra("")
{
}
MWAWGraphicShape(MWAWGraphicShape const &)=default;
MWAWGraphicShape &operator=(MWAWGraphicShape const &)=default;
MWAWGraphicShape &operator=(MWAWGraphicShape &&)=default;
~MWAWGraphicShape();
static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest);
static MWAWGraphicShape measure(MWAWVec2f const &orign, MWAWVec2f const &dest);
static MWAWGraphicShape rectangle(MWAWBox2f const &box, MWAWVec2f const &corners=MWAWVec2f(0,0))
{
MWAWGraphicShape res;
res.m_type=Rectangle;
res.m_bdBox=res.m_formBox=box;
res.m_cornerWidth=corners;
return res;
}
static MWAWGraphicShape circle(MWAWBox2f const &box)
{
MWAWGraphicShape res;
res.m_type=Circle;
res.m_bdBox=res.m_formBox=box;
return res;
}
static MWAWGraphicShape arc(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
{
MWAWGraphicShape res;
res.m_type=Arc;
res.m_bdBox=box;
res.m_formBox=circleBox;
res.m_arcAngles=angles;
return res;
}
static MWAWGraphicShape pie(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
{
MWAWGraphicShape res;
res.m_type=Pie;
res.m_bdBox=box;
res.m_formBox=circleBox;
res.m_arcAngles=angles;
return res;
}
static MWAWGraphicShape polyline(MWAWBox2f const &box)
{
MWAWGraphicShape res;
res.m_type=Polyline;
res.m_bdBox=box;
return res;
}
static MWAWGraphicShape polygon(MWAWBox2f const &box)
{
MWAWGraphicShape res;
res.m_type=Polygon;
res.m_bdBox=box;
return res;
}
static MWAWGraphicShape path(MWAWBox2f const &box)
{
MWAWGraphicShape res;
res.m_type=Path;
res.m_bdBox=box;
return res;
}
void translate(MWAWVec2f const &delta);
void scale(MWAWVec2f const &factor);
MWAWGraphicShape rotate(float angle, MWAWVec2f const &center) const;
MWAWGraphicShape transform(MWAWTransformation const &matrix) const;
Type getType() const
{
return m_type;
}
MWAWBox2f getBdBox() const
{
return m_bdBox;
}
MWAWBox2f getBdBox(MWAWGraphicStyle const &style, bool moveToO=false) const;
Command addTo(MWAWVec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const;
bool addPathTo(MWAWVec2f const &orig, librevenge::RVNGPropertyListVector &propList) const;
friend std::ostream &operator<<(std::ostream &o, MWAWGraphicShape const &sh);
int cmp(MWAWGraphicShape const &a) const;
// -----------------------------
// low level
// -----------------------------
std::vector<PathData> getPath(bool forTransformation) const;
static std::vector<PathData> offsetVertices(std::vector<PathData> const &path, float offset, MWAWBox2f &finalBox);
public:
Type m_type;
MWAWBox2f m_bdBox;
MWAWBox2f m_formBox;
MWAWVec2f m_cornerWidth;
MWAWVec2f m_arcAngles;
std::vector<MWAWVec2f> m_vertices;
std::vector<PathData> m_path;
std::string m_extra;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWGraphicShape
a structure used to define a picture shape
Definition MWAWGraphicShape.hxx:46
MWAWGraphicShape::m_formBox
MWAWBox2f m_formBox
the internal shape bdbox ( used for arc, circle to store the circle bdbox )
Definition MWAWGraphicShape.hxx:226
MWAWGraphicShape::operator=
MWAWGraphicShape & operator=(MWAWGraphicShape const &)=default
MWAWGraphicShape::m_arcAngles
MWAWVec2f m_arcAngles
the start and end value which defines an arc
Definition MWAWGraphicShape.hxx:230
MWAWGraphicShape::cmp
int cmp(MWAWGraphicShape const &a) const
compare two shapes
Definition MWAWGraphicShape.cxx:314
MWAWGraphicShape::polygon
static MWAWGraphicShape polygon(MWAWBox2f const &box)
static constructor to create a polygon
Definition MWAWGraphicShape.hxx:165
MWAWGraphicShape::m_vertices
std::vector< MWAWVec2f > m_vertices
the list of vertices for lines or polygons
Definition MWAWGraphicShape.hxx:232
MWAWGraphicShape::MWAWGraphicShape
MWAWGraphicShape()
constructor
Definition MWAWGraphicShape.hxx:99
MWAWGraphicShape::arc
static MWAWGraphicShape arc(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
static constructor to create a arc
Definition MWAWGraphicShape.hxx:137
MWAWGraphicShape::pie
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 & operator=(MWAWGraphicShape &&)=default
MWAWGraphicShape::rectangle
static MWAWGraphicShape rectangle(MWAWBox2f const &box, MWAWVec2f const &corners=MWAWVec2f(0, 0))
static constructor to create a rectangle
Definition MWAWGraphicShape.hxx:120
MWAWGraphicShape::polyline
static MWAWGraphicShape polyline(MWAWBox2f const &box)
static constructor to create a polyline
Definition MWAWGraphicShape.hxx:157
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
MWAWGraphicShape::scale
void scale(MWAWVec2f const &factor)
rescale all the coordinate
Definition MWAWGraphicShape.cxx:368
MWAWGraphicShape::getPath
std::vector< PathData > getPath(bool forTransformation) const
return a path corresponding to the shape
Definition MWAWGraphicShape.cxx:597
MWAWGraphicShape::line
static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest)
static constructor to create a line
Definition MWAWGraphicShape.cxx:228
MWAWGraphicShape::addPathTo
bool addPathTo(MWAWVec2f const &orig, librevenge::RVNGPropertyListVector &propList) const
adds the shape path to a propListVector
Definition MWAWGraphicShape.cxx:434
MWAWGraphicShape::Type
Type
an enum used to define the shape type
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::Pie
@ Pie
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::Path
@ Path
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::ShapeUnknown
@ ShapeUnknown
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::Line
@ Line
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::Measure
@ Measure
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::Rectangle
@ Rectangle
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::Circle
@ Circle
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::Polyline
@ Polyline
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::Polygon
@ Polygon
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::Arc
@ Arc
Definition MWAWGraphicShape.hxx:49
MWAWGraphicShape::m_cornerWidth
MWAWVec2f m_cornerWidth
the rectangle round corner
Definition MWAWGraphicShape.hxx:228
MWAWGraphicShape::translate
void translate(MWAWVec2f const &delta)
translate all the coordinate by delta
Definition MWAWGraphicShape.cxx:356
MWAWGraphicShape::path
static MWAWGraphicShape path(MWAWBox2f const &box)
static constructor to create a path
Definition MWAWGraphicShape.hxx:173
MWAWGraphicShape::m_type
Type m_type
the type
Definition MWAWGraphicShape.hxx:222
MWAWGraphicShape::m_bdBox
MWAWBox2f m_bdBox
the shape bdbox
Definition MWAWGraphicShape.hxx:224
MWAWGraphicShape::offsetVertices
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
MWAWGraphicShape::getType
Type getType() const
returns the type corresponding to a shape
Definition MWAWGraphicShape.hxx:192
MWAWGraphicShape::Command
Command
an enum used to define the interface command
Definition MWAWGraphicShape.hxx:51
MWAWGraphicShape::C_Rectangle
@ C_Rectangle
Definition MWAWGraphicShape.hxx:51
MWAWGraphicShape::C_Bad
@ C_Bad
Definition MWAWGraphicShape.hxx:51
MWAWGraphicShape::C_Polygon
@ C_Polygon
Definition MWAWGraphicShape.hxx:51
MWAWGraphicShape::C_Ellipse
@ C_Ellipse
Definition MWAWGraphicShape.hxx:51
MWAWGraphicShape::C_Polyline
@ C_Polyline
Definition MWAWGraphicShape.hxx:51
MWAWGraphicShape::C_Path
@ C_Path
Definition MWAWGraphicShape.hxx:51
MWAWGraphicShape::m_path
std::vector< PathData > m_path
the list of path component
Definition MWAWGraphicShape.hxx:234
MWAWGraphicShape::rotate
MWAWGraphicShape rotate(float angle, MWAWVec2f const &center) const
return a new shape corresponding to a rotation from center.
Definition MWAWGraphicShape.cxx:381
MWAWGraphicShape::m_extra
std::string m_extra
extra data
Definition MWAWGraphicShape.hxx:236
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::getBdBox
MWAWBox2f getBdBox() const
returns the basic bdbox
Definition MWAWGraphicShape.hxx:197
MWAWGraphicShape::MWAWGraphicShape
MWAWGraphicShape(MWAWGraphicShape const &)=default
MWAWGraphicShape::circle
static MWAWGraphicShape circle(MWAWBox2f const &box)
static constructor to create a circle
Definition MWAWGraphicShape.hxx:129
MWAWGraphicShape::transform
MWAWGraphicShape transform(MWAWTransformation const &matrix) const
returns a new shape corresponding to a matrix transformation
Definition MWAWGraphicShape.cxx:404
MWAWGraphicShape::~MWAWGraphicShape
~MWAWGraphicShape()
destructor
Definition MWAWGraphicShape.cxx:224
MWAWGraphicStyle
a structure used to define a picture style
Definition MWAWGraphicStyle.hxx:48
MWAWTransformation
a transformation which stored the first row of a 3x3 perspective matrix
Definition libmwaw_internal.hxx:1199
libmwaw_internal.hxx
MWAWBox2f
MWAWBox2< float > MWAWBox2f
MWAWBox2 of float.
Definition libmwaw_internal.hxx:1193
MWAWVec2f
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition libmwaw_internal.hxx:842
MWAWGraphicShape::PathData
a simple path component
Definition MWAWGraphicShape.hxx:53
MWAWGraphicShape::PathData::m_rotate
float m_rotate
the rotate ( A command)
Definition MWAWGraphicShape.hxx:91
MWAWGraphicShape::PathData::m_type
char m_type
the type: M, L, ...
Definition MWAWGraphicShape.hxx:81
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::PathData::rotate
void rotate(float angle, MWAWVec2f const &delta)
rotate all the coordinate by angle (origin rotation) then translate coordinate
Definition MWAWGraphicShape.cxx:121
MWAWGraphicShape::PathData::translate
void translate(MWAWVec2f const &delta)
translate all the coordinate by delta
Definition MWAWGraphicShape.cxx:95
MWAWGraphicShape::PathData::scale
void scale(MWAWVec2f const &factor)
scale all the coordinate by a factor
Definition MWAWGraphicShape.cxx:108
MWAWGraphicShape::PathData::m_sweep
bool m_sweep
sweep value ( A command)
Definition MWAWGraphicShape.hxx:95
MWAWGraphicShape::PathData::cmp
int cmp(PathData const &a) const
comparison function
Definition MWAWGraphicShape.cxx:200
MWAWGraphicShape::PathData::transform
void transform(MWAWTransformation const &matrix, float rotation)
multiply all the coordinate by a matrix
Definition MWAWGraphicShape.cxx:142
MWAWGraphicShape::PathData::m_largeAngle
bool m_largeAngle
large angle ( A command)
Definition MWAWGraphicShape.hxx:93
MWAWGraphicShape::PathData::m_r
MWAWVec2f m_r
the radius ( A command)
Definition MWAWGraphicShape.hxx:89
MWAWGraphicShape::PathData::operator<<
friend std::ostream & operator<<(std::ostream &o, PathData const &path)
a print operator
Definition MWAWGraphicShape.cxx:59
MWAWGraphicShape::PathData::m_x1
MWAWVec2f m_x1
x1 value
Definition MWAWGraphicShape.hxx:85
MWAWGraphicShape::PathData::m_x
MWAWVec2f m_x
the main x value
Definition MWAWGraphicShape.hxx:83
MWAWGraphicShape::PathData::m_x2
MWAWVec2f m_x2
x2 value
Definition MWAWGraphicShape.hxx:87
MWAWGraphicShape::PathData::PathData
PathData(char type, MWAWVec2f const &x=MWAWVec2f(), MWAWVec2f const &x1=MWAWVec2f(), MWAWVec2f const &x2=MWAWVec2f())
constructor
Definition MWAWGraphicShape.hxx:55