| 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 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 |
|
| 51 |
namespace Canvas5ParserInternal |
| 52 |
{ |
| 53 |
struct Layer; |
| 54 |
struct Slide; |
| 55 |
|
| 56 |
struct State; |
| 57 |
} |
| 58 |
|
| 59 |
class Canvas5Graph; |
| 60 |
class Canvas5Image; |
| 61 |
class Canvas5StyleManager; |
| 62 |
|
| 63 |
namespace Canvas5Structure |
| 64 |
{ |
| 65 |
struct Stream; |
| 66 |
} |
| 67 |
|
| 68 |
/** \brief the main class to read a Canvas 5-10 files (and probably some not password protected Windows 11 files) |
| 69 |
* |
| 70 |
*/ |
| 71 |
class Canvas5Parser final : public MWAWGraphicParser |
| 72 |
{ |
| 73 |
friend class Canvas5Graph; |
| 74 |
friend class Canvas5Image; |
| 75 |
friend class Canvas5StyleManager; |
| 76 |
public: |
| 77 |
//! constructor |
| 78 |
Canvas5Parser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 79 |
//! destructor |
| 80 |
~Canvas5Parser() final; |
| 81 |
|
| 82 |
//! checks if the document header is correct (or not) |
| 83 |
bool checkHeader(MWAWHeader *header, bool strict=false) final; |
| 84 |
|
| 85 |
// the main parse function |
| 86 |
void parse(librevenge::RVNGDrawingInterface *documentInterface) final; |
| 87 |
|
| 88 |
protected: |
| 89 |
//! creates the listener which will be associated to the document |
| 90 |
void createDocument(librevenge::RVNGDrawingInterface *documentInterface); |
| 91 |
|
| 92 |
// |
| 93 |
// interface |
| 94 |
// |
| 95 |
|
| 96 |
//! returns true if the file is a windows file |
| 97 |
bool isWindowsFile() const; |
| 98 |
//! returns the link corresponding to a text id |
| 99 |
librevenge::RVNGString getTextLink(int textLinkId) const; |
| 100 |
|
| 101 |
protected: |
| 102 |
//! finds the different objects zones |
| 103 |
bool createZones(); |
| 104 |
//! try to read the first big block |
| 105 |
bool readMainBlock(std::shared_ptr<Canvas5Structure::Stream> stream); |
| 106 |
//! try to read the first big block: v9 |
| 107 |
bool readMainBlock9(std::shared_ptr<Canvas5Structure::Stream> stream); |
| 108 |
//! try to read the third big block: a list of resource?, font, ... |
| 109 |
bool readFileRSRCs(std::shared_ptr<Canvas5Structure::Stream> stream); |
| 110 |
//! try to read the SI200 zone: v6 |
| 111 |
bool readSI200(Canvas5Structure::Stream &stream); |
| 112 |
//! try to read the last block: some pathes, ... |
| 113 |
bool readFileDesc(Canvas5Structure::Stream &stream); |
| 114 |
|
| 115 |
// Intermediate level |
| 116 |
|
| 117 |
// |
| 118 |
// first block |
| 119 |
// |
| 120 |
|
| 121 |
//! try to read the file header |
| 122 |
bool readFileHeader(std::shared_ptr<Canvas5Structure::Stream> stream); |
| 123 |
|
| 124 |
//! read the document settings |
| 125 |
bool readDocumentSettings(std::shared_ptr<Canvas5Structure::Stream> stream); |
| 126 |
//! try to read the different layers |
| 127 |
bool readLayers(std::shared_ptr<Canvas5Structure::Stream> stream); |
| 128 |
//! try to read the list of slides |
| 129 |
bool readSlides(std::shared_ptr<Canvas5Structure::Stream> stream); |
| 130 |
//! try to read the text links |
| 131 |
bool readTextLinks(std::shared_ptr<Canvas5Structure::Stream> stream); |
| 132 |
|
| 133 |
// |
| 134 |
// second block |
| 135 |
// |
| 136 |
|
| 137 |
// |
| 138 |
// third block |
| 139 |
// |
| 140 |
|
| 141 |
//! try to read a printer rsrc |
| 142 |
bool readPrinterRsrc(Canvas5Structure::Stream &stream); |
| 143 |
//! try to read the OLnk rsrc block: v6 |
| 144 |
bool readOLnkRsrc(std::shared_ptr<Canvas5Structure::Stream> stream); |
| 145 |
//! try to read the object database: XOBD v6 |
| 146 |
bool readObjectDBRsrc(std::shared_ptr<Canvas5Structure::Stream> stream); |
| 147 |
|
| 148 |
// |
| 149 |
// Mac RSRC |
| 150 |
// |
| 151 |
//! read the RSRC 0 pnot zone |
| 152 |
bool readPnot(Canvas5Structure::Stream &stream, MWAWEntry const &entry); |
| 153 |
//! read the RSRC Pict zone |
| 154 |
bool readPicture(Canvas5Structure::Stream &stream, MWAWEntry const &entry); |
| 155 |
|
| 156 |
// |
| 157 |
// Windows RSRC |
| 158 |
// |
| 159 |
|
| 160 |
// |
| 161 |
// send data to the listener |
| 162 |
// |
| 163 |
|
| 164 |
//! try to send a page/slide |
| 165 |
bool send(Canvas5ParserInternal::Slide const &slide); |
| 166 |
//! try to send a layer |
| 167 |
bool send(Canvas5ParserInternal::Layer const &layer); |
| 168 |
|
| 169 |
// |
| 170 |
// low level |
| 171 |
// |
| 172 |
|
| 173 |
//! try to read a pascal string in the data fork or a Pascal/C string depending on the file type |
| 174 |
bool readString(Canvas5Structure::Stream &stream, librevenge::RVNGString &string, int maxSize, bool canBeCString=false); |
| 175 |
//! try to read a double 8 |
| 176 |
bool readDouble(Canvas5Structure::Stream &stream, double &val, bool &isNaN) const; |
| 177 |
//! try to read a float: either a double: fieldSize=8 or a int32 (divided by 65536) |
| 178 |
double readDouble(Canvas5Structure::Stream &stream, int fieldSize) const; |
| 179 |
//! try to read a int: either a cast a double: fieldSize=8 or a int32/int16 |
| 180 |
int readInteger(Canvas5Structure::Stream &stream, int fieldSize) const; |
| 181 |
|
| 182 |
//! a structure used to store the item data of a Canvas5Parser |
| 183 |
struct Item { |
| 184 |
//! constructor |
| 185 |
Item() |
| 186 |
: m_id(-1) |
| 187 |
, m_type(unsigned(-1)) |
| 188 |
, m_length(0) |
| 189 |
, m_pos(-1) |
| 190 |
, m_decal(0) |
| 191 |
{ |
| 192 |
} |
| 193 |
|
| 194 |
//! the identifier |
| 195 |
int m_id; |
| 196 |
//! the type (if known) |
| 197 |
unsigned m_type; |
| 198 |
//! the data length (from current position) |
| 199 |
long m_length; |
| 200 |
//! the data beginning position (may be before the current position: v9) |
| 201 |
long m_pos; |
| 202 |
//! the decal position |
| 203 |
int m_decal; |
| 204 |
}; |
| 205 |
//! a function used to parse the data of a index map/a extended header |
| 206 |
typedef std::function<void(std::shared_ptr<Canvas5Structure::Stream>, Item const &, std::string const &)> DataFunction; |
| 207 |
//! the default function to parse the data of a index map/a extended header |
| 208 |
static void defDataFunction(std::shared_ptr<Canvas5Structure::Stream>, Item const &, std::string const &) {} |
| 209 |
//! the default function to parse a string |
| 210 |
static void stringDataFunction(std::shared_ptr<Canvas5Structure::Stream> stream, Item const &item, std::string const &what); |
| 211 |
|
| 212 |
//! try to read a data header, ie. N fields with a given size |
| 213 |
bool readDataHeader(Canvas5Structure::Stream &stream, int expectedSize, int &N); |
| 214 |
/** try to read an extended data header, ie. N0 is expected to be value |
| 215 |
|
| 216 |
\note the function func is called on each entry excepted the first one |
| 217 |
*/ |
| 218 |
bool readExtendedHeader(std::shared_ptr<Canvas5Structure::Stream> stream, int expectedValue, std::string const &what, DataFunction const &func); |
| 219 |
|
| 220 |
//! try to read the used list |
| 221 |
bool readUsed(Canvas5Structure::Stream &stream, std::string const &what); |
| 222 |
//! try to read the defined list |
| 223 |
bool readDefined(Canvas5Structure::Stream &stream, std::vector<bool> &defined, std::string const &what); |
| 224 |
|
| 225 |
//! try to read a index map |
| 226 |
bool readIndexMap(std::shared_ptr<Canvas5Structure::Stream> stream, std::string const &what, DataFunction const &func=&Canvas5Parser::defDataFunction); |
| 227 |
|
| 228 |
//////////////////////////////////////////////////////////// |
| 229 |
// v9 new structures |
| 230 |
//////////////////////////////////////////////////////////// |
| 231 |
|
| 232 |
//! try to read an array: v9 |
| 233 |
bool readArray9(std::shared_ptr<Canvas5Structure::Stream> stream, std::string const &what, |
| 234 |
DataFunction const &func=&Canvas5Parser::defDataFunction); |
| 235 |
//! try to read an array item header: v9 |
| 236 |
bool readItemHeader9(Canvas5Structure::Stream &stream, int &id, int &used); |
| 237 |
|
| 238 |
//! try to return a tag, type:0 means begin, type:1 means end: v9 |
| 239 |
bool getTAG9(Canvas5Structure::Stream &stream, std::string &tag, int &type); |
| 240 |
/** try to check is the following is a tag: v9 */ |
| 241 |
bool checkTAG9(Canvas5Structure::Stream &stream, std::string const &tag, int type); |
| 242 |
|
| 243 |
//! try to decode the input stream |
| 244 |
static MWAWInputStreamPtr decode(MWAWInputStreamPtr input, int version); |
| 245 |
|
| 246 |
// |
| 247 |
// data |
| 248 |
// |
| 249 |
//! the state |
| 250 |
std::shared_ptr<Canvas5ParserInternal::State> m_state; |
| 251 |
//! the graph parser |
| 252 |
std::shared_ptr<Canvas5Graph> m_graphParser; |
| 253 |
//! the image parser |
| 254 |
std::shared_ptr<Canvas5Image> m_imageParser; |
| 255 |
//! the style manager |
| 256 |
std::shared_ptr<Canvas5StyleManager> m_styleManager; |
| 257 |
}; |
| 258 |
#endif |
| 259 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |