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 #ifndef MSW_STRUCT
00039 # define MSW_STRUCT
00040
00041 #include <iostream>
00042 #include <string>
00043 #include <vector>
00044
00045 #include "libmwaw_internal.hxx"
00046
00047 #include "MWAWFont.hxx"
00048 #include "MWAWParagraph.hxx"
00049
00051 namespace MSWStruct
00052 {
00054 MWAWBorder getBorder(int val, std::string &extra);
00055
00057 struct Font {
00058 enum { NumFlags =9 };
00059
00061 Font(): m_font(MWAWFont(-1,0)), m_size(0), m_value(0), m_picturePos(0), m_unknown(0), m_extra("") {
00062 for (int i = 0; i < NumFlags; i++) m_flags[i]=Variable<int>(0);
00063 }
00064
00066 void insert(Font const &font, Font const *styleFont=0);
00067
00069 void updateFontToFinalState(Font const *styleFont=0);
00070
00072 friend std::ostream &operator<<(std::ostream &o, Font const &font);
00073
00075 int cmp(Font const &oth) const {
00076 int diff = m_font.get().cmp(oth.m_font.get());
00077 if (diff) return diff;
00078 if (m_size.get() < oth.m_size.get()) return -1;
00079 if (m_size.get() > oth.m_size.get()) return 1;
00080 diff = m_value.get()-oth.m_value.get();
00081 if (diff) return diff;
00082 for (int i = 0; i < NumFlags; i++) {
00083 diff = m_flags[i].get()-oth.m_flags[i].get();
00084 if (diff) return diff;
00085 }
00086 if (m_picturePos.get()<oth.m_picturePos.get()) return -1;
00087 if (m_picturePos.get()>oth.m_picturePos.get()) return 1;
00088 diff = m_unknown.get()-oth.m_unknown.get();
00089 if (diff) return diff;
00090 return 0;
00091 }
00093 Variable<MWAWFont> m_font;
00095 Variable<float> m_size;
00097 Variable<int> m_value;
00099 Variable<int> m_flags[NumFlags];
00101 Variable<long> m_picturePos;
00103 Variable<int> m_unknown;
00105 std::string m_extra;
00106 };
00107
00109 struct Section {
00111 Section() : m_id(-1), m_type(0), m_paragraphId(-9999), m_col(1),
00112 m_colSep(0.5), m_colBreak(false), m_flag(0), m_extra("") {
00113 }
00115 MWAWSection getSection(double pageWidth) const;
00116
00118 void insert(Section const &sec) {
00119 m_id.insert(sec.m_id);
00120 m_type.insert(sec.m_type);
00121 m_paragraphId.insert(sec.m_paragraphId);
00122 m_col.insert(sec.m_col);
00123 m_colSep.insert(sec.m_colSep);
00124 m_colBreak.insert(sec.m_colBreak);
00125 m_flag.insert(sec.m_flag);
00126 m_extra+=sec.m_extra;
00127 }
00129 bool read(MWAWInputStreamPtr &input, long endPos);
00131 bool readV3(MWAWInputStreamPtr &input, long endPos);
00132
00134 friend std::ostream &operator<<(std::ostream &o, Section const §ion);
00135
00137 Variable<int> m_id;
00139 Variable<int> m_type;
00141 Variable<int> m_paragraphId;
00143 Variable<int> m_col;
00145 Variable<float> m_colSep;
00147 Variable<bool> m_colBreak;
00149 Variable<int> m_flag;
00151 std::string m_extra;
00152 };
00153
00155 struct Table {
00156 struct Cell;
00158 Table() : m_height(0), m_justify(MWAWParagraph::JustificationLeft), m_indent(0),
00159 m_columns(), m_columnsWidthMod(), m_cells(), m_extra("") {
00160 }
00162 void insert(Table const &table);
00164 bool read(MWAWInputStreamPtr &input, long endPos);
00166 Variable<Cell> &getCell(int id);
00167
00169 friend std::ostream &operator<<(std::ostream &o, Table const &table);
00170
00172 Variable<float> m_height;
00174 Variable<MWAWParagraph::Justification> m_justify;
00176 Variable<float> m_indent;
00178 Variable<std::vector<float> > m_columns;
00180 Variable<std::vector<float> > m_columnsWidthMod;
00182 std::vector<Variable<Cell> > m_cells;
00184 std::string m_extra;
00185
00187 struct Cell {
00189 Cell() : m_borders(), m_backColor(1.0f), m_extra("") {
00190 }
00192 void insert(Cell const &cell) {
00193 size_t cNumBorders = cell.m_borders.size();
00194 if (cNumBorders > m_borders.size())
00195 m_borders.resize(cNumBorders);
00196 for (size_t i=0; i < cNumBorders; i++)
00197 if (cell.m_borders[i].isSet()) m_borders[i]=*cell.m_borders[i];
00198 m_backColor.insert(cell.m_backColor);
00199 m_extra+=cell.m_extra;
00200 }
00202 bool hasBorders() const {
00203 for (size_t i = 0; i < m_borders.size(); i++)
00204 if (m_borders[i].isSet() && m_borders[i]->m_style != MWAWBorder::None)
00205 return true;
00206 return false;
00207 }
00209 friend std::ostream &operator<<(std::ostream &o, Cell const &cell);
00211 std::vector<Variable<MWAWBorder> > m_borders;
00213 Variable<float> m_backColor;
00215 std::string m_extra;
00216 };
00217 };
00218
00220 struct ParagraphInfo {
00222 ParagraphInfo() : m_type(0), m_dim(), m_numLines(-1), m_error("") {
00223 }
00225 bool isLineSet() const {
00226 return *m_numLines!=0;
00227 }
00229 bool isEmpty() const {
00230 if (*m_numLines || *m_type) return false;
00231 if (!m_dim.isSet()) return true;
00232 if ((*m_dim)[0] > 0 || (*m_dim)[1] > 0) return false;
00233 return true;
00234 }
00236 bool read(MWAWInputStreamPtr &input, long endPos, int vers);
00238 friend std::ostream &operator<<(std::ostream &o, ParagraphInfo const &pInfo) {
00239
00240 if (*pInfo.m_type&0xd0) o << "type?=" << ((*pInfo.m_type&0xd0)>>4) << ",";
00241 if (*pInfo.m_type&0x0f) o << "#unkn=" << (*pInfo.m_type&0xf) << ",";
00242 if (pInfo.m_dim.isSet()) {
00243 if ((*pInfo.m_dim)[0] > 0)
00244 o << "width=" << (*pInfo.m_dim)[0] << ",";
00245 if ((*pInfo.m_dim)[1] > 0) {
00246 o << "height=" << (*pInfo.m_dim)[1];
00247 if (*pInfo.m_type&0x20)
00248 o << "[total]";
00249 o << ",";
00250 }
00251 }
00252 if (pInfo.m_numLines.isSet() && *pInfo.m_numLines!=-1 && *pInfo.m_numLines!=1)
00253 o << "nLines=" << *pInfo.m_numLines << ",";
00254 if (pInfo.m_error.length()) o << pInfo.m_error << ",";
00255 return o;
00256 }
00258 void insert(ParagraphInfo const &pInfo);
00260 Variable<int> m_type;
00262 Variable<Vec2f> m_dim;
00264 Variable<int> m_numLines;
00266 std::string m_error;
00267 };
00268
00270 struct Paragraph : public MWAWParagraph {
00272 Paragraph(int version) : MWAWParagraph(), m_version(version), m_styleId(-1000),
00273 m_interline(0), m_deletedTabs(), m_info(), m_font(), m_modFont(), m_section(),
00274 m_bordersStyle(), m_inCell(false), m_tableDef(false), m_table() {
00275 m_tabsRelativeToLeftMargin=false;
00276 }
00278 void insert(Paragraph const ¶, bool insertModif=true);
00280 bool read(MWAWInputStreamPtr &input, long endPos);
00282 void updateParagraphToFinalState(Paragraph const *style=0);
00284 bool getFont(Font &font, Font const *styleFont=0) const;
00286 bool inTable() const {
00287 return m_inCell.get();
00288 }
00290 friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind);
00291
00293 void print(std::ostream &o, MWAWFontConverterPtr converter) const;
00294
00296 int getNumLines() const {
00297 return m_info.get().m_numLines.get();
00298 }
00300 int m_version;
00302 Variable<int> m_styleId;
00304 Variable<double> m_interline;
00306 std::vector<float> m_deletedTabs;
00308 Variable<ParagraphInfo> m_info;
00310 Variable<Font> m_font, m_modFont ;
00312 Variable<Section> m_section;
00314 Variable<MWAWBorder> m_bordersStyle;
00316 Variable<bool> m_inCell;
00318 Variable<bool> m_tableDef;
00320 Variable<Table> m_table;
00321 };
00322 }
00323 #endif
00324