MWAWPictData.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
/* This header contains code specific to a pict which can be stored in a
* WPXBinaryData, this includes :
* - the mac Pict format (in MWAWPictMac)
* - some old data names db3
* - some potential short data file
*/
#ifndef MWAW_PICT_DATA
# define MWAW_PICT_DATA
# include <assert.h>
# include <ostream>
# include <libwpd/libwpd.h>
# include "libmwaw_internal.hxx"
# include "MWAWPict.hxx"
class WPXBinaryData;
class MWAWPictData : public MWAWPict
{
public:
enum SubType { PictMac, DB3, Unknown };
virtual Type getType() const {
return MWAWPict::PictData;
}
virtual SubType getSubType() const = 0;
virtual bool getBinary(WPXBinaryData &res, std::string &s) const {
if (!valid() || isEmpty()) return false;
s = "image/pict";
createFileData(m_data, res);
return true;
}
virtual bool sure() const {
return getSubType() != Unknown;
}
virtual bool valid() const {
return false;
}
bool isEmpty() const {
return m_empty;
}
static ReadResult check(MWAWInputStreamPtr input, int size, Box2f &box) {
return checkOrGet(input, size, box, 0L);
}
static MWAWPictData *get(MWAWInputStreamPtr input, int size) {
MWAWPictData *res = 0L;
Box2f box;
if (checkOrGet(input, size, box, &res) == MWAW_R_BAD) return 0L;
if (res) { // if the bdbox is good, we set it
Vec2f sz = box.size();
if (sz.x()>0 && sz.y()>0) res->setBdBox(box);
}
return res;
}
virtual int cmp(MWAWPict const &a) const {
int diff = MWAWPict::cmp(a);
if (diff) return diff;
MWAWPictData const &aPict = static_cast<MWAWPictData const &>(a);
diff = (int) m_empty - (int) aPict.m_empty;
if (diff) return (diff < 0) ? -1 : 1;
// the type
diff = getSubType() - aPict.getSubType();
if (diff) return (diff < 0) ? -1 : 1;
if (m_data.size() < aPict.m_data.size())
return 1;
if (m_data.size() > aPict.m_data.size())
return -1;
unsigned char const *data=m_data.getDataBuffer();
unsigned char const *aData=m_data.getDataBuffer();
for (unsigned long c=0; c < m_data.size(); c++, data++, aData++) {
if (*data < *aData) return -1;
if (*data > *aData) return 1;
}
return 0;
}
protected:
static bool createFileData(WPXBinaryData const &orig, WPXBinaryData &result);
MWAWPictData(): m_data(), m_empty(false) { }
MWAWPictData(Box2f &): m_data(), m_empty(false) { }
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
Box2f &box, MWAWPictData **result = 0L);
WPXBinaryData m_data;
bool m_empty;
};
class MWAWPictDB3 : public MWAWPictData
{
public:
virtual SubType getSubType() const {
return DB3;
}
virtual bool valid() const {
return m_data.size() != 0;
}
virtual int cmp(MWAWPict const &a) const {
return MWAWPictData::cmp(a);
}
protected:
MWAWPictDB3() {
m_empty = false;
}
friend class MWAWPictData;
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
};
class MWAWPictDUnknown : public MWAWPictData
{
public:
virtual SubType getSubType() const {
return Unknown;
}
virtual bool valid() const {
return m_data.size() != 0;
}
virtual int cmp(MWAWPict const &a) const {
return MWAWPictData::cmp(a);
}
protected:
MWAWPictDUnknown() {
m_empty = false;
}
friend class MWAWPictData;
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWPictData::sure
virtual bool sure() const
returns true if we are relatively sure that the data are correct
Definition: MWAWPictData.hxx:77
MWAWPictData::checkOrGet
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
MWAWPictData::DB3
Definition: MWAWPictData.hxx:59
MWAWPictDB3
a small table file (known by open office)
Definition: MWAWPictData.hxx:164
MWAWPictData::valid
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:82
MWAWPictData::check
static ReadResult check(MWAWInputStreamPtr input, int size, Box2f &box)
checks if the data pointed by input is known
Definition: MWAWPictData.hxx:95
MWAWPictData::Unknown
Definition: MWAWPictData.hxx:59
libmwaw_internal.hxx
MWAWPictData::MWAWPictData
MWAWPictData(Box2f &)
Definition: MWAWPictData.hxx:146
Box2< float >
MWAWPictDB3::valid
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:173
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:77
MWAWPictData::getType
virtual Type getType() const
returns the picture type
Definition: MWAWPictData.hxx:61
MWAWPictDUnknown
class to store small data which are potentially a picture
Definition: MWAWPictData.hxx:200
MWAWPictDUnknown::valid
virtual bool valid() const
returns true if the picture is valid
Definition: MWAWPictData.hxx:209
MWAWPictDB3::getSubType
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictData.hxx:168
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:95
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:117
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:102
Vec2::y
T y() const
second element
Definition: libmwaw_internal.hxx:434
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:179
MWAWPictData::PictMac
Definition: MWAWPictData.hxx:59
MWAWPictData::createFileData
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
MWAWPict.hxx
MWAWPictData::m_empty
bool m_empty
some picture can be valid but empty
Definition: MWAWPictData.hxx:160
MWAWPictData
an abstract class which defines basic formated picture ( AppleŠ Pict, DB3, ...)
Definition: MWAWPictData.hxx:55
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:215
Vec2::x
T x() const
first element
Definition: libmwaw_internal.hxx:430
MWAWPictData::MWAWPictData
MWAWPictData()
protected constructor: use check to construct a picture
Definition: MWAWPictData.hxx:145
MWAWPict::setBdBox
void setBdBox(Box2f const &box)
sets the bdbox of the picture
Definition: MWAWPict.hxx:87
MWAWPict::Type
Type
the different picture types:
Definition: MWAWPict.hxx:67
MWAWPictDUnknown::MWAWPictDUnknown
MWAWPictDUnknown()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:222
MWAWPictData::getBinary
virtual bool getBinary(WPXBinaryData &res, std::string &s) const
returns the final WPXBinary data
Definition: MWAWPictData.hxx:68
MWAWPict::PictData
Definition: MWAWPict.hxx:67
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:115
MWAWPictData::m_data
WPXBinaryData m_data
the data size (without the empty header of 512 characters)
Definition: MWAWPictData.hxx:157
MWAWInputStreamPtr
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:336
MWAWPictData::getSubType
virtual SubType getSubType() const =0
returns the picture subtype
MWAWPictData::SubType
SubType
the picture subtype
Definition: MWAWPictData.hxx:59
MWAWPict::MWAW_R_BAD
Definition: MWAWPict.hxx:77
MWAWPictDUnknown::getSubType
virtual SubType getSubType() const
returns the picture subtype
Definition: MWAWPictData.hxx:204
MWAWPictData::isEmpty
bool isEmpty() const
returns true if the picture is valid and has size 0 or contains no data
Definition: MWAWPictData.hxx:87
Vec2< float >
Box2::size
Vec2< T > size() const
the box size
Definition: libmwaw_internal.hxx:778
MWAWPict
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:53
MWAWPictDB3::MWAWPictDB3
MWAWPictDB3()
protected constructor: uses check to construct a picture
Definition: MWAWPictData.hxx:186