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 <librevenge/librevenge.h>
00048
00049 # include "libmwaw_internal.hxx"
00050 # include "MWAWPict.hxx"
00051
00053 class MWAWPictData : public MWAWPict
00054 {
00055 public:
00057 enum SubType { PictMac, DB3, Unknown };
00059 virtual Type getType() const
00060 {
00061 return MWAWPict::PictData;
00062 }
00064 virtual SubType getSubType() const = 0;
00065
00067 virtual bool getBinary(librevenge::RVNGBinaryData &res, std::string &s) const
00068 {
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 {
00079 return getSubType() != Unknown;
00080 }
00081
00083 virtual bool valid() const
00084 {
00085 return false;
00086 }
00087
00089 bool isEmpty() const
00090 {
00091 return m_empty;
00092 }
00093
00098 static ReadResult check(MWAWInputStreamPtr input, int size, MWAWBox2f &box)
00099 {
00100 return checkOrGet(input, size, box, 0L);
00101 }
00102
00106 static MWAWPictData *get(MWAWInputStreamPtr input, int size)
00107 {
00108 MWAWPictData *res = 0L;
00109 MWAWBox2f box;
00110 if (checkOrGet(input, size, box, &res) == MWAW_R_BAD) return 0L;
00111 if (res) {
00112 MWAWVec2f sz = box.size();
00113 if (sz.x()>0 && sz.y()>0) res->setBdBox(box);
00114 }
00115 return res;
00116 }
00117
00120 virtual int cmp(MWAWPict const &a) const
00121 {
00122 int diff = MWAWPict::cmp(a);
00123 if (diff) return diff;
00124 MWAWPictData const &aPict = static_cast<MWAWPictData const &>(a);
00125
00126 diff = (int) m_empty - (int) aPict.m_empty;
00127 if (diff) return (diff < 0) ? -1 : 1;
00128 else if (m_empty)
00129 return 0;
00130
00131 diff = getSubType() - aPict.getSubType();
00132 if (diff) return (diff < 0) ? -1 : 1;
00133
00134 if (m_data.size() < aPict.m_data.size())
00135 return 1;
00136 if (m_data.size() > aPict.m_data.size())
00137 return -1;
00138 unsigned char const *data=m_data.getDataBuffer();
00139 unsigned char const *aData=m_data.getDataBuffer();
00140 if (!data || !aData) return 0;
00141 for (unsigned long c=0; c < m_data.size(); c++, data++, aData++) {
00142 if (*data < *aData) return -1;
00143 if (*data > *aData) return 1;
00144 }
00145 return 0;
00146 }
00147
00148 protected:
00151 static bool createFileData(librevenge::RVNGBinaryData const &orig, librevenge::RVNGBinaryData &result);
00152
00154 MWAWPictData(): m_data(), m_empty(false) { }
00155 MWAWPictData(MWAWBox2f &): m_data(), m_empty(false) { }
00156
00162 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size,
00163 MWAWBox2f &box, MWAWPictData **result = 0L);
00164
00166 librevenge::RVNGBinaryData m_data;
00167
00169 bool m_empty;
00170 };
00171
00173 class MWAWPictDB3 : public MWAWPictData
00174 {
00175 public:
00177 virtual SubType getSubType() const
00178 {
00179 return DB3;
00180 }
00181
00183 virtual bool valid() const
00184 {
00185 return m_data.size() != 0;
00186 }
00187
00190 virtual int cmp(MWAWPict const &a) const
00191 {
00192 return MWAWPictData::cmp(a);
00193 }
00194
00195 protected:
00196
00198 MWAWPictDB3()
00199 {
00200 m_empty = false;
00201 }
00202
00203 friend class MWAWPictData;
00209 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
00210 };
00211
00213 class MWAWPictDUnknown : public MWAWPictData
00214 {
00215 public:
00217 virtual SubType getSubType() const
00218 {
00219 return Unknown;
00220 }
00221
00223 virtual bool valid() const
00224 {
00225 return m_data.size() != 0;
00226 }
00227
00230 virtual int cmp(MWAWPict const &a) const
00231 {
00232 return MWAWPictData::cmp(a);
00233 }
00234
00235 protected:
00236
00238 MWAWPictDUnknown()
00239 {
00240 m_empty = false;
00241 }
00242
00243 friend class MWAWPictData;
00244
00250 static ReadResult checkOrGet(MWAWInputStreamPtr input, int size, MWAWPictData **result = 0L);
00251 };
00252
00253 #endif
00254