MSWStruct.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 MSW structures
36  */
37 
38 #ifndef MSW_STRUCT
39 # define MSW_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 MSWStruct
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  for (int i = 0; i < NumFlags; i++) m_flags[i]=Variable<int>(0);
63  }
64 
66  void insert(Font const &font, Font const *styleFont=0);
67 
69  void updateFontToFinalState(Font const *styleFont=0);
70 
72  friend std::ostream &operator<<(std::ostream &o, Font const &font);
73 
75  int cmp(Font const &oth) const {
76  int diff = m_font.get().cmp(oth.m_font.get());
77  if (diff) return diff;
78  if (m_size.get() < oth.m_size.get()) return -1;
79  if (m_size.get() > oth.m_size.get()) return 1;
80  diff = m_value.get()-oth.m_value.get();
81  if (diff) return diff;
82  for (int i = 0; i < NumFlags; i++) {
83  diff = m_flags[i].get()-oth.m_flags[i].get();
84  if (diff) return diff;
85  }
86  if (m_picturePos.get()<oth.m_picturePos.get()) return -1;
87  if (m_picturePos.get()>oth.m_picturePos.get()) return 1;
88  diff = m_unknown.get()-oth.m_unknown.get();
89  if (diff) return diff;
90  return 0;
91  }
105  std::string m_extra;
106 };
107 
109 struct Section {
111  Section() : m_id(-1), m_type(0), m_paragraphId(-9999), m_col(1),
112  m_colSep(0.5), m_colBreak(false), m_flag(0), m_extra("") {
113  }
115  MWAWSection getSection(double pageWidth) const;
116 
118  void insert(Section const &sec) {
119  m_id.insert(sec.m_id);
120  m_type.insert(sec.m_type);
122  m_col.insert(sec.m_col);
123  m_colSep.insert(sec.m_colSep);
125  m_flag.insert(sec.m_flag);
126  m_extra+=sec.m_extra;
127  }
129  bool read(MWAWInputStreamPtr &input, long endPos);
131  bool readV3(MWAWInputStreamPtr &input, long endPos);
132 
134  friend std::ostream &operator<<(std::ostream &o, Section const &section);
135 
151  std::string m_extra;
152 };
153 
155 struct Table {
156  struct Cell;
158  Table() : m_height(0), m_justify(MWAWParagraph::JustificationLeft), m_indent(0),
160  }
162  void insert(Table const &table);
164  bool read(MWAWInputStreamPtr &input, long endPos);
166  Variable<Cell> &getCell(int id);
167 
169  friend std::ostream &operator<<(std::ostream &o, Table const &table);
170 
182  std::vector<Variable<Cell> > m_cells;
184  std::string m_extra;
185 
187  struct Cell {
189  Cell() : m_borders(), m_backColor(1.0f), m_extra("") {
190  }
192  void insert(Cell const &cell) {
193  size_t cNumBorders = cell.m_borders.size();
194  if (cNumBorders > m_borders.size())
195  m_borders.resize(cNumBorders);
196  for (size_t i=0; i < cNumBorders; i++)
197  if (cell.m_borders[i].isSet()) m_borders[i]=*cell.m_borders[i];
199  m_extra+=cell.m_extra;
200  }
202  bool hasBorders() const {
203  for (size_t i = 0; i < m_borders.size(); i++)
204  if (m_borders[i].isSet() && m_borders[i]->m_style != MWAWBorder::None)
205  return true;
206  return false;
207  }
209  friend std::ostream &operator<<(std::ostream &o, Cell const &cell);
211  std::vector<Variable<MWAWBorder> > m_borders;
215  std::string m_extra;
216  };
217 };
218 
223  }
225  bool isLineSet() const {
226  return *m_numLines!=0;
227  }
229  bool isEmpty() const {
230  if (*m_numLines || *m_type) return false;
231  if (!m_dim.isSet()) return true;
232  if ((*m_dim)[0] > 0 || (*m_dim)[1] > 0) return false;
233  return true;
234  }
236  bool read(MWAWInputStreamPtr &input, long endPos, int vers);
238  friend std::ostream &operator<<(std::ostream &o, ParagraphInfo const &pInfo) {
239  // find also pInfo.m_type&0x40 : ?
240  if (*pInfo.m_type&0xd0) o << "type?=" << ((*pInfo.m_type&0xd0)>>4) << ",";
241  if (*pInfo.m_type&0x0f) o << "#unkn=" << (*pInfo.m_type&0xf) << ",";
242  if (pInfo.m_dim.isSet()) {
243  if ((*pInfo.m_dim)[0] > 0)
244  o << "width=" << (*pInfo.m_dim)[0] << ",";
245  if ((*pInfo.m_dim)[1] > 0) {
246  o << "height=" << (*pInfo.m_dim)[1];
247  if (*pInfo.m_type&0x20)
248  o << "[total]";
249  o << ",";
250  }
251  }
252  if (pInfo.m_numLines.isSet() && *pInfo.m_numLines!=-1 && *pInfo.m_numLines!=1)
253  o << "nLines=" << *pInfo.m_numLines << ",";
254  if (pInfo.m_error.length()) o << pInfo.m_error << ",";
255  return o;
256  }
258  void insert(ParagraphInfo const &pInfo);
266  std::string m_error;
267 };
268 
270 struct Paragraph : public MWAWParagraph {
272  Paragraph(int version) : MWAWParagraph(), m_version(version), m_styleId(-1000),
274  m_bordersStyle(), m_inCell(false), m_tableDef(false), m_table() {
276  }
278  void insert(Paragraph const &para, bool insertModif=true);
280  bool read(MWAWInputStreamPtr &input, long endPos);
282  void updateParagraphToFinalState(Paragraph const *style=0);
284  bool getFont(Font &font, Font const *styleFont=0) const;
286  bool inTable() const {
287  return m_inCell.get();
288  }
290  friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind);
291 
293  void print(std::ostream &o, MWAWFontConverterPtr converter) const;
294 
296  int getNumLines() const {
297  return m_info.get().m_numLines.get();
298  }
306  std::vector<float> m_deletedTabs;
321 };
322 }
323 #endif
324 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
the section structure of a Microsoft Word file
Definition: MSWStruct.hxx:109
Variable< double > m_interline
the interline if set
Definition: MSWStruct.hxx:304
Variable< Vec2f > m_dim
the zone dimension
Definition: MSWStruct.hxx:262
bool readV3(MWAWInputStreamPtr &input, long endPos)
try to read a data ( v3 code )
Definition: MSWStruct.cxx:233
Variable< Font > m_font
the font
Definition: MSWStruct.hxx:310
std::string m_extra
the errors
Definition: MSWStruct.hxx:151
void updateFontToFinalState(Font const *styleFont=0)
update the font to obtain the final font
Definition: MSWStruct.cxx:98
friend std::ostream & operator<<(std::ostream &o, Paragraph const &ind)
operator&lt;&lt;
Definition: MSWStruct.cxx:1089
std::vector< Variable< Cell > > m_cells
the table cells
Definition: MSWStruct.hxx:182
Variable< bool > m_inCell
a cell/textbox
Definition: MSWStruct.hxx:316
void insert(Variable const &orig)
update the current value if orig is set
Definition: libmwaw_internal.hxx:388
void print(std::ostream &o, MWAWFontConverterPtr converter) const
operator&lt;&lt;
Definition: MSWStruct.cxx:1195
friend std::ostream & operator<<(std::ostream &o, Table const &table)
operator&lt;&lt;
Definition: MSWStruct.cxx:647
void insert(Font const &font, Font const *styleFont=0)
insert new font data ( beginning by updating font flags )
Definition: MSWStruct.cxx:82
Variable< std::vector< float > > m_columnsWidthMod
the columns width modifier
Definition: MSWStruct.hxx:180
the paragraph structure of a Microsoft Word file
Definition: MSWStruct.hxx:270
MWAWBorder getBorder(int val, std::string &extra)
generic function use to fill a border using the read data
Definition: MSWStruct.cxx:1205
Variable< Font > m_modFont
font (modifier)
Definition: MSWStruct.hxx:310
bool isSet() const
return true if the variable is set
Definition: libmwaw_internal.hxx:417
Variable< float > m_indent
the indent
Definition: MSWStruct.hxx:176
Variable< MWAWBorder > m_bordersStyle
the border style ( old v3)
Definition: MSWStruct.hxx:314
std::string m_extra
extra data
Definition: MSWStruct.hxx:215
Variable< int > m_value
a unknown value
Definition: MSWStruct.hxx:97
the table in a Microsoft Word file
Definition: MSWStruct.hxx:155
the cells definitions in a Microsoft Word Table
Definition: MSWStruct.hxx:187
Variable< MWAWParagraph::Justification > m_justify
the justification
Definition: MSWStruct.hxx:174
the number of flags needed to store all datas
Definition: MSWStruct.hxx:58
Variable< int > m_col
the num of columns
Definition: MSWStruct.hxx:143
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition: MSWStruct.cxx:167
Variable< bool > m_colBreak
only a column break
Definition: MSWStruct.hxx:147
Variable< float > m_height
the row height in inches
Definition: MSWStruct.hxx:172
friend std::ostream & operator<<(std::ostream &o, Cell const &cell)
operator&lt;&lt;
Definition: MSWStruct.cxx:629
a border
Definition: libmwaw_internal.hxx:237
Paragraph(int version)
Constructor.
Definition: MSWStruct.hxx:272
Cell()
constructor
Definition: MSWStruct.hxx:189
bool inTable() const
returns true if we are in table
Definition: MSWStruct.hxx:286
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition: MSWStruct.cxx:435
Variable< long > m_picturePos
a picture file position (if this corresponds to a picture)
Definition: MSWStruct.hxx:101
MWAWSection getSection(double pageWidth) const
returns a section
Definition: MSWStruct.cxx:150
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:157
void insert(ParagraphInfo const &pInfo)
insert the new values
Definition: MSWStruct.cxx:722
std::string m_extra
extra data
Definition: MSWStruct.hxx:105
friend std::ostream & operator<<(std::ostream &o, Font const &font)
operator&lt;&lt;
Definition: MSWStruct.cxx:44
Definition: libmwaw_internal.hxx:239
Variable< bool > m_tableDef
a table flag
Definition: MSWStruct.hxx:318
Variable< std::vector< float > > m_columns
the table columns
Definition: MSWStruct.hxx:178
a class which stores section properties
Definition: MWAWSection.hxx:45
std::vector< Variable< MWAWBorder > > m_borders
the borders TLBR
Definition: MSWStruct.hxx:211
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:348
void insert(Cell const &cell)
update the cell data by merging
Definition: MSWStruct.hxx:192
the paragraph information of a Microsoft Word file (PHE)
Definition: MSWStruct.hxx:220
Variable< ParagraphInfo > m_info
the dimension
Definition: MSWStruct.hxx:308
T const & get() const
return the current value
Definition: libmwaw_internal.hxx:413
bool isLineSet() const
returns true if num lines is set
Definition: MSWStruct.hxx:225
Variable< Section > m_section
the section
Definition: MSWStruct.hxx:312
ParagraphInfo()
constructor
Definition: MSWStruct.hxx:222
std::string m_error
the errors
Definition: MSWStruct.hxx:266
Variable< float > m_backColor
the background gray color
Definition: MSWStruct.hxx:213
shared_ptr< MWAWFontConverter > MWAWFontConverterPtr
a smart pointer of MWAWFontConverter
Definition: libmwaw_internal.hxx:344
void insert(Table const &table)
insert the new values
Definition: MSWStruct.cxx:597
Variable< float > m_colSep
the spacing between column
Definition: MSWStruct.hxx:145
friend std::ostream & operator<<(std::ostream &o, Section const &section)
operator&lt;&lt;
Definition: MSWStruct.cxx:406
int m_version
the file version
Definition: MSWStruct.hxx:300
class to store the paragraph properties
Definition: MWAWParagraph.hxx:82
bool getFont(Font &font, Font const *styleFont=0) const
returns the font which correspond to the paragraph if possible
Definition: MSWStruct.cxx:1113
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition: MSWStruct.cxx:731
Variable< MWAWFont > m_font
the font
Definition: MSWStruct.hxx:93
the font structure of a Microsoft Word file
Definition: MSWStruct.hxx:57
Font()
the constructor
Definition: MSWStruct.hxx:61
std::vector< float > m_deletedTabs
the delete tabulation
Definition: MSWStruct.hxx:306
bool hasBorders() const
returns true if the cell has borders
Definition: MSWStruct.hxx:202
Section()
constructor
Definition: MSWStruct.hxx:111
Variable< int > m_flags[NumFlags]
a list of flags
Definition: MSWStruct.hxx:99
void insert(Paragraph const &para, bool insertModif=true)
insert the new values
Definition: MSWStruct.cxx:1154
Variable< Table > m_table
the table
Definition: MSWStruct.hxx:320
void updateParagraphToFinalState(Paragraph const *style=0)
update the paragraph to obtain the final paragraph
Definition: MSWStruct.cxx:1127
Variable< int > m_unknown
some unknown flag
Definition: MSWStruct.hxx:103
int cmp(Font const &oth) const
a comparison function
Definition: MSWStruct.hxx:75
bool isEmpty() const
returns true if no data are been set
Definition: MSWStruct.hxx:229
friend std::ostream & operator<<(std::ostream &o, ParagraphInfo const &pInfo)
operator&lt;&lt;
Definition: MSWStruct.hxx:238
Variable< Cell > & getCell(int id)
returns the ith Cell
Definition: MSWStruct.cxx:424
bool read(MWAWInputStreamPtr &input, long endPos, int vers)
try to read a data
Definition: MSWStruct.cxx:707
Variable< int > m_styleId
the style id (if known)
Definition: MSWStruct.hxx:302
Variable< int > m_paragraphId
the paragraph id
Definition: MSWStruct.hxx:141
Variable< int > m_numLines
the number of lines
Definition: MSWStruct.hxx:264
void insert(Section const &sec)
insert the new values
Definition: MSWStruct.hxx:118
Variable< int > m_type
the type
Definition: MSWStruct.hxx:260
int getNumLines() const
returns the number of line stored in m_info or -1
Definition: MSWStruct.hxx:296
Variable< int > m_id
the identificator
Definition: MSWStruct.hxx:137
Variable< float > m_size
a second size
Definition: MSWStruct.hxx:95
std::string m_extra
the errors
Definition: MSWStruct.hxx:184
Variable< int > m_type
the type
Definition: MSWStruct.hxx:139
Variable< int > m_flag
some flag ( in the main position)
Definition: MSWStruct.hxx:149
Table()
constructor
Definition: MSWStruct.hxx:158

Generated on Tue Mar 10 2015 17:32:08 for libmwaw by doxygen 1.8.5