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  * WPXBinaryData, 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 <libwpd/libwpd.h>
48 
49 # include "libmwaw_internal.hxx"
50 # include "MWAWPict.hxx"
51 
52 class WPXBinaryData;
53 
55 class MWAWPictData : public MWAWPict
56 {
57 public:
59  enum SubType { PictMac, DB3, Unknown };
61  virtual Type getType() const {
62  return MWAWPict::PictData;
63  }
65  virtual SubType getSubType() const = 0;
66 
68  virtual bool getBinary(WPXBinaryData &res, std::string &s) const {
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  return getSubType() != Unknown;
79  }
80 
82  virtual bool valid() const {
83  return false;
84  }
85 
87  bool isEmpty() const {
88  return m_empty;
89  }
90 
95  static ReadResult check(MWAWInputStreamPtr input, int size, Box2f &box) {
96  return checkOrGet(input, size, box, 0L);
97  }
98 
102  static MWAWPictData *get(MWAWInputStreamPtr input, int size) {
103  MWAWPictData *res = 0L;
104  Box2f box;
105  if (checkOrGet(input, size, box, &res) == MWAW_R_BAD) return 0L;
106  if (res) { // if the bdbox is good, we set it
107  Vec2f sz = box.size();
108  if (sz.x()>0 && sz.y()>0) res->setBdBox(box);
109  }
110  return res;
111  }
112 
115  virtual int cmp(MWAWPict const &a) const {
116  int diff = MWAWPict::cmp(a);
117  if (diff) return diff;
118  MWAWPictData const &aPict = static_cast<MWAWPictData const &>(a);
119 
120  diff = (int) m_empty - (int) aPict.m_empty;
121  if (diff) return (diff < 0) ? -1 : 1;
122  // the type
123  diff = getSubType() - aPict.getSubType();
124  if (diff) return (diff < 0) ? -1 : 1;
125 
126  if (m_data.size() < aPict.m_data.size())
127  return 1;
128  if (m_data.size() > aPict.m_data.size())
129  return -1;
130  unsigned char const *data=m_data.getDataBuffer();
131  unsigned char const *aData=m_data.getDataBuffer();
132  for (unsigned long c=0; c < m_data.size(); c++, data++, aData++) {
133  if (*data < *aData) return -1;
134  if (*data > *aData) return 1;
135  }
136  return 0;
137  }
138 
139 protected:
142  static bool createFileData(WPXBinaryData const &orig, WPXBinaryData &result);
143 
145  MWAWPictData(): m_data(), m_empty(false) { }
146  MWAWPictData(Box2f &): m_data(), m_empty(false) { }
147 
153  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
154  Box2f &box, MWAWPictData **result = 0L);
155 
157  WPXBinaryData m_data;
158 
160  bool m_empty;
161 };
162 
164 class MWAWPictDB3 : public MWAWPictData
165 {
166 public:
168  virtual SubType getSubType() const {
169  return DB3;
170  }
171 
173  virtual bool valid() const {
174  return m_data.size() != 0;
175  }
176 
179  virtual int cmp(MWAWPict const &a) const {
180  return MWAWPictData::cmp(a);
181  }
182 
183 protected:
184 
187  m_empty = false;
188  }
189 
190  friend class MWAWPictData;
196  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
197 };
198 
201 {
202 public:
204  virtual SubType getSubType() const {
205  return Unknown;
206  }
207 
209  virtual bool valid() const {
210  return m_data.size() != 0;
211  }
212 
215  virtual int cmp(MWAWPict const &a) const {
216  return MWAWPictData::cmp(a);
217  }
218 
219 protected:
220 
223  m_empty = false;
224  }
225 
226  friend class MWAWPictData;
227 
233  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
234 };
235 
236 #endif
237 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
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:59
a small table file (known by open office)
Definition: MWAWPictData.hxx:164
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:82
static ReadResult check(MWAWInputStreamPtr input, int size, Box2f &box)
checks if the data pointed by input is known
Definition: MWAWPictData.hxx:95
Definition: MWAWPictData.hxx:59
MWAWPictData(Box2f &)
Definition: MWAWPictData.hxx:146
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:173
ReadResult
an enum to defined the result of a parsing use by some picture&#39;s classes which can read their data ...
Definition: MWAWPict.hxx:74
virtual Type getType() const
returns the picture type
Definition: MWAWPictData.hxx:61
class to store small data which are potentially a picture
Definition: MWAWPictData.hxx:200
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:209
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictData.hxx:168
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:95
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:117
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:99
T y() const
second element
Definition: libmwaw_internal.hxx:448
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:179
Definition: MWAWPictData.hxx:59
static bool createFileData(WPXBinaryData const &orig, WPXBinaryData &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
bool m_empty
some picture can be valid but empty
Definition: MWAWPictData.hxx:160
an abstract class which defines basic formated picture ( AppleŠ Pict, DB3, ...)
Definition: MWAWPictData.hxx:55
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:215
T x() const
first element
Definition: libmwaw_internal.hxx:444
MWAWPictData()
protected constructor: use check to construct a picture
Definition: MWAWPictData.hxx:145
void setBdBox(Box2f const &box)
sets the bdbox of the picture
Definition: MWAWPict.hxx:84
Type
the different picture types:
Definition: MWAWPict.hxx:64
MWAWPictDUnknown()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:222
virtual bool getBinary(WPXBinaryData &res, std::string &s) const
returns the final WPXBinary data
Definition: MWAWPictData.hxx:68
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:115
WPXBinaryData m_data
the data size (without the empty header of 512 characters)
Definition: MWAWPictData.hxx:157
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:348
virtual SubType getSubType() const =0
returns the picture subtype
SubType
the picture subtype
Definition: MWAWPictData.hxx:59
Definition: MWAWPict.hxx:74
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictData.hxx:204
bool isEmpty() const
returns true if the picture is valid and has size 0 or contains no data
Definition: MWAWPictData.hxx:87
Vec2< T > size() const
the box size
Definition: libmwaw_internal.hxx:792
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:52
MWAWPictDB3()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:186

Generated on Tue Mar 10 2015 17:32:09 for libmwaw by doxygen 1.8.5