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 
38 {
39 public:
46 
48  struct GradientStop
49  {
51  GradientStop(float offset=0.0, WPSColor const &col=WPSColor::black(), float opacity=1.0)
52  : m_offset(offset)
53  , m_color(col)
54  , m_opacity(opacity)
55  {
56  }
58  int cmp(GradientStop const &a) const
59  {
60  if (m_offset < a.m_offset) return -1;
61  if (m_offset > a.m_offset) return 1;
62  if (m_color < a.m_color) return -1;
63  if (m_color > a.m_color) return 1;
64  if (m_opacity < a.m_opacity) return -1;
65  if (m_opacity > a.m_opacity) return 1;
66  return 0;
67  }
69  friend std::ostream &operator<<(std::ostream &o, GradientStop const &st)
70  {
71  o << "offset=" << st.m_offset << ",";
72  o << "color=" << st.m_color << ",";
73  if (st.m_opacity<1.0)
74  o << "opacity=" << st.m_opacity*100.f << "%,";
75  return o;
76  }
78  float m_offset;
82  float m_opacity;
83  };
88  struct Pattern
89  {
92  : m_dim(0,0)
93  , m_data()
94  , m_picture()
95  , m_pictureMime("")
97  {
100  }
102  Pattern(Vec2i dim, librevenge::RVNGBinaryData const &picture, std::string const &mime, WPSColor const &avColor)
103  : m_dim(dim)
104  , m_data()
105  , m_picture(picture)
106  , m_pictureMime(mime)
107  , m_pictureAverageColor(avColor)
108  {
111  }
113  virtual ~Pattern() {}
115  bool empty() const
116  {
117  if (m_dim[0]==0 || m_dim[1]==0) return true;
118  if (m_picture.size()) return false;
119  if (m_dim[0]!=8 && m_dim[0]!=16 && m_dim[0]!=32) return true;
120  return m_data.size()!=size_t((m_dim[0]/8)*m_dim[1]);
121  }
123  bool getAverageColor(WPSColor &col) const;
125  bool getUniqueColor(WPSColor &col) const;
127  bool getBinary(librevenge::RVNGBinaryData &data, std::string &type) const;
128 
130  int cmp(Pattern const &a) const
131  {
132  int diff = m_dim.cmp(a.m_dim);
133  if (diff) return diff;
134  if (m_data.size() < a.m_data.size()) return -1;
135  if (m_data.size() > a.m_data.size()) return 1;
136  for (size_t h=0; h < m_data.size(); ++h)
137  {
138  if (m_data[h]<a.m_data[h]) return 1;
139  if (m_data[h]>a.m_data[h]) return -1;
140  }
141  for (int i=0; i<2; ++i)
142  {
143  if (m_colors[i] < a.m_colors[i]) return 1;
144  if (m_colors[i] > a.m_colors[i]) return -1;
145  }
147  if (m_pictureAverageColor > a.m_pictureAverageColor) return -1;
148  if (m_pictureMime < a.m_pictureMime) return 1;
149  if (m_pictureMime > a.m_pictureMime) return -1;
150  if (m_picture.size() < a.m_picture.size()) return 1;
151  if (m_picture.size() > a.m_picture.size()) return -1;
152  const unsigned char *ptr=m_picture.getDataBuffer();
153  const unsigned char *aPtr=a.m_picture.getDataBuffer();
154  if (!ptr || !aPtr) return 0; // must only appear if the two buffers are empty
155  for (unsigned long h=0; h < m_picture.size(); ++h, ++ptr, ++aPtr)
156  {
157  if (*ptr < *aPtr) return 1;
158  if (*ptr > *aPtr) return -1;
159  }
160  return 0;
161  }
163  friend std::ostream &operator<<(std::ostream &o, Pattern const &pat)
164  {
165  o << "dim=" << pat.m_dim << ",";
166  if (pat.m_picture.size())
167  {
168  o << "type=" << pat.m_pictureMime << ",";
169  o << "col[average]=" << pat.m_pictureAverageColor << ",";
170  }
171  else
172  {
173  if (!pat.m_colors[0].isBlack()) o << "col0=" << pat.m_colors[0] << ",";
174  if (!pat.m_colors[1].isWhite()) o << "col1=" << pat.m_colors[1] << ",";
175  o << "[";
176  for (auto const &data : pat.m_data)
177  o << std::hex << (int) data << std::dec << ",";
178  o << "],";
179  }
180  return o;
181  }
184 
188  std::vector<unsigned char> m_data;
189  protected:
191  librevenge::RVNGBinaryData m_picture;
193  std::string m_pictureMime;
196  };
199  : m_lineWidth(1)
200  , m_lineDashWidth()
201  , m_lineCap(C_Butt)
203  , m_lineOpacity(1)
204  , m_lineColor(WPSColor::black())
205  , m_fillRuleEvenOdd(false)
206  , m_surfaceColor(WPSColor::white())
207  , m_surfaceOpacity(0)
208  , m_shadowColor(WPSColor::black())
209  , m_shadowOpacity(0)
210  , m_shadowOffset(1,1)
211  , m_pattern()
214  , m_gradientAngle(0)
215  , m_gradientBorder(0)
216  , m_gradientPercentCenter(0.5f,0.5f)
217  , m_gradientRadius(1)
218  , m_backgroundColor(WPSColor::white())
219  , m_backgroundOpacity(-1)
220  , m_bordersList()
221  , m_frameName("")
222  , m_frameNextName("")
223  , m_rotate(0)
224  , m_extra("")
225  {
226  m_arrows[0]=m_arrows[1]=false;
227  m_flip[0]=m_flip[1]=false;
230  }
233  {
234  WPSGraphicStyle res;
235  res.m_lineWidth=0;
236  return res;
237  }
239  virtual ~WPSGraphicStyle() { }
241  bool hasLine() const
242  {
243  return m_lineWidth>0 && m_lineOpacity>0;
244  }
246  void setSurfaceColor(WPSColor const &col, float opacity = 1)
247  {
248  m_surfaceColor = col;
249  m_surfaceOpacity = opacity;
250  }
252  bool hasSurfaceColor() const
253  {
254  return m_surfaceOpacity > 0;
255  }
257  void setPattern(Pattern const &pat)
258  {
259  m_pattern=pat;
260  }
262  bool hasPattern() const
263  {
264  return !m_pattern.empty();
265  }
267  bool hasGradient(bool complex=false) const
268  {
269  return m_gradientType != G_None && (int) m_gradientStopList.size() >= (complex ? 3 : 2);
270  }
272  bool hasSurface() const
273  {
274  return hasSurfaceColor() || hasPattern() || hasGradient();
275  }
277  void setBackgroundColor(WPSColor const &col, float opacity = 1)
278  {
279  m_backgroundColor = col;
280  m_backgroundOpacity = opacity;
281  }
283  bool hasBackgroundColor() const
284  {
285  return m_backgroundOpacity > 0;
286  }
288  void setShadowColor(WPSColor const &col, float opacity = 1)
289  {
290  m_shadowColor = col;
291  m_shadowOpacity = opacity;
292  }
294  bool hasShadow() const
295  {
296  return m_shadowOpacity > 0;
297  }
299  bool hasBorders() const
300  {
301  return !m_bordersList.empty();
302  }
304  bool hasSameBorders() const
305  {
306  if (m_bordersList.empty()) return true;
307  if (m_bordersList.size()!=4) return false;
308  for (size_t i=1; i<m_bordersList.size(); ++i)
309  {
310  if (m_bordersList[i]!=m_bordersList[0])
311  return false;
312  }
313  return true;
314  }
316  std::vector<WPSBorder> const &borders() const
317  {
318  return m_bordersList;
319  }
322  {
323  m_bordersList.resize(0);
324  }
326  void setBorders(int wh, WPSBorder const &border);
328  friend std::ostream &operator<<(std::ostream &o, WPSGraphicStyle const &st);
330  void addTo(librevenge::RVNGPropertyList &pList, bool only1d=false) const;
332  void addFrameTo(librevenge::RVNGPropertyList &pList) const;
334  int cmp(WPSGraphicStyle const &a) const;
335 
337  float m_lineWidth;
339  std::vector<float> m_lineDashWidth;
354 
361 
364 
368  std::vector<GradientStop> m_gradientStopList;
377 
379  bool m_arrows[2];
380 
381  //
382  // related to the frame
383  //
384 
390  std::vector<WPSBorder> m_bordersList;
392  librevenge::RVNGString m_frameName;
394  librevenge::RVNGString m_frameNextName;
395 
396  //
397  // some transformation: must probably be somewhere else
398  //
399 
401  float m_rotate;
403  bool m_flip[2];
404 
406  std::string m_extra;
407 };
408 #endif
409 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
int cmp(Pattern const &a) const
compare two patterns
Definition: WPSGraphicStyle.h:130
virtual ~WPSGraphicStyle()
virtual destructor
Definition: WPSGraphicStyle.h:239
bool m_flip[2]
two bool to indicated we need to flip the shape or not
Definition: WPSGraphicStyle.h:403
bool getAverageColor(WPSColor &col) const
return the average color
Definition: WPSGraphicStyle.cpp:57
a structure used to define the gradient limit
Definition: WPSGraphicStyle.h:48
std::string m_pictureMime
the picture type
Definition: WPSGraphicStyle.h:193
Vec2f m_shadowOffset
the shadow offset
Definition: WPSGraphicStyle.h:360
a border list
Definition: libwps_internal.h:394
float m_surfaceOpacity
true if the surface has some color
Definition: WPSGraphicStyle.h:353
librevenge::RVNGString m_frameName
the frame name
Definition: WPSGraphicStyle.h:392
Definition: WPSGraphicStyle.h:45
bool hasLine() const
returns true if the border is defined
Definition: WPSGraphicStyle.h:241
bool empty() const
return true if we does not have a pattern
Definition: WPSGraphicStyle.h:115
LineJoin m_lineJoin
the line join
Definition: WPSGraphicStyle.h:343
float m_shadowOpacity
true if the shadow has some color
Definition: WPSGraphicStyle.h:358
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:188
float m_rotate
the rotation
Definition: WPSGraphicStyle.h:401
LineCap m_lineCap
the line cap
Definition: WPSGraphicStyle.h:341
Definition: WPSGraphicStyle.h:43
Definition: WPSGraphicStyle.h:45
Definition: WPSGraphicStyle.h:45
WPSColor m_pictureAverageColor
the picture average color
Definition: WPSGraphicStyle.h:195
std::vector< WPSBorder > const & borders() const
return the frame border: libwps::Left | ...
Definition: WPSGraphicStyle.h:316
static WPSColor black()
return the back color
Definition: libwps_internal.h:306
void setBorders(int wh, WPSBorder const &border)
sets the cell border: wh=libwps::LeftBit|...
Definition: WPSGraphicStyle.cpp:136
std::vector< WPSBorder > m_bordersList
the borders WPSBorder::Pos (for a frame)
Definition: WPSGraphicStyle.h:390
static WPSColor white()
return the white color
Definition: libwps_internal.h:311
int cmp(GradientStop const &a) const
compare two gradient
Definition: WPSGraphicStyle.h:58
Definition: WPSGraphicStyle.h:45
std::vector< float > m_lineDashWidth
the dash array: a sequence of (fullsize, emptysize)
Definition: WPSGraphicStyle.h:339
bool hasShadow() const
returns true if the shadow is defined
Definition: WPSGraphicStyle.h:294
bool isWhite() const
return true if the color is white
Definition: libwps_internal.h:350
float m_opacity
the opacity
Definition: WPSGraphicStyle.h:82
virtual ~Pattern()
virtual destructor
Definition: WPSGraphicStyle.h:113
Definition: WPSGraphicStyle.h:43
int cmp(WPSGraphicStyle const &a) const
compare two styles
Definition: WPSGraphicStyle.cpp:413
void setSurfaceColor(WPSColor const &col, float opacity=1)
set the surface color
Definition: WPSGraphicStyle.h:246
float m_gradientAngle
the gradient angle
Definition: WPSGraphicStyle.h:370
Vec2i m_dim
the dimension width x height
Definition: WPSGraphicStyle.h:183
float m_gradientRadius
the gradient radius
Definition: WPSGraphicStyle.h:376
Pattern(Vec2i dim, librevenge::RVNGBinaryData const &picture, std::string const &mime, WPSColor const &avColor)
constructor from a binary data
Definition: WPSGraphicStyle.h:102
a structure used to define a picture style
Definition: WPSGraphicStyle.h:37
bool getBinary(librevenge::RVNGBinaryData &data, std::string &type) const
tries to convert the picture in a binary data ( ppm)
Definition: WPSGraphicStyle.cpp:88
Vec2f m_gradientPercentCenter
the gradient center
Definition: WPSGraphicStyle.h:374
static WPSGraphicStyle emptyStyle()
returns an empty style.
Definition: WPSGraphicStyle.h:232
bool isBlack() const
return true if the color is black
Definition: libwps_internal.h:345
bool hasPattern() const
returns true if the pattern is defined
Definition: WPSGraphicStyle.h:262
librevenge::RVNGBinaryData m_picture
a picture
Definition: WPSGraphicStyle.h:191
LineJoin
an enum used to define the basic line join
Definition: WPSGraphicStyle.h:43
bool hasBorders() const
return true if the frame has some border
Definition: WPSGraphicStyle.h:299
void setPattern(Pattern const &pat)
set the pattern
Definition: WPSGraphicStyle.h:257
Pattern m_pattern
the pattern if it exists
Definition: WPSGraphicStyle.h:363
WPSColor m_shadowColor
the shadow color
Definition: WPSGraphicStyle.h:356
bool getUniqueColor(WPSColor &col) const
check if the pattern has only one color; if so returns true...
Definition: WPSGraphicStyle.cpp:41
bool hasSurface() const
returns true if the interior surface is defined
Definition: WPSGraphicStyle.h:272
int cmp(Vec2< T > const &p) const
a comparison function: which first compares x then y
Definition: libwps_internal.h:647
float m_lineOpacity
the line opacity: 0=transparent
Definition: WPSGraphicStyle.h:345
float m_offset
the offset
Definition: WPSGraphicStyle.h:78
WPSColor m_colors[2]
the two indexed colors
Definition: WPSGraphicStyle.h:186
std::string m_extra
extra data
Definition: WPSGraphicStyle.h:406
Definition: WPSGraphicStyle.h:45
std::vector< GradientStop > m_gradientStopList
the list of gradient limits
Definition: WPSGraphicStyle.h:368
bool m_fillRuleEvenOdd
true if the fill rule is evenod
Definition: WPSGraphicStyle.h:349
WPSColor m_backgroundColor
the background color
Definition: WPSGraphicStyle.h:386
WPSColor m_color
the color
Definition: WPSGraphicStyle.h:80
the class to store a color
Definition: libwps_internal.h:280
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
bool hasSurfaceColor() const
returns true if the surface is defined
Definition: WPSGraphicStyle.h:252
WPSColor m_surfaceColor
the surface color
Definition: WPSGraphicStyle.h:351
void addFrameTo(librevenge::RVNGPropertyList &pList) const
add all the frame parameters to propList: the background and the borders
Definition: WPSGraphicStyle.cpp:361
Pattern()
constructor
Definition: WPSGraphicStyle.h:91
Definition: WPSGraphicStyle.h:43
Definition: WPSGraphicStyle.h:41
bool hasGradient(bool complex=false) const
returns true if the gradient is defined
Definition: WPSGraphicStyle.h:267
bool m_arrows[2]
two bool to indicated if extremity has arrow or not
Definition: WPSGraphicStyle.h:379
WPSColor m_lineColor
the line color
Definition: WPSGraphicStyle.h:347
float m_backgroundOpacity
true if the background has some color
Definition: WPSGraphicStyle.h:388
float m_gradientBorder
the gradient border opacity
Definition: WPSGraphicStyle.h:372
bool hasSameBorders() const
return true if the frame has some border
Definition: WPSGraphicStyle.h:304
friend std::ostream & operator<<(std::ostream &o, Pattern const &pat)
a print operator
Definition: WPSGraphicStyle.h:163
bool hasBackgroundColor() const
returns true if the background is defined
Definition: WPSGraphicStyle.h:283
Definition: WPSGraphicStyle.h:41
GradientStop(float offset=0.0, WPSColor const &col=WPSColor::black(), float opacity=1.0)
constructor
Definition: WPSGraphicStyle.h:51
LineCap
an enum used to define the basic line cap
Definition: WPSGraphicStyle.h:41
WPSGraphicStyle()
constructor
Definition: WPSGraphicStyle.h:198
void setBackgroundColor(WPSColor const &col, float opacity=1)
set the background color
Definition: WPSGraphicStyle.h:277
float m_lineWidth
the linewidth
Definition: WPSGraphicStyle.h:337
Definition: WPSGraphicStyle.h:41
friend std::ostream & operator<<(std::ostream &o, WPSGraphicStyle const &st)
a print operator
Definition: WPSGraphicStyle.cpp:501
void setShadowColor(WPSColor const &col, float opacity=1)
set the shadow color
Definition: WPSGraphicStyle.h:288
a basic pattern used in a WPSGraphicStyle:
Definition: WPSGraphicStyle.h:88
void resetBorders()
reset the border
Definition: WPSGraphicStyle.h:321
Definition: WPSGraphicStyle.h:45
GradientType m_gradientType
the gradient type
Definition: WPSGraphicStyle.h:366
GradientType
an enum used to define the gradient type
Definition: WPSGraphicStyle.h:45
Definition: WPSGraphicStyle.h:45
friend std::ostream & operator<<(std::ostream &o, GradientStop const &st)
a print operator
Definition: WPSGraphicStyle.h:69
librevenge::RVNGString m_frameNextName
the frame next name (if there is a link)
Definition: WPSGraphicStyle.h:394

Generated on Fri May 27 2022 03:07:00 for libwps by doxygen 1.8.14