Debian Codegraph @

src/lib/ZWrtParser.hxx

raw
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 ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
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 #ifndef Z_WRT_PARSER
35 # define Z_WRT_PARSER
36
37 #include <string>
38 #include <vector>
39
40 #include <librevenge/librevenge.h>
41
42 #include "MWAWDebug.hxx"
43 #include "MWAWInputStream.hxx"
44
45 #include "MWAWParser.hxx"
46
47 namespace ZWrtParserInternal
48 {
49 class SubDocument;
50 struct State;
51 }
52
53 class ZWrtText;
54
55 /** a structure to store a field of a ZWrite file */
56 struct ZWField {
57 //! constructor
58 ZWField()
59 : m_pos()
60 {
61 }
62 //! returns the string corresponding to a field
63 bool getString(MWAWInputStreamPtr &input, std::string &str) const;
64 //! returns the boolean corresponding to a field ( T or F )
65 bool getBool(MWAWInputStreamPtr &input, bool &val) const;
66 //! returns the int corresponding to a field
67 bool getInt(MWAWInputStreamPtr &input, int &val) const;
68 //! returns the float corresponding to a field
69 bool getFloat(MWAWInputStreamPtr &input, float &val) const;
70 //! returns a list of int corresponding to a field
71 bool getIntList(MWAWInputStreamPtr &input, std::vector<int> &val) const;
72
73 //! returns a debug string corresponding to a field ( replacing \\n by ##[0d], ...)
74 bool getDebugString(MWAWInputStreamPtr &input, std::string &str) const;
75
76 //! the field position in the rsrc data file
77 MWAWEntry m_pos;
78 };
79
80 /** \brief the main class to read a ZWrite file
81 */
82 class ZWrtParser final : public MWAWTextParser
83 {
84 friend class ZWrtParserInternal::SubDocument;
85 friend class ZWrtText;
86 public:
87 //! constructor
88 ZWrtParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
89 //! destructor
90 ~ZWrtParser() final;
91
92 //! checks if the document header is correct (or not)
93 bool checkHeader(MWAWHeader *header, bool strict=false) final;
94
95 // the main parse function
96 void parse(librevenge::RVNGTextInterface *documentInterface) final;
97
98 protected:
99 //! inits all internal variables
100 void init();
101
102 //! creates the listener which will be associated to the document
103 void createDocument(librevenge::RVNGTextInterface *documentInterface);
104
105 //! returns the page left top point ( in inches)
106 MWAWVec2f getPageLeftTop() const;
107 //! adds a new page
108 void newPage(int number);
109
110 // interface with the text parser
111
112 //! try to send the header/footer
113 bool sendHeaderFooter(bool header);
114
115 protected:
116 //! finds the different objects zones
117 bool createZones();
118
119 //! read the bar state
120 bool readBarState(MWAWEntry const &entry);
121 //! read the html export pref
122 bool readHTMLPref(MWAWEntry const &entry);
123 //! read a PrintInfo block
124 bool readPrintInfo(MWAWEntry const &entry);
125 /** try to read a xml printinfo zone */
126 bool readCPRT(MWAWEntry const &entry);
127 //! read the section range block
128 bool readSectionRange(MWAWEntry const &entry);
129 //! read the window position
130 bool readWindowPos(MWAWEntry const &entry);
131
132 //! read a unknown block
133 bool readUnknownZone(MWAWEntry const &entry);
134
135 //! read a cursor position in a section?
136 bool readCPos(MWAWEntry const &entry);
137 //! read a section length ?
138 bool readSLen(MWAWEntry const &entry);
139
140 //! returns a list of field
141 bool getFieldList(MWAWEntry const &entry, std::vector<ZWField> &list);
142
143 //! return the input input
144 MWAWInputStreamPtr rsrcInput();
145
146 //! a DebugFile used to write what we recognize when we parse the document in rsrc
147 libmwaw::DebugFile &rsrcAscii();
148
149 //
150 // data
151 //
152
153 //! the state
154 std::shared_ptr<ZWrtParserInternal::State> m_state;
155
156 //! the text parser
157 std::shared_ptr<ZWrtText> m_textParser;
158 };
159 #endif
160 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: