MWAWPictMac.hxx Source File documentation

MWAWPictMac.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 mac file
35 * see http://developer.apple.com/legacy/mac/library/documentation/mac/QuickDraw/QuickDraw-458.html
36 */
37
38 #ifndef MWAW_PICT_MAC
39 # define MWAW_PICT_MAC
40
41 # include <ostream>
42 # include <string>
43
44 # include <librevenge/librevenge.h>
45
46 # include "libmwaw_internal.hxx"
47 # include "MWAWPictData.hxx"
48
50 class MWAWPictMac final : public MWAWPictData
51 {
52 public:
54 ~MWAWPictMac() final;
56 SubType getSubType() const final
57 {
58 return MWAWPictData::PictMac;
59 }
61 bool getBinary(MWAWEmbeddedObject &picture) const final
62 {
63 if (!valid() || isEmpty()) return false;
64 librevenge::RVNGBinaryData res;
65 if (m_version == 1) {
66 librevenge::RVNGBinaryData dataV2;
67 if (convertPict1To2(m_data, dataV2)) {
68 createFileData(dataV2, res);
69 picture=MWAWEmbeddedObject(res, "image/pict");
70 return true;
71 }
72 }
73 createFileData(m_data, res);
74 picture=MWAWEmbeddedObject(res, "image/pict");
75 return true;
76
77 }
78
80 bool valid() const final
81 {
82 return (m_version >= 1) && (m_version <= 2);
83 }
84
87 int cmp(MWAWPict const &a) const final
88 {
89 int diff = MWAWPictData::cmp(a);
90 if (diff) return diff;
91 auto const &aPict = static_cast<MWAWPictMac const &>(a);
92
93 diff = m_version - aPict.m_version;
94 if (diff) return (diff < 0) ? -1 : 1;
95 diff = m_subVersion - aPict.m_subVersion;
96 if (diff) return (diff < 0) ? -1 : 1;
97
98 return 0;
99 }
100
102 static bool convertPict1To2(librevenge::RVNGBinaryData const &orig, librevenge::RVNGBinaryData &result);
103
104 protected:
106 explicit MWAWPictMac(MWAWBox2f box)
107 : MWAWPictData(box)
108 , m_version(-1)
109 , m_subVersion(-1)
110 {
111 extendBDBox(1.0);
112 }
113
114 friend class MWAWPictData;
121 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
122 MWAWBox2f &box, MWAWPictData **result = nullptr);
123
125 int m_version;
127 int m_subVersion;
128 };
129
130 #endif
131 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
libmwaw_applepict1::PictParser
internal and low level: map opcode id -> OpCode
Definition: MWAWPictMac.cxx:1057
MWAWInputStreamPtr
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:551
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
MWAWPictMac::getSubType
SubType getSubType() const final
returns the picture subtype
Definition: MWAWPictMac.hxx:56
MWAWInputStream::get
static std::shared_ptr< MWAWInputStream > get(librevenge::RVNGBinaryData const &data, bool inverted)
returns a new input stream corresponding to a librevenge::RVNGBinaryData
Definition: MWAWInputStream.cxx:102
MWAWInputStream::seek
int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType)
seeks to a offset position, from actual, beginning or ending position
Definition: MWAWInputStream.cxx:148
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:129
libmwaw_applepict1::WP_POINT
@ WP_POINT
Definition: MWAWPictMac.cxx:138
MWAWVec2f
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition: libmwaw_internal.hxx:842
MWAWBox2::set
void set(MWAWVec2< T > const &x, MWAWVec2< T > const &y)
resets the data to minimum x and maximum y
Definition: libmwaw_internal.hxx:1079
libmwaw_applepict1::Value::~Value
virtual ~Value()
Definition: MWAWPictMac.cxx:539
libmwaw_applepict1::Bitmap::operator<<
friend std::ostream & operator<<(std::ostream &o, Bitmap const &f)
operator<< for Bitmap
Definition: MWAWPictMac.cxx:290
libmwaw_applepict1::WP_BITMAP
@ WP_BITMAP
Definition: MWAWPictMac.cxx:139
libmwaw_applepict1::Value::m_rgb
MWAWColor m_rgb
the color when type=WP_COLOR
Definition: MWAWPictMac.cxx:522
libmwaw_applepict1::Value
Internal and low level: a class used to read and store all possible value.
Definition: MWAWPictMac.cxx:427
libmwaw_applepict1::Bitmap::m_dst
MWAWBox2i m_dst
another final dimension
Definition: MWAWPictMac.cxx:417
libmwaw_applepict1::WP_PATTERN
@ WP_PATTERN
Definition: MWAWPictMac.cxx:138
libmwaw_applepict1::Value::m_region
std::shared_ptr< Region > m_region
the region when type=WP_REGION
Definition: MWAWPictMac.cxx:534
MWAWPictData::isEmpty
bool isEmpty() const
returns true if the picture is valid and has size 0 or contains no data
Definition: MWAWPictData.hxx:91
libmwaw_applepict1::Region::m_box
MWAWBox2i m_box
the bounding box
Definition: MWAWPictMac.cxx:223
MWAWInputStream
Internal class used to read the file stream Internal class used to read the file stream,...
Definition: MWAWInputStream.hxx:53
MWAWEmbeddedObject::m_dataList
std::vector< librevenge::RVNGBinaryData > m_dataList
the picture content: one data by representation
Definition: libmwaw_internal.hxx:512
MWAWColor::white
static MWAWColor white()
return the white color
Definition: libmwaw_internal.hxx:250
MWAWInputStream::readLong
long readLong(int num)
return a int8, int16, int32 readed from actualPos
Definition: MWAWInputStream.cxx:223
MWAWColor
the class to store a color
Definition: libmwaw_internal.hxx:192
MWAWEmbeddedObject
small class use to define a embedded object
Definition: libmwaw_internal.hxx:467
libmwaw_applepict1::WP_RECT
@ WP_RECT
Definition: MWAWPictMac.cxx:138
MWAWPict::MWAW_R_OK
@ MWAW_R_OK
Definition: MWAWPict.hxx:73
libmwaw_applepict1::PictParser::PictParser
PictParser()
the constructor
Definition: MWAWPictMac.cxx:1061
libmwaw_applepict1::OpCode::OpCode
OpCode(int id, char const *nm, DataType type1=WP_NONE, DataType type2=WP_NONE, DataType type3=WP_NONE, DataType type4=WP_NONE, DataType type5=WP_NONE)
constructor
Definition: MWAWPictMac.cxx:555
libmwaw_applepict1::Value::m_bitmap
std::shared_ptr< Bitmap > m_bitmap
the bitmap when type=WP_BITMAP
Definition: MWAWPictMac.cxx:536
libmwaw_applepict1::WP_PBITMAP
@ WP_PBITMAP
Definition: MWAWPictMac.cxx:139
libmwaw_applepict1::Bitmap::readBitmapData
bool readBitmapData(MWAWInputStream &input, bool packed)
parses the bitmap data zone
Definition: MWAWPictMac.cxx:369
MWAWInputStream::isEnd
bool isEnd()
returns true if we are at the end of the section/file
Definition: MWAWInputStream.cxx:171
MWAWPictBitmap::getBinary
bool getBinary(MWAWEmbeddedObject &picture) const override
returns the final picture
Definition: MWAWPictBitmap.hxx:225
MWAWInputStream::tell
long tell()
returns actual offset position
Definition: MWAWInputStream.cxx:141
MWAWPictData::SubType
SubType
the picture subtype
Definition: MWAWPictData.hxx:56
libmwaw_applepict1::OpCode::m_id
int m_id
the opCode
Definition: MWAWPictMac.cxx:654
MWAWPictMac::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 1.0, 2.0 or 2.1
Definition: MWAWPictMac.cxx:59
libmwaw_applepict1::Value::m_int
int m_int
the int value when type=WP_INT
Definition: MWAWPictMac.cxx:520
libmwaw_applepict1::WP_POINTUBYTE
@ WP_POINTUBYTE
Definition: MWAWPictMac.cxx:138
MWAWPictMac::~MWAWPictMac
~MWAWPictMac() final
destructor
Definition: MWAWPictMac.cxx:54
libmwaw_applepict1::WP_UBYTE
@ WP_UBYTE
Definition: MWAWPictMac.cxx:137
libmwaw_applepict1::OpCode
Internal and low level: a class to define each opcode and their arguments and read their data.
Definition: MWAWPictMac.cxx:544
MWAWPictData::PictMac
@ PictMac
Definition: MWAWPictData.hxx:56
libmwaw_applepict1::OpCode::m_types
std::vector< DataType > m_types
the different argument types
Definition: MWAWPictMac.cxx:658
libmwaw_applepict1::WP_UFIXED
@ WP_UFIXED
Definition: MWAWPictMac.cxx:137
libmwaw_applepict1::OpCode::readRect
static bool readRect(MWAWInputStream &input, DataType type, MWAWBox2i &res)
read a rectangles field
Definition: MWAWPictMac.cxx:613
libmwaw_applepict1::DataType
DataType
Internal and low level: the different types of arguments.
Definition: MWAWPictMac.cxx:136
libmwaw_applepict1::WP_POLY
@ WP_POLY
Definition: MWAWPictMac.cxx:138
libmwaw_applepict1::Value::m_box
MWAWBox2i m_box
the rectangle when type=WP_RECT
Definition: MWAWPictMac.cxx:530
libmwaw_applepict1::WP_INT
@ WP_INT
Definition: MWAWPictMac.cxx:137
libmwaw_applepict1::Bitmap::m_rowBytes
int m_rowBytes
the num of bytes used to store a row
Definition: MWAWPictMac.cxx:416
libmwaw_applepict1::Bitmap::m_mode
int m_mode
the encoding mode ?
Definition: MWAWPictMac.cxx:423
MWAWPictBitmapBW
a bitmap of bool to store black-white bitmap
Definition: MWAWPictBitmap.hxx:268
MWAWPictMac::m_subVersion
int m_subVersion
the picture subversion
Definition: MWAWPictMac.hxx:127
MWAWVec2::y
T y() const
second element
Definition: libmwaw_internal.hxx:673
libmwaw_applepict1::Region
Internal and low level: class used to read/store a picture region.
Definition: MWAWPictMac.cxx:146
libmwaw::Debug::dumpFile
bool dumpFile(librevenge::RVNGBinaryData &data, char const *fileName)
a debug function to store in a datafile in the current directory WARNING: this function erase the fil...
Definition: MWAWDebug.cxx:193
libmwaw_internal.hxx
ADD_DATA_SHORT
#define ADD_DATA_SHORT(resPtr, val)
MWAWVec2::x
T x() const
first element
Definition: libmwaw_internal.hxx:668
libmwaw_applepict1::Value::m_text
std::string m_text
the text when type=WP_TEXT
Definition: MWAWPictMac.cxx:526
MWAWPict::extendBDBox
void extendBDBox(float val)
udaptes the bdbox, by extended it by (val-previousVal)
Definition: MWAWPict.hxx:137
libmwaw_applepict1::Bitmap::read
bool read(MWAWInputStream &input, bool packed, bool hasRegion)
tries to read a bitmap
Definition: MWAWPictMac.cxx:241
MWAWPictMac::valid
bool valid() const final
returns true if the picture is valid
Definition: MWAWPictMac.hxx:80
libmwaw_applepict1::WP_RPBITMAP
@ WP_RPBITMAP
Definition: MWAWPictMac.cxx:139
MWAWPictBitmapBW::setRowPacked
void setRowPacked(int j, unsigned char const *val, unsigned char const *end)
sets all cell contents of a row given packed m_data
Definition: MWAWPictBitmap.hxx:337
libmwaw_applepict1::OpCode::computeSize
bool computeSize(MWAWInputStream &input, int &sz) const
computes the size of the data
Definition: MWAWPictMac.cxx:595
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
libmwaw_applepict1::Value::m_listPoint
std::vector< MWAWVec2i > m_listPoint
the list of points which defined the polygon when type=WP_POLY
Definition: MWAWPictMac.cxx:532
MWAWPictMac::m_version
int m_version
the picture version
Definition: MWAWPictMac.hxx:125
MWAWPictData.hxx
MWAWPictMac::getBinary
bool getBinary(MWAWEmbeddedObject &picture) const final
returns the final picture
Definition: MWAWPictMac.hxx:61
libmwaw_applepict1::Bitmap::saveBitmap
bool saveBitmap() const
saves the bitmap in file (debugging function)
Definition: MWAWPictMac.cxx:323
MWAWPict
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:51
MWAWPict::MWAW_R_BAD
@ MWAW_R_BAD
Definition: MWAWPict.hxx:73
MWAWVec2< int >
MWAWInputStream::readULong
unsigned long readULong(int num)
returns a uint8, uint16, uint32 readed from actualPos
Definition: MWAWInputStream.hxx:137
MWAWPictMac.hxx
MWAWDebug.hxx
libmwaw_applepict1::OpCode::readText
static bool readText(MWAWInputStream &input, DataType type, std::string &res)
low level: reads a string argument
Definition: MWAWPictMac.cxx:998
libmwaw_applepict1::OpCode::readInt
static bool readInt(MWAWInputStream &input, DataType type, int &res)
low level: reads a integer ( bytes or 2 bytes, signed or unsigned)
Definition: MWAWPictMac.cxx:773
libmwaw_applepict1::OpCode::readPattern
static bool readPattern(MWAWInputStream &input, DataType type, int(&pat)[8])
low level: reads a pattern argument
Definition: MWAWPictMac.cxx:872
libmwaw_applepict1::Value::Value
Value()
Definition: MWAWPictMac.cxx:428
MWAWColor::black
static MWAWColor black()
return the back color
Definition: libmwaw_internal.hxx:245
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
libmwaw_applepict1::WP_UNKNOWN
@ WP_UNKNOWN
Definition: MWAWPictMac.cxx:139
libmwaw_applepict1::OpCode::readValue
static bool readValue(MWAWInputStream &input, DataType type, Value &val)
reads a argument of type type, if successfull updates val.
Definition: MWAWPictMac.cxx:711
libmwaw_applepict1::Region::read
bool read(MWAWInputStream &input)
tries to read the data
Definition: MWAWPictMac.cxx:168
MWAWPictBitmapBW::valid
bool valid() const final
returns true if the picture is valid
Definition: MWAWPictBitmap.hxx:289
libmwaw_applepict1::WP_UINT
@ WP_UINT
Definition: MWAWPictMac.cxx:137
libmwaw_applepict1::Bitmap::unpackedData
bool unpackedData(unsigned char const *pData, int sz)
creates the bitmap from the packdata
Definition: MWAWPictMac.cxx:342
libmwaw_applepict1::Value::operator<<
friend std::ostream & operator<<(std::ostream &o, Value const &f)
operator<< for Value
Definition: MWAWPictMac.cxx:451
libmwaw_applepict1::Value::operator=
Value & operator=(Value const &)=default
libmwaw_applepict1::OpCode::~OpCode
virtual ~OpCode()
Definition: MWAWPictMac.cxx:1052
libmwaw_applepict1::Bitmap::m_region
std::shared_ptr< Region > m_region
the region
Definition: MWAWPictMac.cxx:419
libmwaw_applepict1::Region::m_points
std::vector< MWAWVec2i > m_points
the set of points which defines the mask
Definition: MWAWPictMac.cxx:225
MWAWPictData::m_data
librevenge::RVNGBinaryData m_data
the data size (without the empty header of 512 characters)
Definition: MWAWPictData.hxx:176
libmwaw_applepict1::Bitmap::m_src
MWAWBox2i m_src
the initial dimension
Definition: MWAWPictMac.cxx:417
libmwaw_applepict1::Bitmap::m_rect
MWAWBox2i m_rect
the bitmap rectangle
Definition: MWAWPictMac.cxx:417
libmwaw_applepict1::OpCode::readData
bool readData(MWAWInputStream &input, std::vector< Value > &listValue) const
tries to read the data in the file
Definition: MWAWPictMac.cxx:577
MWAWPict::MWAW_R_OK_EMPTY
@ MWAW_R_OK_EMPTY
Definition: MWAWPict.hxx:73
MWAWPictData
an abstract class which defines basic formated picture ( AppleŠ Pict, DB3, ...)
Definition: MWAWPictData.hxx:52
libmwaw_applepict1::Bitmap
Internal and low level: a class used to read pack/unpack black-white bitmap.
Definition: MWAWPictMac.cxx:229
MWAWInputStream::checkPosition
bool checkPosition(long pos) const
checks if a position is or not a valid file position
Definition: MWAWInputStream.hxx:105
libmwaw_applepict1::OpCode::m_name
std::string m_name
the opCode name
Definition: MWAWPictMac.cxx:656
libmwaw_applepict1::Value::m_type
DataType m_type
the stored type of the data
Definition: MWAWPictMac.cxx:448
libmwaw_applepict1::WP_LTEXT
@ WP_LTEXT
Definition: MWAWPictMac.cxx:138
libmwaw_applepict1::PictParser::convertToPict2
bool convertToPict2(librevenge::RVNGBinaryData const &orig, librevenge::RVNGBinaryData &result)
internal and low level: tries to convert a Pict1.0 picture stored in orig in a Pict2....
Definition: MWAWPictMac.cxx:1146
libmwaw_applepict1::WP_RBITMAP
@ WP_RBITMAP
Definition: MWAWPictMac.cxx:139
libmwaw_applepict1::WP_TEXT
@ WP_TEXT
Definition: MWAWPictMac.cxx:138
MWAWBox2::size
MWAWVec2< T > size() const
the box size
Definition: libmwaw_internal.hxx:1067
libmwaw_applepict1::Bitmap::Bitmap
Bitmap()
Definition: MWAWPictMac.cxx:230
libmwaw_applepict1
Internal and low level: generic tools about Mac Pict1.0 picture.
Definition: MWAWPictMac.cxx:127
libmwaw_applepict1::OpCode::readColor
static bool readColor(MWAWInputStream &input, DataType type, MWAWColor &col)
low level: reads a color argument
Definition: MWAWPictMac.cxx:825
MWAWVec2::set
void set(T xx, T yy)
resets the two elements
Definition: libmwaw_internal.hxx:691
MWAWInputStream.hxx
libmwaw_applepict1::WP_REGION
@ WP_REGION
Definition: MWAWPictMac.cxx:138
MWAWPictBitmap.hxx
MWAWBox2< float >
libmwaw_applepict1::Value::m_pat
int m_pat[8]
the pattern when type=WP_PATTERN
Definition: MWAWPictMac.cxx:524
libmwaw_applepict1::Region::Region
Region()
Definition: MWAWPictMac.cxx:149
libmwaw_applepict1::OpCode::getSize
static int getSize(MWAWInputStream &input, DataType type)
returns the size of the next argument of type type.
Definition: MWAWPictMac.cxx:664
libmwaw_applepict1::OpCode::readPoly
static bool readPoly(MWAWInputStream &input, DataType type, MWAWBox2i &box, std::vector< MWAWVec2i > &res)
low level: reads a polygon argument
Definition: MWAWPictMac.cxx:936
libmwaw_applepict1::Bitmap::m_bitmap
std::vector< unsigned char > m_bitmap
the bitmap
Definition: MWAWPictMac.cxx:421
libmwaw_applepict1::WP_NONE
@ WP_NONE
Definition: MWAWPictMac.cxx:137
libmwaw_applepict1::Region::operator<<
friend std::ostream & operator<<(std::ostream &o, Region const &f)
operator << for a Region
Definition: MWAWPictMac.cxx:155
MWAWPictMac::convertPict1To2
static bool convertPict1To2(librevenge::RVNGBinaryData const &orig, librevenge::RVNGBinaryData &result)
convert a Pict1.0 in Pict2.0, if possible
Definition: MWAWPictMac.cxx:1254
MWAWVec2i
MWAWVec2< int > MWAWVec2i
MWAWVec2 of int.
Definition: libmwaw_internal.hxx:838
MWAWInputStream::read
const uint8_t * read(size_t numBytes, unsigned long &numBytesRead)
! reads numbytes data, WITHOUT using any endian or section consideration
Definition: MWAWInputStream.cxx:134
libmwaw_applepict1::OpCode::readPoint
static bool readPoint(MWAWInputStream &input, DataType type, MWAWVec2i &res)
low level: reads a point argument
Definition: MWAWPictMac.cxx:890
MWAWPictMac::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: MWAWPictMac.hxx:87
libmwaw_applepict1::Value::m_point
MWAWVec2i m_point
the point when type=WP_POINT
Definition: MWAWPictMac.cxx:528
libmwaw_applepict1::WP_POINTBYTE
@ WP_POINTBYTE
Definition: MWAWPictMac.cxx:138
libmwaw_applepict1::PictParser::m_mapIdOp
std::map< int, OpCode > m_mapIdOp
the map
Definition: MWAWPictMac.cxx:1141
MWAWPictMac::MWAWPictMac
MWAWPictMac(MWAWBox2f box)
protected constructor: use check to construct a picture
Definition: MWAWPictMac.hxx:106
libmwaw_applepict1::WP_BYTE
@ WP_BYTE
Definition: MWAWPictMac.cxx:137
MWAWPictMac
Class to read/store a Mac Pict1.0/2.0.
Definition: MWAWPictMac.hxx:50
libmwaw_applepict1::WP_COLOR
@ WP_COLOR
Definition: MWAWPictMac.cxx:138