Debian Codegraph @

src/lib/CanvasParser.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 CANVAS_PARSER
35 # define CANVAS_PARSER
36
37 #include <string>
38 #include <vector>
39
40 #include <librevenge/librevenge.h>
41
42 #include "MWAWDebug.hxx"
43 #include "MWAWGraphicStyle.hxx"
44 #include "MWAWInputStream.hxx"
45 #include "MWAWPosition.hxx"
46
47 #include "MWAWParser.hxx"
48
49 namespace CanvasParserInternal
50 {
51 struct Layer;
52 struct State;
53 }
54
55 class CanvasGraph;
56 class CanvasStyleManager;
57
58 /** \brief the main class to read a Canvas 2 and 3 files
59 *
60 */
61 class CanvasParser final : public MWAWGraphicParser
62 {
63 friend class CanvasGraph;
64 friend class CanvasStyleManager;
65 public:
66 //! constructor
67 CanvasParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
68 //! destructor
69 ~CanvasParser() final;
70
71 //! checks if the document header is correct (or not)
72 bool checkHeader(MWAWHeader *header, bool strict=false) final;
73
74 // the main parse function
75 void parse(librevenge::RVNGDrawingInterface *documentInterface) final;
76
77 protected:
78 //! creates the listener which will be associated to the document
79 void createDocument(librevenge::RVNGDrawingInterface *documentInterface);
80
81 //
82 // interface
83 //
84
85 //! returns true if the file is a windows file
86 bool isWindowsFile() const;
87
88 protected:
89 //! finds the different objects zones
90 bool createZones();
91 //! returns the current input
92 MWAWInputStreamPtr &getInput();
93
94
95 // Intermediate level
96
97 //! read the file header: list of unknown numbers
98 bool readFileHeader();
99 //! read the document header
100 bool readDocumentHeader();
101 //! try to read the brush
102 bool readBrushes();
103 //! read the grid: or a list which begins by a grid
104 bool readGrids();
105 //! try to read the layers
106 bool readLayers();
107 //! read the macro names
108 bool readMacroNames();
109 //! read the formats' zone, mainly an unit's conversion table
110 bool readFormats();
111 //! try to read the spray
112 bool readSprays();
113 //! try to read the views
114 bool readViews();
115
116 //
117 // last v3 zones
118 //
119
120 //! try to read the end zone: v3
121 bool readEndV3();
122
123 //
124 // Mac RSRC
125 //
126
127 //! read the RSRC HeAd(a copy of file header) zone: v3
128 bool readRSRCFileHeader(MWAWInputStreamPtr input, MWAWEntry const &entry, libmwaw::DebugFile &ascFile);
129 //! read the print info zone
130 bool readPrintInfo(MWAWInputStreamPtr input, MWAWEntry const &entry, libmwaw::DebugFile &ascFile);
131 //! read the RSRC LPol zone: v3
132 bool readLPOL(MWAWInputStreamPtr input, MWAWEntry const &entry, libmwaw::DebugFile &ascFile);
133 //! read the RSRC user zone: v3
134 bool readUsers(MWAWInputStreamPtr input, MWAWEntry const &entry, libmwaw::DebugFile &ascFile);
135 //! read the RSRC Windows zone: v3
136 bool readWindows(MWAWInputStreamPtr input, MWAWEntry const &entry, libmwaw::DebugFile &ascFile);
137
138 //
139 // Windows RSRC
140 //
141
142 //! read the resource file which ends the file
143 bool readRSRCWindowsFile();
144 //! read the Windows CNam RSRC: v3 (always 256 0's bytes)
145 bool readCNam(MWAWEntry const &entry);
146 //! read the Windows CSet RSRC: v3 (contains the string Default)
147 bool readCSet(MWAWEntry const &entry);
148 //! read the Windows DevM RSRC: v3 (main data of the printer device)
149 bool readPrinterDev(MWAWEntry const &entry);
150 //! read the Windows Page RSRC: v3
151 bool readPage(MWAWEntry const &entry);
152 //! read the Windows PSST RSRC: v3 (the printer, device name, ...)
153 bool readPrinterSST(MWAWEntry const &entry);
154
155 //! read the first unknown zone
156 bool readUnknownZoneHeader();
157 //! read an unknown zone: contains a layer name, some font id,sz, ...
158 bool readUnknownZone0();
159 //! read an unknown zone
160 bool readUnknownZone1();
161 //! read an unknown zone
162 bool readUnknownZone2();
163 //! read an unknown zone
164 bool readUnknownZone3();
165 //! read an unknown zone: the last zone of a v2 files
166 bool readUnknownZone4();
167
168 //
169 // send data to the listener
170 //
171
172 //! tries to send a layer
173 bool send(CanvasParserInternal::Layer const &layer);
174
175 //
176 // low level
177 //
178
179 //! try to read a pascal string in the data fork or a Pascal/C string depending on the file type
180 bool readString(librevenge::RVNGString &string, int maxSize, bool canBeCString=false);
181 //! try to read a pascal string in the data fork or the resource fork
182 bool readString(MWAWInputStreamPtr input, librevenge::RVNGString &string, int maxSize, bool canBeCString=false);
183
184 //! try to decode some data: length==-1 means decode end of input
185 bool decode(long length);
186
187 //
188 // data
189 //
190 //! the state
191 std::shared_ptr<CanvasParserInternal::State> m_state;
192 //! the graph parser
193 std::shared_ptr<CanvasGraph> m_graphParser;
194 //! the style manager
195 std::shared_ptr<CanvasStyleManager> m_styleManager;
196 };
197 #endif
198 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: