MWAWPictData.hxx Source File documentation

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{
54public:
56 enum SubType { PictMac, DB3, Unknown };
58 ~MWAWPictData() override;
60 Type getType() const override
61 {
62 return MWAWPict::PictData;
63 }
65 virtual SubType getSubType() const = 0;
66
68 bool getBinary(MWAWEmbeddedObject &picture) const override
69 {
70 if (!valid() || isEmpty()) return false;
71
72 librevenge::RVNGBinaryData data;
73 createFileData(m_data, data);
74 picture=MWAWEmbeddedObject(data, "image/pict");
75 return true;
76 }
77
79 virtual bool sure() const
80 {
81 return getSubType() != Unknown;
82 }
83
85 virtual bool valid() const
86 {
87 return false;
88 }
89
91 bool isEmpty() const
92 {
93 return m_empty;
94 }
95
100 static ReadResult check(MWAWInputStreamPtr const &input, int size, MWAWBox2f &box)
101 {
102 return checkOrGet(input, size, box, nullptr);
103 }
104
108 static MWAWPictData *get(MWAWInputStreamPtr const &input, int size)
109 {
110 MWAWPictData *res = nullptr;
111 MWAWBox2f box;
112 if (checkOrGet(input, size, box, &res) == MWAW_R_BAD) return nullptr;
113 if (res) { // if the bdbox is good, we set it
114 MWAWVec2f sz = box.size();
115 if (sz.x()>0 && sz.y()>0) res->setBdBox(box);
116 }
117 return res;
118 }
119
122 int cmp(MWAWPict const &a) const override
123 {
124 int diff = MWAWPict::cmp(a);
125 if (diff) return diff;
126 auto const &aPict = static_cast<MWAWPictData const &>(a);
127
128 diff = static_cast<int>(m_empty) - static_cast<int>(aPict.m_empty);
129 if (diff) return (diff < 0) ? -1 : 1;
130 else if (m_empty) // both empty
131 return 0;
132 // the type
133 diff = getSubType() - aPict.getSubType();
134 if (diff) return (diff < 0) ? -1 : 1;
135
136 if (m_data.size() < aPict.m_data.size())
137 return 1;
138 if (m_data.size() > aPict.m_data.size())
139 return -1;
140 unsigned char const *data=m_data.getDataBuffer();
141 unsigned char const *aData=aPict.m_data.getDataBuffer();
142 if (!data || !aData) return 0; // must only appear if the two buffers are empty
143 for (unsigned long c=0; c < m_data.size(); c++, data++, aData++) {
144 if (*data < *aData) return -1;
145 if (*data > *aData) return 1;
146 }
147 return 0;
148 }
149
150protected:
153 static bool createFileData(librevenge::RVNGBinaryData const &orig, librevenge::RVNGBinaryData &result);
154
156 MWAWPictData()
157 : m_data()
158 , m_empty(false)
159 {
160 }
161 explicit MWAWPictData(MWAWBox2f &)
162 : m_data()
163 , m_empty(false)
164 {
165 }
166
172 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
173 MWAWBox2f &box, MWAWPictData **result = nullptr);
174
176 librevenge::RVNGBinaryData m_data;
177
179 bool m_empty;
180};
181
183 class MWAWPictDB3 final : public MWAWPictData
184{
185public:
187 ~MWAWPictDB3() final;
188
190 SubType getSubType() const final
191 {
192 return DB3;
193 }
194
196 bool valid() const final
197 {
198 return m_data.size() != 0;
199 }
200
203 int cmp(MWAWPict const &a) const final
204 {
205 return MWAWPictData::cmp(a);
206 }
207
208protected:
209
211 MWAWPictDB3()
212 {
213 m_empty = false;
214 }
215
216 friend class MWAWPictData;
222 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = nullptr);
223};
224
226 class MWAWPictDUnknown final : public MWAWPictData
227{
228public:
230 ~MWAWPictDUnknown() final;
231
233 SubType getSubType() const final
234 {
235 return Unknown;
236 }
237
239 bool valid() const final
240 {
241 return m_data.size() != 0;
242 }
243
246 int cmp(MWAWPict const &a) const final
247 {
248 return MWAWPictData::cmp(a);
249 }
250
251protected:
252
254 MWAWPictDUnknown()
255 {
256 m_empty = false;
257 }
258
259 friend class MWAWPictData;
260
266 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = nullptr);
267};
268
269#endif
270// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWPict.hxx
MWAWBox2< float >
MWAWBox2::size
MWAWVec2< T > size() const
the box size
Definition: libmwaw_internal.hxx:1067
MWAWPictDB3
a small table file (known by open office)
Definition: MWAWPictData.hxx:184
MWAWPictDB3::cmp
int cmp(MWAWPict const &a) const final
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition: MWAWPictData.hxx:203
MWAWPictDB3::getSubType
SubType getSubType() const final
returns the picture subtype
Definition: MWAWPictData.hxx:190
MWAWPictDB3::MWAWPictDB3
MWAWPictDB3()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:211
MWAWPictDB3::~MWAWPictDB3
~MWAWPictDB3() final
destructor
Definition: MWAWPictData.cxx:99
MWAWPictDB3::checkOrGet
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result=nullptr)
checks if the data pointed by input and of given size is a pict
Definition: MWAWPictData.cxx:104
MWAWPictDB3::valid
bool valid() const final
returns true if the picture is valid
Definition: MWAWPictData.hxx:196
MWAWPictDUnknown
class to store small data which are potentially a picture
Definition: MWAWPictData.hxx:227
MWAWPictDUnknown::cmp
int cmp(MWAWPict const &a) const final
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition: MWAWPictData.hxx:246
MWAWPictDUnknown::MWAWPictDUnknown
MWAWPictDUnknown()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:254
MWAWPictDUnknown::checkOrGet
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result=nullptr)
checks if the data pointed by input and of given size is a pict
Definition: MWAWPictData.cxx:130
MWAWPictDUnknown::valid
bool valid() const final
returns true if the picture is valid
Definition: MWAWPictData.hxx:239
MWAWPictDUnknown::getSubType
SubType getSubType() const final
returns the picture subtype
Definition: MWAWPictData.hxx:233
MWAWPictDUnknown::~MWAWPictDUnknown
~MWAWPictDUnknown() final
destructor
Definition: MWAWPictData.cxx:125
MWAWPictData
an abstract class which defines basic formated picture ( AppleŠ Pict, DB3, ...)
Definition: MWAWPictData.hxx:53
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:49
MWAWPictData::cmp
int cmp(MWAWPict const &a) const override
a virtual function used to obtain a strict order, must be redefined in the subs class
Definition: MWAWPictData.hxx:122
MWAWPictData::getSubType
virtual SubType getSubType() const =0
returns the picture subtype
MWAWPictData::SubType
SubType
the picture subtype
Definition: MWAWPictData.hxx:56
MWAWPictData::Unknown
@ Unknown
Definition: MWAWPictData.hxx:56
MWAWPictData::DB3
@ DB3
Definition: MWAWPictData.hxx:56
MWAWPictData::PictMac
@ PictMac
Definition: MWAWPictData.hxx:56
MWAWPictData::get
static MWAWPictData * get(MWAWInputStreamPtr const &input, int size)
checks if the data pointed by input is known
Definition: MWAWPictData.hxx:108
MWAWPictData::checkOrGet
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWBox2f &box, MWAWPictData **result=nullptr)
checks if the data pointed by input and of given size is a pict
Definition: MWAWPictData.cxx:60
MWAWPictData::MWAWPictData
MWAWPictData(MWAWBox2f &)
Definition: MWAWPictData.hxx:161
MWAWPictData::m_data
librevenge::RVNGBinaryData m_data
the data size (without the empty header of 512 characters)
Definition: MWAWPictData.hxx:176
MWAWPictData::m_empty
bool m_empty
some picture can be valid but empty
Definition: MWAWPictData.hxx:179
MWAWPictData::check
static ReadResult check(MWAWInputStreamPtr const &input, int size, MWAWBox2f &box)
checks if the data pointed by input is known
Definition: MWAWPictData.hxx:100
MWAWPictData::getType
Type getType() const override
returns the picture type
Definition: MWAWPictData.hxx:60
MWAWPictData::getBinary
bool getBinary(MWAWEmbeddedObject &picture) const override
returns the final picture
Definition: MWAWPictData.hxx:68
MWAWPictData::sure
virtual bool sure() const
returns true if we are relatively sure that the data are correct
Definition: MWAWPictData.hxx:79
MWAWPictData::valid
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:85
MWAWPictData::MWAWPictData
MWAWPictData()
protected constructor: use check to construct a picture
Definition: MWAWPictData.hxx:156
MWAWPictData::isEmpty
bool isEmpty() const
returns true if the picture is valid and has size 0 or contains no data
Definition: MWAWPictData.hxx:91
MWAWPictData::~MWAWPictData
~MWAWPictData() override
destructor
Definition: MWAWPictData.cxx:45
MWAWPict
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:52
MWAWPict::Type
Type
the different picture types:
Definition: MWAWPict.hxx:63
MWAWPict::PictData
@ PictData
Definition: MWAWPict.hxx:63
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
MWAWPict::MWAW_R_BAD
@ MWAW_R_BAD
Definition: MWAWPict.hxx:73
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
MWAWPict::setBdBox
void setBdBox(MWAWBox2f const &box)
sets the bdbox of the picture
Definition: MWAWPict.hxx:84
MWAWVec2< float >
MWAWVec2::y
T y() const
second element
Definition: libmwaw_internal.hxx:673
MWAWVec2::x
T x() const
first element
Definition: libmwaw_internal.hxx:668
libmwaw_internal.hxx
MWAWInputStreamPtr
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:551
MWAWEmbeddedObject
small class use to define a embedded object
Definition: libmwaw_internal.hxx:467