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;
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:

Generated on Wed Jul 10 2013 18:02:04 for libmwaw by doxygen 1.8.4