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 
51 class WPXBinaryData;
52 class WPXPropertyList;
53 class MWAWPropertyHandlerEncoder;
54 
55 /*
56  libmwaw:document w="..pt" h="..pt"
57  libmwaw:graphicStyle lineColor="#......" lineWidth="..pt" lineFill="solid/none"
58  surfaceColor="#......" surfaceFill="solid/none"
59  startArrow="true/false" startArrowWidth="..pt"
60  endArrow="true/false" endArrowWidth="..pt" /
61  libmwaw:drawLine x0=".." y0=".." x1=".." y1=".." /
62  libmwaw:drawRectangle x0=".." y0=".." w=".." h=".." [ rw=".." rh=".." ] /
63  libmwaw:drawCircle x0=".." y0=".." w=".." h=".." /
64  libmwaw:drawArc x0=".." y0=".." w=".." h=".." angle0=".." angle1=".." /
65  libmwaw:drawPolygon x0=".." y0=".." ... x{N-1}=".." y{N-1}=".." w=".." h=".." /
66  libmwaw:drawPath path=".." w=".." h=".." /
67  /libmwaw:document
68 */
69 
71 class MWAWPictBasic: public MWAWPict
72 {
73 public:
75  virtual ~MWAWPictBasic() {}
76 
80  virtual Type getType() const {
81  return Basic;
82  }
84  virtual SubType getSubType() const = 0;
85 
87  void setLineWidth(float w) {
88  m_lineWidth = w;
90  }
93  void setLineColor(MWAWColor const &col) {
94  m_lineColor = col;
95  }
96 
98  void setSurfaceColor(MWAWColor const &col, bool hasColor = true) {
99  m_surfaceColor = col;
100  m_surfaceHasColor = hasColor;
101  }
102  bool hasSurfaceColor() const {
103  return m_surfaceHasColor;
104  }
105 
107  virtual bool getBinary(WPXBinaryData &data, std::string &s) const {
108  if (!getODGBinary(data)) return false;
109  s = "image/mwaw-odg";
110  return true;
111  }
113  virtual bool getODGBinary(WPXBinaryData &) const {
114  return false;
115  }
116 
120  virtual int cmp(MWAWPict const &a) const {
121  int diff = MWAWPict::cmp(a);
122  if (diff) return diff;
123 
124  MWAWPictBasic const &aPict = static_cast<MWAWPictBasic const &>(a);
125  // the type
126  diff = getSubType() - aPict.getSubType();
127  if (diff) return (diff < 0) ? -1 : 1;
128 
129  float diffF = m_lineWidth - aPict.m_lineWidth;
130  if (diffF < 0) return -1;
131  if (diffF > 0) return 1;
132 
133  if (m_lineColor < aPict.m_lineColor) return -1;
134  if (m_lineColor > aPict.m_lineColor) return 1;
135  if (m_surfaceColor < aPict.m_surfaceColor) return -1;
136  if (m_surfaceColor > aPict.m_surfaceColor) return 1;
137  for (int c = 0; c < 2; c++) {
138  diffF = m_extend[c]-aPict.m_extend[c];
139  if (diffF < 0) return -1;
140  if (diffF > 0) return 1;
141  }
143  return m_surfaceHasColor;
144  return 0;
145  }
146 protected:
148  virtual void getGraphicStyleProperty(WPXPropertyList &list) const = 0;
149 
151  void getStyle1DProperty(WPXPropertyList &list) const;
153  void getStyle2DProperty(WPXPropertyList &list) const;
154 
156  void startODG(MWAWPropertyHandlerEncoder &doc) const;
158  void endODG(MWAWPropertyHandlerEncoder &doc) const;
159 
161  // - \param id=0 corresponds to linewidth
162  // - \param id=1 corresponds to a second extension (arrow)
163  void extendBDBox(float val, int id) {
164  assert(id>=0&& id<=1);
165  m_extend[id] = val;
167  }
168 
171  for (int c = 0; c < 2; c++) m_extend[c]=0;
172  setLineWidth(1.0);
173  }
176  *this=p;
177  }
180  if (&p == this) return *this;
185  for (int c=0; c < 2; c++) m_extend[c] = p.m_extend[c];
187  return *this;
188  }
189 
190 private:
192  float m_lineWidth;
200  float m_extend[2];
201 };
202 
205 {
206 public:
209  m_extremity[0] = orig;
210  m_extremity[1] = end;
211  m_arrows[0] = m_arrows[1] = false;
213  }
215  virtual ~MWAWPictLine() {}
217  void setArrow(int v, bool val) {
218  assert(v>=0 && v<=1);
219  m_arrows[v]=val;
220  extendBDBox ((m_arrows[0] || m_arrows[1]) ? 5 : 0, 1);
221  }
222 
224  virtual bool getODGBinary(WPXBinaryData &res) const;
225 
226 protected:
228  virtual SubType getSubType() const {
229  return Line;
230  }
232  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
234  virtual int cmp(MWAWPict const &a) const {
235  int diff = MWAWPictBasic::cmp(a);
236  if (diff) return diff;
237  MWAWPictLine const &aLine = static_cast<MWAWPictLine const &>(a);
238  for (int c = 0; c < 2; c++) {
239  diff = m_extremity[c].cmpY(aLine.m_extremity[c]);
240  if (diff) return diff;
241  }
242  for (int c = 0; c < 2; c++) {
243  diff = m_arrows[c]-aLine.m_arrows[c];
244  if (diff) return (diff < 0) ? -1 : 1;
245  }
246  return 0;
247  }
248 
249 
253  bool m_arrows[2];
254 };
255 
258 {
259 public:
262  setBdBox(box);
263  for (int i = 0; i < 2; i++) m_cornerWidth[i] = 0;
264  }
266  virtual ~MWAWPictRectangle() {}
267 
269  void setRoundCornerWidth(int w) {
270  m_cornerWidth[0] = m_cornerWidth[1] = w;
271  }
272 
274  void setRoundCornerWidth(int xw, int yw) {
275  m_cornerWidth[0] = xw;
276  m_cornerWidth[1] = yw;
277  }
278 
280  virtual bool getODGBinary(WPXBinaryData &res) const;
281 
282 protected:
284  virtual SubType getSubType() const {
285  return Rectangle;
286  }
288  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
290  virtual int cmp(MWAWPict const &a) const {
291  int diff = MWAWPictBasic::cmp(a);
292  if (diff) return diff;
293  MWAWPictRectangle const &aRect = static_cast<MWAWPictRectangle const &>(a);
294  for (int i = 0; i < 2; i++) {
295  diff = m_cornerWidth[i] - aRect.m_cornerWidth[i];
296  if (diff) return (diff < 0) ? -1 : 1;
297  }
298  return 0;
299  }
300 
305 };
306 
309 {
310 public:
313  setBdBox(box);
314  }
316  virtual ~MWAWPictCircle() {}
317 
319  virtual bool getODGBinary(WPXBinaryData &res) const;
320 
321 protected:
323  virtual SubType getSubType() const {
324  return Circle;
325  }
327  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
329  virtual int cmp(MWAWPict const &a) const {
330  return MWAWPictBasic::cmp(a);
331  }
332 
333  // corner point
335 };
336 
339 {
340 public:
343  MWAWPictArc(Box2f box, Box2f ellBox, float ang1, float ang2) : MWAWPictBasic(), m_circleBox(ellBox) {
344  setBdBox(box);
345  m_angle[0] = ang1;
346  m_angle[1] = ang2;
347  }
349  virtual ~MWAWPictArc() {}
350 
352  virtual bool getODGBinary(WPXBinaryData &res) const;
353 
354 protected:
356  virtual SubType getSubType() const {
357  return Arc;
358  }
360  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
362  virtual int cmp(MWAWPict const &a) const {
363  int diff = MWAWPictBasic::cmp(a);
364  if (diff) return diff;
365  MWAWPictArc const &aArc = static_cast<MWAWPictArc const &>(a);
366  // first check the bdbox
367  diff = m_circleBox.cmp(aArc.m_circleBox);
368  if (diff) return diff;
369  for (int c = 0; c < 2; c++) {
370  float diffF = m_angle[c]-aArc.m_angle[c];
371  if (diffF < 0) return -1;
372  if (diffF > 0) return 1;
373  }
374  return 0;
375  }
376 
379 
381  float m_angle[2];
382 };
383 
386 {
387 public:
389  MWAWPictPath(Box2f bdBox, std::string path) : MWAWPictBasic(), m_path(path) {
390  setBdBox(bdBox);
391  }
393  virtual ~MWAWPictPath() {}
394 
396  virtual bool getODGBinary(WPXBinaryData &res) const;
397 
398 protected:
400  virtual SubType getSubType() const {
401  return Path;
402  }
404  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
406  virtual int cmp(MWAWPict const &a) const {
407  int diff = MWAWPictBasic::cmp(a);
408  if (diff) return diff;
409  MWAWPictPath const &aPath = static_cast<MWAWPictPath const &>(a);
410  // first check the bdbox
411  diff = m_path.compare(aPath.m_path);
412  if (diff) return diff;
413  return 0;
414  }
415 
417  std::string m_path;
418 };
419 
422 {
423 public:
426  MWAWPictPolygon(Box2f bdBox, std::vector<Vec2f> const &lVect) : MWAWPictBasic(), m_verticesList(lVect) {
427  setBdBox(bdBox);
428  }
430  virtual ~MWAWPictPolygon() {}
431 
433  virtual bool getODGBinary(WPXBinaryData &res) const;
434 
435 protected:
437  virtual SubType getSubType() const {
438  return Polygon;
439  }
441  virtual void getGraphicStyleProperty(WPXPropertyList &list) const;
443  virtual int cmp(MWAWPict const &a) const {
444  int diff = MWAWPictBasic::cmp(a);
445  if (diff) return diff;
446  MWAWPictPolygon const &aPoly = static_cast<MWAWPictPolygon const &>(a);
447  if (m_verticesList.size()<aPoly.m_verticesList.size())
448  return -1;
449  if (m_verticesList.size()>aPoly.m_verticesList.size())
450  return 1;
451 
452  // check the vertices
453  for (size_t c = 0; c < m_verticesList.size(); c++) {
454  diff = m_verticesList[c].cmpY(aPoly.m_verticesList[c]);
455  if (diff) return diff;
456  }
457  return 0;
458  }
459 
461  std::vector<Vec2f> m_verticesList;
462 };
463 
464 #endif
465 // 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:179
virtual bool getODGBinary(WPXBinaryData &res) const
returns a ODG (encoded)
Definition: MWAWPictBasic.cxx:292
void setSurfaceColor(MWAWColor const &col, bool hasColor=true)
sets the surface color.
Definition: MWAWPictBasic.hxx:98
Definition: MWAWPictBasic.hxx:78
float m_extend[2]
m_extend[0]: from lineWidth, m_extend[1]: came from extra data
Definition: MWAWPictBasic.hxx:200
MWAWPictPath(Box2f bdBox, std::string path)
constructor: bdbox followed by the path definition
Definition: MWAWPictBasic.hxx:389
a class used to define a generic path ( a bezier curve, ... )
Definition: MWAWPictBasic.hxx:385
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:343
virtual ~MWAWPictRectangle()
virtual destructor
Definition: MWAWPictBasic.hxx:266
void setLineWidth(float w)
sets the line width (by default 1.0)
Definition: MWAWPictBasic.hxx:87
void setLineColor(MWAWColor const &col)
sets the line color.
Definition: MWAWPictBasic.hxx:93
a class used to define an arc
Definition: MWAWPictBasic.hxx:338
int cmp(Box2< T > const &p) const
comparison function : fist sorts min by Y,X values then max extremity
Definition: libmwaw_internal.hxx:806
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:329
virtual ~MWAWPictPath()
virtual destructor
Definition: MWAWPictBasic.hxx:393
MWAWPictCircle(Box2f box)
constructor
Definition: MWAWPictBasic.hxx:312
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:284
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:120
virtual void getGraphicStyleProperty(WPXPropertyList &list) const
returns the graphics style
Definition: MWAWPictBasic.cxx:332
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:228
virtual bool getODGBinary(WPXBinaryData &res) const
returns a ODG (encoded)
Definition: MWAWPictBasic.cxx:254
bool hasSurfaceColor() const
Definition: MWAWPictBasic.hxx:102
MWAWColor m_lineColor
the line color
Definition: MWAWPictBasic.hxx:194
Definition: MWAWPictBasic.hxx:78
MWAWPictLine(Vec2f orig, Vec2f end)
constructor
Definition: MWAWPictBasic.hxx:208
float m_angle[2]
the two angles
Definition: MWAWPictBasic.hxx:381
Box2f m_rectBox
corner point
Definition: MWAWPictBasic.hxx:304
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:426
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:356
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:104
virtual bool getODGBinary(WPXBinaryData &res) const
returns a ODG (encoded)
Definition: MWAWPictBasic.cxx:107
Definition: MWAWPictBasic.hxx:78
a class used to define a polygon
Definition: MWAWPictBasic.hxx:421
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:437
virtual void getGraphicStyleProperty(WPXPropertyList &list) const
returns the graphics style
Definition: MWAWPictBasic.cxx:279
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:290
virtual ~MWAWPictLine()
virtual destructor
Definition: MWAWPictBasic.hxx:215
SubType
the picture subtype ( line, rectangle, polygon, circle, arc)
Definition: MWAWPictBasic.hxx:78
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:406
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:269
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:113
Definition: MWAWPictBasic.hxx:78
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:323
bool m_arrows[2]
two bool to indicated if extremity has arrow or not
Definition: MWAWPictBasic.hxx:253
int m_cornerWidth[2]
an int used to define round corner
Definition: MWAWPictBasic.hxx:302
MWAWPictBasic()
protected constructor must not be called directly
Definition: MWAWPictBasic.hxx:170
Definition: MWAWPictBasic.hxx:78
std::vector< Vec2f > m_verticesList
the vertices list
Definition: MWAWPictBasic.hxx:461
Definition: MWAWPict.hxx:69
virtual ~MWAWPictArc()
virtual destructor
Definition: MWAWPictBasic.hxx:349
virtual ~MWAWPictCircle()
virtual destructor
Definition: MWAWPictBasic.hxx:316
Definition: MWAWPictBasic.hxx:78
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:89
Type
the different picture types:
Definition: MWAWPict.hxx:69
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:163
int cmpY(Vec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libmwaw_internal.hxx:493
a class used to define a circle or an ellipse
Definition: MWAWPictBasic.hxx:308
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:362
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:80
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:75
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:234
virtual bool getODGBinary(WPXBinaryData &res) const
returns a ODG (encoded)
Definition: MWAWPictBasic.cxx:219
Box2f m_circleBox
corner ellipse rectangle point
Definition: MWAWPictBasic.hxx:378
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:175
std::string m_path
the string represented the path (in svg)
Definition: MWAWPictBasic.hxx:417
virtual SubType getSubType() const
returns the class type
Definition: MWAWPictBasic.hxx:400
Box2f m_circleBox
Definition: MWAWPictBasic.hxx:334
virtual ~MWAWPictPolygon()
virtual destructor
Definition: MWAWPictBasic.hxx:430
a class to store a simple line
Definition: MWAWPictBasic.hxx:204
Box2f getBdBox() const
returns the bdbox of the picture
Definition: MWAWPict.hxx:82
MWAWColor m_surfaceColor
the line color
Definition: MWAWPictBasic.hxx:196
virtual bool getBinary(WPXBinaryData &data, std::string &s) const
returns the final representation in encoded odg (if possible)
Definition: MWAWPictBasic.hxx:107
bool m_surfaceHasColor
true if the surface has some color
Definition: MWAWPictBasic.hxx:198
MWAWPictRectangle(Box2f box)
constructor
Definition: MWAWPictBasic.hxx:261
Vec2f m_extremity[2]
the extremity coordinate
Definition: MWAWPictBasic.hxx:251
an abstract class which defines basic picture (a line, a rectangle, ...)
Definition: MWAWPictBasic.hxx:71
void setRoundCornerWidth(int xw, int yw)
sets the corner width
Definition: MWAWPictBasic.hxx:274
virtual int cmp(MWAWPict const &a) const
comparison function
Definition: MWAWPictBasic.hxx:443
virtual void getGraphicStyleProperty(WPXPropertyList &list) const
returns the graphics style
Definition: MWAWPictBasic.cxx:244
void extendBDBox(float val)
udaptes the bdbox, by extended it by (val-previousVal)
Definition: MWAWPict.hxx:138
a class to define a rectangle (or a rectangle with round corner)
Definition: MWAWPictBasic.hxx:257
float m_lineWidth
the linewidth
Definition: MWAWPictBasic.hxx:192
void setArrow(int v, bool val)
sets the arrow: orig(v=0), end(v=1)
Definition: MWAWPictBasic.hxx:217
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:55
MWAWPict & operator=(MWAWPict const &p)
protected operator= must not be called directly
Definition: MWAWPict.hxx:149

Generated for libmwaw by doxygen 1.8.5