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()
62  : m_font(MWAWFont(-1,0))
63  , m_size(0)
64  , m_value(0)
65  , m_picturePos(0)
66  , m_unknown(0)
67  , m_extra("")
68  {
69  for (auto &fl : m_flags) fl=MWAWVariable<int>(0);
70  }
71 
73  void insert(Font const &font, Font const *styleFont=nullptr);
74 
76  void updateFontToFinalState(Font const *styleFont=nullptr);
77 
79  friend std::ostream &operator<<(std::ostream &o, Font const &font);
80 
82  int cmp(Font const &oth) const
83  {
84  int diff = m_font.get().cmp(oth.m_font.get());
85  if (diff) return diff;
86  if (m_size.get() < oth.m_size.get()) return -1;
87  if (m_size.get() > oth.m_size.get()) return 1;
88  diff = m_value.get()-oth.m_value.get();
89  if (diff) return diff;
90  for (int i = 0; i < NumFlags; i++) {
91  diff = m_flags[i].get()-oth.m_flags[i].get();
92  if (diff) return diff;
93  }
94  if (m_picturePos.get()<oth.m_picturePos.get()) return -1;
95  if (m_picturePos.get()>oth.m_picturePos.get()) return 1;
96  diff = m_unknown.get()-oth.m_unknown.get();
97  if (diff) return diff;
98  return 0;
99  }
113  std::string m_extra;
114 };
115 
117 struct Section {
120  : m_id(-1)
121  , m_type(0)
122  , m_paragraphId(-9999)
123  , m_col(1)
124  , m_colSep(0.5)
125  , m_colBreak(false)
126  , m_flag(0)
127  , m_extra("")
128  {
129  }
131  MWAWSection getSection(double pageWidth) const;
132 
134  void insert(Section const &sec)
135  {
136  m_id.insert(sec.m_id);
137  m_type.insert(sec.m_type);
138  m_paragraphId.insert(sec.m_paragraphId);
139  m_col.insert(sec.m_col);
140  m_colSep.insert(sec.m_colSep);
141  m_colBreak.insert(sec.m_colBreak);
142  m_flag.insert(sec.m_flag);
143  m_extra+=sec.m_extra;
144  }
146  bool read(MWAWInputStreamPtr &input, long endPos);
148  bool readV3(MWAWInputStreamPtr &input, long endPos);
149 
151  friend std::ostream &operator<<(std::ostream &o, Section const &section);
152 
168  std::string m_extra;
169 };
170 
172 struct Table {
173  struct Cell;
176  : m_height(0)
177  , m_justify(MWAWParagraph::JustificationLeft)
178  , m_indent(0)
179  , m_columns()
180  , m_columnsWidthMod()
181  , m_cells()
182  , m_badCell()
183  , m_extra("")
184  {
185  }
187  void insert(Table const &table);
189  bool read(MWAWInputStreamPtr &input, long endPos);
191  MWAWVariable<Cell> &getCell(int id);
192 
194  friend std::ostream &operator<<(std::ostream &o, Table const &table);
195 
197  struct Cell {
200  : m_borders()
201  , m_backColor(1.0f)
202  , m_extra("")
203  {
204  }
206  void insert(Cell const &cell)
207  {
208  size_t cNumBorders = cell.m_borders.size();
209  if (cNumBorders > m_borders.size())
210  m_borders.resize(cNumBorders);
211  for (size_t i=0; i < cNumBorders; i++)
212  if (cell.m_borders[i].isSet()) m_borders[i]=*cell.m_borders[i];
213  m_backColor.insert(cell.m_backColor);
214  m_extra+=cell.m_extra;
215  }
217  bool hasBorders() const
218  {
219  for (auto const &bd : m_borders)
220  if (bd.isSet() && bd->m_style != MWAWBorder::None)
221  return true;
222  return false;
223  }
225  friend std::ostream &operator<<(std::ostream &o, Cell const &cell);
227  std::vector<MWAWVariable<MWAWBorder> > m_borders;
231  std::string m_extra;
232  };
233 
245  std::vector<MWAWVariable<Cell> > m_cells;
249  std::string m_extra;
250 };
251 
256  : m_type(0)
257  , m_dim()
258  , m_numLines(-1)
259  , m_error("")
260  {
261  }
263  bool isLineSet() const
264  {
265  return *m_numLines!=0;
266  }
268  bool isEmpty() const
269  {
270  if (*m_numLines || *m_type) return false;
271  if (!m_dim.isSet()) return true;
272  if ((*m_dim)[0] > 0 || (*m_dim)[1] > 0) return false;
273  return true;
274  }
276  bool read(MWAWInputStreamPtr &input, long endPos, int vers);
278  friend std::ostream &operator<<(std::ostream &o, ParagraphInfo const &pInfo)
279  {
280  // find also pInfo.m_type&0x40 : ?
281  if (*pInfo.m_type&0xd0) o << "type?=" << ((*pInfo.m_type&0xd0)>>4) << ",";
282  if (*pInfo.m_type&0x0f) o << "#unkn=" << (*pInfo.m_type&0xf) << ",";
283  if (pInfo.m_dim.isSet()) {
284  if ((*pInfo.m_dim)[0] > 0)
285  o << "width=" << (*pInfo.m_dim)[0] << ",";
286  if ((*pInfo.m_dim)[1] > 0) {
287  o << "height=" << (*pInfo.m_dim)[1];
288  if (*pInfo.m_type&0x20)
289  o << "[total]";
290  o << ",";
291  }
292  }
293  if (pInfo.m_numLines.isSet() && *pInfo.m_numLines!=-1 && *pInfo.m_numLines!=1)
294  o << "nLines=" << *pInfo.m_numLines << ",";
295  if (pInfo.m_error.length()) o << pInfo.m_error << ",";
296  return o;
297  }
299  void insert(ParagraphInfo const &pInfo);
307  std::string m_error;
308 };
309 
311 struct Paragraph final : public MWAWParagraph {
313  explicit Paragraph(int version)
314  : MWAWParagraph()
315  , m_version(version)
316  , m_styleId(-1000)
317  , m_interline(0)
318  , m_deletedTabs()
319  , m_info()
320  , m_font()
321  , m_modFont()
322  , m_section()
323  , m_bordersStyle()
324  , m_inCell(false)
325  , m_tableDef(false)
326  , m_table()
327  {
328  m_tabsRelativeToLeftMargin=false;
329  }
331  ~Paragraph() final;
333  void insert(Paragraph const &para, bool insertModif=true);
335  bool read(MWAWInputStreamPtr &input, long endPos);
337  void updateParagraphToFinalState(Paragraph const *style=nullptr);
339  bool getFont(Font &font, Font const *styleFont=nullptr) const;
341  bool inTable() const
342  {
343  return m_inCell.get();
344  }
346  friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind);
347 
349  void print(std::ostream &o, MWAWFontConverterPtr converter) const;
350 
352  int getNumLines() const
353  {
354  return m_info.get().m_numLines.get();
355  }
363  std::vector<float> m_deletedTabs;
378 };
379 }
380 #endif
381 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWVariable< int > m_flags[NumFlags]
a list of flags
Definition: MsWrdStruct.hxx:107
the font structure of a Microsoft Word file
Definition: MsWrdStruct.hxx:57
std::string m_extra
extra data
Definition: MsWrdStruct.hxx:231
the number of flags needed to store all datas
Definition: MsWrdStruct.hxx:58
MWAWVariable< float > m_size
a second size
Definition: MsWrdStruct.hxx:103
MWAWVariable< int > m_type
the type
Definition: MsWrdStruct.hxx:301
MWAWVariable< float > m_backColor
the background gray color
Definition: MsWrdStruct.hxx:229
Cell()
constructor
Definition: MsWrdStruct.hxx:199
T const & get() const
return the current value
Definition: libmwaw_internal.hxx:626
bool isLineSet() const
returns true if num lines is set
Definition: MsWrdStruct.hxx:263
ParagraphInfo()
constructor
Definition: MsWrdStruct.hxx:255
MWAWVariable< Table > m_table
the table
Definition: MsWrdStruct.hxx:377
int m_version
the file version
Definition: MsWrdStruct.hxx:357
std::vector< MWAWVariable< MWAWBorder > > m_borders
the borders TLBR
Definition: MsWrdStruct.hxx:227
void insert(Cell const &cell)
update the cell data by merging
Definition: MsWrdStruct.hxx:206
void insert(Font const &font, Font const *styleFont=nullptr)
insert new font data ( beginning by updating font flags )
Definition: MsWrdStruct.cxx:82
MWAWVariable< bool > m_inCell
a cell/textbox
Definition: MsWrdStruct.hxx:373
MWAWVariable< MWAWParagraph::Justification > m_justify
the justification
Definition: MsWrdStruct.hxx:237
Section()
constructor
Definition: MsWrdStruct.hxx:119
void updateFontToFinalState(Font const *styleFont=nullptr)
update the font to obtain the final font
Definition: MsWrdStruct.cxx:98
namespace to store the main structure which appears in a Microsoft Word 3.0-5.0 file ...
Definition: MsWrdStruct.cxx:41
the paragraph structure of a Microsoft Word file
Definition: MsWrdStruct.hxx:311
MWAWVariable< int > m_paragraphId
the paragraph id
Definition: MsWrdStruct.hxx:158
Table()
constructor
Definition: MsWrdStruct.hxx:175
bool isSet() const
return true if the variable is set
Definition: libmwaw_internal.hxx:631
Paragraph(int version)
Constructor.
Definition: MsWrdStruct.hxx:313
MWAWVariable< float > m_indent
the indent
Definition: MsWrdStruct.hxx:239
MWAWVariable< MWAWFont > m_font
the font
Definition: MsWrdStruct.hxx:101
Section getSection(const State &state, const long id)
Definition: HanMacWrdKText.cxx:268
MWAWVariable< double > m_interline
the interline if set
Definition: MsWrdStruct.hxx:361
std::vector< float > m_deletedTabs
the delete tabulation
Definition: MsWrdStruct.hxx:363
void insert(Section const &sec)
insert the new values
Definition: MsWrdStruct.hxx:134
Class to store font.
Definition: MWAWFont.hxx:43
a border
Definition: libmwaw_internal.hxx:333
std::string m_error
the errors
Definition: MsWrdStruct.hxx:307
std::string m_extra
the errors
Definition: MsWrdStruct.hxx:249
int getNumLines() const
returns the number of line stored in m_info or -1
Definition: MsWrdStruct.hxx:352
std::string m_extra
the errors
Definition: MsWrdStruct.hxx:168
std::string m_extra
extra data
Definition: MsWrdStruct.hxx:113
MWAWVariable< int > m_value
a unknown value
Definition: MsWrdStruct.hxx:105
MWAWVariable< float > m_colSep
the spacing between column
Definition: MsWrdStruct.hxx:162
MWAWVariable< bool > m_tableDef
a table flag
Definition: MsWrdStruct.hxx:375
MWAWVariable< std::vector< float > > m_columns
the table columns
Definition: MsWrdStruct.hxx:241
the cells definitions in a Microsoft Word Table
Definition: MsWrdStruct.hxx:197
MWAWVariable< int > m_id
the identificator
Definition: MsWrdStruct.hxx:154
int cmp(Font const &oth) const
a comparison function
Definition: MsWrdStruct.hxx:82
Definition: libmwaw_internal.hxx:335
MWAWVariable< bool > m_colBreak
only a column break
Definition: MsWrdStruct.hxx:164
the paragraph information of a Microsoft Word file (PHE)
Definition: MsWrdStruct.hxx:253
MWAWVariable< ParagraphInfo > m_info
the dimension
Definition: MsWrdStruct.hxx:365
bool inTable() const
returns true if we are in table
Definition: MsWrdStruct.hxx:341
bool hasBorders() const
returns true if the cell has borders
Definition: MsWrdStruct.hxx:217
a class which stores section properties
Definition: MWAWSection.hxx:45
MWAWVariable< int > m_type
the type
Definition: MsWrdStruct.hxx:156
MWAWBorder getBorder(int val, std::string &extra)
generic function use to fill a border using the read data
Definition: MsWrdStruct.cxx:1206
MWAWVariable< MWAWBorder > m_bordersStyle
the border style ( old v3)
Definition: MsWrdStruct.hxx:371
MWAWVariable< std::vector< float > > m_columnsWidthMod
the columns width modifier
Definition: MsWrdStruct.hxx:243
MWAWVariable< int > m_unknown
some unknown flag
Definition: MsWrdStruct.hxx:111
friend std::ostream & operator<<(std::ostream &o, Font const &font)
operator<<
Definition: MsWrdStruct.cxx:44
the section structure of a Microsoft Word file
Definition: MsWrdStruct.hxx:117
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:547
MWAWVariable< Cell > m_badCell
empty cell used by getCell to return unknown cell
Definition: MsWrdStruct.hxx:247
bool isEmpty() const
returns true if no data are been set
Definition: MsWrdStruct.hxx:268
class to store the paragraph properties
Definition: MWAWParagraph.hxx:84
std::shared_ptr< MWAWFontConverter > MWAWFontConverterPtr
a smart pointer of MWAWFontConverter
Definition: libmwaw_internal.hxx:539
MWAWVariable< int > m_numLines
the number of lines
Definition: MsWrdStruct.hxx:305
MWAWVariable< int > m_col
the num of columns
Definition: MsWrdStruct.hxx:160
MWAWVariable< long > m_picturePos
a picture file position (if this corresponds to a picture)
Definition: MsWrdStruct.hxx:109
MWAWVariable< Section > m_section
the section
Definition: MsWrdStruct.hxx:369
Font()
the constructor
Definition: MsWrdStruct.hxx:61
the table in a Microsoft Word file
Definition: MsWrdStruct.hxx:172
int cmp(MWAWFont const &oth) const
a comparison function
Definition: MWAWFont.hxx:524
friend std::ostream & operator<<(std::ostream &o, ParagraphInfo const &pInfo)
operator<<
Definition: MsWrdStruct.hxx:278
MWAWVariable< int > m_styleId
the style id (if known)
Definition: MsWrdStruct.hxx:359
MWAWVariable< int > m_flag
some flag ( in the main position)
Definition: MsWrdStruct.hxx:166
MWAWVariable< MWAWVec2f > m_dim
the zone dimension
Definition: MsWrdStruct.hxx:303
MWAWVariable< float > m_height
the row height in inches
Definition: MsWrdStruct.hxx:235
std::vector< MWAWVariable< Cell > > m_cells
the table cells
Definition: MsWrdStruct.hxx:245

Generated on Sun Nov 19 2017 23:54:16 for libmwaw by doxygen 1.8.13