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;
54 typedef shared_ptr<MWAWInputStream> MWAWInputStreamPtr;
55 
57 class MWAWPictData : public MWAWPict
58 {
59 public:
61  enum SubType { PictMac, DB3, Unknown };
63  virtual Type getType() const {
64  return MWAWPict::PictData;
65  }
67  virtual SubType getSubType() const = 0;
68 
70  virtual bool getBinary(WPXBinaryData &res, std::string &s) const {
71  if (!valid() || isEmpty()) return false;
72 
73  s = "image/pict";
74  createFileData(m_data, res);
75  return true;
76  }
77 
79  virtual bool sure() const {
80  return getSubType() != Unknown;
81  }
82 
84  virtual bool valid() const {
85  return false;
86  }
87 
89  bool isEmpty() const {
90  return m_empty;
91  }
92 
97  static ReadResult check(MWAWInputStreamPtr input, int size, Box2f &box) {
98  return checkOrGet(input, size, box, 0L);
99  }
100 
104  static MWAWPictData *get(MWAWInputStreamPtr input, int size) {
105  MWAWPictData *res = 0L;
106  Box2f box;
107  if (checkOrGet(input, size, box, &res) == MWAW_R_BAD) return 0L;
108  if (res) { // if the bdbox is good, we set it
109  Vec2f sz = box.size();
110  if (sz.x()>0 && sz.y()>0) res->setBdBox(box);
111  }
112  return res;
113  }
114 
117  virtual int cmp(MWAWPict const &a) const {
118  int diff = MWAWPict::cmp(a);
119  if (diff) return diff;
120  MWAWPictData const &aPict = static_cast<MWAWPictData const &>(a);
121 
122  diff = (int) m_empty - (int) aPict.m_empty;
123  if (diff) return (diff < 0) ? -1 : 1;
124  // the type
125  diff = getSubType() - aPict.getSubType();
126  if (diff) return (diff < 0) ? -1 : 1;
127 
128  if (m_data.size() < aPict.m_data.size())
129  return 1;
130  if (m_data.size() > aPict.m_data.size())
131  return -1;
132  unsigned char const *data=m_data.getDataBuffer();
133  unsigned char const *aData=m_data.getDataBuffer();
134  for (unsigned long c=0; c < m_data.size(); c++, data++, aData++) {
135  if (*data < *aData) return -1;
136  if (*data > *aData) return 1;
137  }
138  return 0;
139  }
140 
141 protected:
144  static bool createFileData(WPXBinaryData const &orig, WPXBinaryData &result);
145 
147  MWAWPictData(): m_data(), m_empty(false) { }
148  MWAWPictData(Box2f &): m_data(), m_empty(false) { }
149 
155  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
156  Box2f &box, MWAWPictData **result = 0L);
157 
159  WPXBinaryData m_data;
160 
162  bool m_empty;
163 };
164 
166 class MWAWPictDB3 : public MWAWPictData
167 {
168 public:
170  virtual SubType getSubType() const {
171  return DB3;
172  }
173 
175  virtual bool valid() const {
176  return m_data.size() != 0;
177  }
178 
181  virtual int cmp(MWAWPict const &a) const {
182  return MWAWPictData::cmp(a);
183  }
184 
185 protected:
186 
189  m_empty = false;
190  }
191 
192  friend class MWAWPictData;
198  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
199 };
200 
203 {
204 public:
206  virtual SubType getSubType() const {
207  return Unknown;
208  }
209 
211  virtual bool valid() const {
212  return m_data.size() != 0;
213  }
214 
217  virtual int cmp(MWAWPict const &a) const {
218  return MWAWPictData::cmp(a);
219  }
220 
221 protected:
222 
225  m_empty = false;
226  }
227 
228  friend class MWAWPictData;
229 
235  static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
236 };
237 
238 #endif
239 // 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:79
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:61
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
Definition: ACText.hxx:44
a small table file (known by open office)
Definition: MWAWPictData.hxx:166
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:84
static ReadResult check(MWAWInputStreamPtr input, int size, Box2f &box)
checks if the data pointed by input is known
Definition: MWAWPictData.hxx:97
Definition: MWAWPictData.hxx:61
MWAWPictData(Box2f &)
Definition: MWAWPictData.hxx:148
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:175
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:79
virtual Type getType() const
returns the picture type
Definition: MWAWPictData.hxx:63
class to store small data which are potentially a picture
Definition: MWAWPictData.hxx:202
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:211
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictData.hxx:170
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:104
T y() const
second element
Definition: libmwaw_internal.hxx:399
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:181
Internal class used to read the file stream Internal class used to read the file stream, this class adds some usefull functions to the basic WPXInputStream:
Definition: MWAWInputStream.hxx:59
Definition: MWAWPictData.hxx:61
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:162
an abstract class which defines basic formated picture ( AppleŠ Pict, DB3, ...)
Definition: MWAWPictData.hxx:57
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:217
T x() const
first element
Definition: libmwaw_internal.hxx:395
MWAWPictData()
protected constructor: use check to construct a picture
Definition: MWAWPictData.hxx:147
void setBdBox(Box2f const &box)
sets the bdbox of the picture
Definition: MWAWPict.hxx:89
Type
the different picture types:
Definition: MWAWPict.hxx:69
MWAWPictDUnknown()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:224
virtual bool getBinary(WPXBinaryData &res, std::string &s) const
returns the final WPXBinary data
Definition: MWAWPictData.hxx:70
Definition: MWAWPict.hxx:69
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:117
WPXBinaryData m_data
the data size (without the empty header of 512 characters)
Definition: MWAWPictData.hxx:159
virtual SubType getSubType() const =0
returns the picture subtype
SubType
the picture subtype
Definition: MWAWPictData.hxx:61
Definition: MWAWPict.hxx:79
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictData.hxx:206
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:743
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:55
MWAWPictDB3()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:188

Generated for libmwaw by doxygen 1.8.5