MWAWPict.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 /*
35  * This header contains code specific to manage basic picture (line, rectangle, ...)
36  *
37  * Note: generic class for all sort of pict
38  * - PictBasic: regroup basic pict shape (line, circle, ...)
39  * - PictBitmap: regroup some classes used to store bitmap
40  * - PictData: regroup the data which can be read via a WPXBinaryData
41  */
42 
43 #ifndef MWAW_PICT
44 # define MWAW_PICT
45 
46 # include <assert.h>
47 # include <ostream>
48 # include <vector>
49 
50 # include "libmwaw_internal.hxx"
51 
52 class WPXBinaryData;
53 
55 class MWAWPict
56 {
57 public:
59  virtual ~MWAWPict() {}
60 
71  virtual Type getType() const = 0;
72 
80 
82  Box2f getBdBox() const {
83  Box2f res(m_bdbox);
84  res.extend(m_bdBoxExt);
85  return res;
86  }
87 
89  void setBdBox(Box2f const &box) {
90  m_bdbox = box;
91  }
92 
97  virtual bool getBinary(WPXBinaryData &, std::string &) const {
98  return false;
99  }
100 
104  virtual int cmp(MWAWPict const &a) const {
105  // first compare the bdbox
106  int diff = m_bdbox.cmp(a.m_bdbox);
107  if (diff) return diff;
108  // the type
109  diff = getType() - a.getType();
110  if (diff) return (diff < 0) ? -1 : 1;
111 
112  return 0;
113  }
114 protected:
116  static Box2f getBdBox(int numPt, Vec2f const *pt) {
117  if (numPt <= 0) {
118  return Box2f();
119  }
120 
121  float minV[2], maxV[2];
122  for (int c = 0; c < 2; c++) minV[c] = maxV[c] = pt[0][c];
123 
124  for (int i = 1; i < numPt; i++) {
125  for (int c = 0; c < 2; c++) {
126  float v = pt[i][c];
127  if (v < minV[c]) minV[c] = v;
128  else if (v > maxV[c]) maxV[c] = v;
129  }
130  }
131 
132  return Box2f(Vec2f(minV[0], minV[1]), Vec2f(maxV[0], maxV[1]));
133  }
134 
135  // a function to extend the bdbox
136 
138  void extendBDBox(float val) {
139  m_bdBoxExt = val;
140  }
141 
143  MWAWPict() : m_bdbox(), m_bdBoxExt (0.0) {}
145  MWAWPict(MWAWPict const &p) : m_bdbox(), m_bdBoxExt (0.0) {
146  *this=p;
147  }
150  if (&p == this) return *this;
151  m_bdbox = p.m_bdbox;
153  return *this;
154  }
155 
156 private:
160  float m_bdBoxExt;
161 };
162 
163 #endif
164 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Wed Jul 10 2013 18:15:30 for libmwaw by doxygen 1.8.4