Debian Codegraph @

src/lib/MoreParser.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 MORE_PARSER
35 # define MORE_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 MoreParserInternal
48 {
49 class SubDocument;
50 struct State;
51 }
52
53 class MoreText;
54
55 /** \brief a namespace used to define basic structures in a More file
56 */
57 namespace MoreStruct
58 {
59 struct Pattern {
60 //!constructor
61 Pattern()
62 : m_frontColor(MWAWColor::black())
63 , m_backColor(MWAWColor::white())
64 {
65 for (auto &val : m_pattern) val=0;
66 }
67 //! operator<<
68 friend std::ostream &operator<<(std::ostream &o, Pattern const &pat);
69 //! the pattern
70 unsigned char m_pattern[8];
71 //! the front color
72 MWAWColor m_frontColor;
73 //! the back color
74 MWAWColor m_backColor;
75 };
76 }
77
78 /** \brief the main class to read a More file
79 */
80 class MoreParser final : public MWAWTextParser
81 {
82 friend class MoreParserInternal::SubDocument;
83 friend class MoreText;
84 public:
85 //! constructor
86 MoreParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
87 //! destructor
88 ~MoreParser() final;
89
90 //! checks if the document header is correct (or not)
91 bool checkHeader(MWAWHeader *header, bool strict=false) final;
92
93 // the main parse function
94 void parse(librevenge::RVNGTextInterface *documentInterface) final;
95
96 protected:
97 //! inits all internal variables
98 void init();
99
100 //! creates the listener which will be associated to the document
101 void createDocument(librevenge::RVNGTextInterface *documentInterface);
102
103 //! returns the page left top point ( in inches)
104 MWAWVec2f getPageLeftTop() const;
105 //! adds a new page
106 void newPage(int number);
107 //! return the color which corresponds to an id (if possible)
108 bool getColor(int id, MWAWColor &col) const;
109
110 // interface with the text parser
111
112 protected:
113 //! finds the different objects zones
114 bool createZones();
115
116 //! read the list of zones ( v2-3) : first 0x80 bytes
117 bool readZonesList();
118
119 //! read a PrintInfo zone ( first block )
120 bool readPrintInfo(MWAWEntry const &entry);
121
122 //! read a docinfo zone ( second block )
123 bool readDocumentInfo(MWAWEntry const &entry);
124
125 //! read the list of slide definitions
126 bool readSlideList(MWAWEntry const &entry);
127
128 //! read a slide definitions
129 bool readSlide(MWAWEntry const &entry);
130
131 //! read a graphic ( in a slide )
132 bool readGraphic(MWAWEntry const &entry);
133
134 //! read a unknown zone ( block 9 )
135 bool readUnknown9(MWAWEntry const &entry);
136
137 //! read a color zone ( beginning of block 9 )
138 bool readColors(long endPos);
139
140 //! read a pattern ( some sub zone of block 9)
141 bool readPattern(long endPos, MoreStruct::Pattern &pattern);
142
143 //! read a backside ( some sub zone of block 9)
144 bool readBackside(long endPos, std::string &extra);
145
146 //! read the list of free file position
147 bool readFreePos(MWAWEntry const &entry);
148
149 //! read the last subzone find in a block 9 ( unknown meaning)
150 bool readUnkn9Sub(long endPos);
151
152 //
153 // low level
154 //
155
156 //! check if the entry is valid, if so store it in the list of entry
157 bool checkAndStore(MWAWEntry const &entry);
158
159 //! check if the entry is valid defined by the begin pos points to a zone: dataSz data
160 bool checkAndFindSize(MWAWEntry &entry);
161
162 //! return the input input
163 MWAWInputStreamPtr rsrcInput();
164
165 //! a DebugFile used to write what we recognize when we parse the document in rsrc
166 libmwaw::DebugFile &rsrcAscii();
167
168 //
169 // data
170 //
171
172 //! the state
173 std::shared_ptr<MoreParserInternal::State> m_state;
174
175 //! the text parser
176 std::shared_ptr<MoreText> m_textParser;
177 };
178 #endif
179 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: