Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef MWAW_PICT_DATA
00042 # define MWAW_PICT_DATA
00043
00044 # include <assert.h>
00045 # include <ostream>
00046
00047 # include <libwpd/libwpd.h>
00048
00049 # include "libmwaw_internal.hxx"
00050 # include "MWAWPict.hxx"
00051
00052 class WPXBinaryData;
00053
00055 class MWAWPictData : public MWAWPict
00056 {
00057 public:
00059 enum SubType { PictMac, DB3, Unknown };
00061 virtual Type getType() const {
00062 return MWAWPict::PictData;
00063 }
00065 virtual SubType getSubType() const = 0;
00066
00068 virtual bool getBinary(WPXBinaryData &res, std::string &s) const {
00069 if (!valid() || isEmpty()) return false;
00070
00071 s = "image/pict";
00072 createFileData(m_data, res);
00073 return true;
00074 }
00075
00077 virtual bool sure() const {
00078 return getSubType() != Unknown;
00079 }
00080
00082 virtual bool valid() const {
00083 return false;
00084 }
00085
00087 bool isEmpty() const {
00088 return m_empty;
00089 }
00090
00095 static ReadResult check(MWAWInputStreamPtr input, int size, Box2f &box) {
00096 return checkOrGet(input, size, box, 0L);
00097 }
00098
00102 static MWAWPictData *get(MWAWInputStreamPtr input, int size) {
00103 MWAWPictData *res = 0L;
00104 Box2f box;
00105 if (checkOrGet(input, size, box, &res) == MWAW_R_BAD) return 0L;
00106 if (res) {
00107 Vec2f sz = box.size();
00108 if (sz.x()>0 && sz.y()>0) res->setBdBox(box);
00109 }
00110 return res;
00111 }
00112
00115 virtual int cmp(MWAWPict const &a) const {
00116 int diff = MWAWPict::cmp(a);
00117 if (diff) return diff;
00118 MWAWPictData const &aPict = static_cast<MWAWPictData const &>(a);
00119
00120 diff = (int) m_empty - (int) aPict.m_empty;
00121 if (diff) return (diff < 0) ? -1 : 1;
00122
00123 diff = getSubType() - aPict.getSubType();
00124 if (diff) return (diff < 0) ? -1 : 1;
00125
00126 if (m_data.size() < aPict.m_data.size())
00127 return 1;
00128 if (m_data.size() > aPict.m_data.size())
00129 return -1;
00130 unsigned char const *data=m_data.getDataBuffer();
00131 unsigned char const *aData=m_data.getDataBuffer();
00132 for (unsigned long c=0; c < m_data.size(); c++, data++, aData++) {
00133 if (*data < *aData) return -1;
00134 if (*data > *aData) return 1;
00135 }
00136 return 0;
00137 }
00138
00139 protected:
00142 static bool createFileData(WPXBinaryData const &orig, WPXBinaryData &result);
00143
00145 MWAWPictData(): m_data(), m_empty(false) { }
00146 MWAWPictData(Box2f &): m_data(), m_empty(false) { }
00147
00153 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
00154 Box2f &box, MWAWPictData **result = 0L);
00155
00157 WPXBinaryData m_data;
00158
00160 bool m_empty;
00161 };
00162
00164 class MWAWPictDB3 : public MWAWPictData
00165 {
00166 public:
00168 virtual SubType getSubType() const {
00169 return DB3;
00170 }
00171
00173 virtual bool valid() const {
00174 return m_data.size() != 0;
00175 }
00176
00179 virtual int cmp(MWAWPict const &a) const {
00180 return MWAWPictData::cmp(a);
00181 }
00182
00183 protected:
00184
00186 MWAWPictDB3() {
00187 m_empty = false;
00188 }
00189
00190 friend class MWAWPictData;
00196 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
00197 };
00198
00200 class MWAWPictDUnknown : public MWAWPictData
00201 {
00202 public:
00204 virtual SubType getSubType() const {
00205 return Unknown;
00206 }
00207
00209 virtual bool valid() const {
00210 return m_data.size() != 0;
00211 }
00212
00215 virtual int cmp(MWAWPict const &a) const {
00216 return MWAWPictData::cmp(a);
00217 }
00218
00219 protected:
00220
00222 MWAWPictDUnknown() {
00223 m_empty = false;
00224 }
00225
00226 friend class MWAWPictData;
00227
00233 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
00234 };
00235
00236 #endif
00237