HMWKParser.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 HanMac Word-K document
36  */
37 #ifndef HMWK_PARSER
38 # define HMWK_PARSER
39 
40 #include <iostream>
41 #include <string>
42 #include <vector>
43 
44 #include <libwpd/libwpd.h>
45 
46 #include "MWAWDebug.hxx"
47 #include "MWAWInputStream.hxx"
48 #include "MWAWPageSpan.hxx"
49 
50 #include "MWAWParser.hxx"
51 
52 class MWAWEntry;
53 class MWAWFont;
54 class MWAWParagraph;
55 
56 namespace HMWKParserInternal
57 {
58 struct State;
59 class SubDocument;
60 }
61 
63 struct HMWKZone {
67  HMWKZone(shared_ptr<libmwaw::DebugFile> asciiFile);
69  ~HMWKZone();
70 
72  long begin() const {
73  return m_asciiFilePtr ? 0 : m_filePos;
74  }
76  long end() const {
77  return m_asciiFilePtr ? (long) m_data.size() : m_endFilePos;
78  }
80  long length() const {
81  if (m_asciiFilePtr) return (long) m_data.size();
82  return m_endFilePos-m_filePos;
83  }
85  bool valid() const {
86  return length() > 0;
87  }
88 
89  // function to define the zone in the original file
90 
92  long fileBeginPos() const {
93  return m_filePos;
94  }
96  long fileEndPos() const {
97  return m_endFilePos;
98  }
100  void setFileBeginPos(long begPos) {
101  m_filePos = m_endFilePos = begPos;
102  }
104  void setFileLength(long len) {
105  m_endFilePos = m_filePos+len;
106  }
108  void setFilePositions(long begPos, long endPos) {
109  m_filePos = begPos;
110  m_endFilePos = endPos;
111  }
113  WPXBinaryData &getBinaryData() {
114  return m_data;
115  }
117  std::string name() const {
118  return name(m_type);
119  }
121  static std::string name(int type);
122 
124  friend std::ostream &operator<<(std::ostream &o, HMWKZone const &zone);
125 
128  return *m_asciiFile;
129  }
130 
132  int m_type;
133 
135  long m_id;
136 
138  long m_subId;
139 
142 
144  std::string m_extra;
145 
147  mutable bool m_parsed;
148 
149 protected:
151  long m_filePos;
152 
155 
157  WPXBinaryData m_data;
158 
161 
163  shared_ptr<libmwaw::DebugFile> m_asciiFilePtr;
164 
165 private:
166  HMWKZone(HMWKZone const &orig);
167  HMWKZone &operator=(HMWKZone const &orig);
168 };
169 
170 class HMWKGraph;
171 class HMWKText;
172 
178 class HMWKParser : public MWAWParser
179 {
180  friend class HMWKGraph;
181  friend class HMWKText;
183 
184 public:
186  HMWKParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
188  virtual ~HMWKParser();
189 
191  bool checkHeader(MWAWHeader *header, bool strict=false);
192 
193  // the main parse function
194  void parse(WPXDocumentInterface *documentInterface);
195 
196 protected:
198  void init();
199 
201  void createDocument(WPXDocumentInterface *documentInterface);
202 
204  bool createZones();
205 
207  float pageHeight() const;
209  float pageWidth() const;
211  Vec2f getPageLeftTop() const;
212 
214  void newPage(int number);
215 
216  // interface with the text parser
217 
219  bool sendText(long id, long subId=0);
220 
221  // interface with the graph parser
222 
224  bool sendZone(long zId);
226  bool getColor(int colId, int patternId, MWAWColor &color) const;
227 
228  //
229  // low level
230  //
231 
233  bool readZonesList();
235  bool readZone(shared_ptr<HMWKZone> zone);
237  shared_ptr<HMWKZone> decodeZone(shared_ptr<HMWKZone> zone);
239  bool readFramesUnkn(shared_ptr<HMWKZone> zone);
241  bool readPrintInfo(HMWKZone &zone);
243  bool readZone6(shared_ptr<HMWKZone> zone);
245  bool readZone8(shared_ptr<HMWKZone> zone);
247  bool readZonea(shared_ptr<HMWKZone> zone);
249  bool readZoneb(HMWKZone &zone);
251  bool readZonec(shared_ptr<HMWKZone> zone);
253  bool isFilePos(long pos);
254 
255 protected:
256  //
257  // data
258  //
260  shared_ptr<HMWKParserInternal::State> m_state;
261 
264 
266  shared_ptr<HMWKGraph> m_graphParser;
267 
269  shared_ptr<HMWKText> m_textParser;
270 };
271 #endif
272 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

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