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 class MWAWEntry;
52 class MWAWFont;
53 class MWAWParagraph;
54 
55 namespace HMWKParserInternal
56 {
57 struct State;
58 class SubDocument;
59 }
60 
62 struct HMWKZone {
66  HMWKZone(shared_ptr<libmwaw::DebugFile> asciiFile);
68  ~HMWKZone();
69 
71  long begin() const {
72  return m_asciiFilePtr ? 0 : m_filePos;
73  }
75  long end() const {
76  return m_asciiFilePtr ? (long) m_data.size() : m_endFilePos;
77  }
79  long length() const {
80  if (m_asciiFilePtr) return (long) m_data.size();
81  return m_endFilePos-m_filePos;
82  }
84  bool valid() const {
85  return length() > 0;
86  }
87 
88  // function to define the zone in the original file
89 
91  long fileBeginPos() const {
92  return m_filePos;
93  }
95  long fileEndPos() const {
96  return m_endFilePos;
97  }
99  void setFileBeginPos(long begPos) {
100  m_filePos = m_endFilePos = begPos;
101  }
103  void setFileLength(long len) {
104  m_endFilePos = m_filePos+len;
105  }
107  void setFilePositions(long begPos, long endPos) {
108  m_filePos = begPos;
109  m_endFilePos = endPos;
110  }
112  WPXBinaryData &getBinaryData() {
113  return m_data;
114  }
116  std::string name() const {
117  return name(m_type);
118  }
120  static std::string name(int type);
121 
123  friend std::ostream &operator<<(std::ostream &o, HMWKZone const &zone);
124 
127  return *m_asciiFile;
128  }
129 
131  int m_type;
132 
134  long m_id;
135 
137  long m_subId;
138 
141 
143  std::string m_extra;
144 
146  mutable bool m_parsed;
147 
148 protected:
150  long m_filePos;
151 
154 
156  WPXBinaryData m_data;
157 
160 
162  shared_ptr<libmwaw::DebugFile> m_asciiFilePtr;
163 
164 private:
165  HMWKZone(HMWKZone const &orig);
166  HMWKZone &operator=(HMWKZone const &orig);
167 };
168 
169 class HMWKGraph;
170 class HMWKText;
171 
177 class HMWKParser : public MWAWParser
178 {
179  friend class HMWKGraph;
180  friend class HMWKText;
182 
183 public:
185  HMWKParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
187  virtual ~HMWKParser();
188 
190  bool checkHeader(MWAWHeader *header, bool strict=false);
191 
192  // the main parse function
193  void parse(WPXDocumentInterface *documentInterface);
194 
195 protected:
197  void init();
198 
200  void createDocument(WPXDocumentInterface *documentInterface);
201 
203  bool createZones();
204 
206  Vec2f getPageLeftTop() const;
207 
209  void newPage(int number);
210 
211  // interface with the text parser
212 
214  bool sendText(long id, long subId=0);
215 
216  // interface with the graph parser
217 
219  bool sendZone(long zId);
221  bool getColor(int colId, int patternId, MWAWColor &color) const;
222 
223  //
224  // low level
225  //
226 
228  bool readZonesList();
230  bool readZone(shared_ptr<HMWKZone> zone);
232  shared_ptr<HMWKZone> decodeZone(shared_ptr<HMWKZone> zone);
234  bool readFramesUnkn(shared_ptr<HMWKZone> zone);
236  bool readPrintInfo(HMWKZone &zone);
238  bool readZone6(shared_ptr<HMWKZone> zone);
240  bool readZone8(shared_ptr<HMWKZone> zone);
242  bool readZonea(shared_ptr<HMWKZone> zone);
244  bool readZoneb(HMWKZone &zone);
246  bool readZonec(shared_ptr<HMWKZone> zone);
248  bool isFilePos(long pos);
249 
250 protected:
251  //
252  // data
253  //
255  shared_ptr<HMWKParserInternal::State> m_state;
256 
258  shared_ptr<HMWKGraph> m_graphParser;
259 
261  shared_ptr<HMWKText> m_textParser;
262 };
263 #endif
264 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
shared_ptr< HMWKText > m_textParser
the text parser
Definition: HMWKParser.hxx:261
the main class to read a HanMac Word-K file
Definition: HMWKParser.hxx:177
bool readZonec(shared_ptr< HMWKZone > zone)
try to read a unknown zone of type c
Definition: HMWKParser.cxx:889
a function used by MWAWDocument to store the version of document and the input
Definition: MWAWHeader.hxx:49
bool getColor(int colId, int patternId, MWAWColor &color) const
returns the color associated with a pattern
Definition: HMWKParser.cxx:177
std::string m_extra
some extra data
Definition: HMWKParser.hxx:143
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
Definition: ACText.hxx:44
long m_subId
the zone subId
Definition: HMWKParser.hxx:137
MWAWInputStreamPtr m_input
the main input
Definition: HMWKParser.hxx:140
the main class to read the text part of HanMac Word file
Definition: HMWKText.hxx:65
an interface used to insert comment in a binary file, written in ascii form (if debug_with_files is n...
Definition: MWAWDebug.hxx:67
libmwaw::DebugFile * m_asciiFile
the debug file
Definition: HMWKParser.hxx:159
bool readZone8(shared_ptr< HMWKZone > zone)
try to read a unknown zone of type 8
Definition: HMWKParser.cxx:753
long m_filePos
the begin of the entry
Definition: HMWKParser.hxx:150
std::string name() const
returns the zone name
Definition: HMWKParser.hxx:116
bool m_parsed
true if the zone is sended
Definition: HMWKParser.hxx:146
void newPage(int number)
adds a new page
Definition: HMWKParser.cxx:194
WPXBinaryData & getBinaryData()
returns a pointer to the binary data
Definition: HMWKParser.hxx:112
~HMWKZone()
destructor
Definition: HMWKParser.cxx:1192
bool readZonea(shared_ptr< HMWKZone > zone)
try to read a unknown zone of type a
Definition: HMWKParser.cxx:787
the main class to read the graphic part of a HanMac Word file
Definition: HMWKGraph.hxx:84
the class to store a color
Definition: libmwaw_internal.hxx:161
Small class used to store the decoded zone of HMWKParser.
Definition: HMWKParser.hxx:62
bool sendZone(long zId)
send a zone
Definition: HMWKParser.cxx:170
Internal: the subdocument of a MWParser.
Definition: HMWKParser.cxx:86
void init()
inits all internal variables
Definition: HMWKParser.cxx:148
bool readPrintInfo(HMWKZone &zone)
try to read a printinfo zone (type 7)
Definition: HMWKParser.cxx:529
Class to store font.
Definition: MWAWFont.hxx:47
void parse(WPXDocumentInterface *documentInterface)
virtual function used to parse the input
Definition: HMWKParser.cxx:224
bool valid() const
returns true if the zone data exists
Definition: HMWKParser.hxx:84
bool readZone(shared_ptr< HMWKZone > zone)
try to read a generic zone
Definition: HMWKParser.cxx:430
virtual ~HMWKParser()
destructor
Definition: HMWKParser.cxx:144
friend std::ostream & operator<<(std::ostream &o, HMWKZone const &zone)
operator &lt;&lt;
Definition: HMWKParser.cxx:1198
void setFilePositions(long begPos, long endPos)
sets the begin/end file pos
Definition: HMWKParser.hxx:107
int m_type
the type : 1(text), ....
Definition: HMWKParser.hxx:131
HMWKZone(MWAWInputStreamPtr input, libmwaw::DebugFile &asciiFile)
constructor given an input and an asciiFile
Definition: HMWKParser.cxx:1182
shared_ptr< HMWKGraph > m_graphParser
the graph parser
Definition: HMWKParser.hxx:258
void setFileBeginPos(long begPos)
sets the begin file pos
Definition: HMWKParser.hxx:99
libmwaw::DebugFile & ascii()
returns the debug file
Definition: HMWKParser.hxx:126
long m_endFilePos
the end of the entry
Definition: HMWKParser.hxx:153
long fileBeginPos() const
returns the file begin position
Definition: HMWKParser.hxx:91
long fileEndPos() const
returns the file begin position
Definition: HMWKParser.hxx:95
long m_id
the zone id
Definition: HMWKParser.hxx:134
void createDocument(WPXDocumentInterface *documentInterface)
creates the listener which will be associated to the document
Definition: HMWKParser.cxx:259
void setFileLength(long len)
sets the file length
Definition: HMWKParser.hxx:103
bool readZoneb(HMWKZone &zone)
try to read a unknown zone of type b
Definition: HMWKParser.cxx:831
bool createZones()
finds the different objects zones
Definition: HMWKParser.cxx:306
bool readZone6(shared_ptr< HMWKZone > zone)
try to read a unknown zone of type 6
Definition: HMWKParser.cxx:709
WPXBinaryData m_data
the storage (if needed)
Definition: HMWKParser.hxx:156
HMWKParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header)
constructor
Definition: HMWKParser.cxx:138
class to store the paragraph properties
Definition: MWAWParagraph.hxx:83
long length() const
returns the zone size
Definition: HMWKParser.hxx:79
long end() const
returns the last position in the input
Definition: HMWKParser.hxx:75
bool checkHeader(MWAWHeader *header, bool strict=false)
checks if the document header is correct (or not)
Definition: HMWKParser.cxx:1081
shared_ptr< HMWKZone > decodeZone(shared_ptr< HMWKZone > zone)
try to decode a zone
Definition: HMWKParser.cxx:972
HMWKZone & operator=(HMWKZone const &orig)
virtual class which defines the ancestor of all main zone parser
Definition: MWAWParser.hxx:98
shared_ptr< libmwaw::DebugFile > m_asciiFilePtr
the file pointer
Definition: HMWKParser.hxx:162
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
bool readFramesUnkn(shared_ptr< HMWKZone > zone)
try to read a zone storing a list of ?, frameType
Definition: HMWKParser.cxx:639
Vec2f getPageLeftTop() const
returns the page left top point ( in inches)
Definition: HMWKParser.cxx:185
shared_ptr< HMWKParserInternal::State > m_state
the state
Definition: HMWKParser.hxx:255
bool sendText(long id, long subId=0)
send a text zone (not implemented)
Definition: HMWKParser.cxx:165
bool isFilePos(long pos)
check if an entry is in file
Definition: HMWKParser.cxx:207
bool readZonesList()
try to read the zones list
Definition: HMWKParser.cxx:337
long begin() const
returns the first position in the input
Definition: HMWKParser.hxx:71
shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
Definition: MWAWParser.hxx:56

Generated for libmwaw by doxygen 1.8.5