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 
56 namespace MSWStruct
57 {
59 MWAWBorder getBorder(int val, std::string &extra);
60 
62 struct Font {
63  enum { NumFlags =9 };
64 
66  Font(): m_font(MWAWFont(-1,0)), m_size(0), m_value(0), m_picturePos(0), m_unknown(0), m_extra("") {
67  for (int i = 0; i < NumFlags; i++) m_flags[i]=Variable<int>(0);
68  }
69 
71  void insert(Font const &font, Font const *styleFont=0);
72 
74  void updateFontToFinalState(Font const *styleFont=0);
75 
77  friend std::ostream &operator<<(std::ostream &o, Font const &font);
78 
80  int cmp(Font const &oth) const {
81  int diff = m_font.get().cmp(oth.m_font.get());
82  if (diff) return diff;
83  if (m_size.get() < oth.m_size.get()) return -1;
84  if (m_size.get() > oth.m_size.get()) return 1;
85  diff = m_value.get()-oth.m_value.get();
86  if (diff) return diff;
87  for (int i = 0; i < NumFlags; i++) {
88  diff = m_flags[i].get()-oth.m_flags[i].get();
89  if (diff) return diff;
90  }
91  if (m_picturePos.get()<oth.m_picturePos.get()) return -1;
92  if (m_picturePos.get()>oth.m_picturePos.get()) return 1;
93  diff = m_unknown.get()-oth.m_unknown.get();
94  if (diff) return diff;
95  return 0;
96  }
110  std::string m_extra;
111 };
112 
114 struct Section {
116  Section() : m_id(-1), m_type(0), m_paragraphId(-9999), m_col(1),
117  m_colSep(0.5), m_colBreak(false), m_flag(0), m_extra("") {
118  }
120  void insert(Section const &sec) {
121  m_id.insert(sec.m_id);
122  m_type.insert(sec.m_type);
124  m_col.insert(sec.m_col);
125  m_colSep.insert(sec.m_colSep);
127  m_flag.insert(sec.m_flag);
128  m_extra+=sec.m_extra;
129  }
131  bool read(MWAWInputStreamPtr &input, long endPos);
133  bool readV3(MWAWInputStreamPtr &input, long endPos);
134 
136  friend std::ostream &operator<<(std::ostream &o, Section const &section);
137 
153  std::string m_extra;
154 };
155 
157 struct Table {
158  struct Cell;
160  Table() : m_height(0), m_justify(MWAWParagraph::JustificationLeft), m_indent(0),
161  m_columns(), m_cells(), m_extra("") {
162  }
164  void insert(Table const &table) {
165  m_height.insert(table.m_height);
166  m_justify.insert(table.m_justify);
167  m_indent.insert(table.m_indent);
168  m_columns.insert(table.m_columns);
169  size_t tNumCells = table.m_cells.size();
170  if (tNumCells > m_cells.size())
171  m_cells.resize(tNumCells, Variable<Cell>());
172  for (size_t i=0; i < tNumCells; i++) {
173  if (!m_cells[i].isSet())
174  m_cells[i] = table.m_cells[i];
175  else if (table.m_cells[i].isSet())
176  m_cells[i]->insert(*table.m_cells[i]);
177  }
178  m_extra+=table.m_extra;
179  }
181  bool read(MWAWInputStreamPtr &input, long endPos);
183  Variable<Cell> &getCell(int id);
184 
186  friend std::ostream &operator<<(std::ostream &o, Table const &table);
187 
197  std::vector<Variable<Cell> > m_cells;
199  std::string m_extra;
200 
202  struct Cell {
204  Cell() : m_borders(), m_backColor(1.0f), m_extra("") {
205  }
207  void insert(Cell const &cell) {
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];
214  m_extra+=cell.m_extra;
215  }
217  bool hasBorders() const {
218  for (size_t i = 0; i < m_borders.size(); i++)
219  if (m_borders[i].isSet() && m_borders[i]->m_style != MWAWBorder::None)
220  return true;
221  return false;
222  }
224  friend std::ostream &operator<<(std::ostream &o, Cell const &cell);
226  std::vector<Variable<MWAWBorder> > m_borders;
230  std::string m_extra;
231  };
232 };
233 
238  }
240  bool isLineSet() const {
241  return m_numLines.get()!=0;
242  }
244  bool read(MWAWInputStreamPtr &input, long endPos, int vers);
246  friend std::ostream &operator<<(std::ostream &o, ParagraphInfo const &pInfo) {
247  // find also pInfo.m_type&0x40 : ?
248  if (*pInfo.m_type&0xd0) o << "type?=" << ((*pInfo.m_type&0xd0)>>4) << ",";
249  if (*pInfo.m_type&0x0f) o << "#unkn=" << (*pInfo.m_type&0xf) << ",";
250  if (pInfo.m_dim.isSet()) {
251  if ((*pInfo.m_dim)[0] > 0)
252  o << "width=" << (*pInfo.m_dim)[0] << ",";
253  if ((*pInfo.m_dim)[1] > 0) {
254  o << "height=" << (*pInfo.m_dim)[1];
255  if (*pInfo.m_type&0x20)
256  o << "[total]";
257  o << ",";
258  }
259  }
260  if (pInfo.m_numLines.isSet() && *pInfo.m_numLines!=-1 && *pInfo.m_numLines!=1)
261  o << "nLines=" << *pInfo.m_numLines << ",";
262  if (pInfo.m_error.length()) o << pInfo.m_error << ",";
263  return o;
264  }
266  void insert(ParagraphInfo const &pInfo);
274  std::string m_error;
275 };
276 
278 struct Paragraph : public MWAWParagraph {
280  Paragraph(int version) : MWAWParagraph(), m_version(version), m_styleId(-1000),
282  m_bordersStyle(), m_inCell(false), m_tableDef(false), m_table() {
284  }
286  void insert(Paragraph const &para, bool insertModif=true);
288  bool read(MWAWInputStreamPtr &input, long endPos);
290  bool getFont(Font &font, Font const *styleFont=0) const;
292  bool inTable() const {
293  return m_inCell.get();
294  }
296  friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind);
297 
299  void print(std::ostream &o, MWAWFontConverterPtr converter) const;
300 
302  int getNumLines() const {
303  return m_info.get().m_numLines.get();
304  }
325 };
326 }
327 #endif
328 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Sat May 4 2013 11:47:11 for libmwaw by doxygen 1.8.3.1