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
* librevenge::RVNGBinaryData, 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 <ostream>
# include <librevenge/librevenge.h>
# include "libmwaw_internal.hxx"
# include "MWAWPict.hxx"
class MWAWPictData : public MWAWPict
{
public:
enum SubType { PictMac, DB3, Unknown };
~MWAWPictData() override;
Type getType() const override
{
return MWAWPict::PictData;
}
virtual SubType getSubType() const = 0;
bool getBinary(MWAWEmbeddedObject &picture) const override
{
if (!valid() || isEmpty()) return false;
librevenge::RVNGBinaryData data;
createFileData(m_data, data);
picture=MWAWEmbeddedObject(data, "image/pict");
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 const &input, int size, MWAWBox2f &box)
{
return checkOrGet(input, size, box, nullptr);
}
static MWAWPictData *get(MWAWInputStreamPtr const &input, int size)
{
MWAWPictData *res = nullptr;
MWAWBox2f box;
if (checkOrGet(input, size, box, &res) == MWAW_R_BAD) return nullptr;
if (res) { // if the bdbox is good, we set it
MWAWVec2f sz = box.size();
if (sz.x()>0 && sz.y()>0) res->setBdBox(box);
}
return res;
}
int cmp(MWAWPict const &a) const override
{
int diff = MWAWPict::cmp(a);
if (diff) return diff;
auto const &aPict = static_cast<MWAWPictData const &>(a);
diff = static_cast<int>(m_empty) - static_cast<int>(aPict.m_empty);
if (diff) return (diff < 0) ? -1 : 1;
else if (m_empty) // both empty
return 0;
// 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=aPict.m_data.getDataBuffer();
if (!data || !aData) return 0; // must only appear if the two buffers are empty
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(librevenge::RVNGBinaryData const &orig, librevenge::RVNGBinaryData &result);
MWAWPictData()
: m_data()
, m_empty(false)
{
}
explicit MWAWPictData(MWAWBox2f &)
: m_data()
, m_empty(false)
{
}
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
MWAWBox2f &box, MWAWPictData **result = nullptr);
librevenge::RVNGBinaryData m_data;
bool m_empty;
};
class MWAWPictDB3 final : public MWAWPictData
{
public:
~MWAWPictDB3() final;
SubType getSubType() const final
{
return DB3;
}
bool valid() const final
{
return m_data.size() != 0;
}
int cmp(MWAWPict const &a) const final
{
return MWAWPictData::cmp(a);
}
protected:
MWAWPictDB3()
{
m_empty = false;
}
friend class MWAWPictData;
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = nullptr);
};
class MWAWPictDUnknown final : public MWAWPictData
{
public:
~MWAWPictDUnknown() final;
SubType getSubType() const final
{
return Unknown;
}
bool valid() const final
{
return m_data.size() != 0;
}
int cmp(MWAWPict const &a) const final
{
return MWAWPictData::cmp(a);
}
protected:
MWAWPictDUnknown()
{
m_empty = false;
}
friend class MWAWPictData;
static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = nullptr);
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWPict.hxx
MWAWBox2::size
MWAWVec2< T > size() const
the box size
Definition libmwaw_internal.hxx:1067
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
MWAWPictDB3::MWAWPictData
friend class MWAWPictData
Definition MWAWPictData.hxx:216
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
MWAWPictDUnknown::MWAWPictData
friend class MWAWPictData
Definition MWAWPictData.hxx:259
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::MWAWPict
MWAWPict()
protected constructor must not be called directly
Definition MWAWPict.hxx:143
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::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
MWAWBox2f
MWAWBox2< float > MWAWBox2f
MWAWBox2 of float.
Definition libmwaw_internal.hxx:1193
MWAWVec2f
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition libmwaw_internal.hxx:842
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