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 typedef shared_ptr<MWAWInputStream> MWAWInputStreamPtr;
53 typedef shared_ptr<MWAWFontConverter> MWAWFontConverterPtr;
54 class MWAWSection;
55 
57 namespace MSWStruct
58 {
60 MWAWBorder getBorder(int val, std::string &extra);
61 
63 struct Font {
64  enum { NumFlags =9 };
65 
67  Font(): m_font(MWAWFont(-1,0)), m_size(0), m_value(0), m_picturePos(0), m_unknown(0), m_extra("") {
68  for (int i = 0; i < NumFlags; i++) m_flags[i]=Variable<int>(0);
69  }
70 
72  void insert(Font const &font, Font const *styleFont=0);
73 
75  void updateFontToFinalState(Font const *styleFont=0);
76 
78  friend std::ostream &operator<<(std::ostream &o, Font const &font);
79 
81  int cmp(Font const &oth) const {
82  int diff = m_font.get().cmp(oth.m_font.get());
83  if (diff) return diff;
84  if (m_size.get() < oth.m_size.get()) return -1;
85  if (m_size.get() > oth.m_size.get()) return 1;
86  diff = m_value.get()-oth.m_value.get();
87  if (diff) return diff;
88  for (int i = 0; i < NumFlags; i++) {
89  diff = m_flags[i].get()-oth.m_flags[i].get();
90  if (diff) return diff;
91  }
92  if (m_picturePos.get()<oth.m_picturePos.get()) return -1;
93  if (m_picturePos.get()>oth.m_picturePos.get()) return 1;
94  diff = m_unknown.get()-oth.m_unknown.get();
95  if (diff) return diff;
96  return 0;
97  }
111  std::string m_extra;
112 };
113 
115 struct Section {
117  Section() : m_id(-1), m_type(0), m_paragraphId(-9999), m_col(1),
118  m_colSep(0.5), m_colBreak(false), m_flag(0), m_extra("") {
119  }
121  MWAWSection getSection(double pageWidth) const;
122 
124  void insert(Section const &sec) {
125  m_id.insert(sec.m_id);
126  m_type.insert(sec.m_type);
128  m_col.insert(sec.m_col);
129  m_colSep.insert(sec.m_colSep);
131  m_flag.insert(sec.m_flag);
132  m_extra+=sec.m_extra;
133  }
135  bool read(MWAWInputStreamPtr &input, long endPos);
137  bool readV3(MWAWInputStreamPtr &input, long endPos);
138 
140  friend std::ostream &operator<<(std::ostream &o, Section const &section);
141 
157  std::string m_extra;
158 };
159 
161 struct Table {
162  struct Cell;
164  Table() : m_height(0), m_justify(MWAWParagraph::JustificationLeft), m_indent(0),
165  m_columns(), m_cells(), m_extra("") {
166  }
168  void insert(Table const &table) {
169  m_height.insert(table.m_height);
170  m_justify.insert(table.m_justify);
171  m_indent.insert(table.m_indent);
172  m_columns.insert(table.m_columns);
173  size_t tNumCells = table.m_cells.size();
174  if (tNumCells > m_cells.size())
175  m_cells.resize(tNumCells, Variable<Cell>());
176  for (size_t i=0; i < tNumCells; i++) {
177  if (!m_cells[i].isSet())
178  m_cells[i] = table.m_cells[i];
179  else if (table.m_cells[i].isSet())
180  m_cells[i]->insert(*table.m_cells[i]);
181  }
182  m_extra+=table.m_extra;
183  }
185  bool read(MWAWInputStreamPtr &input, long endPos);
187  Variable<Cell> &getCell(int id);
188 
190  friend std::ostream &operator<<(std::ostream &o, Table const &table);
191 
201  std::vector<Variable<Cell> > m_cells;
203  std::string m_extra;
204 
206  struct Cell {
208  Cell() : m_borders(), m_backColor(1.0f), m_extra("") {
209  }
211  void insert(Cell const &cell) {
212  size_t cNumBorders = cell.m_borders.size();
213  if (cNumBorders > m_borders.size())
214  m_borders.resize(cNumBorders);
215  for (size_t i=0; i < cNumBorders; i++)
216  if (cell.m_borders[i].isSet()) m_borders[i]=*cell.m_borders[i];
218  m_extra+=cell.m_extra;
219  }
221  bool hasBorders() const {
222  for (size_t i = 0; i < m_borders.size(); i++)
223  if (m_borders[i].isSet() && m_borders[i]->m_style != MWAWBorder::None)
224  return true;
225  return false;
226  }
228  friend std::ostream &operator<<(std::ostream &o, Cell const &cell);
230  std::vector<Variable<MWAWBorder> > m_borders;
234  std::string m_extra;
235  };
236 };
237 
242  }
244  bool isLineSet() const {
245  return *m_numLines!=0;
246  }
248  bool isEmpty() const {
249  if (*m_numLines || *m_type) return false;
250  if (!m_dim.isSet()) return true;
251  if ((*m_dim)[0] > 0 || (*m_dim)[1] > 0) return false;
252  return true;
253  }
255  bool read(MWAWInputStreamPtr &input, long endPos, int vers);
257  friend std::ostream &operator<<(std::ostream &o, ParagraphInfo const &pInfo) {
258  // find also pInfo.m_type&0x40 : ?
259  if (*pInfo.m_type&0xd0) o << "type?=" << ((*pInfo.m_type&0xd0)>>4) << ",";
260  if (*pInfo.m_type&0x0f) o << "#unkn=" << (*pInfo.m_type&0xf) << ",";
261  if (pInfo.m_dim.isSet()) {
262  if ((*pInfo.m_dim)[0] > 0)
263  o << "width=" << (*pInfo.m_dim)[0] << ",";
264  if ((*pInfo.m_dim)[1] > 0) {
265  o << "height=" << (*pInfo.m_dim)[1];
266  if (*pInfo.m_type&0x20)
267  o << "[total]";
268  o << ",";
269  }
270  }
271  if (pInfo.m_numLines.isSet() && *pInfo.m_numLines!=-1 && *pInfo.m_numLines!=1)
272  o << "nLines=" << *pInfo.m_numLines << ",";
273  if (pInfo.m_error.length()) o << pInfo.m_error << ",";
274  return o;
275  }
277  void insert(ParagraphInfo const &pInfo);
285  std::string m_error;
286 };
287 
289 struct Paragraph : public MWAWParagraph {
291  Paragraph(int version) : MWAWParagraph(), m_version(version), m_styleId(-1000),
293  m_bordersStyle(), m_inCell(false), m_tableDef(false), m_table() {
295  }
297  void insert(Paragraph const &para, bool insertModif=true);
299  bool read(MWAWInputStreamPtr &input, long endPos);
301  bool getFont(Font &font, Font const *styleFont=0) const;
303  bool inTable() const {
304  return m_inCell.get();
305  }
307  friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind);
308 
310  void print(std::ostream &o, MWAWFontConverterPtr converter) const;
311 
313  int getNumLines() const {
314  return m_info.get().m_numLines.get();
315  }
336 };
337 }
338 #endif
339 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
the section structure of a Microsoft Word file
Definition: MSWStruct.hxx:115
Variable< Vec2f > m_dim
the zone dimension
Definition: MSWStruct.hxx:281
bool readV3(MWAWInputStreamPtr &input, long endPos)
try to read a data ( v3 code )
Definition: MSWStruct.cxx:233
Variable< Font > m_font
the font (simplified)
Definition: MSWStruct.hxx:325
std::string m_extra
the errors
Definition: MSWStruct.hxx:157
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:1029
std::vector< Variable< Cell > > m_cells
the table cells
Definition: MSWStruct.hxx:201
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
Definition: ACText.hxx:44
Variable< bool > m_inCell
a cell/textbox
Definition: MSWStruct.hxx:331
void insert(Variable const &orig)
update the current value if orig is set
Definition: libmwaw_internal.hxx:339
void print(std::ostream &o, MWAWFontConverterPtr converter) const
operator&lt;&lt;
Definition: MSWStruct.cxx:1115
friend std::ostream & operator<<(std::ostream &o, Table const &table)
operator&lt;&lt;
Definition: MSWStruct.cxx:604
void insert(Font const &font, Font const *styleFont=0)
insert new font data ( beginning by updating font flags )
Definition: MSWStruct.cxx:82
the paragraph structure of a Microsoft Word file
Definition: MSWStruct.hxx:289
MWAWBorder getBorder(int val, std::string &extra)
generic function use to fill a border using the read data
Definition: MSWStruct.cxx:1127
Variable< Font > m_modFont
font (modifier)
Definition: MSWStruct.hxx:325
bool isSet() const
return true if the variable is set
Definition: libmwaw_internal.hxx:368
Variable< float > m_indent
the indent
Definition: MSWStruct.hxx:197
Variable< MWAWBorder > m_bordersStyle
the border style ( old v3)
Definition: MSWStruct.hxx:329
std::string m_extra
extra data
Definition: MSWStruct.hxx:234
Variable< int > m_value
a unknown value
Definition: MSWStruct.hxx:103
the table in a Microsoft Word file
Definition: MSWStruct.hxx:161
the cells definitions in a Microsoft Word Table
Definition: MSWStruct.hxx:206
Variable< MWAWParagraph::Justification > m_justify
the justification
Definition: MSWStruct.hxx:195
the number of flags needed to store all datas
Definition: MSWStruct.hxx:64
Variable< int > m_col
the num of columns
Definition: MSWStruct.hxx:149
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:153
Variable< float > m_height
the row height in inches
Definition: MSWStruct.hxx:193
Internal class used to read the file stream Internal class used to read the file stream, this class adds some usefull functions to the basic WPXInputStream:
Definition: MWAWInputStream.hxx:59
friend std::ostream & operator<<(std::ostream &o, Cell const &cell)
operator&lt;&lt;
Definition: MSWStruct.cxx:586
Class to store font.
Definition: MWAWFont.hxx:47
a border
Definition: libmwaw_internal.hxx:232
Variable< Font > m_font2
font ( not simplified )
Definition: MSWStruct.hxx:325
Paragraph(int version)
Constructor.
Definition: MSWStruct.hxx:291
Cell()
constructor
Definition: MSWStruct.hxx:208
bool inTable() const
returns true if we are in table
Definition: MSWStruct.hxx:303
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:107
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 (default)
Definition: MWAWParagraph.hxx:154
void insert(ParagraphInfo const &pInfo)
insert the new values
Definition: MSWStruct.cxx:667
std::string m_extra
extra data
Definition: MSWStruct.hxx:111
friend std::ostream & operator<<(std::ostream &o, Font const &font)
operator&lt;&lt;
Definition: MSWStruct.cxx:44
Definition: libmwaw_internal.hxx:234
shared_ptr< MWAWFontConverter > MWAWFontConverterPtr
Definition: MSWStruct.hxx:52
Variable< bool > m_tableDef
a table flag
Definition: MSWStruct.hxx:333
Variable< std::vector< float > > m_columns
the table columns
Definition: MSWStruct.hxx:199
a class which stores section properties
Definition: MWAWSection.hxx:45
std::vector< Variable< MWAWBorder > > m_borders
the borders TLBR
Definition: MSWStruct.hxx:230
void insert(Cell const &cell)
update the cell data by merging
Definition: MSWStruct.hxx:211
the paragraph information of a Microsoft Word file (PHE)
Definition: MSWStruct.hxx:239
Variable< ParagraphInfo > m_info
the dimension
Definition: MSWStruct.hxx:323
T const & get() const
return the current value
Definition: libmwaw_internal.hxx:364
a namespace used to convert Mac font characters in unicode
Definition: MWAWFontConverter.hxx:66
bool isLineSet() const
returns true if num lines is set
Definition: MSWStruct.hxx:244
Variable< Section > m_section
the section
Definition: MSWStruct.hxx:327
ParagraphInfo()
constructor
Definition: MSWStruct.hxx:241
std::string m_error
the errors
Definition: MSWStruct.hxx:285
Variable< float > m_backColor
the background gray color
Definition: MSWStruct.hxx:232
void insert(Table const &table)
insert the new values
Definition: MSWStruct.hxx:168
Variable< float > m_colSep
the spacing between column
Definition: MSWStruct.hxx:151
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:317
class to store the paragraph properties
Definition: MWAWParagraph.hxx:83
bool getFont(Font &font, Font const *styleFont=0) const
returns the font which correspond to the paragraph if possible
Definition: MSWStruct.cxx:1051
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition: MSWStruct.cxx:676
Variable< MWAWFont > m_font
the font
Definition: MSWStruct.hxx:99
the font structure of a Microsoft Word file
Definition: MSWStruct.hxx:63
Font()
the constructor
Definition: MSWStruct.hxx:67
bool hasBorders() const
returns true if the cell has borders
Definition: MSWStruct.hxx:221
Section()
constructor
Definition: MSWStruct.hxx:117
Variable< int > m_flags[NumFlags]
a list of flags
Definition: MSWStruct.hxx:105
void insert(Paragraph const &para, bool insertModif=true)
insert the new values
Definition: MSWStruct.cxx:1067
Variable< Table > m_table
the table
Definition: MSWStruct.hxx:335
Variable< int > m_unknown
some unknown flag
Definition: MSWStruct.hxx:109
int cmp(Font const &oth) const
operator==
Definition: MSWStruct.hxx:81
bool isEmpty() const
returns true if no data are been set
Definition: MSWStruct.hxx:248
friend std::ostream & operator<<(std::ostream &o, ParagraphInfo const &pInfo)
operator&lt;&lt;
Definition: MSWStruct.hxx:257
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:652
Variable< int > m_styleId
the style id (if known)
Definition: MSWStruct.hxx:319
Variable< int > m_paragraphId
the paragraph id
Definition: MSWStruct.hxx:147
Variable< int > m_numLines
the number of lines
Definition: MSWStruct.hxx:283
void insert(Section const &sec)
insert the new values
Definition: MSWStruct.hxx:124
Variable< int > m_type
the type
Definition: MSWStruct.hxx:279
int getNumLines() const
returns the number of line stored in m_info or -1
Definition: MSWStruct.hxx:313
Variable< std::vector< float > > m_deletedTabs
the delete tabulation
Definition: MSWStruct.hxx:321
Variable< int > m_id
the identificator
Definition: MSWStruct.hxx:143
Variable< float > m_size
a second size
Definition: MSWStruct.hxx:101
std::string m_extra
the errors
Definition: MSWStruct.hxx:203
Variable< int > m_type
the type
Definition: MSWStruct.hxx:145
Variable< int > m_flag
some flag ( in the main position)
Definition: MSWStruct.hxx:155
Table()
constructor
Definition: MSWStruct.hxx:164

Generated for libmwaw by doxygen 1.8.5