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 
49 #include "MWAWParser.hxx"
50 
51 namespace HMWKParserInternal
52 {
53 struct State;
54 class SubDocument;
55 }
56 
58 struct HMWKZone {
62  HMWKZone(shared_ptr<libmwaw::DebugFile> asciiFile);
64  ~HMWKZone();
65 
67  long begin() const {
68  return m_asciiFilePtr ? 0 : m_filePos;
69  }
71  long end() const {
72  return m_asciiFilePtr ? (long) m_data.size() : m_endFilePos;
73  }
75  long length() const {
76  if (m_asciiFilePtr) return (long) m_data.size();
77  return m_endFilePos-m_filePos;
78  }
80  bool valid() const {
81  return length() > 0;
82  }
83 
84  // function to define the zone in the original file
85 
87  long fileBeginPos() const {
88  return m_filePos;
89  }
91  long fileEndPos() const {
92  return m_endFilePos;
93  }
95  void setFileBeginPos(long begPos) {
96  m_filePos = m_endFilePos = begPos;
97  }
99  void setFileLength(long len) {
100  m_endFilePos = m_filePos+len;
101  }
103  void setFilePositions(long begPos, long endPos) {
104  m_filePos = begPos;
105  m_endFilePos = endPos;
106  }
108  WPXBinaryData &getBinaryData() {
109  return m_data;
110  }
112  std::string name() const {
113  return name(m_type);
114  }
116  static std::string name(int type);
117 
119  friend std::ostream &operator<<(std::ostream &o, HMWKZone const &zone);
120 
123  return *m_asciiFile;
124  }
125 
127  int m_type;
128 
130  long m_id;
131 
133  long m_subId;
134 
137 
139  std::string m_extra;
140 
142  mutable bool m_parsed;
143 
144 protected:
146  long m_filePos;
147 
150 
152  WPXBinaryData m_data;
153 
156 
158  shared_ptr<libmwaw::DebugFile> m_asciiFilePtr;
159 
160 private:
161  HMWKZone(HMWKZone const &orig);
162  HMWKZone &operator=(HMWKZone const &orig);
163 };
164 
165 class HMWKGraph;
166 class HMWKText;
167 
173 class HMWKParser : public MWAWParser
174 {
175  friend class HMWKGraph;
176  friend class HMWKText;
178 
179 public:
181  HMWKParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
183  virtual ~HMWKParser();
184 
186  bool checkHeader(MWAWHeader *header, bool strict=false);
187 
188  // the main parse function
189  void parse(WPXDocumentInterface *documentInterface);
190 
191 protected:
193  void init();
194 
196  void createDocument(WPXDocumentInterface *documentInterface);
197 
199  bool createZones();
200 
202  Vec2f getPageLeftTop() const;
203 
205  void newPage(int number);
206 
207  // interface with the text parser
208 
210  bool sendText(long id, long subId=0);
211 
212  // interface with the graph parser
213 
215  bool sendZone(long zId);
217  bool getColor(int colId, int patternId, MWAWColor &color) const;
218 
219  //
220  // low level
221  //
222 
224  bool readZonesList();
226  bool readZone(shared_ptr<HMWKZone> zone);
228  shared_ptr<HMWKZone> decodeZone(shared_ptr<HMWKZone> zone);
230  bool readFramesUnkn(shared_ptr<HMWKZone> zone);
232  bool readPrintInfo(HMWKZone &zone);
234  bool readZone6(shared_ptr<HMWKZone> zone);
236  bool readZone8(shared_ptr<HMWKZone> zone);
238  bool readZonea(shared_ptr<HMWKZone> zone);
240  bool readZoneb(HMWKZone &zone);
242  bool readZonec(shared_ptr<HMWKZone> zone);
243 
244 protected:
245  //
246  // data
247  //
249  shared_ptr<HMWKParserInternal::State> m_state;
250 
252  shared_ptr<HMWKGraph> m_graphParser;
253 
255  shared_ptr<HMWKText> m_textParser;
256 };
257 #endif
258 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:

Generated on Tue Oct 22 2013 08:24:48 for libmwaw by doxygen 1.8.4