HanMacWrdKParser.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 HAN_MAC_WRD_K_PARSER
38# define HAN_MAC_WRD_K_PARSER
39
40#include <iostream>
41#include <string>
42#include <vector>
43
44#include <librevenge/librevenge.h>
45
46#include "MWAWDebug.hxx"
47#include "MWAWInputStream.hxx"
48
49#include "MWAWParser.hxx"
50
52{
53struct State;
54class SubDocument;
55}
56
62 explicit HanMacWrdKZone(std::shared_ptr<libmwaw::DebugFile> const &asciiFile);
65
67 long begin() const
68 {
69 return m_asciiFilePtr ? 0 : m_filePos;
70 }
72 long end() const
73 {
74 return m_asciiFilePtr ? long(m_data.size()) : m_endFilePos;
75 }
77 long length() const
78 {
79 if (m_asciiFilePtr) return long(m_data.size());
81 }
83 bool valid() const
84 {
85 return length() > 0;
86 }
87
88 // function to define the zone in the original file
89
91 long fileBeginPos() const
92 {
93 return m_filePos;
94 }
96 long fileEndPos() const
97 {
98 return m_endFilePos;
99 }
101 void setFileBeginPos(long begPos)
102 {
103 m_filePos = m_endFilePos = begPos;
104 }
106 void setFileLength(long len)
107 {
109 }
111 void setFilePositions(long begPos, long endPos)
112 {
113 m_filePos = begPos;
114 m_endFilePos = endPos;
115 }
117 librevenge::RVNGBinaryData &getBinaryData()
118 {
119 return m_data;
120 }
122 std::string name() const
123 {
124 return name(m_type);
125 }
127 static std::string name(int type);
128
130 friend std::ostream &operator<<(std::ostream &o, HanMacWrdKZone const &zone);
131
134 {
135 return *m_asciiFile;
136 }
137
140
142 long m_id;
143
146
149
151 std::string m_extra;
152
154 mutable bool m_parsed;
155
156protected:
159
162
164 librevenge::RVNGBinaryData m_data;
165
168
170 std::shared_ptr<libmwaw::DebugFile> m_asciiFilePtr;
171
172private:
173 HanMacWrdKZone(HanMacWrdKZone const &orig) = delete;
175};
176
177class HanMacWrdKGraph;
178class HanMacWrdKText;
179
186{
187 friend class HanMacWrdKGraph;
188 friend class HanMacWrdKText;
190
191public:
193 HanMacWrdKParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
195 ~HanMacWrdKParser() final;
196
198 bool checkHeader(MWAWHeader *header, bool strict=false) final;
199
200 // the main parse function
201 void parse(librevenge::RVNGTextInterface *documentInterface) final;
202
203protected:
205 void init();
206
208 void createDocument(librevenge::RVNGTextInterface *documentInterface);
209
211 bool createZones();
212
215
217 void newPage(int number);
218
219 // interface with the text parser
220
222 bool sendText(long id, long subId, MWAWListenerPtr listener=MWAWListenerPtr());
223
225 bool canSendTextAsGraphic(long id, long subId);
226
227 // interface with the graph parser
228
230 bool sendZone(long zId);
232 bool getColor(int colId, int patternId, MWAWColor &color) const;
233
234 //
235 // low level
236 //
237
239 bool readZonesList();
241 bool readZone(std::shared_ptr<HanMacWrdKZone> zone);
243 std::shared_ptr<HanMacWrdKZone> decodeZone(std::shared_ptr<HanMacWrdKZone> zone);
245 bool readFramesUnkn(std::shared_ptr<HanMacWrdKZone> zone);
247 bool readPrintInfo(HanMacWrdKZone &zone);
249 bool readZone6(std::shared_ptr<HanMacWrdKZone> zone);
251 bool readZone8(std::shared_ptr<HanMacWrdKZone> zone);
253 bool readZonea(std::shared_ptr<HanMacWrdKZone> zone);
255 bool readZoneb(HanMacWrdKZone &zone);
257 bool readZonec(std::shared_ptr<HanMacWrdKZone> zone);
258
259protected:
260 //
261 // data
262 //
264 std::shared_ptr<HanMacWrdKParserInternal::State> m_state;
265
268
270 std::shared_ptr<HanMacWrdKText> m_textParser;
271};
272#endif
273// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
the main class to read the graphic part of a HanMac Word file
Definition: HanMacWrdKGraph.hxx:78
Internal: the subdocument of a HanMacWrdKParser.
Definition: HanMacWrdKParser.cxx:91
the main class to read a HanMac Word-K file
Definition: HanMacWrdKParser.hxx:186
~HanMacWrdKParser() final
destructor
Definition: HanMacWrdKParser.cxx:151
bool readZone8(std::shared_ptr< HanMacWrdKZone > zone)
try to read a unknown zone of type 8
Definition: HanMacWrdKParser.cxx:754
std::shared_ptr< HanMacWrdKZone > decodeZone(std::shared_ptr< HanMacWrdKZone > zone)
try to decode a zone
Definition: HanMacWrdKParser.cxx:971
void init()
inits all internal variables
Definition: HanMacWrdKParser.cxx:155
void parse(librevenge::RVNGTextInterface *documentInterface) final
virtual function used to parse the input
Definition: HanMacWrdKParser.cxx:222
bool sendText(long id, long subId, MWAWListenerPtr listener=MWAWListenerPtr())
send a text zone
Definition: HanMacWrdKParser.cxx:172
bool readZonesList()
try to read the zones list
Definition: HanMacWrdKParser.cxx:336
std::shared_ptr< HanMacWrdKParserInternal::State > m_state
the state
Definition: HanMacWrdKParser.hxx:264
bool checkHeader(MWAWHeader *header, bool strict=false) final
checks if the document header is correct (or not)
Definition: HanMacWrdKParser.cxx:1082
bool readPrintInfo(HanMacWrdKZone &zone)
try to read a printinfo zone (type 7)
Definition: HanMacWrdKParser.cxx:530
bool getColor(int colId, int patternId, MWAWColor &color) const
returns the color associated with a pattern
Definition: HanMacWrdKParser.cxx:189
bool readFramesUnkn(std::shared_ptr< HanMacWrdKZone > zone)
try to read a zone storing a list of ?, frameType
Definition: HanMacWrdKParser.cxx:641
MWAWVec2f getPageLeftTop() const
returns the page left top point ( in inches)
Definition: HanMacWrdKParser.cxx:197
bool readZone6(std::shared_ptr< HanMacWrdKZone > zone)
try to read a unknown zone of type 6
Definition: HanMacWrdKParser.cxx:710
void createDocument(librevenge::RVNGTextInterface *documentInterface)
creates the listener which will be associated to the document
Definition: HanMacWrdKParser.cxx:258
bool createZones()
finds the different objects zones
Definition: HanMacWrdKParser.cxx:305
bool readZonec(std::shared_ptr< HanMacWrdKZone > zone)
try to read a unknown zone of type c
Definition: HanMacWrdKParser.cxx:889
std::shared_ptr< HanMacWrdKText > m_textParser
the text parser
Definition: HanMacWrdKParser.hxx:270
void newPage(int number)
adds a new page
Definition: HanMacWrdKParser.cxx:206
bool readZonea(std::shared_ptr< HanMacWrdKZone > zone)
try to read a unknown zone of type a
Definition: HanMacWrdKParser.cxx:787
bool canSendTextAsGraphic(long id, long subId)
check if we can send a textzone as graphic
Definition: HanMacWrdKParser.cxx:177
bool readZoneb(HanMacWrdKZone &zone)
try to read a unknown zone of type b
Definition: HanMacWrdKParser.cxx:831
bool sendZone(long zId)
send a zone
Definition: HanMacWrdKParser.cxx:182
std::shared_ptr< HanMacWrdKGraph > m_graphParser
the graph parser
Definition: HanMacWrdKParser.hxx:267
bool readZone(std::shared_ptr< HanMacWrdKZone > zone)
try to read a generic zone
Definition: HanMacWrdKParser.cxx:430
the main class to read the text part of HanMac Word file
Definition: HanMacWrdKText.hxx:62
a function used by MWAWDocument to store the version of document
Definition: MWAWHeader.hxx:57
virtual class which defines the ancestor of all text zone parser
Definition: MWAWParser.hxx:299
an interface used to insert comment in a binary file, written in ascii form (if debug_with_files is n...
Definition: MWAWDebug.hxx:66
std::shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
a smart pointer of MWAWRSRCParser
Definition: libmwaw_internal.hxx:561
std::shared_ptr< MWAWListener > MWAWListenerPtr
a smart pointer of MWAWListener
Definition: libmwaw_internal.hxx:553
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:551
Internal: the structures of a HanMacWrdKParser.
Definition: HanMacWrdKParser.cxx:63
Definition: MWAWDocument.hxx:57
Small class used to store the decoded zone of HanMacWrdKParser.
Definition: HanMacWrdKParser.hxx:58
long m_endFilePos
the end of the entry
Definition: HanMacWrdKParser.hxx:161
librevenge::RVNGBinaryData m_data
the storage (if needed)
Definition: HanMacWrdKParser.hxx:164
HanMacWrdKZone(HanMacWrdKZone const &orig)=delete
long fileEndPos() const
returns the file begin position
Definition: HanMacWrdKParser.hxx:96
long begin() const
returns the first position in the input
Definition: HanMacWrdKParser.hxx:67
libmwaw::DebugFile & ascii() const
returns the debug file
Definition: HanMacWrdKParser.hxx:133
bool m_parsed
true if the zone is sended
Definition: HanMacWrdKParser.hxx:154
std::string name() const
returns the zone name
Definition: HanMacWrdKParser.hxx:122
int m_type
the type : 1(text), ....
Definition: HanMacWrdKParser.hxx:139
~HanMacWrdKZone()
destructor
Definition: HanMacWrdKParser.cxx:1215
void setFileBeginPos(long begPos)
sets the begin file pos
Definition: HanMacWrdKParser.hxx:101
bool valid() const
returns true if the zone data exists
Definition: HanMacWrdKParser.hxx:83
std::shared_ptr< libmwaw::DebugFile > m_asciiFilePtr
the file pointer
Definition: HanMacWrdKParser.hxx:170
libmwaw::DebugFile * m_asciiFile
the debug file
Definition: HanMacWrdKParser.hxx:167
void setFilePositions(long begPos, long endPos)
sets the begin/end file pos
Definition: HanMacWrdKParser.hxx:111
HanMacWrdKZone & operator=(HanMacWrdKZone const &orig)=delete
long length() const
returns the zone size
Definition: HanMacWrdKParser.hxx:77
long m_filePos
the begin of the entry
Definition: HanMacWrdKParser.hxx:158
long end() const
returns the last position in the input
Definition: HanMacWrdKParser.hxx:72
long fileBeginPos() const
returns the file begin position
Definition: HanMacWrdKParser.hxx:91
std::string m_extra
some extra data
Definition: HanMacWrdKParser.hxx:151
long m_id
the zone id
Definition: HanMacWrdKParser.hxx:142
long m_subId
the zone subId
Definition: HanMacWrdKParser.hxx:145
friend std::ostream & operator<<(std::ostream &o, HanMacWrdKZone const &zone)
operator <<
Definition: HanMacWrdKParser.cxx:1221
void setFileLength(long len)
sets the file length
Definition: HanMacWrdKParser.hxx:106
MWAWInputStreamPtr m_input
the main input
Definition: HanMacWrdKParser.hxx:148
librevenge::RVNGBinaryData & getBinaryData()
returns a pointer to the binary data
Definition: HanMacWrdKParser.hxx:117
the class to store a color
Definition: libmwaw_internal.hxx:192

Generated on Wed May 3 2023 07:18:29 for libmwaw by doxygen 1.9.6