| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifndef WPS_GRAPHIC_SHAPE |
| 24 |
# define WPS_GRAPHIC_SHAPE |
| 25 |
# include <ostream> |
| 26 |
# include <string> |
| 27 |
# include <vector> |
| 28 |
|
| 29 |
# include "librevenge/librevenge.h" |
| 30 |
|
| 31 |
# include "libwps_internal.h" |
| 32 |
|
| 33 |
|
| 34 |
class WPSGraphicShape |
| 35 |
{ |
| 36 |
public: |
| 37 |
|
| 38 |
enum Type { Arc, Circle, Line, Rectangle, Path, Pie, Polygon, Polyline, ShapeUnknown }; |
| 39 |
|
| 40 |
enum Command { C_Ellipse, C_Polyline, C_Rectangle, C_Path, C_Polygon, C_Bad }; |
| 41 |
|
| 42 |
struct PathData |
| 43 |
{ |
| 44 |
|
| 45 |
explicit PathData(char type, Vec2f const &x=Vec2f(), Vec2f const &x1=Vec2f(), Vec2f const &x2=Vec2f()) |
| 46 |
: m_type(type) |
| 47 |
, m_x(x) |
| 48 |
, m_x1(x1) |
| 49 |
, m_x2(x2) |
| 50 |
, m_r() |
| 51 |
, m_rotate(0) |
| 52 |
, m_largeAngle(false) |
| 53 |
, m_sweep(false) |
| 54 |
{ |
| 55 |
} |
| 56 |
|
| 57 |
void translate(Vec2f const &delta); |
| 58 |
|
| 59 |
void scale(Vec2f const &factor); |
| 60 |
|
| 61 |
void rotate(float angle, Vec2f const &delta); |
| 62 |
|
| 63 |
void transform(WPSTransformation const &matrix, float rotation); |
| 64 |
|
| 65 |
bool get(librevenge::RVNGPropertyList &pList, Vec2f const &orig) const; |
| 66 |
|
| 67 |
friend std::ostream &operator<<(std::ostream &o, PathData const &path); |
| 68 |
|
| 69 |
int cmp(PathData const &a) const; |
| 70 |
|
| 71 |
char m_type; |
| 72 |
|
| 73 |
Vec2f m_x; |
| 74 |
|
| 75 |
Vec2f m_x1; |
| 76 |
|
| 77 |
Vec2f m_x2; |
| 78 |
|
| 79 |
Vec2f m_r; |
| 80 |
|
| 81 |
float m_rotate; |
| 82 |
|
| 83 |
bool m_largeAngle; |
| 84 |
|
| 85 |
bool m_sweep; |
| 86 |
}; |
| 87 |
|
| 88 |
|
| 89 |
WPSGraphicShape() |
| 90 |
: m_type(ShapeUnknown) |
| 91 |
, m_bdBox() |
| 92 |
, m_formBox() |
| 93 |
, m_cornerWidth(0,0) |
| 94 |
, m_arcAngles(0,0) |
| 95 |
, m_vertices() |
| 96 |
, m_path() |
| 97 |
, m_extra("") |
| 98 |
{ |
| 99 |
} |
| 100 |
WPSGraphicShape(WPSGraphicShape const &)=default; |
| 101 |
WPSGraphicShape(WPSGraphicShape &&)=default; |
| 102 |
WPSGraphicShape &operator=(WPSGraphicShape const &)=default; |
| 103 |
WPSGraphicShape &operator=(WPSGraphicShape &&)=default; |
| 104 |
|
| 105 |
~WPSGraphicShape() { } |
| 106 |
|
| 107 |
static WPSGraphicShape line(Vec2f const &orign, Vec2f const &dest); |
| 108 |
|
| 109 |
static WPSGraphicShape rectangle(WPSBox2f const &box, Vec2f const &corners=Vec2f(0,0)) |
| 110 |
{ |
| 111 |
WPSGraphicShape res; |
| 112 |
res.m_type=Rectangle; |
| 113 |
res.m_bdBox=res.m_formBox=box; |
| 114 |
res.m_cornerWidth=corners; |
| 115 |
return res; |
| 116 |
} |
| 117 |
|
| 118 |
static WPSGraphicShape circle(WPSBox2f const &box) |
| 119 |
{ |
| 120 |
WPSGraphicShape res; |
| 121 |
res.m_type=Circle; |
| 122 |
res.m_bdBox=res.m_formBox=box; |
| 123 |
return res; |
| 124 |
} |
| 125 |
|
| 126 |
static WPSGraphicShape arc(WPSBox2f const &box, WPSBox2f const &circleWPSBox, Vec2f const &angles) |
| 127 |
{ |
| 128 |
WPSGraphicShape res; |
| 129 |
res.m_type=Arc; |
| 130 |
res.m_bdBox=box; |
| 131 |
res.m_formBox=circleWPSBox; |
| 132 |
res.m_arcAngles=angles; |
| 133 |
return res; |
| 134 |
} |
| 135 |
|
| 136 |
static WPSGraphicShape pie(WPSBox2f const &box, WPSBox2f const &circleWPSBox, Vec2f const &angles) |
| 137 |
{ |
| 138 |
WPSGraphicShape res; |
| 139 |
res.m_type=Pie; |
| 140 |
res.m_bdBox=box; |
| 141 |
res.m_formBox=circleWPSBox; |
| 142 |
res.m_arcAngles=angles; |
| 143 |
return res; |
| 144 |
} |
| 145 |
|
| 146 |
static WPSGraphicShape polygon(WPSBox2f const &box) |
| 147 |
{ |
| 148 |
WPSGraphicShape res; |
| 149 |
res.m_type=Polygon; |
| 150 |
res.m_bdBox=box; |
| 151 |
return res; |
| 152 |
} |
| 153 |
|
| 154 |
static WPSGraphicShape polyline(WPSBox2f const &box) |
| 155 |
{ |
| 156 |
WPSGraphicShape res; |
| 157 |
res.m_type=Polyline; |
| 158 |
res.m_bdBox=box; |
| 159 |
return res; |
| 160 |
} |
| 161 |
|
| 162 |
static WPSGraphicShape path(WPSBox2f const &box) |
| 163 |
{ |
| 164 |
WPSGraphicShape res; |
| 165 |
res.m_type=Path; |
| 166 |
res.m_bdBox=box; |
| 167 |
return res; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
void translate(Vec2f const &delta); |
| 172 |
|
| 173 |
void scale(Vec2f const &factor); |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
WPSGraphicShape rotate(float angle, Vec2f const ¢er) const; |
| 178 |
|
| 179 |
WPSGraphicShape transform(WPSTransformation const &matrix) const; |
| 180 |
|
| 181 |
Type getType() const |
| 182 |
{ |
| 183 |
return m_type; |
| 184 |
} |
| 185 |
|
| 186 |
WPSBox2f getBdBox() const |
| 187 |
{ |
| 188 |
return m_bdBox; |
| 189 |
} |
| 190 |
|
| 191 |
Command addTo(Vec2f const &orig, bool asSurface, librevenge::RVNGPropertyList &propList) const; |
| 192 |
|
| 193 |
friend std::ostream &operator<<(std::ostream &o, WPSGraphicShape const &sh); |
| 194 |
|
| 195 |
int cmp(WPSGraphicShape const &a) const; |
| 196 |
protected: |
| 197 |
|
| 198 |
std::vector<PathData> getPath(bool forTransformation) const; |
| 199 |
public: |
| 200 |
|
| 201 |
Type m_type; |
| 202 |
|
| 203 |
WPSBox2f m_bdBox; |
| 204 |
|
| 205 |
WPSBox2f m_formBox; |
| 206 |
|
| 207 |
Vec2f m_cornerWidth; |
| 208 |
|
| 209 |
Vec2f m_arcAngles; |
| 210 |
|
| 211 |
std::vector<Vec2f> m_vertices; |
| 212 |
|
| 213 |
std::vector<PathData> m_path; |
| 214 |
|
| 215 |
std::string m_extra; |
| 216 |
}; |
| 217 |
#endif |
| 218 |
|