MWAWPictData.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 a pict which can be stored in a
35  * librevenge::RVNGBinaryData, this includes :
36  * - the mac Pict format (in MWAWPictMac)
37  * - some old data names db3
38  * - some potential short data file
39  */
40 
41 #ifndef MWAW_PICT_DATA
42 # define MWAW_PICT_DATA
43 
44 # include <assert.h>
45 # include <ostream>
46 
47 # include <librevenge/librevenge.h>
48 
49 # include "libmwaw_internal.hxx"
50 # include "MWAWPict.hxx"
51 
53 class MWAWPictData : public MWAWPict
54 {
55 public:
57  enum SubType { PictMac, DB3, Unknown };
59  virtual Type getType() const
60  {
61  return MWAWPict::PictData;
62  }
64  virtual SubType getSubType() const = 0;
65 
67  virtual bool getBinary(librevenge::RVNGBinaryData &res, std::string &s) const
68  {
69  if (!valid() || isEmpty()) return false;
70 
71  s = "image/pict";
72  createFileData(m_data, res);
73  return true;
74  }
75 
77  virtual bool sure() const
78  {
79  return getSubType() != Unknown;
80  }
81 
83  virtual bool valid() const
84  {
85  return false;
86  }
87 
89  bool isEmpty() const
90  {
91  return m_empty;
92  }
93 
98  static ReadResult check(MWAWInputStreamPtr input, int size, Box2f &box)
99  {
100  return checkOrGet(input, size, box, 0L);
101  }
102 
106  static MWAWPictData *get(MWAWInputStreamPtr input, int size)
107  {
108  MWAWPictData *res = 0L;
109  Box2f box;
110  if (checkOrGet(input, size, box, &res) == MWAW_R_BAD) return 0L;
111  if (res) { // if the bdbox is good, we set it
112  Vec2f sz = box.size();
113  if (sz.x()>0 && sz.y()>0) res->setBdBox(box);
114  }
115  return res;
116  }
117 
120  virtual int cmp(MWAWPict const &a) const
121  {
122  int diff = MWAWPict::cmp(a);
123  if (diff) return diff;
124  MWAWPictData const &aPict = static_cast<MWAWPictData const &>(a);
125 
126  diff = (int) m_empty - (int) aPict.m_empty;
127  if (diff) return (diff < 0) ? -1 : 1;
128  // the type
129  diff = getSubType() - aPict.getSubType();
130  if (diff) return (diff < 0) ? -1 : 1;
131 
132  if (m_data.size() < aPict.m_data.size())
133  return 1;
134  if (m_data.size() > aPict.m_data.size())
135  return -1;
136  unsigned char const *data=m_data.getDataBuffer();
137  unsigned char const *aData=m_data.getDataBuffer();
138  for (unsigned long c=0; c < m_data.size(); c++, data++, aData++) {
139  if (*data < *aData) return -1;
140  if (*data > *aData) return 1;
141  }
142  return 0;
143  }
144 
145 protected:
148  static bool createFileData(librevenge::RVNGBinaryData const &orig, librevenge::RVNGBinaryData &result);
149 
151  MWAWPictData(): m_data(), m_empty(false) { }
152  MWAWPictData(Box2f &): m_data(), m_empty(false) { }
153 
159  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
160  Box2f &box, MWAWPictData **result = 0L);
161 
163  librevenge::RVNGBinaryData m_data;
164 
166  bool m_empty;
167 };
168 
170 class MWAWPictDB3 : public MWAWPictData
171 {
172 public:
174  virtual SubType getSubType() const
175  {
176  return DB3;
177  }
178 
180  virtual bool valid() const
181  {
182  return m_data.size() != 0;
183  }
184 
187  virtual int cmp(MWAWPict const &a) const
188  {
189  return MWAWPictData::cmp(a);
190  }
191 
192 protected:
193 
196  {
197  m_empty = false;
198  }
199 
200  friend class MWAWPictData;
206  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
207 };
208 
211 {
212 public:
214  virtual SubType getSubType() const
215  {
216  return Unknown;
217  }
218 
220  virtual bool valid() const
221  {
222  return m_data.size() != 0;
223  }
224 
227  virtual int cmp(MWAWPict const &a) const
228  {
229  return MWAWPictData::cmp(a);
230  }
231 
232 protected:
233 
236  {
237  m_empty = false;
238  }
239 
240  friend class MWAWPictData;
241 
247  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
248 };
249 
250 #endif
251 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
librevenge::RVNGBinaryData m_data
the data size (without the empty header of 512 characters)
Definition: MWAWPictData.hxx:163
virtual bool sure() const
returns true if we are relatively sure that the data are correct
Definition: MWAWPictData.hxx:77
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, Box2f &box, MWAWPictData **result=0L)
checks if the data pointed by input and of given size is a pict
Definition: MWAWPictData.cxx:56
Definition: MWAWPictData.hxx:57
a small table file (known by open office)
Definition: MWAWPictData.hxx:170
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:83
static ReadResult check(MWAWInputStreamPtr input, int size, Box2f &box)
checks if the data pointed by input is known
Definition: MWAWPictData.hxx:98
Definition: MWAWPictData.hxx:57
MWAWPictData(Box2f &)
Definition: MWAWPictData.hxx:152
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:180
static bool createFileData(librevenge::RVNGBinaryData const &orig, librevenge::RVNGBinaryData &result)
a file pict can be created from the data pict by adding a header with size 512, this function do this...
Definition: MWAWPictData.cxx:45
ReadResult
an enum to defined the result of a parsing use by some picture's classes which can read their data ...
Definition: MWAWPict.hxx:74
virtual Type getType() const
returns the picture type
Definition: MWAWPictData.hxx:59
class to store small data which are potentially a picture
Definition: MWAWPictData.hxx:210
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:220
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictData.hxx:174
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result=0L)
checks if the data pointed by input and of given size is a pict
Definition: MWAWPictData.cxx:96
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result=0L)
checks if the data pointed by input and of given size is a pict
Definition: MWAWPictData.cxx:118
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
T y() const
second element
Definition: libmwaw_internal.hxx:495
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class ...
Definition: MWAWPictData.hxx:187
Definition: MWAWPictData.hxx:57
virtual bool getBinary(librevenge::RVNGBinaryData &res, std::string &s) const
returns the final librevenge::RVNGBinary data
Definition: MWAWPictData.hxx:67
bool m_empty
some picture can be valid but empty
Definition: MWAWPictData.hxx:166
an abstract class which defines basic formated picture ( AppleŠ Pict, DB3, ...)
Definition: MWAWPictData.hxx:53
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class ...
Definition: MWAWPictData.hxx:227
T x() const
first element
Definition: libmwaw_internal.hxx:490
MWAWPictData()
protected constructor: use check to construct a picture
Definition: MWAWPictData.hxx:151
void setBdBox(Box2f const &box)
sets the bdbox of the picture
Definition: MWAWPict.hxx:85
Type
the different picture types:
Definition: MWAWPict.hxx:64
MWAWPictDUnknown()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:235
Definition: MWAWPict.hxx:64
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class ...
Definition: MWAWPictData.hxx:120
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:380
virtual SubType getSubType() const =0
returns the picture subtype
SubType
the picture subtype
Definition: MWAWPictData.hxx:57
Definition: MWAWPict.hxx:74
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictData.hxx:214
bool isEmpty() const
returns true if the picture is valid and has size 0 or contains no data
Definition: MWAWPictData.hxx:89
Vec2< T > size() const
the box size
Definition: libmwaw_internal.hxx:887
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:52
MWAWPictDB3()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:195

Generated on Fri Jul 25 2014 13:24:33 for libmwaw by doxygen 1.8.7