MWAWGraphicStyle.hxx
Go to the documentation of this file.
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 (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
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_STYLE
34 # define MWAW_GRAPHIC_STYLE
35 # include <ostream>
36 # include <string>
37 # include <vector>
38 
39 # include "librevenge/librevenge.h"
40 # include "libmwaw_internal.hxx"
41 
48 {
49 public:
56 
58  struct GradientStop {
60  GradientStop(float offset=0.0, MWAWColor const &col=MWAWColor::black(), float opacity=1.0) :
61  m_offset(offset), m_color(col), m_opacity(opacity)
62  {
63  }
65  int cmp(GradientStop const &a) const
66  {
67  if (m_offset < a.m_offset) return -1;
68  if (m_offset > a.m_offset) return 1;
69  if (m_color < a.m_color) return -1;
70  if (m_color > a.m_color) return 1;
71  if (m_opacity < a.m_opacity) return -1;
72  if (m_opacity > a.m_opacity) return 1;
73  return 0;
74  }
76  friend std::ostream &operator<<(std::ostream &o, GradientStop const &st)
77  {
78  o << "offset=" << st.m_offset << ",";
79  o << "color=" << st.m_color << ",";
80  if (st.m_opacity<1.0)
81  o << "opacity=" << st.m_opacity*100.f << "%,";
82  return o;
83  }
85  float m_offset;
89  float m_opacity;
90  };
95  struct Pattern {
98  {
101  }
103  Pattern(Vec2i dim, librevenge::RVNGBinaryData const &picture, std::string const &mime, MWAWColor const &avColor) :
104  m_dim(dim), m_data(), m_picture(picture), m_pictureMime(mime), m_pictureAverageColor(avColor)
105  {
108  }
110  virtual ~Pattern() {}
112  bool empty() const
113  {
114  if (m_dim[0]==0 || m_dim[1]==0) return true;
115  if (m_picture.size()) return false;
116  if (m_dim[0]!=8 && m_dim[0]!=16 && m_dim[0]!=32) return true;
117  return m_data.size()!=size_t((m_dim[0]/8)*m_dim[1]);
118  }
120  bool getAverageColor(MWAWColor &col) const;
122  bool getUniqueColor(MWAWColor &col) const;
124  bool getBinary(librevenge::RVNGBinaryData &data, std::string &type) const;
125 
127  int cmp(Pattern const &a) const
128  {
129  int diff = m_dim.cmp(a.m_dim);
130  if (diff) return diff;
131  if (m_data.size() < a.m_data.size()) return -1;
132  if (m_data.size() > a.m_data.size()) return 1;
133  for (size_t h=0; h < m_data.size(); ++h) {
134  if (m_data[h]<a.m_data[h]) return 1;
135  if (m_data[h]>a.m_data[h]) return -1;
136  }
137  for (int i=0; i<2; ++i) {
138  if (m_colors[i] < a.m_colors[i]) return 1;
139  if (m_colors[i] > a.m_colors[i]) return -1;
140  }
142  if (m_pictureAverageColor > a.m_pictureAverageColor) return -1;
143  if (m_pictureMime < a.m_pictureMime) return 1;
144  if (m_pictureMime > a.m_pictureMime) return -1;
145  if (m_picture.size() < a.m_picture.size()) return 1;
146  if (m_picture.size() > a.m_picture.size()) return -1;
147  const unsigned char *ptr=m_picture.getDataBuffer();
148  const unsigned char *aPtr=a.m_picture.getDataBuffer();
149  for (unsigned long h=0; h < m_picture.size(); ++h, ++ptr, ++aPtr) {
150  if (*ptr < *aPtr) return 1;
151  if (*ptr > *aPtr) return -1;
152  }
153  return 0;
154  }
156  friend std::ostream &operator<<(std::ostream &o, Pattern const &pat)
157  {
158  o << "dim=" << pat.m_dim << ",";
159  if (pat.m_picture.size()) {
160  o << "type=" << pat.m_pictureMime << ",";
161  o << "col[average]=" << pat.m_pictureAverageColor << ",";
162  }
163  else {
164  if (!pat.m_colors[0].isBlack()) o << "col0=" << pat.m_colors[0] << ",";
165  if (!pat.m_colors[1].isWhite()) o << "col1=" << pat.m_colors[1] << ",";
166  o << "[";
167  for (size_t h=0; h < pat.m_data.size(); ++h)
168  o << std::hex << (int) pat.m_data[h] << std::dec << ",";
169  o << "],";
170  }
171  return o;
172  }
175 
179  std::vector<unsigned char> m_data;
180  protected:
182  librevenge::RVNGBinaryData m_picture;
184  std::string m_pictureMime;
187  };
192  m_pattern(),
195  m_rotate(0), m_extra("")
196  {
197  m_arrows[0]=m_arrows[1]=false;
198  m_flip[0]=m_flip[1]=false;
201  }
204  {
205  MWAWGraphicStyle res;
206  res.m_lineWidth=0;
207  return res;
208  }
210  virtual ~MWAWGraphicStyle() { }
212  bool hasLine() const
213  {
214  return m_lineWidth>0 && m_lineOpacity>0;
215  }
217  void setSurfaceColor(MWAWColor const &col, float opacity = 1)
218  {
219  m_surfaceColor = col;
220  m_surfaceOpacity = opacity;
221  }
223  bool hasSurfaceColor() const
224  {
225  return m_surfaceOpacity > 0;
226  }
228  void setPattern(Pattern const &pat)
229  {
230  m_pattern=pat;
231  }
233  bool hasPattern() const
234  {
235  return !m_pattern.empty();
236  }
238  bool hasGradient(bool complex=false) const
239  {
240  return m_gradientType != G_None && m_gradientStopList.size() >= (complex ? 3 : 2);
241  }
243  bool hasSurface() const
244  {
245  return hasSurfaceColor() || hasPattern() || hasGradient();
246  }
248  void setBackgroundColor(MWAWColor const &col, float opacity = 1)
249  {
250  m_backgroundColor = col;
251  m_backgroundOpacity = opacity;
252  }
254  bool hasBackgroundColor() const
255  {
256  return m_backgroundOpacity > 0;
257  }
259  void setShadowColor(MWAWColor const &col, float opacity = 1)
260  {
261  m_shadowColor = col;
262  m_shadowOpacity = opacity;
263  }
265  bool hasShadow() const
266  {
267  return m_shadowOpacity > 0;
268  }
270  bool hasBorders() const
271  {
272  return !m_bordersList.empty();
273  }
275  bool hasSameBorders() const
276  {
277  if (m_bordersList.empty()) return true;
278  if (m_bordersList.size()!=4) return false;
279  for (size_t i=1; i<m_bordersList.size(); ++i) {
280  if (m_bordersList[i]!=m_bordersList[0])
281  return false;
282  }
283  return true;
284  }
286  std::vector<MWAWBorder> const &borders() const
287  {
288  return m_bordersList;
289  }
292  {
293  m_bordersList.resize(0);
294  }
296  void setBorders(int wh, MWAWBorder const &border);
298  friend std::ostream &operator<<(std::ostream &o, MWAWGraphicStyle const &st);
300  void addTo(librevenge::RVNGPropertyList &pList, bool only1d=false) const;
302  void addFrameTo(librevenge::RVNGPropertyList &pList) const;
304  int cmp(MWAWGraphicStyle const &a) const;
305 
307  float m_lineWidth;
309  std::vector<float> m_lineDashWidth;
324 
331 
334 
338  std::vector<GradientStop> m_gradientStopList;
347 
349  bool m_arrows[2];
350 
351  //
352  // related to the frame
353  //
354 
360  std::vector<MWAWBorder> m_bordersList;
362  std::string m_frameName;
364  std::string m_frameNextName;
365 
366  //
367  // some transformation: must probably be somewhere else
368  //
369 
371  float m_rotate;
373  bool m_flip[2];
374 
376  std::string m_extra;
377 };
378 #endif
379 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
bool m_flip[2]
two bool to indicated we need to flip the shape or not
Definition: MWAWGraphicStyle.hxx:373
friend std::ostream & operator<<(std::ostream &o, GradientStop const &st)
a print operator
Definition: MWAWGraphicStyle.hxx:76
bool hasSurfaceColor() const
returns true if the surface is defined
Definition: MWAWGraphicStyle.hxx:223
Vec2i m_dim
the dimension width x height
Definition: MWAWGraphicStyle.hxx:174
bool empty() const
return true if we does not have a pattern
Definition: MWAWGraphicStyle.hxx:112
MWAWColor m_surfaceColor
the surface color
Definition: MWAWGraphicStyle.hxx:321
std::string m_frameNextName
the frame next name (if there is a link)
Definition: MWAWGraphicStyle.hxx:364
MWAWColor m_shadowColor
the shadow color
Definition: MWAWGraphicStyle.hxx:326
Definition: MWAWGraphicStyle.hxx:53
float m_opacity
the opacity
Definition: MWAWGraphicStyle.hxx:89
float m_backgroundOpacity
true if the background has some color
Definition: MWAWGraphicStyle.hxx:358
std::string m_frameName
the frame name
Definition: MWAWGraphicStyle.hxx:362
float m_shadowOpacity
true if the shadow has some color
Definition: MWAWGraphicStyle.hxx:328
Pattern()
constructor
Definition: MWAWGraphicStyle.hxx:97
static MWAWColor white()
return the white color
Definition: libmwaw_internal.hxx:188
MWAWGraphicStyle()
constructor
Definition: MWAWGraphicStyle.hxx:189
Definition: MWAWGraphicStyle.hxx:55
MWAWColor m_colors[2]
the two indexed colors
Definition: MWAWGraphicStyle.hxx:177
LineCap
an enum used to define the basic line cap
Definition: MWAWGraphicStyle.hxx:51
LineJoin m_lineJoin
the line join
Definition: MWAWGraphicStyle.hxx:313
MWAWColor m_lineColor
the line color
Definition: MWAWGraphicStyle.hxx:317
Pattern(Vec2i dim, librevenge::RVNGBinaryData const &picture, std::string const &mime, MWAWColor const &avColor)
constructor from a binary data
Definition: MWAWGraphicStyle.hxx:103
static MWAWColor black()
return the back color
Definition: libmwaw_internal.hxx:183
float m_gradientRadius
the gradient radius
Definition: MWAWGraphicStyle.hxx:346
a structure used to define a picture style
Definition: MWAWGraphicStyle.hxx:47
Definition: MWAWGraphicStyle.hxx:51
GradientType
an enum used to define the gradient type
Definition: MWAWGraphicStyle.hxx:55
Definition: MWAWGraphicStyle.hxx:55
bool getUniqueColor(MWAWColor &col) const
check if the pattern has only one color; if so returns true...
Definition: MWAWGraphicStyle.cxx:56
std::string m_pictureMime
the picture type
Definition: MWAWGraphicStyle.hxx:184
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: MWAWGraphicStyle.cxx:158
bool hasSameBorders() const
return true if the frame has some border
Definition: MWAWGraphicStyle.hxx:275
void addFrameTo(librevenge::RVNGPropertyList &pList) const
add all the frame parameters to propList: the background and the borders
Definition: MWAWGraphicStyle.cxx:336
friend std::ostream & operator<<(std::ostream &o, MWAWGraphicStyle const &st)
a print operator
Definition: MWAWGraphicStyle.cxx:466
the class to store a color
Definition: libmwaw_internal.hxx:166
bool m_arrows[2]
two bool to indicated if extremity has arrow or not
Definition: MWAWGraphicStyle.hxx:349
Definition: MWAWGraphicStyle.hxx:51
bool hasGradient(bool complex=false) const
returns true if the gradient is defined
Definition: MWAWGraphicStyle.hxx:238
float m_rotate
the rotation
Definition: MWAWGraphicStyle.hxx:371
std::vector< float > m_lineDashWidth
the dash array: a sequence of (fullsize, emptysize)
Definition: MWAWGraphicStyle.hxx:309
a structure used to define the gradient limit
Definition: MWAWGraphicStyle.hxx:58
a border
Definition: libmwaw_internal.hxx:251
Definition: MWAWGraphicStyle.hxx:55
std::string m_extra
extra data
Definition: MWAWGraphicStyle.hxx:376
bool hasPattern() const
returns true if the pattern is defined
Definition: MWAWGraphicStyle.hxx:233
void setPattern(Pattern const &pat)
set the pattern
Definition: MWAWGraphicStyle.hxx:228
LineCap m_lineCap
the line cap
Definition: MWAWGraphicStyle.hxx:311
float m_surfaceOpacity
true if the surface has some color
Definition: MWAWGraphicStyle.hxx:323
float m_gradientBorder
the gradient border opacity
Definition: MWAWGraphicStyle.hxx:342
GradientType m_gradientType
the gradient type
Definition: MWAWGraphicStyle.hxx:336
MWAWColor m_backgroundColor
the background color
Definition: MWAWGraphicStyle.hxx:356
Definition: MWAWGraphicStyle.hxx:53
float m_gradientAngle
the gradient angle
Definition: MWAWGraphicStyle.hxx:340
bool hasBackgroundColor() const
returns true if the background is defined
Definition: MWAWGraphicStyle.hxx:254
Pattern m_pattern
the pattern if it exists
Definition: MWAWGraphicStyle.hxx:333
bool hasBorders() const
return true if the frame has some border
Definition: MWAWGraphicStyle.hxx:270
Definition: MWAWGraphicStyle.hxx:53
void setSurfaceColor(MWAWColor const &col, float opacity=1)
set the surface color
Definition: MWAWGraphicStyle.hxx:217
Definition: MWAWGraphicStyle.hxx:51
virtual ~MWAWGraphicStyle()
virtual destructor
Definition: MWAWGraphicStyle.hxx:210
librevenge::RVNGBinaryData m_picture
a picture
Definition: MWAWGraphicStyle.hxx:182
bool m_fillRuleEvenOdd
true if the fill rule is evenod
Definition: MWAWGraphicStyle.hxx:319
bool getAverageColor(MWAWColor &col) const
return the average color
Definition: MWAWGraphicStyle.cxx:71
bool hasSurface() const
returns true if the interior surface is defined
Definition: MWAWGraphicStyle.hxx:243
Definition: MWAWGraphicStyle.hxx:55
std::vector< MWAWBorder > const & borders() const
return the frame border: libmwaw::Left | ...
Definition: MWAWGraphicStyle.hxx:286
Definition: MWAWGraphicStyle.hxx:55
int cmp(GradientStop const &a) const
compare two gradient
Definition: MWAWGraphicStyle.hxx:65
MWAWColor m_color
the color
Definition: MWAWGraphicStyle.hxx:87
Definition: MWAWGraphicStyle.hxx:55
bool hasShadow() const
returns true if the shadow is defined
Definition: MWAWGraphicStyle.hxx:265
std::vector< MWAWBorder > m_bordersList
the borders MWAWBorder::Pos (for a frame)
Definition: MWAWGraphicStyle.hxx:360
LineJoin
an enum used to define the basic line join
Definition: MWAWGraphicStyle.hxx:53
void setShadowColor(MWAWColor const &col, float opacity=1)
set the shadow color
Definition: MWAWGraphicStyle.hxx:259
float m_lineOpacity
the line opacity: 0=transparent
Definition: MWAWGraphicStyle.hxx:315
MWAWColor m_pictureAverageColor
the picture average color
Definition: MWAWGraphicStyle.hxx:186
void setBackgroundColor(MWAWColor const &col, float opacity=1)
set the background color
Definition: MWAWGraphicStyle.hxx:248
Vec2f m_shadowOffset
the shadow offset
Definition: MWAWGraphicStyle.hxx:330
float m_lineWidth
the linewidth
Definition: MWAWGraphicStyle.hxx:307
friend std::ostream & operator<<(std::ostream &o, Pattern const &pat)
a print operator
Definition: MWAWGraphicStyle.hxx:156
bool isWhite() const
return true if the color is white
Definition: libmwaw_internal.hxx:207
Vec2f m_gradientPercentCenter
the gradient center
Definition: MWAWGraphicStyle.hxx:344
bool isBlack() const
return true if the color is black
Definition: libmwaw_internal.hxx:202
bool hasLine() const
returns true if the border is defined
Definition: MWAWGraphicStyle.hxx:212
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: MWAWGraphicStyle.hxx:179
int cmp(Pattern const &a) const
compare two patterns
Definition: MWAWGraphicStyle.hxx:127
GradientStop(float offset=0.0, MWAWColor const &col=MWAWColor::black(), float opacity=1.0)
constructor
Definition: MWAWGraphicStyle.hxx:60
int cmp(MWAWGraphicStyle const &a) const
compare two styles
Definition: MWAWGraphicStyle.cxx:382
a basic pattern used in a MWAWGraphicStyle:
Definition: MWAWGraphicStyle.hxx:95
float m_offset
the offset
Definition: MWAWGraphicStyle.hxx:85
void setBorders(int wh, MWAWBorder const &border)
sets the cell border: wh=libmwaw::LeftBit|...
Definition: MWAWGraphicStyle.cxx:139
int cmp(Vec2< T > const &p) const
a comparison function: which first compares x then y
Definition: libmwaw_internal.hxx:595
Definition: MWAWGraphicStyle.hxx:55
std::vector< GradientStop > m_gradientStopList
the list of gradient limits
Definition: MWAWGraphicStyle.hxx:338
static MWAWGraphicStyle emptyStyle()
returns an empty style.
Definition: MWAWGraphicStyle.hxx:203
void resetBorders()
reset the border
Definition: MWAWGraphicStyle.hxx:291
virtual ~Pattern()
virtual destructor
Definition: MWAWGraphicStyle.hxx:110
bool getBinary(librevenge::RVNGBinaryData &data, std::string &type) const
tries to convert the picture in a binary data ( ppm)
Definition: MWAWGraphicStyle.cxx:98

Generated for libmwaw by doxygen 1.8.8