- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

WPSGraphicStyle.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
3 /* libwps
4 * Version: MPL 2.0 / LGPLv2.1+
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 *
10 * Major Contributor(s):
11 * Copyright (C) 2002, 2005 William Lachance (william.lachance@sympatico.ca)
12 * Copyright (C) 2002, 2004 Marc Maurer (uwog@uwog.net)
13 *
14 * For minor contributions see the git repository.
15 *
16 * Alternatively, the contents of this file may be used under the terms
17 * of the GNU Lesser General Public License Version 2.1 or later
18 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19 * applicable instead of those above.
20 *
21 * For further information visit http://libwps.sourceforge.net
22 */
23 #ifndef WPS_GRAPHIC_STYLE
24 # define WPS_GRAPHIC_STYLE
25 # include <ostream>
26 # include <string>
27 # include <vector>
28
29 # include "librevenge/librevenge.h"
30 # include "libwps_internal.h"
31
37 class WPSGraphicStyle
38 {
39 public:
41 enum LineCap { C_Butt, C_Square, C_Round };
43 enum LineJoin { J_Miter, J_Round, J_Bevel };
45 enum GradientType { G_None, G_Axial, G_Linear, G_Radial, G_Rectangular, G_Square, G_Ellipsoid };
46
48 struct GradientStop
49 {
51 GradientStop(float offset=0.0, WPSColor const &col=WPSColor::black(), float opacity=1.0) :
52 m_offset(offset), m_color(col), m_opacity(opacity)
53 {
54 }
56 int cmp(GradientStop const &a) const
57 {
58 if (m_offset < a.m_offset) return -1;
59 if (m_offset > a.m_offset) return 1;
60 if (m_color < a.m_color) return -1;
61 if (m_color > a.m_color) return 1;
62 if (m_opacity < a.m_opacity) return -1;
63 if (m_opacity > a.m_opacity) return 1;
64 return 0;
65 }
67 friend std::ostream &operator<<(std::ostream &o, GradientStop const &st)
68 {
69 o << "offset=" << st.m_offset << ",";
70 o << "color=" << st.m_color << ",";
71 if (st.m_opacity<1.0)
72 o << "opacity=" << st.m_opacity*100.f << "%,";
73 return o;
74 }
76 float m_offset;
78 WPSColor m_color;
80 float m_opacity;
81 };
86 struct Pattern
87 {
89 Pattern() : m_dim(0,0), m_data(), m_picture(), m_pictureMime(""), m_pictureAverageColor(WPSColor::white())
90 {
91 m_colors[0]=WPSColor::black();
92 m_colors[1]=WPSColor::white();
93 }
95 Pattern(Vec2i dim, librevenge::RVNGBinaryData const &picture, std::string const &mime, WPSColor const &avColor) :
96 m_dim(dim), m_data(), m_picture(picture), m_pictureMime(mime), m_pictureAverageColor(avColor)
97 {
98 m_colors[0]=WPSColor::black();
99 m_colors[1]=WPSColor::white();
100 }
102 virtual ~Pattern() {}
104 bool empty() const
105 {
106 if (m_dim[0]==0 || m_dim[1]==0) return true;
107 if (m_picture.size()) return false;
108 if (m_dim[0]!=8 && m_dim[0]!=16 && m_dim[0]!=32) return true;
109 return m_data.size()!=size_t((m_dim[0]/8)*m_dim[1]);
110 }
112 bool getAverageColor(WPSColor &col) const;
114 bool getUniqueColor(WPSColor &col) const;
116 bool getBinary(librevenge::RVNGBinaryData &data, std::string &type) const;
117
119 int cmp(Pattern const &a) const
120 {
121 int diff = m_dim.cmp(a.m_dim);
122 if (diff) return diff;
123 if (m_data.size() < a.m_data.size()) return -1;
124 if (m_data.size() > a.m_data.size()) return 1;
125 for (size_t h=0; h < m_data.size(); ++h)
126 {
127 if (m_data[h]<a.m_data[h]) return 1;
128 if (m_data[h]>a.m_data[h]) return -1;
129 }
130 for (int i=0; i<2; ++i)
131 {
132 if (m_colors[i] < a.m_colors[i]) return 1;
133 if (m_colors[i] > a.m_colors[i]) return -1;
134 }
135 if (m_pictureAverageColor < a.m_pictureAverageColor) return 1;
136 if (m_pictureAverageColor > a.m_pictureAverageColor) return -1;
137 if (m_pictureMime < a.m_pictureMime) return 1;
138 if (m_pictureMime > a.m_pictureMime) return -1;
139 if (m_picture.size() < a.m_picture.size()) return 1;
140 if (m_picture.size() > a.m_picture.size()) return -1;
141 const unsigned char *ptr=m_picture.getDataBuffer();
142 const unsigned char *aPtr=a.m_picture.getDataBuffer();
143 if (!ptr || !aPtr) return 0; // must only appear if the two buffers are empty
144 for (unsigned long h=0; h < m_picture.size(); ++h, ++ptr, ++aPtr)
145 {
146 if (*ptr < *aPtr) return 1;
147 if (*ptr > *aPtr) return -1;
148 }
149 return 0;
150 }
152 friend std::ostream &operator<<(std::ostream &o, Pattern const &pat)
153 {
154 o << "dim=" << pat.m_dim << ",";
155 if (pat.m_picture.size())
156 {
157 o << "type=" << pat.m_pictureMime << ",";
158 o << "col[average]=" << pat.m_pictureAverageColor << ",";
159 }
160 else
161 {
162 if (!pat.m_colors[0].isBlack()) o << "col0=" << pat.m_colors[0] << ",";
163 if (!pat.m_colors[1].isWhite()) o << "col1=" << pat.m_colors[1] << ",";
164 o << "[";
165 for (size_t h=0; h < pat.m_data.size(); ++h)
166 o << std::hex << (int) pat.m_data[h] << std::dec << ",";
167 o << "],";
168 }
169 return o;
170 }
172 Vec2i m_dim;
173
175 WPSColor m_colors[2];
177 std::vector<unsigned char> m_data;
178 protected:
180 librevenge::RVNGBinaryData m_picture;
182 std::string m_pictureMime;
184 WPSColor m_pictureAverageColor;
185 };
187 WPSGraphicStyle() : m_lineWidth(1), m_lineDashWidth(), m_lineCap(C_Butt), m_lineJoin(J_Miter), m_lineOpacity(1), m_lineColor(WPSColor::black()),
188 m_fillRuleEvenOdd(false), m_surfaceColor(WPSColor::white()), m_surfaceOpacity(0),
189 m_shadowColor(WPSColor::black()), m_shadowOpacity(0), m_shadowOffset(1,1),
190 m_pattern(),
191 m_gradientType(G_None), m_gradientStopList(), m_gradientAngle(0), m_gradientBorder(0), m_gradientPercentCenter(0.5f,0.5f), m_gradientRadius(1),
192 m_backgroundColor(WPSColor::white()), m_backgroundOpacity(-1), m_bordersList(), m_frameName(""), m_frameNextName(""),
193 m_rotate(0), m_extra("")
194 {
195 m_arrows[0]=m_arrows[1]=false;
196 m_flip[0]=m_flip[1]=false;
197 m_gradientStopList.push_back(GradientStop(0.0, WPSColor::white()));
198 m_gradientStopList.push_back(GradientStop(1.0, WPSColor::black()));
199 }
201 static WPSGraphicStyle emptyStyle()
202 {
203 WPSGraphicStyle res;
204 res.m_lineWidth=0;
205 return res;
206 }
208 virtual ~WPSGraphicStyle() { }
210 bool hasLine() const
211 {
212 return m_lineWidth>0 && m_lineOpacity>0;
213 }
215 void setSurfaceColor(WPSColor const &col, float opacity = 1)
216 {
217 m_surfaceColor = col;
218 m_surfaceOpacity = opacity;
219 }
221 bool hasSurfaceColor() const
222 {
223 return m_surfaceOpacity > 0;
224 }
226 void setPattern(Pattern const &pat)
227 {
228 m_pattern=pat;
229 }
231 bool hasPattern() const
232 {
233 return !m_pattern.empty();
234 }
236 bool hasGradient(bool complex=false) const
237 {
238 return m_gradientType != G_None && (int) m_gradientStopList.size() >= (complex ? 3 : 2);
239 }
241 bool hasSurface() const
242 {
243 return hasSurfaceColor() || hasPattern() || hasGradient();
244 }
246 void setBackgroundColor(WPSColor const &col, float opacity = 1)
247 {
248 m_backgroundColor = col;
249 m_backgroundOpacity = opacity;
250 }
252 bool hasBackgroundColor() const
253 {
254 return m_backgroundOpacity > 0;
255 }
257 void setShadowColor(WPSColor const &col, float opacity = 1)
258 {
259 m_shadowColor = col;
260 m_shadowOpacity = opacity;
261 }
263 bool hasShadow() const
264 {
265 return m_shadowOpacity > 0;
266 }
268 bool hasBorders() const
269 {
270 return !m_bordersList.empty();
271 }
273 bool hasSameBorders() const
274 {
275 if (m_bordersList.empty()) return true;
276 if (m_bordersList.size()!=4) return false;
277 for (size_t i=1; i<m_bordersList.size(); ++i)
278 {
279 if (m_bordersList[i]!=m_bordersList[0])
280 return false;
281 }
282 return true;
283 }
285 std::vector<WPSBorder> const &borders() const
286 {
287 return m_bordersList;
288 }
290 void resetBorders()
291 {
292 m_bordersList.resize(0);
293 }
295 void setBorders(int wh, WPSBorder const &border);
297 friend std::ostream &operator<<(std::ostream &o, WPSGraphicStyle const &st);
299 void addTo(librevenge::RVNGPropertyList &pList, bool only1d=false) const;
301 void addFrameTo(librevenge::RVNGPropertyList &pList) const;
303 int cmp(WPSGraphicStyle const &a) const;
304
306 float m_lineWidth;
308 std::vector<float> m_lineDashWidth;
310 LineCap m_lineCap;
312 LineJoin m_lineJoin;
314 float m_lineOpacity;
316 WPSColor m_lineColor;
318 bool m_fillRuleEvenOdd;
320 WPSColor m_surfaceColor;
322 float m_surfaceOpacity;
323
325 WPSColor m_shadowColor;
327 float m_shadowOpacity;
329 Vec2f m_shadowOffset;
330
332 Pattern m_pattern;
333
335 GradientType m_gradientType;
337 std::vector<GradientStop> m_gradientStopList;
339 float m_gradientAngle;
341 float m_gradientBorder;
343 Vec2f m_gradientPercentCenter;
345 float m_gradientRadius;
346
348 bool m_arrows[2];
349
350 //
351 // related to the frame
352 //
353
355 WPSColor m_backgroundColor;
357 float m_backgroundOpacity;
359 std::vector<WPSBorder> m_bordersList;
361 std::string m_frameName;
363 std::string m_frameNextName;
364
365 //
366 // some transformation: must probably be somewhere else
367 //
368
370 float m_rotate;
372 bool m_flip[2];
373
375 std::string m_extra;
376 };
377 #endif
378 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPSGraphicStyle::~WPSGraphicStyle
virtual ~WPSGraphicStyle()
virtual destructor
Definition: WPSGraphicStyle.h:208
WPSGraphicStyle::m_flip
bool m_flip[2]
two bool to indicated we need to flip the shape or not
Definition: WPSGraphicStyle.h:372
WPSGraphicStyle::GradientStop
a structure used to define the gradient limit
Definition: WPSGraphicStyle.h:48
WPSGraphicStyle::Pattern::m_pictureMime
std::string m_pictureMime
the picture type
Definition: WPSGraphicStyle.h:182
WPSGraphicStyle::hasGradient
bool hasGradient(bool complex=false) const
returns true if the gradient is defined
Definition: WPSGraphicStyle.h:236
WPSGraphicStyle::hasSurface
bool hasSurface() const
returns true if the interior surface is defined
Definition: WPSGraphicStyle.h:241
WPSGraphicStyle::m_shadowOffset
Vec2f m_shadowOffset
the shadow offset
Definition: WPSGraphicStyle.h:329
WPSBorder
a border list
Definition: libwps_internal.h:372
WPSGraphicStyle::m_surfaceOpacity
float m_surfaceOpacity
true if the surface has some color
Definition: WPSGraphicStyle.h:322
WPSGraphicStyle::G_Square
Definition: WPSGraphicStyle.h:45
WPSGraphicStyle::m_lineJoin
LineJoin m_lineJoin
the line join
Definition: WPSGraphicStyle.h:312
WPSGraphicStyle::hasBackgroundColor
bool hasBackgroundColor() const
returns true if the background is defined
Definition: WPSGraphicStyle.h:252
WPSGraphicStyle::m_shadowOpacity
float m_shadowOpacity
true if the shadow has some color
Definition: WPSGraphicStyle.h:327
WPSGraphicStyle::Pattern::m_data
std::vector< unsigned char > m_data
the pattern data: a sequence of data: p[0..7,0],p[8..15,0]...p[0..7,1],p[8..15,1], ...
Definition: WPSGraphicStyle.h:177
WPSGraphicStyle::Pattern::empty
bool empty() const
return true if we does not have a pattern
Definition: WPSGraphicStyle.h:104
WPSGraphicStyle::m_rotate
float m_rotate
the rotation
Definition: WPSGraphicStyle.h:370
WPSGraphicStyle::m_lineCap
LineCap m_lineCap
the line cap
Definition: WPSGraphicStyle.h:310
WPSGraphicStyle::J_Round
Definition: WPSGraphicStyle.h:43
WPSGraphicStyle::G_Rectangular
Definition: WPSGraphicStyle.h:45
WPSGraphicStyle::G_None
Definition: WPSGraphicStyle.h:45
WPSGraphicStyle::hasBorders
bool hasBorders() const
return true if the frame has some border
Definition: WPSGraphicStyle.h:268
WPSGraphicStyle::Pattern::m_pictureAverageColor
WPSColor m_pictureAverageColor
the picture average color
Definition: WPSGraphicStyle.h:184
WPSColor::black
static WPSColor black()
return the back color
Definition: libwps_internal.h:284
WPSGraphicStyle::setBorders
void setBorders(int wh, WPSBorder const &border)
sets the cell border: wh=libwps::LeftBit|...
Definition: WPSGraphicStyle.cpp:136
WPSGraphicStyle::m_bordersList
std::vector< WPSBorder > m_bordersList
the borders WPSBorder::Pos (for a frame)
Definition: WPSGraphicStyle.h:359
WPSColor::white
static WPSColor white()
return the white color
Definition: libwps_internal.h:289
WPSGraphicStyle::G_Axial
Definition: WPSGraphicStyle.h:45
WPSGraphicStyle::m_lineDashWidth
std::vector< float > m_lineDashWidth
the dash array: a sequence of (fullsize, emptysize)
Definition: WPSGraphicStyle.h:308
WPSGraphicStyle::GradientStop::m_opacity
float m_opacity
the opacity
Definition: WPSGraphicStyle.h:80
WPSGraphicStyle::Pattern::~Pattern
virtual ~Pattern()
virtual destructor
Definition: WPSGraphicStyle.h:102
WPSColor::isBlack
bool isBlack() const
return true if the color is black
Definition: libwps_internal.h:323
WPSGraphicStyle::J_Miter
Definition: WPSGraphicStyle.h:43
WPSGraphicStyle::hasSameBorders
bool hasSameBorders() const
return true if the frame has some border
Definition: WPSGraphicStyle.h:273
WPSGraphicStyle::setSurfaceColor
void setSurfaceColor(WPSColor const &col, float opacity=1)
set the surface color
Definition: WPSGraphicStyle.h:215
WPSGraphicStyle::m_gradientAngle
float m_gradientAngle
the gradient angle
Definition: WPSGraphicStyle.h:339
WPSGraphicStyle::Pattern::m_dim
Vec2i m_dim
the dimension width x height
Definition: WPSGraphicStyle.h:172
WPSGraphicStyle::m_gradientRadius
float m_gradientRadius
the gradient radius
Definition: WPSGraphicStyle.h:345
WPSGraphicStyle::Pattern::Pattern
Pattern(Vec2i dim, librevenge::RVNGBinaryData const &picture, std::string const &mime, WPSColor const &avColor)
constructor from a binary data
Definition: WPSGraphicStyle.h:95
WPSGraphicStyle
a structure used to define a picture style
Definition: WPSGraphicStyle.h:37
WPSGraphicStyle::borders
std::vector< WPSBorder > const & borders() const
return the frame border: libwps::Left | ...
Definition: WPSGraphicStyle.h:285
WPSGraphicStyle::Pattern::cmp
int cmp(Pattern const &a) const
compare two patterns
Definition: WPSGraphicStyle.h:119
WPSGraphicStyle::m_gradientPercentCenter
Vec2f m_gradientPercentCenter
the gradient center
Definition: WPSGraphicStyle.h:343
WPSGraphicStyle::m_frameName
std::string m_frameName
the frame name
Definition: WPSGraphicStyle.h:361
WPSGraphicStyle::emptyStyle
static WPSGraphicStyle emptyStyle()
returns an empty style.
Definition: WPSGraphicStyle.h:201
libwps_internal.h
WPSGraphicStyle::Pattern::m_picture
librevenge::RVNGBinaryData m_picture
a picture
Definition: WPSGraphicStyle.h:180
WPSGraphicStyle::LineJoin
LineJoin
an enum used to define the basic line join
Definition: WPSGraphicStyle.h:43
WPSGraphicStyle::setPattern
void setPattern(Pattern const &pat)
set the pattern
Definition: WPSGraphicStyle.h:226
WPSGraphicStyle::m_pattern
Pattern m_pattern
the pattern if it exists
Definition: WPSGraphicStyle.h:332
WPSColor::isWhite
bool isWhite() const
return true if the color is white
Definition: libwps_internal.h:328
WPSGraphicStyle::m_shadowColor
WPSColor m_shadowColor
the shadow color
Definition: WPSGraphicStyle.h:325
WPSGraphicStyle::hasPattern
bool hasPattern() const
returns true if the pattern is defined
Definition: WPSGraphicStyle.h:231
WPSGraphicStyle::hasLine
bool hasLine() const
returns true if the border is defined
Definition: WPSGraphicStyle.h:210
WPSGraphicStyle::addFrameTo
void addFrameTo(librevenge::RVNGPropertyList &pList) const
add all the frame parameters to propList: the background and the borders
Definition: WPSGraphicStyle.cpp:361
WPSGraphicStyle::GradientStop::cmp
int cmp(GradientStop const &a) const
compare two gradient
Definition: WPSGraphicStyle.h:56
WPSGraphicStyle::m_lineOpacity
float m_lineOpacity
the line opacity: 0=transparent
Definition: WPSGraphicStyle.h:314
WPSGraphicStyle::GradientStop::m_offset
float m_offset
the offset
Definition: WPSGraphicStyle.h:76
WPSGraphicStyle::Pattern::m_colors
WPSColor m_colors[2]
the two indexed colors
Definition: WPSGraphicStyle.h:175
WPSGraphicStyle::m_extra
std::string m_extra
extra data
Definition: WPSGraphicStyle.h:375
WPSGraphicStyle::G_Ellipsoid
Definition: WPSGraphicStyle.h:45
WPSGraphicStyle::m_gradientStopList
std::vector< GradientStop > m_gradientStopList
the list of gradient limits
Definition: WPSGraphicStyle.h:337
WPSGraphicStyle::m_fillRuleEvenOdd
bool m_fillRuleEvenOdd
true if the fill rule is evenod
Definition: WPSGraphicStyle.h:318
WPSGraphicStyle::m_backgroundColor
WPSColor m_backgroundColor
the background color
Definition: WPSGraphicStyle.h:355
WPSGraphicStyle::GradientStop::m_color
WPSColor m_color
the color
Definition: WPSGraphicStyle.h:78
WPSGraphicStyle::hasShadow
bool hasShadow() const
returns true if the shadow is defined
Definition: WPSGraphicStyle.h:263
WPSColor
the class to store a color
Definition: libwps_internal.h:266
WPSGraphicStyle::m_surfaceColor
WPSColor m_surfaceColor
the surface color
Definition: WPSGraphicStyle.h:320
WPSGraphicStyle::Pattern::Pattern
Pattern()
constructor
Definition: WPSGraphicStyle.h:89
WPSGraphicStyle::J_Bevel
Definition: WPSGraphicStyle.h:43
WPSGraphicStyle::addTo
void addTo(librevenge::RVNGPropertyList &pList, bool only1d=false) const
add all the parameters to the propList excepted the frame parameter: the background and the borders ...
Definition: WPSGraphicStyle.cpp:157
WPSGraphicStyle::C_Butt
Definition: WPSGraphicStyle.h:41
WPSGraphicStyle::m_arrows
bool m_arrows[2]
two bool to indicated if extremity has arrow or not
Definition: WPSGraphicStyle.h:348
WPSGraphicStyle::m_lineColor
WPSColor m_lineColor
the line color
Definition: WPSGraphicStyle.h:316
WPSGraphicStyle::m_backgroundOpacity
float m_backgroundOpacity
true if the background has some color
Definition: WPSGraphicStyle.h:357
WPSGraphicStyle::m_gradientBorder
float m_gradientBorder
the gradient border opacity
Definition: WPSGraphicStyle.h:341
WPSGraphicStyle::Pattern::operator<<
friend std::ostream & operator<<(std::ostream &o, Pattern const &pat)
a print operator
Definition: WPSGraphicStyle.h:152
WPSGraphicStyle::C_Round
Definition: WPSGraphicStyle.h:41
WPSGraphicStyle::GradientStop::GradientStop
GradientStop(float offset=0.0, WPSColor const &col=WPSColor::black(), float opacity=1.0)
constructor
Definition: WPSGraphicStyle.h:51
WPSGraphicStyle::LineCap
LineCap
an enum used to define the basic line cap
Definition: WPSGraphicStyle.h:41
WPSGraphicStyle::hasSurfaceColor
bool hasSurfaceColor() const
returns true if the surface is defined
Definition: WPSGraphicStyle.h:221
WPSGraphicStyle::WPSGraphicStyle
WPSGraphicStyle()
constructor
Definition: WPSGraphicStyle.h:187
Vec2< int >
WPSGraphicStyle::setBackgroundColor
void setBackgroundColor(WPSColor const &col, float opacity=1)
set the background color
Definition: WPSGraphicStyle.h:246
WPSGraphicStyle::m_lineWidth
float m_lineWidth
the linewidth
Definition: WPSGraphicStyle.h:306
WPSGraphicStyle::m_frameNextName
std::string m_frameNextName
the frame next name (if there is a link)
Definition: WPSGraphicStyle.h:363
WPSGraphicStyle::C_Square
Definition: WPSGraphicStyle.h:41
WPSGraphicStyle::setShadowColor
void setShadowColor(WPSColor const &col, float opacity=1)
set the shadow color
Definition: WPSGraphicStyle.h:257
WPSGraphicStyle::Pattern
a basic pattern used in a WPSGraphicStyle:
Definition: WPSGraphicStyle.h:86
WPSGraphicStyle::resetBorders
void resetBorders()
reset the border
Definition: WPSGraphicStyle.h:290
WPSGraphicStyle::G_Radial
Definition: WPSGraphicStyle.h:45
WPSGraphicStyle::m_gradientType
GradientType m_gradientType
the gradient type
Definition: WPSGraphicStyle.h:335
WPSGraphicStyle::GradientType
GradientType
an enum used to define the gradient type
Definition: WPSGraphicStyle.h:45
WPSGraphicStyle::G_Linear
Definition: WPSGraphicStyle.h:45
WPSGraphicStyle::GradientStop::operator<<
friend std::ostream & operator<<(std::ostream &o, GradientStop const &st)
a print operator
Definition: WPSGraphicStyle.h:67