MWAWPictBasic.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 
34 /* This header contains code specific to manage basic picture (line, rectangle, ...)
35  *
36  * Note: all unit are points
37  *
38  */
39 
40 #ifndef MWAW_PICT_BASIC
41 # define MWAW_PICT_BASIC
42 
43 # include <assert.h>
44 # include <ostream>
45 # include <string>
46 # include <vector>
47 
48 # include "libmwaw_internal.hxx"
49 # include "MWAWPict.hxx"
50 
52 
53 /*
54  libmwaw:document w="..pt" h="..pt"
55  libmwaw:graphicStyle lineColor="#......" lineWidth="..pt" lineFill="solid/none"
56  surfaceColor="#......" surfaceFill="solid/none"
57  startArrow="true/false" startArrowWidth="..pt"
58  endArrow="true/false" endArrowWidth="..pt" /
59  libmwaw:drawLine x0=".." y0=".." x1=".." y1=".." /
60  libmwaw:drawRectangle x0=".." y0=".." w=".." h=".." [ rw=".." rh=".." ] /
61  libmwaw:drawCircle x0=".." y0=".." w=".." h=".." /
62  libmwaw:drawArc x0=".." y0=".." w=".." h=".." angle0=".." angle1=".." /
63  libmwaw:drawPolygon x0=".." y0=".." ... x{N-1}=".." y{N-1}=".." w=".." h=".." /
64  libmwaw:drawPath path=".." w=".." h=".." /
65  /libmwaw:document
66 */
67 
69 class MWAWPictBasic: public MWAWPict
70 {
71 public:
73  virtual ~MWAWPictBasic() {}
74 
78  virtual Type getType() const {
79  return Basic;
80  }
82  virtual SubType getSubType() const = 0;
83 
85  void setLineWidth(float w) {
86  m_lineWidth = w;
88  }
91  void setLineColor(MWAWColor const &col) {
92  m_lineColor = col;
93  }
94 
96  void setSurfaceColor(MWAWColor const &col, bool hasColor = true) {
97  m_surfaceColor = col;
98  m_surfaceHasColor = hasColor;
99  }
100  bool hasSurfaceColor() const {
101  return m_surfaceHasColor;
102  }
103 
105  virtual bool getBinary(WPXBinaryData &data, std::string &s) const {
106  if (!getODGBinary(data)) return false;
107  s = "image/mwaw-odg";
108  return true;
109  }
111  virtual bool getODGBinary(WPXBinaryData &) const {
112  return false;
113  }
114 
118  virtual int cmp(MWAWPict const &a) const {
119  int diff = MWAWPict::cmp(a);
120  if (diff) return diff;
121 
122  MWAWPictBasic const &aPict = static_cast<MWAWPictBasic const &>(a);
123  // the type
124  diff = getSubType() - aPict.getSubType();
125  if (diff) return (diff < 0) ? -1 : 1;
126 
127  float diffF = m_lineWidth - aPict.m_lineWidth;
128  if (diffF < 0) return -1;
129  if (diffF > 0) return 1;
130 
131  if (m_lineColor < aPict.m_lineColor) return -1;
132  if (m_lineColor > aPict.m_lineColor) return 1;
133  if (m_surfaceColor < aPict.m_surfaceColor) return -1;
134  if (m_surfaceColor > aPict.m_surfaceColor) return 1;
135  for (int c = 0; c < 2; c++) {
136  diffF = m_extend[c]-aPict.m_extend[c];
137  if (diffF < 0) return -1;
138  if (diffF > 0) return 1;
139  }
141  return m_surfaceHasColor;
142  return 0;
143  }
144 protected:
146  virtual void getGraphicStyleProperty(WPXPropertyList &list) const = 0;
147 
149  void getStyle1DProperty(WPXPropertyList &list) const;
151  void getStyle2DProperty(WPXPropertyList &list) const;
152 
154  void startODG(MWAWPropertyHandlerEncoder &doc) const;
156  void endODG(MWAWPropertyHandlerEncoder &doc) const;
157 
159  // - \param id=0 corresponds to linewidth
160  // - \param id=1 corresponds to a second extension (arrow)
161  void extendBDBox(float val, int id) {
162  assert(id>=0&& id<=1);
163  m_extend[id] = val;
165  }
166 
169  for (int c = 0; c < 2; c++) m_extend[c]=0;
170  setLineWidth(1.0);
171  }
174  *this=p;
175  }
178  if (&p == this) return *this;
183  for (int c=0; c < 2; c++) m_extend[c] = p.m_extend[c];
185  return *this;
186  }
187 
188 private:
190  float m_lineWidth;
198  float m_extend[2];
199 };
200 
203 {
204 public:
207  m_extremity[0] = orig;
208  m_extremity[1] = end;
209  m_arrows[0] = m_arrows[1] = false;
211  }
213  virtual ~MWAWPictLine() {}
215  void setArrow(int v, bool val) {
216  assert(v>=0 && v<=1);
217  m_arrows[v]=val;
218  extendBDBox ((m_arrows[0] || m_arrows[1]) ? 5 : 0, 1);
219  }
220 
222  virtual bool getODGBinary(WPXBinaryData &res) const;
223 
224 protected:
226  virtual SubType getSubType() const {
227  return Line;
228  }
230  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
232  virtual int cmp(MWAWPict const &a) const {
233  int diff = MWAWPictBasic::cmp(a);
234  if (diff) return diff;
235  MWAWPictLine const &aLine = static_cast<MWAWPictLine const &>(a);
236  for (int c = 0; c < 2; c++) {
237  diff = m_extremity[c].cmpY(aLine.m_extremity[c]);
238  if (diff) return diff;
239  }
240  for (int c = 0; c < 2; c++) {
241  diff = m_arrows[c]-aLine.m_arrows[c];
242  if (diff) return (diff < 0) ? -1 : 1;
243  }
244  return 0;
245  }
246 
247 
251  bool m_arrows[2];
252 };
253 
256 {
257 public:
260  setBdBox(box);
261  for (int i = 0; i < 2; i++) m_cornerWidth[i] = 0;
262  }
264  virtual ~MWAWPictRectangle() {}
265 
267  void setRoundCornerWidth(int w) {
268  m_cornerWidth[0] = m_cornerWidth[1] = w;
269  }
270 
272  void setRoundCornerWidth(int xw, int yw) {
273  m_cornerWidth[0] = xw;
274  m_cornerWidth[1] = yw;
275  }
276 
278  virtual bool getODGBinary(WPXBinaryData &res) const;
279 
280 protected:
282  virtual SubType getSubType() const {
283  return Rectangle;
284  }
286  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
288  virtual int cmp(MWAWPict const &a) const {
289  int diff = MWAWPictBasic::cmp(a);
290  if (diff) return diff;
291  MWAWPictRectangle const &aRect = static_cast<MWAWPictRectangle const &>(a);
292  for (int i = 0; i < 2; i++) {
293  diff = m_cornerWidth[i] - aRect.m_cornerWidth[i];
294  if (diff) return (diff < 0) ? -1 : 1;
295  }
296  return 0;
297  }
298 
303 };
304 
307 {
308 public:
311  setBdBox(box);
312  }
314  virtual ~MWAWPictCircle() {}
315 
317  virtual bool getODGBinary(WPXBinaryData &res) const;
318 
319 protected:
321  virtual SubType getSubType() const {
322  return Circle;
323  }
325  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
327  virtual int cmp(MWAWPict const &a) const {
328  return MWAWPictBasic::cmp(a);
329  }
330 
331  // corner point
333 };
334 
337 {
338 public:
341  MWAWPictArc(Box2f box, Box2f ellBox, float ang1, float ang2) : MWAWPictBasic(), m_circleBox(ellBox) {
342  setBdBox(box);
343  m_angle[0] = ang1;
344  m_angle[1] = ang2;
345  }
347  virtual ~MWAWPictArc() {}
348 
350  virtual bool getODGBinary(WPXBinaryData &res) const;
351 
352 protected:
354  virtual SubType getSubType() const {
355  return Arc;
356  }
358  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
360  virtual int cmp(MWAWPict const &a) const {
361  int diff = MWAWPictBasic::cmp(a);
362  if (diff) return diff;
363  MWAWPictArc const &aArc = static_cast<MWAWPictArc const &>(a);
364  // first check the bdbox
365  diff = m_circleBox.cmp(aArc.m_circleBox);
366  if (diff) return diff;
367  for (int c = 0; c < 2; c++) {
368  float diffF = m_angle[c]-aArc.m_angle[c];
369  if (diffF < 0) return -1;
370  if (diffF > 0) return 1;
371  }
372  return 0;
373  }
374 
377 
379  float m_angle[2];
380 };
381 
384 {
385 public:
387  MWAWPictPath(Box2f bdBox, std::string path) : MWAWPictBasic(), m_path(path) {
388  setBdBox(bdBox);
389  }
391  virtual ~MWAWPictPath() {}
392 
394  virtual bool getODGBinary(WPXBinaryData &res) const;
395 
396 protected:
398  virtual SubType getSubType() const {
399  return Path;
400  }
402  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
404  virtual int cmp(MWAWPict const &a) const {
405  int diff = MWAWPictBasic::cmp(a);
406  if (diff) return diff;
407  MWAWPictPath const &aPath = static_cast<MWAWPictPath const &>(a);
408  // first check the bdbox
409  diff = m_path.compare(aPath.m_path);
410  if (diff) return diff;
411  return 0;
412  }
413 
415  std::string m_path;
416 };
417 
420 {
421 public:
424  MWAWPictPolygon(Box2f bdBox, std::vector<Vec2f> const &lVect) : MWAWPictBasic(), m_verticesList(lVect) {
425  setBdBox(bdBox);
426  }
428  virtual ~MWAWPictPolygon() {}
429 
431  virtual bool getODGBinary(WPXBinaryData &res) const;
432 
433 protected:
435  virtual SubType getSubType() const {
436  return Polygon;
437  }
439  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
441  virtual int cmp(MWAWPict const &a) const {
442  int diff = MWAWPictBasic::cmp(a);
443  if (diff) return diff;
444  MWAWPictPolygon const &aPoly = static_cast<MWAWPictPolygon const &>(a);
445  if (m_verticesList.size()<aPoly.m_verticesList.size())
446  return -1;
447  if (m_verticesList.size()>aPoly.m_verticesList.size())
448  return 1;
449 
450  // check the vertices
451  for (size_t c = 0; c < m_verticesList.size(); c++) {
452  diff = m_verticesList[c].cmpY(aPoly.m_verticesList[c]);
453  if (diff) return diff;
454  }
455  return 0;
456  }
457 
459  std::vector<Vec2f> m_verticesList;
460 };
461 
462 #endif
463 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWPictBasic & operator=(MWAWPictBasic const &p)
protected= must not be called directly
Definition: MWAWPictBasic.hxx:177
virtual bool getODGBinary(WPXBinaryData &res) const
returns a ODG (encoded)
Definition: MWAWPictBasic.cxx:300
void setSurfaceColor(MWAWColor const &col, bool hasColor=true)
sets the surface color.
Definition: MWAWPictBasic.hxx:96
Definition: MWAWPictBasic.hxx:76
float m_extend[2]
m_extend[0]: from lineWidth, m_extend[1]: came from extra data
Definition: MWAWPictBasic.hxx:198
MWAWPictPath(Box2f bdBox, std::string path)
constructor: bdbox followed by the path definition
Definition: MWAWPictBasic.hxx:387
a class used to define a generic path ( a bezier curve, ... )
Definition: MWAWPictBasic.hxx:383
MWAWPictArc(Box2f box, Box2f ellBox, float ang1, float ang2)
constructor: bdbox followed by the bdbox of the circle and 2 angles exprimed in degree ...
Definition: MWAWPictBasic.hxx:341
virtual ~MWAWPictRectangle()
virtual destructor
Definition: MWAWPictBasic.hxx:264
void setLineWidth(float w)
sets the line width (by default 1.0)
Definition: MWAWPictBasic.hxx:85
void setLineColor(MWAWColor const &col)
sets the line color.
Definition: MWAWPictBasic.hxx:91
a class used to define an arc
Definition: MWAWPictBasic.hxx:336
int cmp(Box2< T > const &p) const
comparison function : fist sorts min by Y,X values then max extremity
Definition: libmwaw_internal.hxx:841
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:327
virtual ~MWAWPictPath()
virtual destructor
Definition: MWAWPictBasic.hxx:391
MWAWPictCircle(Box2f box)
constructor
Definition: MWAWPictBasic.hxx:310
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:282
virtual bool getODGBinary(WPXBinaryData &res) const
returns a ODG (encoded)
Definition: MWAWPictBasic.cxx:186
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order.
Definition: MWAWPictBasic.hxx:118
virtual void getGraphicStyleProperty(WPXPropertyList &list) const
returns the graphics style
Definition: MWAWPictBasic.cxx:340
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:226
virtual bool getODGBinary(WPXBinaryData &res) const
returns a ODG (encoded)
Definition: MWAWPictBasic.cxx:262
bool hasSurfaceColor() const
Definition: MWAWPictBasic.hxx:100
MWAWColor m_lineColor
the line color
Definition: MWAWPictBasic.hxx:192
Definition: MWAWPictBasic.hxx:76
MWAWPictLine(Vec2f orig, Vec2f end)
constructor
Definition: MWAWPictBasic.hxx:206
write in WPXBinaryData a list of tags/and properties
Definition: MWAWPropertyHandler.hxx:82
float m_angle[2]
the two angles
Definition: MWAWPictBasic.hxx:379
Box2f m_rectBox
corner point
Definition: MWAWPictBasic.hxx:302
MWAWPictPolygon(Box2f bdBox, std::vector< Vec2f > const &lVect)
constructor: bdbox followed by the bdbox of the circle and 2 angl exprimed in degree ...
Definition: MWAWPictBasic.hxx:424
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:354
the class to store a color
Definition: libmwaw_internal.hxx:161
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class ...
Definition: MWAWPict.hxx:102
virtual bool getODGBinary(WPXBinaryData &res) const
returns a ODG (encoded)
Definition: MWAWPictBasic.cxx:107
Definition: MWAWPictBasic.hxx:76
a class used to define a polygon
Definition: MWAWPictBasic.hxx:419
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:435
virtual void getGraphicStyleProperty(WPXPropertyList &list) const
returns the graphics style
Definition: MWAWPictBasic.cxx:287
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:288
virtual ~MWAWPictLine()
virtual destructor
Definition: MWAWPictBasic.hxx:213
SubType
the picture subtype ( line, rectangle, polygon, circle, arc)
Definition: MWAWPictBasic.hxx:76
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:404
void getStyle2DProperty(WPXPropertyList &list) const
returns the basic style property for 2D form (line, ...)
Definition: MWAWPictBasic.cxx:91
void setRoundCornerWidth(int w)
sets the corner width
Definition: MWAWPictBasic.hxx:267
virtual SubType getSubType() const =0
returns the picture subtype
virtual bool getODGBinary(WPXBinaryData &) const
virtual function which tries to convert the picture in ODG and put the result in a WPXBinaryData ...
Definition: MWAWPictBasic.hxx:111
Definition: MWAWPictBasic.hxx:76
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:321
bool m_arrows[2]
two bool to indicated if extremity has arrow or not
Definition: MWAWPictBasic.hxx:251
int m_cornerWidth[2]
an int used to define round corner
Definition: MWAWPictBasic.hxx:300
MWAWPictBasic()
protected constructor must not be called directly
Definition: MWAWPictBasic.hxx:168
Definition: MWAWPictBasic.hxx:76
std::vector< Vec2f > m_verticesList
the vertices list
Definition: MWAWPictBasic.hxx:459
Definition: MWAWPict.hxx:67
virtual ~MWAWPictArc()
virtual destructor
Definition: MWAWPictBasic.hxx:347
virtual ~MWAWPictCircle()
virtual destructor
Definition: MWAWPictBasic.hxx:314
Definition: MWAWPictBasic.hxx:76
virtual bool getODGBinary(WPXBinaryData &res) const
returns a ODG (encoded)
Definition: MWAWPictBasic.cxx:149
void setBdBox(Box2f const &box)
sets the bdbox of the picture
Definition: MWAWPict.hxx:87
Type
the different picture types:
Definition: MWAWPict.hxx:67
virtual void getGraphicStyleProperty(WPXPropertyList &list) const
returns the graphics style
Definition: MWAWPictBasic.cxx:209
virtual void getGraphicStyleProperty(WPXPropertyList &list) const =0
function to implement in subclass in order to get the graphics style
void extendBDBox(float val, int id)
a function to extend the bdbox
Definition: MWAWPictBasic.hxx:161
int cmpY(Vec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libmwaw_internal.hxx:528
a class used to define a circle or an ellipse
Definition: MWAWPictBasic.hxx:306
virtual void getGraphicStyleProperty(WPXPropertyList &list) const
returns the graphics style
Definition: MWAWPictBasic.cxx:176
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:360
void endODG(MWAWPropertyHandlerEncoder &doc) const
adds the odg footer
Definition: MWAWPictBasic.cxx:74
void getStyle1DProperty(WPXPropertyList &list) const
returns the basic style property for 1D form (line, ...)
Definition: MWAWPictBasic.cxx:78
virtual Type getType() const
returns the picture type
Definition: MWAWPictBasic.hxx:78
void startODG(MWAWPropertyHandlerEncoder &doc) const
adds the odg header knowing the minPt and the maxPt
Definition: MWAWPictBasic.cxx:59
virtual ~MWAWPictBasic()
virtual destructor
Definition: MWAWPictBasic.hxx:73
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:232
virtual bool getODGBinary(WPXBinaryData &res) const
returns a ODG (encoded)
Definition: MWAWPictBasic.cxx:219
Box2f m_circleBox
corner ellipse rectangle point
Definition: MWAWPictBasic.hxx:376
virtual void getGraphicStyleProperty(WPXPropertyList &list) const
returns the graphics style
Definition: MWAWPictBasic.cxx:130
MWAWPictBasic(MWAWPictBasic const &p)
protected constructor must not be called directly
Definition: MWAWPictBasic.hxx:173
std::string m_path
the string represented the path (in svg)
Definition: MWAWPictBasic.hxx:415
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:398
Box2f m_circleBox
Definition: MWAWPictBasic.hxx:332
virtual ~MWAWPictPolygon()
virtual destructor
Definition: MWAWPictBasic.hxx:428
a class to store a simple line
Definition: MWAWPictBasic.hxx:202
Box2f getBdBox() const
returns the bdbox of the picture
Definition: MWAWPict.hxx:80
MWAWColor m_surfaceColor
the line color
Definition: MWAWPictBasic.hxx:194
virtual bool getBinary(WPXBinaryData &data, std::string &s) const
returns the final representation in encoded odg (if possible)
Definition: MWAWPictBasic.hxx:105
bool m_surfaceHasColor
true if the surface has some color
Definition: MWAWPictBasic.hxx:196
MWAWPictRectangle(Box2f box)
constructor
Definition: MWAWPictBasic.hxx:259
Vec2f m_extremity[2]
the extremity coordinate
Definition: MWAWPictBasic.hxx:249
an abstract class which defines basic picture (a line, a rectangle, ...)
Definition: MWAWPictBasic.hxx:69
void setRoundCornerWidth(int xw, int yw)
sets the corner width
Definition: MWAWPictBasic.hxx:272
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:441
virtual void getGraphicStyleProperty(WPXPropertyList &list) const
returns the graphics style
Definition: MWAWPictBasic.cxx:249
void extendBDBox(float val)
udaptes the bdbox, by extended it by (val-previousVal)
Definition: MWAWPict.hxx:136
a class to define a rectangle (or a rectangle with round corner)
Definition: MWAWPictBasic.hxx:255
float m_lineWidth
the linewidth
Definition: MWAWPictBasic.hxx:190
void setArrow(int v, bool val)
sets the arrow: orig(v=0), end(v=1)
Definition: MWAWPictBasic.hxx:215
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:53
MWAWPict & operator=(MWAWPict const &p)
protected operator= must not be called directly
Definition: MWAWPict.hxx:147

Generated on Tue Jun 24 2014 16:46:27 for libmwaw by doxygen 1.8.5