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(MWAWVec2i 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  if (!ptr || !aPtr) return 0; // must only appear if the two buffers are empty
150  for (unsigned long h=0; h < m_picture.size(); ++h, ++ptr, ++aPtr) {
151  if (*ptr < *aPtr) return 1;
152  if (*ptr > *aPtr) return -1;
153  }
154  return 0;
155  }
157  friend std::ostream &operator<<(std::ostream &o, Pattern const &pat)
158  {
159  o << "dim=" << pat.m_dim << ",";
160  if (pat.m_picture.size()) {
161  o << "type=" << pat.m_pictureMime << ",";
162  o << "col[average]=" << pat.m_pictureAverageColor << ",";
163  }
164  else {
165  if (!pat.m_colors[0].isBlack()) o << "col0=" << pat.m_colors[0] << ",";
166  if (!pat.m_colors[1].isWhite()) o << "col1=" << pat.m_colors[1] << ",";
167  o << "[";
168  for (size_t h=0; h < pat.m_data.size(); ++h)
169  o << std::hex << (int) pat.m_data[h] << std::dec << ",";
170  o << "],";
171  }
172  return o;
173  }
176 
180  std::vector<unsigned char> m_data;
181  protected:
183  librevenge::RVNGBinaryData m_picture;
185  std::string m_pictureMime;
188  };
193  m_pattern(),
196  m_rotate(0), m_extra("")
197  {
198  m_arrows[0]=m_arrows[1]=false;
199  m_flip[0]=m_flip[1]=false;
202  }
205  {
206  MWAWGraphicStyle res;
207  res.m_lineWidth=0;
208  return res;
209  }
211  virtual ~MWAWGraphicStyle() { }
213  bool hasLine() const
214  {
215  return m_lineWidth>0 && m_lineOpacity>0;
216  }
218  void setSurfaceColor(MWAWColor const &col, float opacity = 1)
219  {
220  m_surfaceColor = col;
221  m_surfaceOpacity = opacity;
222  }
224  bool hasSurfaceColor() const
225  {
226  return m_surfaceOpacity > 0;
227  }
229  void setPattern(Pattern const &pat)
230  {
231  m_pattern=pat;
232  }
234  bool hasPattern() const
235  {
236  return !m_pattern.empty();
237  }
239  bool hasGradient(bool complex=false) const
240  {
241  return m_gradientType != G_None && (int) m_gradientStopList.size() >= (complex ? 3 : 2);
242  }
244  bool hasSurface() const
245  {
246  return hasSurfaceColor() || hasPattern() || hasGradient();
247  }
249  void setBackgroundColor(MWAWColor const &col, float opacity = 1)
250  {
251  m_backgroundColor = col;
252  m_backgroundOpacity = opacity;
253  }
255  bool hasBackgroundColor() const
256  {
257  return m_backgroundOpacity > 0;
258  }
260  void setShadowColor(MWAWColor const &col, float opacity = 1)
261  {
262  m_shadowColor = col;
263  m_shadowOpacity = opacity;
264  }
266  bool hasShadow() const
267  {
268  return m_shadowOpacity > 0;
269  }
271  bool hasBorders() const
272  {
273  return !m_bordersList.empty();
274  }
276  bool hasSameBorders() const
277  {
278  if (m_bordersList.empty()) return true;
279  if (m_bordersList.size()!=4) return false;
280  for (size_t i=1; i<m_bordersList.size(); ++i) {
281  if (m_bordersList[i]!=m_bordersList[0])
282  return false;
283  }
284  return true;
285  }
287  std::vector<MWAWBorder> const &borders() const
288  {
289  return m_bordersList;
290  }
293  {
294  m_bordersList.resize(0);
295  }
297  void setBorders(int wh, MWAWBorder const &border);
299  friend std::ostream &operator<<(std::ostream &o, MWAWGraphicStyle const &st);
301  void addTo(librevenge::RVNGPropertyList &pList, bool only1d=false) const;
303  void addFrameTo(librevenge::RVNGPropertyList &pList) const;
305  int cmp(MWAWGraphicStyle const &a) const;
306 
308  float m_lineWidth;
310  std::vector<float> m_lineDashWidth;
325 
332 
335 
339  std::vector<GradientStop> m_gradientStopList;
348 
350  bool m_arrows[2];
351 
352  //
353  // related to the frame
354  //
355 
361  std::vector<MWAWBorder> m_bordersList;
363  std::string m_frameName;
365  std::string m_frameNextName;
366 
367  //
368  // some transformation: must probably be somewhere else
369  //
370 
372  float m_rotate;
374  bool m_flip[2];
375 
377  std::string m_extra;
378 };
379 #endif
380 // 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:374
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:224
MWAWVec2i m_dim
the dimension width x height
Definition: MWAWGraphicStyle.hxx:175
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:322
std::string m_frameNextName
the frame next name (if there is a link)
Definition: MWAWGraphicStyle.hxx:365
MWAWColor m_shadowColor
the shadow color
Definition: MWAWGraphicStyle.hxx:327
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:359
std::string m_frameName
the frame name
Definition: MWAWGraphicStyle.hxx:363
int cmp(MWAWVec2< T > const &p) const
a comparison function: which first compares x then y
Definition: libmwaw_internal.hxx:656
float m_shadowOpacity
true if the shadow has some color
Definition: MWAWGraphicStyle.hxx:329
Pattern()
constructor
Definition: MWAWGraphicStyle.hxx:97
static MWAWColor white()
return the white color
Definition: libmwaw_internal.hxx:226
MWAWGraphicStyle()
constructor
Definition: MWAWGraphicStyle.hxx:190
Definition: MWAWGraphicStyle.hxx:55
MWAWVec2f m_gradientPercentCenter
the gradient center
Definition: MWAWGraphicStyle.hxx:345
MWAWColor m_colors[2]
the two indexed colors
Definition: MWAWGraphicStyle.hxx:178
LineCap
an enum used to define the basic line cap
Definition: MWAWGraphicStyle.hxx:51
LineJoin m_lineJoin
the line join
Definition: MWAWGraphicStyle.hxx:314
MWAWColor m_lineColor
the line color
Definition: MWAWGraphicStyle.hxx:318
static MWAWColor black()
return the back color
Definition: libmwaw_internal.hxx:221
float m_gradientRadius
the gradient radius
Definition: MWAWGraphicStyle.hxx:347
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:185
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:276
void addFrameTo(librevenge::RVNGPropertyList &pList) const
add all the frame parameters to propList: the background and the borders
Definition: MWAWGraphicStyle.cxx:337
friend std::ostream & operator<<(std::ostream &o, MWAWGraphicStyle const &st)
a print operator
Definition: MWAWGraphicStyle.cxx:467
the class to store a color
Definition: libmwaw_internal.hxx:177
bool m_arrows[2]
two bool to indicated if extremity has arrow or not
Definition: MWAWGraphicStyle.hxx:350
Definition: MWAWGraphicStyle.hxx:51
bool hasGradient(bool complex=false) const
returns true if the gradient is defined
Definition: MWAWGraphicStyle.hxx:239
float m_rotate
the rotation
Definition: MWAWGraphicStyle.hxx:372
std::vector< float > m_lineDashWidth
the dash array: a sequence of (fullsize, emptysize)
Definition: MWAWGraphicStyle.hxx:310
a structure used to define the gradient limit
Definition: MWAWGraphicStyle.hxx:58
a border
Definition: libmwaw_internal.hxx:309
Definition: MWAWGraphicStyle.hxx:55
std::string m_extra
extra data
Definition: MWAWGraphicStyle.hxx:377
bool hasPattern() const
returns true if the pattern is defined
Definition: MWAWGraphicStyle.hxx:234
MWAWVec2f m_shadowOffset
the shadow offset
Definition: MWAWGraphicStyle.hxx:331
void setPattern(Pattern const &pat)
set the pattern
Definition: MWAWGraphicStyle.hxx:229
LineCap m_lineCap
the line cap
Definition: MWAWGraphicStyle.hxx:312
float m_surfaceOpacity
true if the surface has some color
Definition: MWAWGraphicStyle.hxx:324
float m_gradientBorder
the gradient border opacity
Definition: MWAWGraphicStyle.hxx:343
GradientType m_gradientType
the gradient type
Definition: MWAWGraphicStyle.hxx:337
MWAWColor m_backgroundColor
the background color
Definition: MWAWGraphicStyle.hxx:357
Definition: MWAWGraphicStyle.hxx:53
float m_gradientAngle
the gradient angle
Definition: MWAWGraphicStyle.hxx:341
bool hasBackgroundColor() const
returns true if the background is defined
Definition: MWAWGraphicStyle.hxx:255
Pattern m_pattern
the pattern if it exists
Definition: MWAWGraphicStyle.hxx:334
bool hasBorders() const
return true if the frame has some border
Definition: MWAWGraphicStyle.hxx:271
Definition: MWAWGraphicStyle.hxx:53
void setSurfaceColor(MWAWColor const &col, float opacity=1)
set the surface color
Definition: MWAWGraphicStyle.hxx:218
Definition: MWAWGraphicStyle.hxx:51
virtual ~MWAWGraphicStyle()
virtual destructor
Definition: MWAWGraphicStyle.hxx:211
librevenge::RVNGBinaryData m_picture
a picture
Definition: MWAWGraphicStyle.hxx:183
bool m_fillRuleEvenOdd
true if the fill rule is evenod
Definition: MWAWGraphicStyle.hxx:320
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:244
Definition: MWAWGraphicStyle.hxx:55
std::vector< MWAWBorder > const & borders() const
return the frame border: libmwaw::Left | ...
Definition: MWAWGraphicStyle.hxx:287
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
Pattern(MWAWVec2i dim, librevenge::RVNGBinaryData const &picture, std::string const &mime, MWAWColor const &avColor)
constructor from a binary data
Definition: MWAWGraphicStyle.hxx:103
bool hasShadow() const
returns true if the shadow is defined
Definition: MWAWGraphicStyle.hxx:266
std::vector< MWAWBorder > m_bordersList
the borders MWAWBorder::Pos (for a frame)
Definition: MWAWGraphicStyle.hxx:361
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:260
float m_lineOpacity
the line opacity: 0=transparent
Definition: MWAWGraphicStyle.hxx:316
MWAWColor m_pictureAverageColor
the picture average color
Definition: MWAWGraphicStyle.hxx:187
void setBackgroundColor(MWAWColor const &col, float opacity=1)
set the background color
Definition: MWAWGraphicStyle.hxx:249
float m_lineWidth
the linewidth
Definition: MWAWGraphicStyle.hxx:308
friend std::ostream & operator<<(std::ostream &o, Pattern const &pat)
a print operator
Definition: MWAWGraphicStyle.hxx:157
bool isWhite() const
return true if the color is white
Definition: libmwaw_internal.hxx:265
bool isBlack() const
return true if the color is black
Definition: libmwaw_internal.hxx:260
bool hasLine() const
returns true if the border is defined
Definition: MWAWGraphicStyle.hxx:213
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:180
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:383
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
Definition: MWAWGraphicStyle.hxx:55
std::vector< GradientStop > m_gradientStopList
the list of gradient limits
Definition: MWAWGraphicStyle.hxx:339
static MWAWGraphicStyle emptyStyle()
returns an empty style.
Definition: MWAWGraphicStyle.hxx:204
void resetBorders()
reset the border
Definition: MWAWGraphicStyle.hxx:292
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 on Thu Jul 9 2015 20:26:36 for libmwaw by doxygen 1.8.8