STOFFOLEParser.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/* libstaroffice
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/*
35 * freely inspired from istorage :
36 * ------------------------------------------------------------
37 * Generic OLE Zones furnished with a copy of the file header
38 *
39 * Compound Storage (32 bit version)
40 * Storage implementation
41 *
42 * This file contains the compound file implementation
43 * of the storage interface.
44 *
45 * Copyright 1999 Francis Beaudet
46 * Copyright 1999 Sylvain St-Germain
47 * Copyright 1999 Thuy Nguyen
48 * Copyright 2005 Mike McCormack
49 *
50 * This library is free software; you can redistribute it and/or
51 * modify it under the terms of the GNU Lesser General Public
52 * License as published by the Free Software Foundation; either
53 * version 2.1 of the License, or (at your option) any later version.
54 *
55 * This library is distributed in the hope that it will be useful,
56 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
58 * Lesser General Public License for more details.
59 *
60 * ------------------------------------------------------------
61 */
62
63#ifndef STOFF_OLE_PARSER_H
64#define STOFF_OLE_PARSER_H
65
66#include <string>
67#include <vector>
68
69#include <librevenge-stream/librevenge-stream.h>
70
71#include <libstaroffice/STOFFDocument.hxx>
72
73#include "libstaroffice_internal.hxx"
74#include "STOFFPosition.hxx"
75
76#include "STOFFDebug.hxx"
77
78 namespace STOFFOLEParserInternal
79{
80 struct State;
81}
82
86 class STOFFOLEParser
87{
88 public:
89 struct OleDirectory;
90
92 STOFFOLEParser();
93
95 ~STOFFOLEParser();
96
99 bool parse(STOFFInputStreamPtr fileInput);
100
102 std::vector<std::shared_ptr<OleDirectory> > &getDirectoryList();
104 std::shared_ptr<OleDirectory> getDirectory(std::string const &dir);
106 bool getCompObjName(STOFFInputStreamPtr fileInput, std::string &programName);
107
109 struct OleContent {
111 OleContent(std::string const &dir, std::string const &base)
112 : m_dir(dir)
113 , m_base(base)
114 , m_isParsed(false)
115 , m_position()
116 , m_imageData()
117 , m_imageType("")
118 {
119 }
121 std::string getBaseName()
122 {
123 return m_base;
124 }
126 std::string getOleName() const
127 {
128 if (m_dir.empty()) return m_base;
129 return m_dir+"/"+m_base;
130 }
132 bool isParsed() const
133 {
134 return m_isParsed;
135 }
137 void setParsed(bool flag=true)
138 {
139 m_isParsed=flag;
140 }
142 STOFFPosition const &getPosition() const
143 {
144 return m_position;
145 }
147 void setPosition(STOFFPosition const &pos)
148 {
149 m_position=pos;
150 }
152 bool getImageData(librevenge::RVNGBinaryData &data, std::string &type) const
153 {
154 if (m_imageData.empty()) {
155 data.clear();
156 type="";
157 return false;
158 }
159 data=m_imageData;
160 type=m_imageType;
161 return true;
162 }
164 void setImageData(librevenge::RVNGBinaryData const &data, std::string const &type)
165 {
166 m_imageData=data;
167 m_imageType=type;
168 }
169 protected:
171 std::string m_dir;
173 std::string m_base;
175 bool m_isParsed;
177 STOFFPosition m_position;
179 librevenge::RVNGBinaryData m_imageData;
181 std::string m_imageType;
182 };
183
185 struct OleDirectory {
187 OleDirectory(STOFFInputStreamPtr &input, std::string const &dir)
188 : m_input(input)
189 , m_dir(dir)
190 , m_contentList()
191 , m_kind(STOFFDocument::STOFF_K_UNKNOWN)
192 , m_hasCompObj(false)
193 , m_clsName("")
194 , m_clipName("")
195 , m_parsed(false)
196 , m_inUse(false) { }
198 void addNewBase(std::string const &base)
199 {
200 if (base=="CompObj")
201 m_hasCompObj=true;
202 else
203 m_contentList.push_back(OleContent(m_dir,base));
204 }
206 std::vector<std::string> getUnparsedOles() const
207 {
208 std::vector<std::string> res;
209 for (auto const &c : m_contentList) {
210 if (c.isParsed()) continue;
211 res.push_back(c.getOleName());
212 }
213 return res;
214 }
216 STOFFInputStreamPtr m_input;
218 std::string m_dir;
220 std::vector<OleContent> m_contentList;
222 STOFFDocument::Kind m_kind;
224 bool m_hasCompObj;
226 std::string m_clsName;
228 std::string m_clipName;
230 bool m_parsed;
232 mutable bool m_inUse;
233 };
234
235 protected:
237 static bool readSummaryInformation(STOFFInputStreamPtr input, std::string const &oleName,
238 libstoff::DebugFile &ascii);
240 bool readCompObj(STOFFInputStreamPtr ip, OleDirectory &directory);
242 static bool readOle(STOFFInputStreamPtr ip, std::string const &oleName,
243 libstoff::DebugFile &ascii);
245 static bool readObjInfo(STOFFInputStreamPtr input, std::string const &oleName,
246 libstoff::DebugFile &ascii);
247
249 static bool isOlePres(STOFFInputStreamPtr ip, std::string const &oleName);
253 static bool readOlePres(STOFFInputStreamPtr ip, OleContent &content);
254
256 static bool isOle10Native(STOFFInputStreamPtr ip, std::string const &oleName);
260 static bool readOle10Native(STOFFInputStreamPtr ip, OleContent &content);
261
265 bool readContents(STOFFInputStreamPtr input, OleContent &content);
266
272 bool readCONTENTS(STOFFInputStreamPtr input, OleContent &content);
273
274 protected:
275 //
276 // data
277 //
278
280 std::shared_ptr<STOFFOLEParserInternal::State> m_state;
281};
282
283#endif
284// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
STOFFDebug.hxx
STOFFDocument.hxx
STOFFPosition.hxx
STOFFDocument
This class provides all the functions an application would need to parse StarOffice documents.
Definition STOFFDocument.hxx:56
STOFFDocument::Kind
Kind
an enum to define the kind of document
Definition STOFFDocument.hxx:66
STOFFOLEParser
a class used to parse some basic oles Tries to read the different ole parts and stores their contents...
Definition STOFFOLEParser.hxx:87
STOFFOLEParser::getCompObjName
bool getCompObjName(STOFFInputStreamPtr fileInput, std::string &programName)
returns the main compobj program name
Definition STOFFOLEParser.cxx:372
STOFFOLEParser::STOFFOLEParser
STOFFOLEParser()
constructor
Definition STOFFOLEParser.cxx:236
STOFFOLEParser::readOle
static bool readOle(STOFFInputStreamPtr ip, std::string const &oleName, libstoff::DebugFile &ascii)
the "Ole" small structure : unknown contain
Definition STOFFOLEParser.cxx:388
STOFFOLEParser::isOle10Native
static bool isOle10Native(STOFFInputStreamPtr ip, std::string const &oleName)
theOle10Native : basic Windows© picture, with no size
Definition STOFFOLEParser.cxx:842
STOFFOLEParser::readCONTENTS
bool readCONTENTS(STOFFInputStreamPtr input, OleContent &content)
the CONTENTS : seems to store a header size, the header and then a object in EMF (with the same heade...
Definition STOFFOLEParser.cxx:1013
STOFFOLEParser::parse
bool parse(STOFFInputStreamPtr fileInput)
tries to parse basic OLE (excepted mainName)
Definition STOFFOLEParser.cxx:263
STOFFOLEParser::m_state
std::shared_ptr< STOFFOLEParserInternal::State > m_state
the class state
Definition STOFFOLEParser.hxx:280
STOFFOLEParser::readContents
bool readContents(STOFFInputStreamPtr input, OleContent &content)
the Contents : in general a picture : a PNG, an JPEG, a basic metafile, I find also a Word art pictur...
Definition STOFFOLEParser.cxx:904
STOFFOLEParser::isOlePres
static bool isOlePres(STOFFInputStreamPtr ip, std::string const &oleName)
the OlePres001 seems to contain standart picture file and size
Definition STOFFOLEParser.cxx:687
STOFFOLEParser::~STOFFOLEParser
~STOFFOLEParser()
destructor
Definition STOFFOLEParser.cxx:241
STOFFOLEParser::readOlePres
static bool readOlePres(STOFFInputStreamPtr ip, OleContent &content)
extracts the picture of OlePres001 if it is possible.
Definition STOFFOLEParser.cxx:732
STOFFOLEParser::getDirectory
std::shared_ptr< OleDirectory > getDirectory(std::string const &dir)
returns a OleDirectory corresponding to a dir if found
Definition STOFFOLEParser.cxx:250
STOFFOLEParser::readObjInfo
static bool readObjInfo(STOFFInputStreamPtr input, std::string const &oleName, libstoff::DebugFile &ascii)
the "ObjInfo" small structure : seems to contain 3 ints=0,3,4
Definition STOFFOLEParser.cxx:541
STOFFOLEParser::readSummaryInformation
static bool readSummaryInformation(STOFFInputStreamPtr input, std::string const &oleName, libstoff::DebugFile &ascii)
the summary information
Definition STOFFOLEParser.cxx:421
STOFFOLEParser::getDirectoryList
std::vector< std::shared_ptr< OleDirectory > > & getDirectoryList()
returns the list of directory ole
Definition STOFFOLEParser.cxx:245
STOFFOLEParser::readOle10Native
static bool readOle10Native(STOFFInputStreamPtr ip, OleContent &content)
extracts the picture if it is possible.
Definition STOFFOLEParser.cxx:858
STOFFOLEParser::readCompObj
bool readCompObj(STOFFInputStreamPtr ip, OleDirectory &directory)
parse the "CompObj" contains : UserType,ClipName,ProgIdName
Definition STOFFOLEParser.cxx:561
STOFFPosition
Class to define the position of an object (textbox, picture, ..) in the document.
Definition STOFFPosition.hxx:48
libstoff::DebugFile
Definition STOFFDebug.hxx:211
libstaroffice_internal.hxx
STOFFInputStreamPtr
std::shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition libstaroffice_internal.hxx:489
STOFFOLEParserInternal
Low level: namespace used to define/store the data used by STOFFOLEParser.
Definition STOFFOLEParser.cxx:94
STOFFOLEParser::OleContent
structure use to store an object content
Definition STOFFOLEParser.hxx:109
STOFFOLEParser::OleContent::OleContent
OleContent(std::string const &dir, std::string const &base)
constructor
Definition STOFFOLEParser.hxx:111
STOFFOLEParser::OleContent::m_isParsed
bool m_isParsed
true if the data has been parsed
Definition STOFFOLEParser.hxx:175
STOFFOLEParser::OleContent::isParsed
bool isParsed() const
returns true if the object if parsed
Definition STOFFOLEParser.hxx:132
STOFFOLEParser::OleContent::setPosition
void setPosition(STOFFPosition const &pos)
set the image position
Definition STOFFOLEParser.hxx:147
STOFFOLEParser::OleContent::setParsed
void setParsed(bool flag=true)
sets the parsed flag
Definition STOFFOLEParser.hxx:137
STOFFOLEParser::OleContent::m_position
STOFFPosition m_position
the image position (if known)
Definition STOFFOLEParser.hxx:177
STOFFOLEParser::OleContent::m_imageData
librevenge::RVNGBinaryData m_imageData
the image content ( if known )
Definition STOFFOLEParser.hxx:179
STOFFOLEParser::OleContent::m_imageType
std::string m_imageType
the image type ( if known)
Definition STOFFOLEParser.hxx:181
STOFFOLEParser::OleContent::m_dir
std::string m_dir
the directory
Definition STOFFOLEParser.hxx:171
STOFFOLEParser::OleContent::getPosition
STOFFPosition const & getPosition() const
return the image position
Definition STOFFOLEParser.hxx:142
STOFFOLEParser::OleContent::getOleName
std::string getOleName() const
returns the ole name
Definition STOFFOLEParser.hxx:126
STOFFOLEParser::OleContent::setImageData
void setImageData(librevenge::RVNGBinaryData const &data, std::string const &type)
sets the image data
Definition STOFFOLEParser.hxx:164
STOFFOLEParser::OleContent::getBaseName
std::string getBaseName()
returns the base name
Definition STOFFOLEParser.hxx:121
STOFFOLEParser::OleContent::m_base
std::string m_base
the base name
Definition STOFFOLEParser.hxx:173
STOFFOLEParser::OleContent::getImageData
bool getImageData(librevenge::RVNGBinaryData &data, std::string &type) const
returns the image data
Definition STOFFOLEParser.hxx:152
STOFFOLEParser::OleDirectory
Internal: internal method to keep ole directory and their content.
Definition STOFFOLEParser.hxx:185
STOFFOLEParser::OleDirectory::m_parsed
bool m_parsed
a flag to know if the directory is parsed or not
Definition STOFFOLEParser.hxx:230
STOFFOLEParser::OleDirectory::m_input
STOFFInputStreamPtr m_input
the main input
Definition STOFFOLEParser.hxx:216
STOFFOLEParser::OleDirectory::m_kind
STOFFDocument::Kind m_kind
the ole kind
Definition STOFFOLEParser.hxx:222
STOFFOLEParser::OleDirectory::addNewBase
void addNewBase(std::string const &base)
add a new base file
Definition STOFFOLEParser.hxx:198
STOFFOLEParser::OleDirectory::m_inUse
bool m_inUse
a flag to know if the directory is currently used
Definition STOFFOLEParser.hxx:232
STOFFOLEParser::OleDirectory::getUnparsedOles
std::vector< std::string > getUnparsedOles() const
returns the list of unknown ole
Definition STOFFOLEParser.hxx:206
STOFFOLEParser::OleDirectory::m_hasCompObj
bool m_hasCompObj
true if the directory contains a compobj object
Definition STOFFOLEParser.hxx:224
STOFFOLEParser::OleDirectory::m_clsName
std::string m_clsName
the compobj CLSname
Definition STOFFOLEParser.hxx:226
STOFFOLEParser::OleDirectory::m_clipName
std::string m_clipName
the compobj clipname
Definition STOFFOLEParser.hxx:228
STOFFOLEParser::OleDirectory::m_dir
std::string m_dir
the dir name
Definition STOFFOLEParser.hxx:218
STOFFOLEParser::OleDirectory::m_contentList
std::vector< OleContent > m_contentList
the list of base name
Definition STOFFOLEParser.hxx:220
STOFFOLEParser::OleDirectory::OleDirectory
OleDirectory(STOFFInputStreamPtr &input, std::string const &dir)
constructor
Definition STOFFOLEParser.hxx:187