Canvas5Parser.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#ifndef CANVAS5_PARSER
35# define CANVAS5_PARSER
36
37#include <functional>
38#include <map>
39#include <string>
40#include <utility>
41#include <vector>
42
43#include <librevenge/librevenge.h>
44
45#include "MWAWDebug.hxx"
46#include "MWAWInputStream.hxx"
47#include "MWAWPosition.hxx"
48
49#include "MWAWParser.hxx"
50
52{
53struct Layer;
54struct Slide;
55
56struct State;
57}
58
59class Canvas5Graph;
61
62namespace Canvas5Structure
63{
64struct Stream;
65}
66
70class Canvas5Parser final : public MWAWGraphicParser
71{
72 friend class Canvas5Graph;
73 friend class Canvas5StyleManager;
74public:
76 Canvas5Parser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
78 ~Canvas5Parser() final;
79
81 bool checkHeader(MWAWHeader *header, bool strict=false) final;
82
83 // the main parse function
84 void parse(librevenge::RVNGDrawingInterface *documentInterface) final;
85
87 static std::string getString(unsigned val);
88
89protected:
91 void createDocument(librevenge::RVNGDrawingInterface *documentInterface);
92
93 //
94 // interface
95 //
96
98 bool isWindowsFile() const;
99
100protected:
102 bool createZones();
104 bool readMainBlock(std::shared_ptr<Canvas5Structure::Stream> stream);
106 bool readFileRSRCs(Canvas5Structure::Stream &stream);
108 bool readFileDesc(Canvas5Structure::Stream &stream);
109
110 // Intermediate level
111
112 //
113 // first block
114 //
115
117 bool readFileHeader(Canvas5Structure::Stream &stream);
118
120 bool readDocumentSettings(Canvas5Structure::Stream &stream);
122 bool readLayers(Canvas5Structure::Stream &stream);
124 bool readPreview(Canvas5Structure::Stream &stream);
126 bool readSlides(Canvas5Structure::Stream &stream);
128 bool readTextLinks(Canvas5Structure::Stream &stream);
129
130 //
131 // second block
132 //
133
135 bool readBitmap(Canvas5Structure::Stream &stream, MWAWEmbeddedObject &object, MWAWColor *avgColor=nullptr);
136
137 //
138 // third block
139 //
140
142 bool readPrinterRsrc(Canvas5Structure::Stream &stream);
143
144 //
145 // Mac RSRC
146 //
148 bool readPnot(Canvas5Structure::Stream &stream, MWAWEntry const &entry);
150 bool readPicture(Canvas5Structure::Stream &stream, MWAWEntry const &entry);
151
152 //
153 // Windows RSRC
154 //
155
156 //
157 // send data to the listener
158 //
159
161 bool send(Canvas5ParserInternal::Slide const &slide);
163 bool send(Canvas5ParserInternal::Layer const &layer);
164
165 //
166 // low level
167 //
168
170 bool readString(Canvas5Structure::Stream &stream, librevenge::RVNGString &string, int maxSize, bool canBeCString=false);
172 bool readDouble(Canvas5Structure::Stream &stream, double &val, bool &isNaN) const;
174 typedef std::function<void(Canvas5Structure::Stream &, int, std::string const &, long)> DataFunction;
176 static void defDataFunction(Canvas5Structure::Stream &, int, std::string const &, long) {}
178 static void stringDataFunction(Canvas5Structure::Stream &stream, int id, std::string const &what, long len);
179
181 bool readDataHeader(Canvas5Structure::Stream &stream, int expectedSize, int &N);
186 bool readExtendedHeader(Canvas5Structure::Stream &stream, int expectedValue, std::string const &what, DataFunction const &func);
188 bool readUnknownHeader(Canvas5Structure::Stream &stream, MWAWEntry(&entries)[2], long len, std::string const &what);
189
191 bool readUsed(Canvas5Structure::Stream &stream, std::string const &what);
193 bool readDefined(Canvas5Structure::Stream &stream, std::vector<bool> &defined, std::string const &what);
194
196 bool readIndexMap(Canvas5Structure::Stream &stream, std::string const &what, DataFunction const &func=&Canvas5Parser::defDataFunction);
197
199 bool readSpecialData(long len, unsigned type, std::string &extra);
200
203
204 //
205 // data
206 //
208 std::shared_ptr<Canvas5ParserInternal::State> m_state;
210 std::shared_ptr<Canvas5Graph> m_graphParser;
212 std::shared_ptr<Canvas5StyleManager> m_styleManager;
213};
214#endif
215// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
the main class to read the graphic part of Canvas5 file
Definition: Canvas5Graph.hxx:83
the main class to read a Canvas 5 files
Definition: Canvas5Parser.hxx:71
static void defDataFunction(Canvas5Structure::Stream &, int, std::string const &, long)
the default function to parse the data of a index map/a extended header
Definition: Canvas5Parser.hxx:176
std::shared_ptr< Canvas5Graph > m_graphParser
the graph parser
Definition: Canvas5Parser.hxx:210
bool readMainBlock(std::shared_ptr< Canvas5Structure::Stream > stream)
try to read the first big block
Definition: Canvas5Parser.cxx:399
static std::string getString(unsigned val)
very low level: debug print some uint32_t either at char4 or sample int
Definition: Canvas5Parser.cxx:2570
bool readString(Canvas5Structure::Stream &stream, librevenge::RVNGString &string, int maxSize, bool canBeCString=false)
try to read a pascal string in the data fork or a Pascal/C string depending on the file type
Definition: Canvas5Parser.cxx:2051
bool readUsed(Canvas5Structure::Stream &stream, std::string const &what)
try to read the used list
Definition: Canvas5Parser.cxx:2445
std::shared_ptr< Canvas5StyleManager > m_styleManager
the style manager
Definition: Canvas5Parser.hxx:212
std::shared_ptr< Canvas5ParserInternal::State > m_state
the state
Definition: Canvas5Parser.hxx:208
std::function< void(Canvas5Structure::Stream &, int, std::string const &, long)> DataFunction
a function used to parse the data of a index map/a extended header
Definition: Canvas5Parser.hxx:174
bool readPreview(Canvas5Structure::Stream &stream)
try to read the preview picture
Definition: Canvas5Parser.cxx:1356
bool readExtendedHeader(Canvas5Structure::Stream &stream, int expectedValue, std::string const &what, DataFunction const &func)
try to read an extended data header, ie.
Definition: Canvas5Parser.cxx:2119
bool readDefined(Canvas5Structure::Stream &stream, std::vector< bool > &defined, std::string const &what)
try to read the defined list
Definition: Canvas5Parser.cxx:2391
bool readSlides(Canvas5Structure::Stream &stream)
try to read the list of slides
Definition: Canvas5Parser.cxx:1666
void createDocument(librevenge::RVNGDrawingInterface *documentInterface)
creates the listener which will be associated to the document
Definition: Canvas5Parser.cxx:230
bool readSpecialData(long len, unsigned type, std::string &extra)
try to read a special shape data (internal helper to understand vkfl structure)
Definition: Canvas5Parser.cxx:190
bool checkHeader(MWAWHeader *header, bool strict=false) final
checks if the document header is correct (or not)
Definition: Canvas5Parser.cxx:1866
~Canvas5Parser() final
destructor
Definition: Canvas5Parser.cxx:181
bool readFileHeader(Canvas5Structure::Stream &stream)
try to read the file header
Definition: Canvas5Parser.cxx:811
bool readLayers(Canvas5Structure::Stream &stream)
try to read the different layers
Definition: Canvas5Parser.cxx:1251
bool readPnot(Canvas5Structure::Stream &stream, MWAWEntry const &entry)
read the RSRC 0 pnot zone
Definition: Canvas5Parser.cxx:1918
bool send(Canvas5ParserInternal::Slide const &slide)
try to send a page/slide
Definition: Canvas5Parser.cxx:1990
bool isWindowsFile() const
returns true if the file is a windows file
Definition: Canvas5Parser.cxx:185
bool readTextLinks(Canvas5Structure::Stream &stream)
try to read the text links
Definition: Canvas5Parser.cxx:1565
bool readPrinterRsrc(Canvas5Structure::Stream &stream)
try to read a printer rsrc
Definition: Canvas5Parser.cxx:1426
Canvas5Parser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
constructor
Definition: Canvas5Parser.cxx:164
bool readBitmap(Canvas5Structure::Stream &stream, MWAWEmbeddedObject &object, MWAWColor *avgColor=nullptr)
try to read a bitmap
Definition: Canvas5Parser.cxx:1032
void parse(librevenge::RVNGDrawingInterface *documentInterface) final
virtual function used to parse the input
Definition: Canvas5Parser.cxx:198
static void stringDataFunction(Canvas5Structure::Stream &stream, int id, std::string const &what, long len)
the default function to parse the data of a index map/a extended header
Definition: Canvas5Parser.cxx:2272
bool readDouble(Canvas5Structure::Stream &stream, double &val, bool &isNaN) const
try to read a double 8
Definition: Canvas5Parser.cxx:2039
bool readPicture(Canvas5Structure::Stream &stream, MWAWEntry const &entry)
read the RSRC Pict zone
Definition: Canvas5Parser.cxx:1946
bool readFileDesc(Canvas5Structure::Stream &stream)
try to read the last block: some pathes, ...
Definition: Canvas5Parser.cxx:750
bool readIndexMap(Canvas5Structure::Stream &stream, std::string const &what, DataFunction const &func=&Canvas5Parser::defDataFunction)
try to read a index map
Definition: Canvas5Parser.cxx:2288
bool readDocumentSettings(Canvas5Structure::Stream &stream)
read the document settings
Definition: Canvas5Parser.cxx:914
static MWAWInputStreamPtr decode(MWAWInputStreamPtr input)
try to decode the input stream
Definition: Canvas5Parser.cxx:2505
bool readUnknownHeader(Canvas5Structure::Stream &stream, MWAWEntry(&entries)[2], long len, std::string const &what)
try to read an unknown structure which defined some position and two entries
Definition: Canvas5Parser.cxx:2187
bool readDataHeader(Canvas5Structure::Stream &stream, int expectedSize, int &N)
try to read a data header, ie. N fields with a given size
Definition: Canvas5Parser.cxx:2098
bool readFileRSRCs(Canvas5Structure::Stream &stream)
try to read the third big block: a list of resource?, font, ...
Definition: Canvas5Parser.cxx:432
bool createZones()
finds the different objects zones
Definition: Canvas5Parser.cxx:342
the main class to read the style part of Canvas 5 file
Definition: Canvas5StyleManager.hxx:77
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:47
virtual class which defines the ancestor of all graphic zone parser
Definition: MWAWParser.hxx:251
a function used by MWAWDocument to store the version of document
Definition: MWAWHeader.hxx:57
std::shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
a smart pointer of MWAWRSRCParser
Definition: libmwaw_internal.hxx:561
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:551
Internal: the structures of a Canvas5Parser.
Definition: Canvas5Parser.cxx:69
a namespace used to define basic structure to read a Canvas 5 file
Definition: Canvas5Graph.hxx:60
Definition: MWAWDocument.hxx:57
a sub stream of Canvas5Structure
Definition: Canvas5Structure.hxx:46
the class to store a color
Definition: libmwaw_internal.hxx:192
small class use to define a embedded object
Definition: libmwaw_internal.hxx:467

Generated on Fri Sep 2 2022 03:21:11 for libmwaw by doxygen 1.9.2