MRWParser.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  * Parser to convert Mariner Write document
36  */
37 #ifndef MRW_PARSER
38 # define MRW_PARSER
39 
40 #include <iostream>
41 #include <string>
42 #include <vector>
43 
44 #include <libwpd/libwpd.h>
45 
46 class WPXBinaryData;
47 
48 #include "MWAWDebug.hxx"
49 #include "MWAWEntry.hxx"
50 #include "MWAWInputStream.hxx"
51 #include "MWAWPageSpan.hxx"
52 
53 #include "MWAWParser.hxx"
54 
55 class MWAWEntry;
56 class MWAWFont;
57 class MWAWParagraph;
58 
59 namespace MRWParserInternal
60 {
61 struct State;
62 class SubDocument;
63 }
64 
65 class MRWGraph;
66 class MRWText;
67 
69 struct MRWEntry : public MWAWEntry {
71  MRWEntry() : MWAWEntry(), m_fileType(0), m_N(0), m_value(0) {
72  }
74  std::string name() const;
76  friend std::ostream &operator<< (std::ostream &o, MRWEntry const &ent) {
77  if (ent.m_N || ent.m_value || ent.m_extra.length()) {
78  o << "[";
79  if (ent.m_N) o << "N=" << ent.m_N << ",";
80  if (ent.m_value) o << "unkn=" << ent.m_value << ",";
81  if (ent.m_extra.length()) o << ent.m_extra;
82  o << "],";
83  }
84  return o;
85  }
89  int m_N;
91  int m_value;
92 };
93 
95 struct MRWStruct {
97  MRWStruct() : m_filePos(-1), m_pos(), m_type(-1), m_data() {
98  }
100  friend std::ostream &operator<<(std::ostream &o, MRWStruct const &dt);
102  int numValues() const {
103  return int(m_data.size());
104  }
106  bool isBasic() const {
107  return (m_type==1 || m_type==2) && m_data.size()<=1;
108  }
110  long value(int i) const;
112  long m_filePos;
116  int m_type;
118  std::vector<long> m_data;
119 };
120 
126 class MRWParser : public MWAWParser
127 {
128  friend class MRWGraph;
129  friend class MRWText;
131 
132 public:
134  MRWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
136  virtual ~MRWParser();
137 
139  bool checkHeader(MWAWHeader *header, bool strict=false);
140 
141  // the main parse function
142  void parse(WPXDocumentInterface *documentInterface);
143 
144 protected:
146  void init();
147 
149  void createDocument(WPXDocumentInterface *documentInterface);
150 
152  bool createZones();
154  bool readZone(int &actZone, bool onlyTest=false);
155 
157  float pageHeight() const;
159  float pageWidth() const;
161  Vec2f getPageLeftTop() const;
163  void getColumnInfo(int zoneId, int &numColumns, std::vector<int> &width) const;
164 
166  void newPage(int number);
167 
168  // interface with the text parser
169 
171  int getZoneId(uint32_t fileId, bool &endNote);
173  void sendText(int zoneId);
174 
175  // interface with the graph parser
177  float getPatternPercent(int id) const;
179  void sendToken(int zoneId, long tokenId, MWAWFont const &actFont);
180 
181  //
182  // low level
183  //
184 
186  bool isFilePos(long pos);
188  bool readEntryHeader(MRWEntry &entry);
190  bool decodeZone(std::vector<MRWStruct> &dataList, long numData=999999);
191 
193  bool readSeparator(MRWEntry const &entry);
195  bool readZoneDim(MRWEntry const &entry, int zoneId);
197  bool readZoneHeader(MRWEntry const &entry, int zoneId, bool onlyTest);
199  bool readZoneb(MRWEntry const &entry, int zoneId);
201  bool readZonec(MRWEntry const &entry, int zoneId);
203  bool readZone13(MRWEntry const &entry, int zoneId);
205  bool readDocInfo(MRWEntry const &entry, int zoneId);
207  bool readPrintInfo(MRWEntry const &entry);
209  bool readCPRT(MRWEntry const &entry);
210 
212  bool readNumbersString(int num, std::vector<long> &res);
213 
214 protected:
215  //
216  // data
217  //
219  shared_ptr<MRWParserInternal::State> m_state;
220 
223 
226 
228  shared_ptr<MRWGraph> m_graphParser;
229 
231  shared_ptr<MRWText> m_textParser;
232 };
233 #endif
234 // 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