MsWrdStruct.hxx Source File documentation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

MsWrdStruct.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 /*
35 * Class to read/store the MsWrd structures
36 */
37
38 #ifndef MS_WRD_STRUCT
39 # define MS_WRD_STRUCT
40
41 #include <iostream>
42 #include <string>
43 #include <vector>
44
45 #include "libmwaw_internal.hxx"
46
47 #include "MWAWFont.hxx"
48 #include "MWAWParagraph.hxx"
49
51 namespace MsWrdStruct
52 {
54 MWAWBorder getBorder(int val, std::string &extra);
55
57 struct Font {
58 enum { NumFlags =9 };
59
61 Font(): m_font(MWAWFont(-1,0)), m_size(0), m_value(0), m_picturePos(0), m_unknown(0), m_extra("")
62 {
63 for (int i = 0; i < NumFlags; i++) m_flags[i]=Variable<int>(0);
64 }
65
67 void insert(Font const &font, Font const *styleFont=0);
68
70 void updateFontToFinalState(Font const *styleFont=0);
71
73 friend std::ostream &operator<<(std::ostream &o, Font const &font);
74
76 int cmp(Font const &oth) const
77 {
78 int diff = m_font.get().cmp(oth.m_font.get());
79 if (diff) return diff;
80 if (m_size.get() < oth.m_size.get()) return -1;
81 if (m_size.get() > oth.m_size.get()) return 1;
82 diff = m_value.get()-oth.m_value.get();
83 if (diff) return diff;
84 for (int i = 0; i < NumFlags; i++) {
85 diff = m_flags[i].get()-oth.m_flags[i].get();
86 if (diff) return diff;
87 }
88 if (m_picturePos.get()<oth.m_picturePos.get()) return -1;
89 if (m_picturePos.get()>oth.m_picturePos.get()) return 1;
90 diff = m_unknown.get()-oth.m_unknown.get();
91 if (diff) return diff;
92 return 0;
93 }
95 Variable<MWAWFont> m_font;
97 Variable<float> m_size;
99 Variable<int> m_value;
101 Variable<int> m_flags[NumFlags];
103 Variable<long> m_picturePos;
105 Variable<int> m_unknown;
107 std::string m_extra;
108 };
109
111 struct Section {
113 Section() : m_id(-1), m_type(0), m_paragraphId(-9999), m_col(1),
114 m_colSep(0.5), m_colBreak(false), m_flag(0), m_extra("")
115 {
116 }
118 MWAWSection getSection(double pageWidth) const;
119
121 void insert(Section const &sec)
122 {
123 m_id.insert(sec.m_id);
124 m_type.insert(sec.m_type);
125 m_paragraphId.insert(sec.m_paragraphId);
126 m_col.insert(sec.m_col);
127 m_colSep.insert(sec.m_colSep);
128 m_colBreak.insert(sec.m_colBreak);
129 m_flag.insert(sec.m_flag);
130 m_extra+=sec.m_extra;
131 }
133 bool read(MWAWInputStreamPtr &input, long endPos);
135 bool readV3(MWAWInputStreamPtr &input, long endPos);
136
138 friend std::ostream &operator<<(std::ostream &o, Section const &section);
139
141 Variable<int> m_id;
143 Variable<int> m_type;
145 Variable<int> m_paragraphId;
147 Variable<int> m_col;
149 Variable<float> m_colSep;
151 Variable<bool> m_colBreak;
153 Variable<int> m_flag;
155 std::string m_extra;
156 };
157
159 struct Table {
160 struct Cell;
162 Table() : m_height(0), m_justify(MWAWParagraph::JustificationLeft), m_indent(0),
163 m_columns(), m_columnsWidthMod(), m_cells(), m_extra("")
164 {
165 }
167 void insert(Table const &table);
169 bool read(MWAWInputStreamPtr &input, long endPos);
171 Variable<Cell> &getCell(int id);
172
174 friend std::ostream &operator<<(std::ostream &o, Table const &table);
175
177 Variable<float> m_height;
179 Variable<MWAWParagraph::Justification> m_justify;
181 Variable<float> m_indent;
183 Variable<std::vector<float> > m_columns;
185 Variable<std::vector<float> > m_columnsWidthMod;
187 std::vector<Variable<Cell> > m_cells;
189 std::string m_extra;
190
192 struct Cell {
194 Cell() : m_borders(), m_backColor(1.0f), m_extra("")
195 {
196 }
198 void insert(Cell const &cell)
199 {
200 size_t cNumBorders = cell.m_borders.size();
201 if (cNumBorders > m_borders.size())
202 m_borders.resize(cNumBorders);
203 for (size_t i=0; i < cNumBorders; i++)
204 if (cell.m_borders[i].isSet()) m_borders[i]=*cell.m_borders[i];
205 m_backColor.insert(cell.m_backColor);
206 m_extra+=cell.m_extra;
207 }
209 bool hasBorders() const
210 {
211 for (size_t i = 0; i < m_borders.size(); i++)
212 if (m_borders[i].isSet() && m_borders[i]->m_style != MWAWBorder::None)
213 return true;
214 return false;
215 }
217 friend std::ostream &operator<<(std::ostream &o, Cell const &cell);
219 std::vector<Variable<MWAWBorder> > m_borders;
221 Variable<float> m_backColor;
223 std::string m_extra;
224 };
225 };
226
228 struct ParagraphInfo {
230 ParagraphInfo() : m_type(0), m_dim(), m_numLines(-1), m_error("")
231 {
232 }
234 bool isLineSet() const
235 {
236 return *m_numLines!=0;
237 }
239 bool isEmpty() const
240 {
241 if (*m_numLines || *m_type) return false;
242 if (!m_dim.isSet()) return true;
243 if ((*m_dim)[0] > 0 || (*m_dim)[1] > 0) return false;
244 return true;
245 }
247 bool read(MWAWInputStreamPtr &input, long endPos, int vers);
249 friend std::ostream &operator<<(std::ostream &o, ParagraphInfo const &pInfo)
250 {
251 // find also pInfo.m_type&0x40 : ?
252 if (*pInfo.m_type&0xd0) o << "type?=" << ((*pInfo.m_type&0xd0)>>4) << ",";
253 if (*pInfo.m_type&0x0f) o << "#unkn=" << (*pInfo.m_type&0xf) << ",";
254 if (pInfo.m_dim.isSet()) {
255 if ((*pInfo.m_dim)[0] > 0)
256 o << "width=" << (*pInfo.m_dim)[0] << ",";
257 if ((*pInfo.m_dim)[1] > 0) {
258 o << "height=" << (*pInfo.m_dim)[1];
259 if (*pInfo.m_type&0x20)
260 o << "[total]";
261 o << ",";
262 }
263 }
264 if (pInfo.m_numLines.isSet() && *pInfo.m_numLines!=-1 && *pInfo.m_numLines!=1)
265 o << "nLines=" << *pInfo.m_numLines << ",";
266 if (pInfo.m_error.length()) o << pInfo.m_error << ",";
267 return o;
268 }
270 void insert(ParagraphInfo const &pInfo);
272 Variable<int> m_type;
274 Variable<Vec2f> m_dim;
276 Variable<int> m_numLines;
278 std::string m_error;
279 };
280
282 struct Paragraph : public MWAWParagraph {
284 Paragraph(int version) : MWAWParagraph(), m_version(version), m_styleId(-1000),
285 m_interline(0), m_deletedTabs(), m_info(), m_font(), m_modFont(), m_section(),
286 m_bordersStyle(), m_inCell(false), m_tableDef(false), m_table()
287 {
288 m_tabsRelativeToLeftMargin=false;
289 }
291 void insert(Paragraph const &para, bool insertModif=true);
293 bool read(MWAWInputStreamPtr &input, long endPos);
295 void updateParagraphToFinalState(Paragraph const *style=0);
297 bool getFont(Font &font, Font const *styleFont=0) const;
299 bool inTable() const
300 {
301 return m_inCell.get();
302 }
304 friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind);
305
307 void print(std::ostream &o, MWAWFontConverterPtr converter) const;
308
310 int getNumLines() const
311 {
312 return m_info.get().m_numLines.get();
313 }
315 int m_version;
317 Variable<int> m_styleId;
319 Variable<double> m_interline;
321 std::vector<float> m_deletedTabs;
323 Variable<ParagraphInfo> m_info;
325 Variable<Font> m_font, m_modFont ;
327 Variable<Section> m_section;
329 Variable<MWAWBorder> m_bordersStyle;
331 Variable<bool> m_inCell;
333 Variable<bool> m_tableDef;
335 Variable<Table> m_table;
336 };
337 }
338 #endif
339 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MsWrdStruct::ParagraphInfo::insert
void insert(ParagraphInfo const &pInfo)
insert the new values
Definition: MsWrdStruct.cxx:722
MsWrdStruct::Section::m_type
Variable< int > m_type
the type
Definition: MsWrdStruct.hxx:143
MsWrdStruct::Table::Cell::hasBorders
bool hasBorders() const
returns true if the cell has borders
Definition: MsWrdStruct.hxx:209
MsWrdStruct::Font
the font structure of a Microsoft Word file
Definition: MsWrdStruct.hxx:57
MsWrdStruct::Table::Cell::m_extra
std::string m_extra
extra data
Definition: MsWrdStruct.hxx:223
MsWrdStruct::Font::NumFlags
the number of flags needed to store all datas
Definition: MsWrdStruct.hxx:58
MsWrdStruct::Paragraph::m_inCell
Variable< bool > m_inCell
a cell/textbox
Definition: MsWrdStruct.hxx:331
MsWrdStruct::Table::m_indent
Variable< float > m_indent
the indent
Definition: MsWrdStruct.hxx:181
MsWrdStruct::Table::Cell::Cell
Cell()
constructor
Definition: MsWrdStruct.hxx:194
MsWrdStruct::Table::Cell::m_borders
std::vector< Variable< MWAWBorder > > m_borders
the borders TLBR
Definition: MsWrdStruct.hxx:219
MsWrdStruct::ParagraphInfo::ParagraphInfo
ParagraphInfo()
constructor
Definition: MsWrdStruct.hxx:230
libmwaw_internal.hxx
Variable::insert
void insert(Variable const &orig)
update the current value if orig is set
Definition: libmwaw_internal.hxx:477
MsWrdStruct::Paragraph::m_version
int m_version
the file version
Definition: MsWrdStruct.hxx:315
MsWrdStruct::Paragraph::m_tableDef
Variable< bool > m_tableDef
a table flag
Definition: MsWrdStruct.hxx:333
MsWrdStruct::Table::Cell::insert
void insert(Cell const &cell)
update the cell data by merging
Definition: MsWrdStruct.hxx:198
MsWrdStruct::Paragraph::inTable
bool inTable() const
returns true if we are in table
Definition: MsWrdStruct.hxx:299
MsWrdStruct::Font::m_flags
Variable< int > m_flags[NumFlags]
a list of flags
Definition: MsWrdStruct.hxx:101
MsWrdStruct::Paragraph::print
void print(std::ostream &o, MWAWFontConverterPtr converter) const
operator<<
Definition: MsWrdStruct.cxx:1199
MsWrdStruct::Section::m_colSep
Variable< float > m_colSep
the spacing between column
Definition: MsWrdStruct.hxx:149
MsWrdStruct::Table::operator<<
friend std::ostream & operator<<(std::ostream &o, Table const &table)
operator<<
Definition: MsWrdStruct.cxx:647
Variable::isSet
bool isSet() const
return true if the variable is set
Definition: libmwaw_internal.hxx:512
MsWrdStruct::Section::Section
Section()
constructor
Definition: MsWrdStruct.hxx:113
MsWrdStruct::Font::insert
void insert(Font const &font, Font const *styleFont=0)
insert new font data ( beginning by updating font flags )
Definition: MsWrdStruct.cxx:82
MsWrdStruct::Section::read
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition: MsWrdStruct.cxx:167
MsWrdStruct::Paragraph::m_section
Variable< Section > m_section
the section
Definition: MsWrdStruct.hxx:327
MsWrdStruct::Table::getCell
Variable< Cell > & getCell(int id)
returns the ith Cell
Definition: MsWrdStruct.cxx:424
MsWrdStruct
namespace to store the main structure which appears in a Microsoft Word 3.0-5.0 file ...
Definition: MsWrdStruct.cxx:41
MsWrdStruct::Paragraph
the paragraph structure of a Microsoft Word file
Definition: MsWrdStruct.hxx:282
MsWrdStruct::Table::Table
Table()
constructor
Definition: MsWrdStruct.hxx:162
MsWrdStruct::Paragraph::Paragraph
Paragraph(int version)
Constructor.
Definition: MsWrdStruct.hxx:284
MsWrdStruct::Section::readV3
bool readV3(MWAWInputStreamPtr &input, long endPos)
try to read a data ( v3 code )
Definition: MsWrdStruct.cxx:233
MsWrdStruct::Font::m_value
Variable< int > m_value
a unknown value
Definition: MsWrdStruct.hxx:99
MsWrdStruct::Paragraph::getFont
bool getFont(Font &font, Font const *styleFont=0) const
returns the font which correspond to the paragraph if possible
Definition: MsWrdStruct.cxx:1117
MsWrdStruct::Paragraph::m_interline
Variable< double > m_interline
the interline if set
Definition: MsWrdStruct.hxx:319
MsWrdStruct::Paragraph::m_deletedTabs
std::vector< float > m_deletedTabs
the delete tabulation
Definition: MsWrdStruct.hxx:321
MsWrdStruct::Section::m_colBreak
Variable< bool > m_colBreak
only a column break
Definition: MsWrdStruct.hxx:151
MsWrdStruct::Section::insert
void insert(Section const &sec)
insert the new values
Definition: MsWrdStruct.hxx:121
MWAWFont
Class to store font.
Definition: MWAWFont.hxx:44
MWAWBorder
a border
Definition: libmwaw_internal.hxx:299
MsWrdStruct::ParagraphInfo::m_error
std::string m_error
the errors
Definition: MsWrdStruct.hxx:278
MsWrdStruct::Paragraph::getNumLines
int getNumLines() const
returns the number of line stored in m_info or -1
Definition: MsWrdStruct.hxx:310
MsWrdStruct::Table::m_extra
std::string m_extra
the errors
Definition: MsWrdStruct.hxx:189
MsWrdStruct::Table::read
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition: MsWrdStruct.cxx:435
MsWrdStruct::Paragraph::m_font
Variable< Font > m_font
the font
Definition: MsWrdStruct.hxx:325
MWAWFont.hxx
MsWrdStruct::Section::m_extra
std::string m_extra
the errors
Definition: MsWrdStruct.hxx:155
MsWrdStruct::Font::m_extra
std::string m_extra
extra data
Definition: MsWrdStruct.hxx:107
MWAWParagraph::m_tabsRelativeToLeftMargin
Variable< bool > m_tabsRelativeToLeftMargin
true if the tabs are relative to left margin, false if there are relative to the page margin (default...
Definition: MWAWParagraph.hxx:159
MsWrdStruct::ParagraphInfo::isEmpty
bool isEmpty() const
returns true if no data are been set
Definition: MsWrdStruct.hxx:239
MsWrdStruct::Section::getSection
MWAWSection getSection(double pageWidth) const
returns a section
Definition: MsWrdStruct.cxx:150
MsWrdStruct::Table::Cell
the cells definitions in a Microsoft Word Table
Definition: MsWrdStruct.hxx:192
MsWrdStruct::Section::m_id
Variable< int > m_id
the identificator
Definition: MsWrdStruct.hxx:141
MWAWFont::cmp
int cmp(MWAWFont const &oth) const
a comparison function
Definition: MWAWFont.hxx:489
MsWrdStruct::Section::m_col
Variable< int > m_col
the num of columns
Definition: MsWrdStruct.hxx:147
MWAWBorder::None
Definition: libmwaw_internal.hxx:301
MsWrdStruct::Paragraph::m_info
Variable< ParagraphInfo > m_info
the dimension
Definition: MsWrdStruct.hxx:323
MsWrdStruct::Paragraph::operator<<
friend std::ostream & operator<<(std::ostream &o, Paragraph const &ind)
operator<<
Definition: MsWrdStruct.cxx:1093
MsWrdStruct::Table::m_columnsWidthMod
Variable< std::vector< float > > m_columnsWidthMod
the columns width modifier
Definition: MsWrdStruct.hxx:185
MsWrdStruct::ParagraphInfo::m_dim
Variable< Vec2f > m_dim
the zone dimension
Definition: MsWrdStruct.hxx:274
MsWrdStruct::Table::insert
void insert(Table const &table)
insert the new values
Definition: MsWrdStruct.cxx:597
MsWrdStruct::ParagraphInfo
the paragraph information of a Microsoft Word file (PHE)
Definition: MsWrdStruct.hxx:228
MsWrdStruct::Paragraph::updateParagraphToFinalState
void updateParagraphToFinalState(Paragraph const *style=0)
update the paragraph to obtain the final paragraph
Definition: MsWrdStruct.cxx:1131
MsWrdStruct::Section::operator<<
friend std::ostream & operator<<(std::ostream &o, Section const &section)
operator<<
Definition: MsWrdStruct.cxx:406
MWAWSection
a class which stores section properties
Definition: MWAWSection.hxx:45
MWAWInputStreamPtr
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:429
MsWrdStruct::Table::Cell::operator<<
friend std::ostream & operator<<(std::ostream &o, Cell const &cell)
operator<<
Definition: MsWrdStruct.cxx:629
MsWrdStruct::getBorder
MWAWBorder getBorder(int val, std::string &extra)
generic function use to fill a border using the read data
Definition: MsWrdStruct.cxx:1209
MsWrdStruct::ParagraphInfo::read
bool read(MWAWInputStreamPtr &input, long endPos, int vers)
try to read a data
Definition: MsWrdStruct.cxx:707
MsWrdStruct::Font::m_font
Variable< MWAWFont > m_font
the font
Definition: MsWrdStruct.hxx:95
Variable::get
T const & get() const
return the current value
Definition: libmwaw_internal.hxx:507
MsWrdStruct::Paragraph::m_bordersStyle
Variable< MWAWBorder > m_bordersStyle
the border style ( old v3)
Definition: MsWrdStruct.hxx:329
MsWrdStruct::Font::operator<<
friend std::ostream & operator<<(std::ostream &o, Font const &font)
operator<<
Definition: MsWrdStruct.cxx:44
MsWrdStruct::Section
the section structure of a Microsoft Word file
Definition: MsWrdStruct.hxx:111
MsWrdStruct::Paragraph::m_modFont
Variable< Font > m_modFont
font (modifier)
Definition: MsWrdStruct.hxx:325
MWAWFontConverterPtr
shared_ptr< MWAWFontConverter > MWAWFontConverterPtr
a smart pointer of MWAWFontConverter
Definition: libmwaw_internal.hxx:423
MsWrdStruct::Table::m_columns
Variable< std::vector< float > > m_columns
the table columns
Definition: MsWrdStruct.hxx:183
MsWrdStruct::Table::m_height
Variable< float > m_height
the row height in inches
Definition: MsWrdStruct.hxx:177
MsWrdStruct::ParagraphInfo::m_numLines
Variable< int > m_numLines
the number of lines
Definition: MsWrdStruct.hxx:276
MsWrdStruct::Paragraph::insert
void insert(Paragraph const &para, bool insertModif=true)
insert the new values
Definition: MsWrdStruct.cxx:1158
MWAWParagraph
class to store the paragraph properties
Definition: MWAWParagraph.hxx:82
MsWrdStruct::Paragraph::read
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition: MsWrdStruct.cxx:731
MsWrdStruct::ParagraphInfo::m_type
Variable< int > m_type
the type
Definition: MsWrdStruct.hxx:272
MsWrdStruct::ParagraphInfo::isLineSet
bool isLineSet() const
returns true if num lines is set
Definition: MsWrdStruct.hxx:234
MsWrdStruct::Font::m_picturePos
Variable< long > m_picturePos
a picture file position (if this corresponds to a picture)
Definition: MsWrdStruct.hxx:103
MsWrdStruct::Font::Font
Font()
the constructor
Definition: MsWrdStruct.hxx:61
MsWrdStruct::Font::cmp
int cmp(Font const &oth) const
a comparison function
Definition: MsWrdStruct.hxx:76
MsWrdStruct::Paragraph::m_table
Variable< Table > m_table
the table
Definition: MsWrdStruct.hxx:335
MsWrdStruct::Table
the table in a Microsoft Word file
Definition: MsWrdStruct.hxx:159
MsWrdStruct::Section::m_flag
Variable< int > m_flag
some flag ( in the main position)
Definition: MsWrdStruct.hxx:153
MsWrdStruct::Paragraph::m_styleId
Variable< int > m_styleId
the style id (if known)
Definition: MsWrdStruct.hxx:317
MsWrdStruct::ParagraphInfo::operator<<
friend std::ostream & operator<<(std::ostream &o, ParagraphInfo const &pInfo)
operator<<
Definition: MsWrdStruct.hxx:249
MsWrdStruct::Table::Cell::m_backColor
Variable< float > m_backColor
the background gray color
Definition: MsWrdStruct.hxx:221
MsWrdStruct::Table::m_cells
std::vector< Variable< Cell > > m_cells
the table cells
Definition: MsWrdStruct.hxx:187
MsWrdStruct::Font::m_size
Variable< float > m_size
a second size
Definition: MsWrdStruct.hxx:97
MsWrdStruct::Section::m_paragraphId
Variable< int > m_paragraphId
the paragraph id
Definition: MsWrdStruct.hxx:145
MsWrdStruct::Table::m_justify
Variable< MWAWParagraph::Justification > m_justify
the justification
Definition: MsWrdStruct.hxx:179
MWAWParagraph.hxx
Variable< MWAWFont >
MsWrdStruct::Font::updateFontToFinalState
void updateFontToFinalState(Font const *styleFont=0)
update the font to obtain the final font
Definition: MsWrdStruct.cxx:98
MsWrdStruct::Font::m_unknown
Variable< int > m_unknown
some unknown flag
Definition: MsWrdStruct.hxx:105