Debian Codegraph @

src/lib/MWAWGraphicShape.hxx

raw
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 ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
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
44 /** a structure used to define a picture shape */
45 class MWAWGraphicShape
46 {
47 public:
48 //! an enum used to define the shape type
49 enum Type { Arc, Circle, Line, Measure, Rectangle, Path, Pie, Polygon, Polyline, ShapeUnknown };
50 //! an enum used to define the interface command
51 enum Command { C_Ellipse, C_Polyline, C_Rectangle, C_Path, C_Polygon, C_Bad };
52 //! a simple path component
53 struct PathData {
54 //! constructor
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 }
66 //! translate all the coordinate by delta
67 void translate(MWAWVec2f const &delta);
68 //! scale all the coordinate by a factor
69 void scale(MWAWVec2f const &factor);
70 //! rotate all the coordinate by angle (origin rotation) then translate coordinate
71 void rotate(float angle, MWAWVec2f const &delta);
72 //! multiply all the coordinate by a matrix
73 void transform(MWAWTransformation const &matrix, float rotation);
74 //! update the property list to correspond to a command
75 bool get(librevenge::RVNGPropertyList &pList, MWAWVec2f const &orig) const;
76 //! a print operator
77 friend std::ostream &operator<<(std::ostream &o, PathData const &path);
78 //! comparison function
79 int cmp(PathData const &a) const;
80 //! the type: M, L, ...
81 char m_type;
82 //! the main x value
83 MWAWVec2f m_x;
84 //! x1 value
85 MWAWVec2f m_x1;
86 //! x2 value
87 MWAWVec2f m_x2;
88 //! the radius ( A command)
89 MWAWVec2f m_r;
90 //! the rotate ( A command)
91 float m_rotate;
92 //! large angle ( A command)
93 bool m_largeAngle;
94 //! sweep value ( A command)
95 bool m_sweep;
96 };
97
98 //! constructor
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 }
110 MWAWGraphicShape(MWAWGraphicShape const &)=default;
111 MWAWGraphicShape &operator=(MWAWGraphicShape const &)=default;
112 MWAWGraphicShape &operator=(MWAWGraphicShape &&)=default;
113 //! destructor
114 ~MWAWGraphicShape();
115 //! static constructor to create a line
116 static MWAWGraphicShape line(MWAWVec2f const &orign, MWAWVec2f const &dest);
117 //! static constructor to create a measure
118 static MWAWGraphicShape measure(MWAWVec2f const &orign, MWAWVec2f const &dest);
119 //! static constructor to create a rectangle
120 static MWAWGraphicShape rectangle(MWAWBox2f const &box, MWAWVec2f const &corners=MWAWVec2f(0,0))
121 {
122 MWAWGraphicShape res;
123 res.m_type=Rectangle;
124 res.m_bdBox=res.m_formBox=box;
125 res.m_cornerWidth=corners;
126 return res;
127 }
128 //! static constructor to create a circle
129 static MWAWGraphicShape circle(MWAWBox2f const &box)
130 {
131 MWAWGraphicShape res;
132 res.m_type=Circle;
133 res.m_bdBox=res.m_formBox=box;
134 return res;
135 }
136 //! static constructor to create a arc
137 static MWAWGraphicShape arc(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
138 {
139 MWAWGraphicShape res;
140 res.m_type=Arc;
141 res.m_bdBox=box;
142 res.m_formBox=circleBox;
143 res.m_arcAngles=angles;
144 return res;
145 }
146 //! static constructor to create a pie
147 static MWAWGraphicShape pie(MWAWBox2f const &box, MWAWBox2f const &circleBox, MWAWVec2f const &angles)
148 {
149 MWAWGraphicShape res;
150 res.m_type=Pie;
151 res.m_bdBox=box;
152 res.m_formBox=circleBox;
153 res.m_arcAngles=angles;
154 return res;
155 }
156 //! static constructor to create a polyline
157 static MWAWGraphicShape polyline(MWAWBox2f const &box)
158 {
159 MWAWGraphicShape res;
160 res.m_type=Polyline;
161 res.m_bdBox=box;
162 return res;
163 }
164 //! static constructor to create a polygon
165 static MWAWGraphicShape polygon(MWAWBox2f const &box)
166 {
167 MWAWGraphicShape res;
168 res.m_type=Polygon;
169 res.m_bdBox=box;
170 return res;
171 }
172 //! static constructor to create a path
173 static MWAWGraphicShape path(MWAWBox2f const &box)
174 {
175 MWAWGraphicShape res;
176 res.m_type=Path;
177 res.m_bdBox=box;
178 return res;
179 }
180
181 //! translate all the coordinate by delta
182 void translate(MWAWVec2f const &delta);
183 //! rescale all the coordinate
184 void scale(MWAWVec2f const &factor);
185 /** return a new shape corresponding to a rotation from center.
186
187 \note the final bdbox is not tight */
188 MWAWGraphicShape rotate(float angle, MWAWVec2f const &center) const;
189 //! returns a new shape corresponding to a matrix transformation
190 MWAWGraphicShape transform(MWAWTransformation const &matrix) const;
191 //! returns the type corresponding to a shape
192 Type getType() const
193 {
194 return m_type;
195 }
196 //! returns the basic bdbox
197 MWAWBox2f getBdBox() const
198 {
199 return m_bdBox;
200 }
201 //! returns the bdbox corresponding to a style
202 MWAWBox2f getBdBox(MWAWGraphicStyle const &style, bool moveToO=false) const;
203 //! updates the propList to send to an interface
204 Command addTo(MWAWVec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const;
205 //! adds the shape path to a propListVector
206 bool addPathTo(MWAWVec2f const &orig, librevenge::RVNGPropertyListVector &propList) const;
207 //! a print operator
208 friend std::ostream &operator<<(std::ostream &o, MWAWGraphicShape const &sh);
209 /** compare two shapes */
210 int cmp(MWAWGraphicShape const &a) const;
211
212 // -----------------------------
213 // low level
214 // -----------------------------
215
216 //! return a path corresponding to the shape
217 std::vector<PathData> getPath(bool forTransformation) const;
218 //! try to decal each path point by an offset (using their normal)
219 static std::vector<PathData> offsetVertices(std::vector<PathData> const &path, float offset, MWAWBox2f &finalBox);
220 public:
221 //! the type
222 Type m_type;
223 //! the shape bdbox
224 MWAWBox2f m_bdBox;
225 //! the internal shape bdbox ( used for arc, circle to store the circle bdbox )
226 MWAWBox2f m_formBox;
227 //! the rectangle round corner
228 MWAWVec2f m_cornerWidth;
229 //! the start and end value which defines an arc
230 MWAWVec2f m_arcAngles;
231 //! the list of vertices for lines or polygons
232 std::vector<MWAWVec2f> m_vertices;
233 //! the list of path component
234 std::vector<PathData> m_path;
235 //! extra data
236 std::string m_extra;
237 };
238 #endif
239 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: