WPSOLEParser.h Source File documentation

WPSOLEParser.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Major Contributor(s):
10 * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
11 * Copyright (C) 2006, 2007 Andrew Ziem
12 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
13 * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
14 * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
15 *
16 * For minor contributions see the git repository.
17 *
18 * Alternatively, the contents of this file may be used under the terms
19 * of the GNU Lesser General Public License Version 2.1 or later
20 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
21 * applicable instead of those above.
22 *
23 * For further information visit http://libwps.sourceforge.net
24 */
25
26 /*
27 * freely inspired from istorage :
28 * ------------------------------------------------------------
29 * Generic OLE Zones furnished with a copy of the file header
30 *
31 * Compound Storage (32 bit version)
32 * Storage implementation
33 *
34 * This file contains the compound file implementation
35 * of the storage interface.
36 *
37 * Copyright 1999 Francis Beaudet
38 * Copyright 1999 Sylvain St-Germain
39 * Copyright 1999 Thuy Nguyen
40 * Copyright 2005 Mike McCormack
41 *
42 * This library is free software; you can redistribute it and/or
43 * modify it under the terms of the GNU Lesser General Public
44 * License as published by the Free Software Foundation; either
45 * version 2.1 of the License, or (at your option) any later version.
46 *
47 * This library is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50 * Lesser General Public License for more details.
51 *
52 * ------------------------------------------------------------
53 */
54
55 #ifndef WPS_OLE_PARSER_H
56 #define WPS_OLE_PARSER_H
57
58 #include <functional>
59 #include <string>
60 #include <map>
61 #include <vector>
62
63 #include <librevenge-stream/librevenge-stream.h>
64
65 #include "libwps_internal.h"
66 #include "libwps_tools_win.h"
67
68 #include "WPSDebug.h"
69 #include "WPSPosition.h"
70
71 namespace libwps
72 {
73 class Storage;
74 }
75
76 namespace WPSOLEParserInternal
77 {
78 class CompObj;
79 struct State;
80 }
81
85 class WPSOLEParser
86 {
87 public:
90 WPSOLEParser(const std::string &mainName,
91 libwps_tools_win::Font::Type fontType,
92 std::function<int(std::string const &)> const &dirToIdFunc=getIdFromDirectory);
93
95 ~WPSOLEParser();
96
99 bool parse(RVNGInputStreamPtr fileInput);
101 void updateMetaData(librevenge::RVNGPropertyList &metaData) const;
102
104 std::vector<std::string> const &getNotParse() const;
106 std::map<int,WPSEmbeddedObject> const &getObjectsMap() const;
107
108 protected:
110 bool readSummaryInformation(RVNGInputStreamPtr input, std::string const &oleName,
111 librevenge::RVNGPropertyList &pList,
112 libwps::DebugFile &ascii) const;
114 bool readSummaryProperty(RVNGInputStreamPtr input, long endPos, int type,
115 libwps::DebugFile &ascii, libwps::DebugStream &f) const;
117 bool readSummaryPropertyString(RVNGInputStreamPtr input, long endPos, int type, librevenge::RVNGString &string,
118 libwps::DebugStream &f) const;
120 static bool readSummaryPropertyLong(RVNGInputStreamPtr input, long endPos, int type, long &value,
121 libwps::DebugStream &f);
122
124 static bool readOle(RVNGInputStreamPtr &ip, std::string const &oleName,
125 libwps::DebugFile &ascii);
127 static bool readMM(RVNGInputStreamPtr &input, std::string const &oleName,
128 libwps::DebugFile &ascii);
130 static bool readObjInfo(RVNGInputStreamPtr &input, std::string const &oleName,
131 libwps::DebugFile &ascii);
133 bool readCompObj(RVNGInputStreamPtr &ip, std::string const &oleName,
134 libwps::DebugFile &ascii);
135
137 static bool isOlePres(RVNGInputStreamPtr &ip, std::string const &oleName);
139 static bool readOlePres(RVNGInputStreamPtr &ip, WPSEmbeddedObject &obj, libwps::DebugFile &ascii);
140
142 static bool isOle10Native(RVNGInputStreamPtr &ip, std::string const &oleName);
144 static bool readOle10Native(RVNGInputStreamPtr &ip, WPSEmbeddedObject &obj, libwps::DebugFile &ascii);
145
149 static bool readContents(RVNGInputStreamPtr &input, std::string const &oleName,
150 WPSEmbeddedObject &obj, libwps::DebugFile &ascii);
151
157 static bool readCONTENTS(RVNGInputStreamPtr &input, std::string const &oleName,
158 WPSEmbeddedObject &obj, libwps::DebugFile &ascii);
159
161 static bool readMN0AndCheckWKS(RVNGInputStreamPtr &input, std::string const &oleName,
162 WPSEmbeddedObject &obj, libwps::DebugFile &ascii);
163
166 static int getIdFromDirectory(std::string const &dirName);
167
169 std::string m_avoidOLE;
171 std::shared_ptr<WPSOLEParserInternal::State> m_state;
172 };
173
174 #endif
175 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPSOLEParserInternal::OleDef::m_name
std::string m_name
the complete name
Definition: WPSOLEParser.cpp:231
WPSOLEParser::m_avoidOLE
std::string m_avoidOLE
if filled, does not parse content with this name
Definition: WPSOLEParser.h:169
libwps::DebugStream::str
static std::string str()
Definition: WPSDebug.h:200
libwps::DebugFile::open
static bool open(std::string const &)
Definition: WPSDebug.h:215
WPSOLEParserInternal::CompObj::m_mapCls
std::map< unsigned long, char const * > m_mapCls
map CLSId <-> name
Definition: WPSOLEParser.cpp:107
libwps::DebugFile::addPos
static void addPos(long)
Definition: WPSDebug.h:220
WPSOLEParser::readCompObj
bool readCompObj(RVNGInputStreamPtr &ip, std::string const &oleName, libwps::DebugFile &ascii)
the "CompObj" contains : UserType,ClipName,ProgIdName
Definition: WPSOLEParser.cpp:545
libwps::Debug::dumpFile
bool dumpFile(librevenge::RVNGBinaryData &, char const *)
Definition: WPSDebug.h:180
WPSOLEParserInternal::State::m_fontType
libwps_tools_win::Font::Type m_fontType
the default font type
Definition: WPSOLEParser.cpp:248
libwps_tools_win::Font::Type
Type
enum Type
Definition: libwps_tools_win.h:46
WPSOLEParser::getObjectsMap
std::map< int, WPSEmbeddedObject > const & getObjectsMap() const
returns the list of data positions which have been read
Definition: WPSOLEParser.cpp:281
libwps
Definition: libwps_internal.cpp:39
WPSOLEParserInternal::CompObj::getCLSName
char const * getCLSName(unsigned long v)
return the CLS Name corresponding to an identifier
Definition: WPSOLEParser.cpp:99
WPSOLEParser::getNotParse
std::vector< std::string > const & getNotParse() const
returns the list of unknown ole
Definition: WPSOLEParser.cpp:276
libwps::DebugFile::reset
static void reset()
Definition: WPSDebug.h:224
WPSOLEParser
a class used to parse some basic oles Tries to read the different ole parts and stores their contents...
Definition: WPSOLEParser.h:86
libwps::DebugFile::skipZone
static void skipZone(long, long)
Definition: WPSDebug.h:226
libwps_tools_win::Font::unicodeString
static librevenge::RVNGString unicodeString(const unsigned char *p, unsigned long size, Type type, bool skipUnknown=true)
converts a list of character in unicode
Definition: libwps_tools_win.cpp:7283
WPSOLEParser::readSummaryInformation
bool readSummaryInformation(RVNGInputStreamPtr input, std::string const &oleName, librevenge::RVNGPropertyList &pList, libwps::DebugFile &ascii) const
the summary information and the doc summary information
Definition: WPSOLEParser.cpp:1160
WPSHeader.h
WPSOLEParserInternal::OleDef
Internal: internal method to keep ole definition.
Definition: WPSOLEParser.cpp:224
WPSOLEParserInternal::State::m_directoryToIdFunction
std::function< int(std::string const &)> m_directoryToIdFunction
the function used to convert a directory name in a id
Definition: WPSOLEParser.cpp:250
WPSOLEParser::readOlePres
static bool readOlePres(RVNGInputStreamPtr &ip, WPSEmbeddedObject &obj, libwps::DebugFile &ascii)
extracts the picture of OlePres001 if it is possible
Definition: WPSOLEParser.cpp:720
WPSOLEParserInternal::State::m_idToObjectMap
std::map< int, WPSEmbeddedObject > m_idToObjectMap
map id to object
Definition: WPSOLEParser.cpp:256
WPSEmbeddedObject::m_size
Vec2f m_size
the picture size in inches(if known)
Definition: libwps_internal.h:1120
WPSOLEParser::parse
bool parse(RVNGInputStreamPtr fileInput)
tries to parse basic OLE (excepted mainName)
Definition: WPSOLEParser.cpp:318
Vec2f
Vec2< float > Vec2f
Vec2 of float.
Definition: libwps_internal.h:704
WPSOLEParser::readOle
static bool readOle(RVNGInputStreamPtr &ip, std::string const &oleName, libwps::DebugFile &ascii)
the "Ole" small structure : unknown contain
Definition: WPSOLEParser.cpp:433
WPSOLEParser::getIdFromDirectory
static int getIdFromDirectory(std::string const &dirName)
the default function which uses the last integer of dirName to return the final id,...
Definition: WPSOLEParser.cpp:295
Vec2< float >
WPS_DEBUG_MSG
#define WPS_DEBUG_MSG(M)
Definition: libwps_internal.h:134
libwps::readU32
uint32_t readU32(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:76
WPSOLEParserInternal::State::m_compObjIdName
std::shared_ptr< WPSOLEParserInternal::CompObj > m_compObjIdName
a smart ptr used to stored the list of compobj id->name
Definition: WPSOLEParser.cpp:259
WPSOLEParser::readSummaryPropertyLong
static bool readSummaryPropertyLong(RVNGInputStreamPtr input, long endPos, int type, long &value, libwps::DebugStream &f)
try to read a summary property: type 2,3,9,12,
Definition: WPSOLEParser.cpp:1336
WPSOLEParser.h
WPSOLEParser::m_state
std::shared_ptr< WPSOLEParserInternal::State > m_state
the main state
Definition: WPSOLEParser.h:171
WPSOLEParserInternal::State
Internal: the state of a WPSOLEParser.
Definition: WPSOLEParser.cpp:236
WPSOLEParser::isOlePres
static bool isOlePres(RVNGInputStreamPtr &ip, std::string const &oleName)
the OlePres001 seems to contain standart picture file and size
Definition: WPSOLEParser.cpp:675
libwps::read32
int32_t read32(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:85
WPSOLEParser::readSummaryProperty
bool readSummaryProperty(RVNGInputStreamPtr input, long endPos, int type, libwps::DebugFile &ascii, libwps::DebugStream &f) const
try to read a summary property
Definition: WPSOLEParser.cpp:1362
libwps::DebugFile::addNote
static void addNote(char const *)
Definition: WPSDebug.h:221
WPSOLEParser::isOle10Native
static bool isOle10Native(RVNGInputStreamPtr &ip, std::string const &oleName)
theOle10Native : basic Windows' picture, with no size
Definition: WPSOLEParser.cpp:833
WPSOLEParser::readObjInfo
static bool readObjInfo(RVNGInputStreamPtr &input, std::string const &oleName, libwps::DebugFile &ascii)
the "ObjInfo" small structure : seems to contain 3 ints=0,3,4
Definition: WPSOLEParser.cpp:468
libwps::WPS_SPREADSHEET
@ WPS_SPREADSHEET
Definition: WPSDocument.h:62
libwps::read8
int8_t read8(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:59
WPSEmbeddedObject::isEmpty
bool isEmpty() const
return true if the picture contains no data
Definition: libwps_internal.h:1095
WPSEmbeddedObject::add
void add(librevenge::RVNGBinaryData const &binaryData, std::string const &type="image/pict")
add a picture
Definition: libwps_internal.h:1105
WPSOLEParserInternal::OleDef::OleDef
OleDef()
Definition: WPSOLEParser.cpp:225
WPSEmbeddedObject
small class use to define a embedded object
Definition: libwps_internal.h:1077
libwps::DebugStream
Definition: WPSDebug.h:192
libwps::readU8
uint8_t readU8(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:40
WPSOLEParserInternal::State::State
State(libwps_tools_win::Font::Type fontType, std::function< int(std::string const &)> const &dirToIdFunc)
constructor
Definition: WPSOLEParser.cpp:238
WPSOLEParser::WPSOLEParser
WPSOLEParser(const std::string &mainName, libwps_tools_win::Font::Type fontType, std::function< int(std::string const &)> const &dirToIdFunc=getIdFromDirectory)
constructor
Definition: WPSOLEParser.cpp:264
WPSOLEParser::readContents
static bool readContents(RVNGInputStreamPtr &input, std::string const &oleName, WPSEmbeddedObject &obj, libwps::DebugFile &ascii)
the Contents : in general a picture : a PNG, an JPEG, a basic metafile, I find also a Word art pictur...
Definition: WPSOLEParser.cpp:893
WPSOLEParser::updateMetaData
void updateMetaData(librevenge::RVNGPropertyList &metaData) const
update the meta data, using information find in SummaryInformation
Definition: WPSOLEParser.cpp:285
libwps_tools_win.h
libwps::readData
bool readData(RVNGInputStreamPtr &input, unsigned long size, librevenge::RVNGBinaryData &data)
try to read sz bytes from input and store them in a librevenge::RVNGBinaryData
Definition: libwps_internal.cpp:332
WPSOLEParserInternal::OleDef::m_dir
std::string m_dir
the directory
Definition: WPSOLEParser.cpp:231
WPSOLEParserInternal::OleDef::m_id
int m_id
main id
Definition: WPSOLEParser.cpp:230
WPSOLEParser::readCONTENTS
static bool readCONTENTS(RVNGInputStreamPtr &input, std::string const &oleName, WPSEmbeddedObject &obj, libwps::DebugFile &ascii)
the CONTENTS : seems to store a header size, the header and then a object in EMF (with the same heade...
Definition: WPSOLEParser.cpp:1015
libwps::readU16
uint16_t readU16(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:64
libwps_tools_win::Language::name
std::string name(long id)
returns the name given Windows© id
Definition: libwps_tools_win.cpp:7332
WPSOLEParser::~WPSOLEParser
~WPSOLEParser()
destructor
Definition: WPSOLEParser.cpp:271
WPSOLEParser::readOle10Native
static bool readOle10Native(RVNGInputStreamPtr &ip, WPSEmbeddedObject &obj, libwps::DebugFile &ascii)
extracts the picture if it is possible
Definition: WPSOLEParser.cpp:849
WPSPosition.h
RVNGInputStreamPtr
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr
shared pointer to librevenge::RVNGInputStream
Definition: libwps_internal.h:87
WPSDebug.h
libwps::DebugFile::addDelimiter
static void addDelimiter(long, char)
Definition: WPSDebug.h:222
libwps::readDataToEnd
bool readDataToEnd(RVNGInputStreamPtr &input, librevenge::RVNGBinaryData &data)
try to read the last bytes from input and store them in a librevenge::RVNGBinaryData
Definition: libwps_internal.cpp:346
WPSHeader::constructHeader
static WPSHeader * constructHeader(RVNGInputStreamPtr &input)
So far, we have identified three categories of Works documents.
Definition: WPSHeader.cpp:55
WPSOLEParserInternal::CompObj::initCLSMap
void initCLSMap()
initialise a map CLSId <-> name
Definition: WPSOLEParser.cpp:110
WPSOLEParserInternal
Definition: WPSOLEParser.cpp:86
libwps::read16
int16_t read16(librevenge::RVNGInputStream *input)
Definition: libwps_internal.cpp:71
WPSOLEParser::readMM
static bool readMM(RVNGInputStreamPtr &input, std::string const &oleName, libwps::DebugFile &ascii)
the "MM" small structure : seems to contain the file versions
Definition: WPSOLEParser.cpp:489
libwps_internal.h
WPSOLEParserInternal::State::m_unknownOLEs
std::vector< std::string > m_unknownOLEs
list of ole which can not be parsed
Definition: WPSOLEParser.cpp:254
WPSOLEParserInternal::OleDef::m_base
std::string m_base
the base name
Definition: WPSOLEParser.cpp:231
WPSOLEParserInternal::CompObj::CompObj
CompObj()
the constructor
Definition: WPSOLEParser.cpp:92
WPSOLEParserInternal::CompObj
Internal: internal method to compobj definition.
Definition: WPSOLEParser.cpp:89
WPSOLEParser::readMN0AndCheckWKS
static bool readMN0AndCheckWKS(RVNGInputStreamPtr &input, std::string const &oleName, WPSEmbeddedObject &obj, libwps::DebugFile &ascii)
the "MN0" small structure : can contains a WKS file...
Definition: WPSOLEParser.cpp:1132
libwps::DebugFile
Definition: WPSDebug.h:208
WPSOLEParserInternal::State::m_metaData
librevenge::RVNGPropertyList m_metaData
the meta data
Definition: WPSOLEParser.cpp:252
WPSOLEParser::readSummaryPropertyString
bool readSummaryPropertyString(RVNGInputStreamPtr input, long endPos, int type, librevenge::RVNGString &string, libwps::DebugStream &f) const
try to read a summary property: type 1e
Definition: WPSOLEParser.cpp:1306