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 "libwpd/libwpd.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  }
64  int cmp(GradientStop const &a) const {
65  if (m_offset < a.m_offset) return -1;
66  if (m_offset > a.m_offset) return 1;
67  if (m_color < a.m_color) return -1;
68  if (m_color > a.m_color) return 1;
69  if (m_opacity < a.m_opacity) return -1;
70  if (m_opacity > a.m_opacity) return 1;
71  return 0;
72  }
74  friend std::ostream &operator<<(std::ostream &o, GradientStop const &st) {
75  o << "offset=" << st.m_offset << ",";
76  o << "color=" << st.m_color << ",";
77  if (st.m_opacity<1.0)
78  o << "opacity=" << st.m_opacity*100.f << "%,";
79  return o;
80  }
82  float m_offset;
86  float m_opacity;
87  };
92  struct Pattern {
97  }
99  Pattern(Vec2i dim, WPXBinaryData const &picture, std::string const &mime, MWAWColor const &avColor) :
100  m_dim(dim), m_data(), m_picture(picture), m_pictureMime(mime), m_pictureAverageColor(avColor) {
103  }
105  virtual ~Pattern() {}
107  bool empty() const {
108  if (m_dim[0]==0 || m_dim[1]==0) return true;
109  if (m_picture.size()) return false;
110  if (m_dim[0]!=8 && m_dim[0]!=16 && m_dim[0]!=32) return true;
111  return m_data.size()!=size_t((m_dim[0]/8)*m_dim[1]);
112  }
114  bool getAverageColor(MWAWColor &col) const;
116  bool getUniqueColor(MWAWColor &col) const;
118  bool getBinary(WPXBinaryData &data, std::string &type) const;
119 
121  int cmp(Pattern const &a) const {
122  int diff = m_dim.cmp(a.m_dim);
123  if (diff) return diff;
124  if (m_data.size() < a.m_data.size()) return -1;
125  if (m_data.size() > a.m_data.size()) return 1;
126  for (size_t h=0; h < m_data.size(); ++h) {
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  if (m_colors[i] < a.m_colors[i]) return 1;
132  if (m_colors[i] > a.m_colors[i]) return -1;
133  }
135  if (m_pictureAverageColor > a.m_pictureAverageColor) return -1;
136  if (m_pictureMime < a.m_pictureMime) return 1;
137  if (m_pictureMime > a.m_pictureMime) return -1;
138  if (m_picture.size() < a.m_picture.size()) return 1;
139  if (m_picture.size() > a.m_picture.size()) return -1;
140  const unsigned char *ptr=m_picture.getDataBuffer();
141  const unsigned char *aPtr=a.m_picture.getDataBuffer();
142  for (unsigned long h=0; h < m_picture.size(); ++h, ++ptr, ++aPtr) {
143  if (*ptr < *aPtr) return 1;
144  if (*ptr > *aPtr) return -1;
145  }
146  return 0;
147  }
149  friend std::ostream &operator<<(std::ostream &o, Pattern const &pat) {
150  o << "dim=" << pat.m_dim << ",";
151  if (pat.m_picture.size()) {
152  o << "type=" << pat.m_pictureMime << ",";
153  o << "col[average]=" << pat.m_pictureAverageColor << ",";
154  } else {
155  if (!pat.m_colors[0].isBlack()) o << "col0=" << pat.m_colors[0] << ",";
156  if (!pat.m_colors[1].isWhite()) o << "col1=" << pat.m_colors[1] << ",";
157  o << "[";
158  for (size_t h=0; h < pat.m_data.size(); ++h)
159  o << std::hex << (int) pat.m_data[h] << std::dec << ",";
160  o << "],";
161  }
162  return o;
163  }
166 
170  std::vector<unsigned char> m_data;
171  protected:
173  WPXBinaryData m_picture;
175  std::string m_pictureMime;
178  };
183  m_pattern(),
185  m_rotate(0), m_extra("") {
186  m_arrows[0]=m_arrows[1]=false;
187  m_flip[0]=m_flip[1]=false;
190  }
192  virtual ~MWAWGraphicStyle() { }
194  bool hasLine() const {
195  return m_lineWidth>0 && m_lineOpacity>0;
196  }
198  void setSurfaceColor(MWAWColor const &col, float opacity = 1) {
199  m_surfaceColor = col;
200  m_surfaceOpacity = opacity;
201  }
203  bool hasSurfaceColor() const {
204  return m_surfaceOpacity > 0;
205  }
207  void setPattern(Pattern const &pat) {
208  m_pattern=pat;
209  }
211  bool hasPattern() const {
212  return !m_pattern.empty();
213  }
215  bool hasGradient(bool complex=false) const {
216  return m_gradientType != G_None && m_gradientStopList.size() >= (complex ? 3 : 2);
217  }
219  bool hasSurface() const {
220  return hasSurfaceColor() || hasPattern() || hasGradient();
221  }
223  void setShadowColor(MWAWColor const &col, float opacity = 1) {
224  m_shadowColor = col;
225  m_shadowOpacity = opacity;
226  }
228  bool hasShadow() const {
229  return m_shadowOpacity > 0;
230  }
232  friend std::ostream &operator<<(std::ostream &o, MWAWGraphicStyle const &st);
234  void addTo(WPXPropertyList &pList, WPXPropertyListVector &gradient, bool only1d=false) const;
235 
237  int cmp(MWAWGraphicStyle const &a) const;
238 
240  float m_lineWidth;
242  std::vector<float> m_lineDashWidth;
257 
264 
267 
271  std::vector<GradientStop> m_gradientStopList;
280 
282  bool m_arrows[2];
283 
284  // some transformation: must probably be somewhere else
285 
287  float m_rotate;
289  bool m_flip[2];
290 
292  std::string m_extra;
293 };
294 #endif
295 // 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:289
friend std::ostream & operator<<(std::ostream &o, GradientStop const &st)
a print operator
Definition: MWAWGraphicStyle.hxx:74
bool hasSurfaceColor() const
returns true if the surface is defined
Definition: MWAWGraphicStyle.hxx:203
Vec2i m_dim
the dimension width x height
Definition: MWAWGraphicStyle.hxx:165
bool empty() const
return true if we does not have a pattern
Definition: MWAWGraphicStyle.hxx:107
MWAWColor m_surfaceColor
the surface color
Definition: MWAWGraphicStyle.hxx:254
MWAWColor m_shadowColor
the shadow color
Definition: MWAWGraphicStyle.hxx:259
Definition: MWAWGraphicStyle.hxx:53
float m_opacity
the opacity
Definition: MWAWGraphicStyle.hxx:86
float m_shadowOpacity
true if the shadow has some color
Definition: MWAWGraphicStyle.hxx:261
Pattern()
constructor
Definition: MWAWGraphicStyle.hxx:94
static MWAWColor white()
return the white color
Definition: libmwaw_internal.hxx:184
MWAWGraphicStyle()
constructor
Definition: MWAWGraphicStyle.hxx:180
Definition: MWAWGraphicStyle.hxx:55
MWAWColor m_colors[2]
the two indexed colors
Definition: MWAWGraphicStyle.hxx:168
LineCap
an enum used to define the basic line cap
Definition: MWAWGraphicStyle.hxx:51
LineJoin m_lineJoin
the line join
Definition: MWAWGraphicStyle.hxx:246
MWAWColor m_lineColor
the line color
Definition: MWAWGraphicStyle.hxx:250
static MWAWColor black()
return the back color
Definition: libmwaw_internal.hxx:180
float m_gradientRadius
the gradient radius
Definition: MWAWGraphicStyle.hxx:279
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:175
friend std::ostream & operator<<(std::ostream &o, MWAWGraphicStyle const &st)
a print operator
Definition: MWAWGraphicStyle.cxx:376
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:282
Definition: MWAWGraphicStyle.hxx:51
bool hasGradient(bool complex=false) const
returns true if the gradient is defined
Definition: MWAWGraphicStyle.hxx:215
float m_rotate
the rotation
Definition: MWAWGraphicStyle.hxx:287
std::vector< float > m_lineDashWidth
the dash array: a sequence of (fullsize, emptysize)
Definition: MWAWGraphicStyle.hxx:242
a structure used to define the gradient limit
Definition: MWAWGraphicStyle.hxx:58
Definition: MWAWGraphicStyle.hxx:55
std::string m_extra
extra data
Definition: MWAWGraphicStyle.hxx:292
bool hasPattern() const
returns true if the pattern is defined
Definition: MWAWGraphicStyle.hxx:211
void setPattern(Pattern const &pat)
set the pattern
Definition: MWAWGraphicStyle.hxx:207
LineCap m_lineCap
the line cap
Definition: MWAWGraphicStyle.hxx:244
float m_surfaceOpacity
true if the surface has some color
Definition: MWAWGraphicStyle.hxx:256
float m_gradientBorder
the gradient border opacity
Definition: MWAWGraphicStyle.hxx:275
GradientType m_gradientType
the gradient type
Definition: MWAWGraphicStyle.hxx:269
Definition: MWAWGraphicStyle.hxx:53
float m_gradientAngle
the gradient angle
Definition: MWAWGraphicStyle.hxx:273
Pattern m_pattern
the pattern if it exists
Definition: MWAWGraphicStyle.hxx:266
Definition: MWAWGraphicStyle.hxx:53
void setSurfaceColor(MWAWColor const &col, float opacity=1)
set the surface color
Definition: MWAWGraphicStyle.hxx:198
Definition: MWAWGraphicStyle.hxx:51
virtual ~MWAWGraphicStyle()
virtual destructor
Definition: MWAWGraphicStyle.hxx:192
bool m_fillRuleEvenOdd
true if the fill rule is evenod
Definition: MWAWGraphicStyle.hxx:252
bool getAverageColor(MWAWColor &col) const
return the average color
Definition: MWAWGraphicStyle.cxx:71
void addTo(WPXPropertyList &pList, WPXPropertyListVector &gradient, bool only1d=false) const
add to propList
Definition: MWAWGraphicStyle.cxx:139
bool hasSurface() const
returns true if the interior surface is defined
Definition: MWAWGraphicStyle.hxx:219
Definition: MWAWGraphicStyle.hxx:55
Definition: MWAWGraphicStyle.hxx:55
int cmp(GradientStop const &a) const
compare two gradient
Definition: MWAWGraphicStyle.hxx:64
MWAWColor m_color
the color
Definition: MWAWGraphicStyle.hxx:84
bool getBinary(WPXBinaryData &data, std::string &type) const
tries to convert the picture in a binary data ( ppm)
Definition: MWAWGraphicStyle.cxx:98
WPXBinaryData m_picture
a picture
Definition: MWAWGraphicStyle.hxx:173
Definition: MWAWGraphicStyle.hxx:55
bool hasShadow() const
returns true if the shadow is defined
Definition: MWAWGraphicStyle.hxx:228
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:223
float m_lineOpacity
the line opacity: 0=transparent
Definition: MWAWGraphicStyle.hxx:248
MWAWColor m_pictureAverageColor
the picture average color
Definition: MWAWGraphicStyle.hxx:177
Vec2f m_shadowOffset
the shadow offset
Definition: MWAWGraphicStyle.hxx:263
float m_lineWidth
the linewidth
Definition: MWAWGraphicStyle.hxx:240
friend std::ostream & operator<<(std::ostream &o, Pattern const &pat)
a print operator
Definition: MWAWGraphicStyle.hxx:149
bool isWhite() const
return true if the color is white
Definition: libmwaw_internal.hxx:200
Vec2f m_gradientPercentCenter
the gradient center
Definition: MWAWGraphicStyle.hxx:277
bool isBlack() const
return true if the color is black
Definition: libmwaw_internal.hxx:196
bool hasLine() const
returns true if the border is defined
Definition: MWAWGraphicStyle.hxx:194
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:170
int cmp(Pattern const &a) const
compare two patterns
Definition: MWAWGraphicStyle.hxx:121
Pattern(Vec2i dim, WPXBinaryData const &picture, std::string const &mime, MWAWColor const &avColor)
constructor from a binary data
Definition: MWAWGraphicStyle.hxx:99
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:312
a basic pattern used in a MWAWGraphicStyle:
Definition: MWAWGraphicStyle.hxx:92
float m_offset
the offset
Definition: MWAWGraphicStyle.hxx:82
int cmp(Vec2< T > const &p) const
a comparison function: which first compares x then y
Definition: libmwaw_internal.hxx:532
Definition: MWAWGraphicStyle.hxx:55
std::vector< GradientStop > m_gradientStopList
the list of gradient limits
Definition: MWAWGraphicStyle.hxx:271
virtual ~Pattern()
virtual destructor
Definition: MWAWGraphicStyle.hxx:105

Generated on Tue Mar 10 2015 17:32:09 for libmwaw by doxygen 1.8.5