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),
159  m_columns(), m_cells(), m_extra("") {
160  }
162  void insert(Table const &table) {
163  m_height.insert(table.m_height);
164  m_justify.insert(table.m_justify);
165  m_indent.insert(table.m_indent);
166  m_columns.insert(table.m_columns);
167  size_t tNumCells = table.m_cells.size();
168  if (tNumCells > m_cells.size())
169  m_cells.resize(tNumCells, Variable<Cell>());
170  for (size_t i=0; i < tNumCells; i++) {
171  if (!m_cells[i].isSet())
172  m_cells[i] = table.m_cells[i];
173  else if (table.m_cells[i].isSet())
174  m_cells[i]->insert(*table.m_cells[i]);
175  }
176  m_extra+=table.m_extra;
177  }
179  bool read(MWAWInputStreamPtr &input, long endPos);
181  Variable<Cell> &getCell(int id);
182 
184  friend std::ostream &operator<<(std::ostream &o, Table const &table);
185 
195  std::vector<Variable<Cell> > m_cells;
197  std::string m_extra;
198 
200  struct Cell {
202  Cell() : m_borders(), m_backColor(1.0f), m_extra("") {
203  }
205  void insert(Cell const &cell) {
206  size_t cNumBorders = cell.m_borders.size();
207  if (cNumBorders > m_borders.size())
208  m_borders.resize(cNumBorders);
209  for (size_t i=0; i < cNumBorders; i++)
210  if (cell.m_borders[i].isSet()) m_borders[i]=*cell.m_borders[i];
212  m_extra+=cell.m_extra;
213  }
215  bool hasBorders() const {
216  for (size_t i = 0; i < m_borders.size(); i++)
217  if (m_borders[i].isSet() && m_borders[i]->m_style != MWAWBorder::None)
218  return true;
219  return false;
220  }
222  friend std::ostream &operator<<(std::ostream &o, Cell const &cell);
224  std::vector<Variable<MWAWBorder> > m_borders;
228  std::string m_extra;
229  };
230 };
231 
236  }
238  bool isLineSet() const {
239  return *m_numLines!=0;
240  }
242  bool isEmpty() const {
243  if (*m_numLines || *m_type) return false;
244  if (!m_dim.isSet()) return true;
245  if ((*m_dim)[0] > 0 || (*m_dim)[1] > 0) return false;
246  return true;
247  }
249  bool read(MWAWInputStreamPtr &input, long endPos, int vers);
251  friend std::ostream &operator<<(std::ostream &o, ParagraphInfo const &pInfo) {
252  // find also pInfo.m_type&0x40 : ?
253  if (*pInfo.m_type&0xd0) o << "type?=" << ((*pInfo.m_type&0xd0)>>4) << ",";
254  if (*pInfo.m_type&0x0f) o << "#unkn=" << (*pInfo.m_type&0xf) << ",";
255  if (pInfo.m_dim.isSet()) {
256  if ((*pInfo.m_dim)[0] > 0)
257  o << "width=" << (*pInfo.m_dim)[0] << ",";
258  if ((*pInfo.m_dim)[1] > 0) {
259  o << "height=" << (*pInfo.m_dim)[1];
260  if (*pInfo.m_type&0x20)
261  o << "[total]";
262  o << ",";
263  }
264  }
265  if (pInfo.m_numLines.isSet() && *pInfo.m_numLines!=-1 && *pInfo.m_numLines!=1)
266  o << "nLines=" << *pInfo.m_numLines << ",";
267  if (pInfo.m_error.length()) o << pInfo.m_error << ",";
268  return o;
269  }
271  void insert(ParagraphInfo const &pInfo);
279  std::string m_error;
280 };
281 
283 struct Paragraph : public MWAWParagraph {
285  Paragraph(int version) : MWAWParagraph(), m_version(version), m_styleId(-1000),
287  m_bordersStyle(), m_inCell(false), m_tableDef(false), m_table() {
289  }
291  void insert(Paragraph const &para, bool insertModif=true);
293  bool read(MWAWInputStreamPtr &input, long endPos);
295  bool getFont(Font &font, Font const *styleFont=0) const;
297  bool inTable() const {
298  return m_inCell.get();
299  }
301  friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind);
302 
304  void print(std::ostream &o, MWAWFontConverterPtr converter) const;
305 
307  int getNumLines() const {
308  return m_info.get().m_numLines.get();
309  }
330 };
331 }
332 #endif
333 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Tue Jul 2 2013 05:26:51 for libmwaw by doxygen 1.8.4