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 
52 #include "MWAWParser.hxx"
53 
54 namespace MRWParserInternal
55 {
56 struct State;
57 class SubDocument;
58 }
59 
60 class MRWGraph;
61 class MRWText;
62 
64 struct MRWEntry : public MWAWEntry {
66  MRWEntry() : MWAWEntry(), m_fileType(0), m_N(0), m_value(0) {
67  }
69  std::string name() const;
71  friend std::ostream &operator<< (std::ostream &o, MRWEntry const &ent) {
72  if (ent.m_N || ent.m_value || ent.m_extra.length()) {
73  o << "[";
74  if (ent.m_N) o << "N=" << ent.m_N << ",";
75  if (ent.m_value) o << "unkn=" << ent.m_value << ",";
76  if (ent.m_extra.length()) o << ent.m_extra;
77  o << "],";
78  }
79  return o;
80  }
84  int m_N;
86  int m_value;
87 };
88 
90 struct MRWStruct {
92  MRWStruct() : m_filePos(-1), m_pos(), m_type(-1), m_data() {
93  }
95  friend std::ostream &operator<<(std::ostream &o, MRWStruct const &dt);
97  int numValues() const {
98  return int(m_data.size());
99  }
101  bool isBasic() const {
102  return (m_type==1 || m_type==2) && m_data.size()<=1;
103  }
105  long value(int i) const;
107  long m_filePos;
111  int m_type;
113  std::vector<long> m_data;
114 };
115 
121 class MRWParser : public MWAWParser
122 {
123  friend class MRWGraph;
124  friend class MRWText;
126 
127 public:
129  MRWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
131  virtual ~MRWParser();
132 
134  bool checkHeader(MWAWHeader *header, bool strict=false);
135 
136  // the main parse function
137  void parse(WPXDocumentInterface *documentInterface);
138 
139 protected:
141  void init();
142 
144  void createDocument(WPXDocumentInterface *documentInterface);
145 
147  bool createZones();
149  bool readZone(int &actZone, bool onlyTest=false);
150 
152  Vec2f getPageLeftTop() const;
154  MWAWSection getSection(int zoneId) const;
155 
157  void newPage(int number);
158 
159  // interface with the text parser
160 
162  int getZoneId(uint32_t fileId, bool &endNote);
164  void sendText(int zoneId);
165 
166  // interface with the graph parser
168  float getPatternPercent(int id) const;
170  void sendToken(int zoneId, long tokenId);
171 
172  //
173  // low level
174  //
175 
177  bool readEntryHeader(MRWEntry &entry);
179  bool decodeZone(std::vector<MRWStruct> &dataList, long numData=999999);
180 
182  bool readSeparator(MRWEntry const &entry);
184  bool readZoneDim(MRWEntry const &entry, int zoneId);
186  bool readZoneHeader(MRWEntry const &entry, int zoneId, bool onlyTest);
188  bool readZoneb(MRWEntry const &entry, int zoneId);
190  bool readZonec(MRWEntry const &entry, int zoneId);
192  bool readZone13(MRWEntry const &entry, int zoneId);
194  bool readDocInfo(MRWEntry const &entry, int zoneId);
196  bool readPrintInfo(MRWEntry const &entry);
198  bool readCPRT(MRWEntry const &entry);
199 
201  bool readNumbersString(int num, std::vector<long> &res);
202 
203 protected:
204  //
205  // data
206  //
208  shared_ptr<MRWParserInternal::State> m_state;
209 
212 
214  shared_ptr<MRWGraph> m_graphParser;
215 
217  shared_ptr<MRWText> m_textParser;
218 };
219 #endif
220 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Wed May 7 2014 00:30:18 for libmwaw by doxygen 1.8.3.1