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
00042 #ifndef MWAW_PICT
00043 # define MWAW_PICT
00044
00045 # include <assert.h>
00046 # include <ostream>
00047 # include <vector>
00048
00049 # include "libmwaw_internal.hxx"
00050
00052 class MWAWPict
00053 {
00054 public:
00056 virtual ~MWAWPict() {}
00057
00064 enum Type { PictData, Bitmap, Unknown };
00066 virtual Type getType() const = 0;
00067
00074 enum ReadResult { MWAW_R_BAD=0, MWAW_R_OK, MWAW_R_OK_EMPTY, MWAW_R_MAYBE };
00075
00077 Box2f getBdBox() const {
00078 Box2f res(m_bdbox);
00079 res.extend(m_bdBoxExt);
00080 return res;
00081 }
00082
00084 void setBdBox(Box2f const &box) {
00085 m_bdbox = box;
00086 }
00087
00092 virtual bool getBinary(WPXBinaryData &, std::string &) const {
00093 return false;
00094 }
00095
00099 virtual int cmp(MWAWPict const &a) const {
00100
00101 int diff = m_bdbox.cmp(a.m_bdbox);
00102 if (diff) return diff;
00103
00104 diff = getType() - a.getType();
00105 if (diff) return (diff < 0) ? -1 : 1;
00106
00107 return 0;
00108 }
00109 protected:
00111 static Box2f getBdBox(int numPt, Vec2f const *pt) {
00112 if (numPt <= 0) {
00113 return Box2f();
00114 }
00115
00116 float minV[2], maxV[2];
00117 for (int c = 0; c < 2; c++) minV[c] = maxV[c] = pt[0][c];
00118
00119 for (int i = 1; i < numPt; i++) {
00120 for (int c = 0; c < 2; c++) {
00121 float v = pt[i][c];
00122 if (v < minV[c]) minV[c] = v;
00123 else if (v > maxV[c]) maxV[c] = v;
00124 }
00125 }
00126
00127 return Box2f(Vec2f(minV[0], minV[1]), Vec2f(maxV[0], maxV[1]));
00128 }
00129
00130
00131
00133 void extendBDBox(float val) {
00134 m_bdBoxExt = val;
00135 }
00136
00138 MWAWPict() : m_bdbox(), m_bdBoxExt (0.0) {}
00140 MWAWPict(MWAWPict const &p) : m_bdbox(), m_bdBoxExt (0.0) {
00141 *this=p;
00142 }
00144 MWAWPict &operator=(MWAWPict const &p) {
00145 if (&p == this) return *this;
00146 m_bdbox = p.m_bdbox;
00147 m_bdBoxExt = p.m_bdBoxExt;
00148 return *this;
00149 }
00150
00151 private:
00153 Box2f m_bdbox;
00155 float m_bdBoxExt;
00156 };
00157
00158 #endif
00159