MWAWPictData.hxx Source File documentation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 <ostream>
45
46 # include <librevenge/librevenge.h>
47
48 # include "libmwaw_internal.hxx"
49 # include "MWAWPict.hxx"
50
52 class MWAWPictData : public MWAWPict
53 {
54 public:
56 enum SubType { PictMac, DB3, Unknown };
58 virtual Type getType() const
59 {
60 return MWAWPict::PictData;
61 }
63 virtual SubType getSubType() const = 0;
64
66 virtual bool getBinary(MWAWEmbeddedObject &picture) const
67 {
68 if (!valid() || isEmpty()) return false;
69
70 librevenge::RVNGBinaryData data;
71 createFileData(m_data, data);
72 picture=MWAWEmbeddedObject(data, "image/pict");
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, MWAWBox2f &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 MWAWBox2f 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 MWAWVec2f 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 else if (m_empty) // both empty
129 return 0;
130 // the type
131 diff = getSubType() - aPict.getSubType();
132 if (diff) return (diff < 0) ? -1 : 1;
133
134 if (m_data.size() < aPict.m_data.size())
135 return 1;
136 if (m_data.size() > aPict.m_data.size())
137 return -1;
138 unsigned char const *data=m_data.getDataBuffer();
139 unsigned char const *aData=m_data.getDataBuffer();
140 if (!data || !aData) return 0; // must only appear if the two buffers are empty
141 for (unsigned long c=0; c < m_data.size(); c++, data++, aData++) {
142 if (*data < *aData) return -1;
143 if (*data > *aData) return 1;
144 }
145 return 0;
146 }
147
148 protected:
151 static bool createFileData(librevenge::RVNGBinaryData const &orig, librevenge::RVNGBinaryData &result);
152
154 MWAWPictData(): m_data(), m_empty(false) { }
155 MWAWPictData(MWAWBox2f &): m_data(), m_empty(false) { }
156
162 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
163 MWAWBox2f &box, MWAWPictData **result = 0L);
164
166 librevenge::RVNGBinaryData m_data;
167
169 bool m_empty;
170 };
171
173 class MWAWPictDB3 : public MWAWPictData
174 {
175 public:
177 virtual SubType getSubType() const
178 {
179 return DB3;
180 }
181
183 virtual bool valid() const
184 {
185 return m_data.size() != 0;
186 }
187
190 virtual int cmp(MWAWPict const &a) const
191 {
192 return MWAWPictData::cmp(a);
193 }
194
195 protected:
196
198 MWAWPictDB3()
199 {
200 m_empty = false;
201 }
202
203 friend class MWAWPictData;
209 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
210 };
211
213 class MWAWPictDUnknown : public MWAWPictData
214 {
215 public:
217 virtual SubType getSubType() const
218 {
219 return Unknown;
220 }
221
223 virtual bool valid() const
224 {
225 return m_data.size() != 0;
226 }
227
230 virtual int cmp(MWAWPict const &a) const
231 {
232 return MWAWPictData::cmp(a);
233 }
234
235 protected:
236
238 MWAWPictDUnknown()
239 {
240 m_empty = false;
241 }
242
243 friend class MWAWPictData;
244
250 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
251 };
252
253 #endif
254 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWPictData::m_data
librevenge::RVNGBinaryData m_data
the data size (without the empty header of 512 characters)
Definition: MWAWPictData.hxx:166
MWAWPictData::MWAWPictData
MWAWPictData(MWAWBox2f &)
Definition: MWAWPictData.hxx:155
MWAWPictData::sure
virtual bool sure() const
returns true if we are relatively sure that the data are correct
Definition: MWAWPictData.hxx:77
MWAWPictData::DB3
Definition: MWAWPictData.hxx:56
MWAWPictDB3
a small table file (known by open office)
Definition: MWAWPictData.hxx:173
MWAWPictData::valid
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:83
MWAWPictData::Unknown
Definition: MWAWPictData.hxx:56
libmwaw_internal.hxx
MWAWPictData::checkOrGet
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWBox2f &box, MWAWPictData **result=0L)
checks if the data pointed by input and of given size is a pict
Definition: MWAWPictData.cxx:56
MWAWPictDB3::valid
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:183
MWAWPictData::createFileData
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
MWAWPict::ReadResult
ReadResult
an enum to defined the result of a parsing use by some picture's classes which can read their data ...
Definition: MWAWPict.hxx:73
MWAWPictData::getType
virtual Type getType() const
returns the picture type
Definition: MWAWPictData.hxx:58
MWAWPictDUnknown
class to store small data which are potentially a picture
Definition: MWAWPictData.hxx:213
MWAWPictDUnknown::valid
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:223
MWAWPictDB3::getSubType
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictData.hxx:177
MWAWPictDB3::checkOrGet
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
MWAWPictDUnknown::checkOrGet
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
MWAWPict::cmp
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:101
MWAWVec2::x
T x() const
first element
Definition: libmwaw_internal.hxx:601
MWAWPict::setBdBox
void setBdBox(MWAWBox2f const &box)
sets the bdbox of the picture
Definition: MWAWPict.hxx:84
MWAWPictDB3::cmp
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:190
MWAWPictData::PictMac
Definition: MWAWPictData.hxx:56
MWAWVec2::y
T y() const
second element
Definition: libmwaw_internal.hxx:606
MWAWBox2< float >
MWAWBox2::size
MWAWVec2< T > size() const
the box size
Definition: libmwaw_internal.hxx:997
MWAWPict.hxx
MWAWPictData::m_empty
bool m_empty
some picture can be valid but empty
Definition: MWAWPictData.hxx:169
MWAWPictData
an abstract class which defines basic formated picture ( AppleŠ Pict, DB3, ...)
Definition: MWAWPictData.hxx:52
MWAWPictDUnknown::cmp
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:230
MWAWPictData::MWAWPictData
MWAWPictData()
protected constructor: use check to construct a picture
Definition: MWAWPictData.hxx:154
MWAWPict::Type
Type
the different picture types:
Definition: MWAWPict.hxx:63
MWAWEmbeddedObject
small class use to define a embedded object
Definition: libmwaw_internal.hxx:412
MWAWPictDUnknown::MWAWPictDUnknown
MWAWPictDUnknown()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:238
MWAWPict::PictData
Definition: MWAWPict.hxx:63
MWAWPictData::cmp
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
MWAWInputStreamPtr
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:489
MWAWPictData::getSubType
virtual SubType getSubType() const =0
returns the picture subtype
MWAWPictData::SubType
SubType
the picture subtype
Definition: MWAWPictData.hxx:56
MWAWPict::MWAW_R_BAD
Definition: MWAWPict.hxx:73
MWAWPictDUnknown::getSubType
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictData.hxx:217
MWAWPictData::isEmpty
bool isEmpty() const
returns true if the picture is valid and has size 0 or contains no data
Definition: MWAWPictData.hxx:89
MWAWPictData::check
static ReadResult check(MWAWInputStreamPtr input, int size, MWAWBox2f &box)
checks if the data pointed by input is known
Definition: MWAWPictData.hxx:98
MWAWPictData::getBinary
virtual bool getBinary(MWAWEmbeddedObject &picture) const
returns the final picture
Definition: MWAWPictData.hxx:66
MWAWPict
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:51
MWAWVec2< float >
MWAWPictDB3::MWAWPictDB3
MWAWPictDB3()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:198