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
72
74#include "STOFFPosition.hxx"
75
76#include "STOFFDebug.hxx"
77
79{
80struct State;
81}
82
87{
88public:
89 struct OleDirectory;
90
93
96
99 bool parse(STOFFInputStreamPtr fileInput);
100
102 std::vector<shared_ptr<OleDirectory> > &getDirectoryList();
104 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), m_base(base), m_isParsed(false), m_position(), m_imageData(), m_imageType("")
113 {
114 }
116 std::string getBaseName()
117 {
118 return m_base;
119 }
121 std::string getOleName() const
122 {
123 if (m_dir.empty()) return m_base;
124 return m_dir+"/"+m_base;
125 }
127 bool isParsed() const
128 {
129 return m_isParsed;
130 }
132 void setParsed(bool flag=true)
133 {
134 m_isParsed=flag;
135 }
138 {
139 return m_position;
140 }
142 void setPosition(STOFFPosition const &pos)
143 {
144 m_position=pos;
145 }
147 bool getImageData(librevenge::RVNGBinaryData &data, std::string &type) const
148 {
149 if (m_imageData.empty()) {
150 data.clear();
151 type="";
152 return false;
153 }
154 data=m_imageData;
155 type=m_imageType;
156 return true;
157 }
159 void setImageData(librevenge::RVNGBinaryData const &data, std::string const &type)
160 {
161 m_imageData=data;
162 m_imageType=type;
163 }
164 protected:
166 std::string m_dir;
168 std::string m_base;
174 librevenge::RVNGBinaryData m_imageData;
176 std::string m_imageType;
177 };
178
182 OleDirectory(STOFFInputStreamPtr input, std::string const &dir) : m_input(input), m_dir(dir), m_contentList(), m_kind(STOFFDocument::STOFF_K_UNKNOWN),
183 m_hasCompObj(false), m_clsName(""), m_clipName(""), m_parsed(false), m_inUse(false) { }
185 void addNewBase(std::string const &base)
186 {
187 if (base=="CompObj")
188 m_hasCompObj=true;
189 else
190 m_contentList.push_back(OleContent(m_dir,base));
191 }
193 std::vector<std::string> getUnparsedOles() const
194 {
195 std::vector<std::string> res;
196 for (size_t i=0; i<m_contentList.size(); ++i) {
197 if (m_contentList[i].isParsed()) continue;
198 res.push_back(m_contentList[i].getOleName());
199 }
200 return res;
201 }
205 std::string m_dir;
207 std::vector<OleContent> m_contentList;
213 std::string m_clsName;
215 std::string m_clipName;
219 mutable bool m_inUse;
220 };
221
222protected:
224 static bool readSummaryInformation(STOFFInputStreamPtr input, std::string const &oleName,
225 libstoff::DebugFile &ascii);
227 bool readCompObj(STOFFInputStreamPtr ip, OleDirectory &directory);
229 static bool readOle(STOFFInputStreamPtr ip, std::string const &oleName,
230 libstoff::DebugFile &ascii);
232 static bool readObjInfo(STOFFInputStreamPtr input, std::string const &oleName,
233 libstoff::DebugFile &ascii);
234
236 static bool isOlePres(STOFFInputStreamPtr ip, std::string const &oleName);
240 static bool readOlePres(STOFFInputStreamPtr ip, OleContent &content);
241
243 static bool isOle10Native(STOFFInputStreamPtr ip, std::string const &oleName);
247 static bool readOle10Native(STOFFInputStreamPtr ip, OleContent &content);
248
252 bool readContents(STOFFInputStreamPtr input, OleContent &content);
253
259 bool readCONTENTS(STOFFInputStreamPtr input, OleContent &content);
260
261protected:
262 //
263 // data
264 //
265
267 shared_ptr<STOFFOLEParserInternal::State> m_state;
268};
269
270#endif
271// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
This class provides all the functions an application would need to parse StarOffice documents.
Definition STOFFDocument.hxx:56
Kind
an enum to define the kind of document
Definition STOFFDocument.hxx:66
a class used to parse some basic oles Tries to read the different ole parts and stores their contents...
Definition STOFFOLEParser.hxx:87
std::vector< shared_ptr< OleDirectory > > & getDirectoryList()
returns the list of directory ole
Definition STOFFOLEParser.cxx:241
bool getCompObjName(STOFFInputStreamPtr fileInput, std::string &programName)
returns the main compobj program name
Definition STOFFOLEParser.cxx:370
shared_ptr< OleDirectory > getDirectory(std::string const &dir)
returns a OleDirectory corresponding to a dir if found
Definition STOFFOLEParser.cxx:246
shared_ptr< STOFFOLEParserInternal::State > m_state
the class state
Definition STOFFOLEParser.hxx:267
STOFFOLEParser()
constructor
Definition STOFFOLEParser.cxx:233
static bool readOle(STOFFInputStreamPtr ip, std::string const &oleName, libstoff::DebugFile &ascii)
the "Ole" small structure : unknown contain
Definition STOFFOLEParser.cxx:386
static bool isOle10Native(STOFFInputStreamPtr ip, std::string const &oleName)
theOle10Native : basic Windows© picture, with no size
Definition STOFFOLEParser.cxx:840
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:1011
bool parse(STOFFInputStreamPtr fileInput)
tries to parse basic OLE (excepted mainName)
Definition STOFFOLEParser.cxx:259
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:902
static bool isOlePres(STOFFInputStreamPtr ip, std::string const &oleName)
the OlePres001 seems to contain standart picture file and size
Definition STOFFOLEParser.cxx:685
~STOFFOLEParser()
destructor
Definition STOFFOLEParser.cxx:237
static bool readOlePres(STOFFInputStreamPtr ip, OleContent &content)
extracts the picture of OlePres001 if it is possible.
Definition STOFFOLEParser.cxx:730
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:539
static bool readSummaryInformation(STOFFInputStreamPtr input, std::string const &oleName, libstoff::DebugFile &ascii)
the summary information
Definition STOFFOLEParser.cxx:419
static bool readOle10Native(STOFFInputStreamPtr ip, OleContent &content)
extracts the picture if it is possible.
Definition STOFFOLEParser.cxx:856
bool readCompObj(STOFFInputStreamPtr ip, OleDirectory &directory)
parse the "CompObj" contains : UserType,ClipName,ProgIdName
Definition STOFFOLEParser.cxx:559
Class to define the position of an object (textbox, picture, ..) in the document.
Definition STOFFPosition.hxx:48
Definition STOFFDebug.hxx:199
shared_ptr< STOFFInputStream > STOFFInputStreamPtr
a smart pointer of STOFFInputStream
Definition libstaroffice_internal.hxx:474
Low level: namespace used to define/store the data used by STOFFOLEParser.
Definition STOFFOLEParser.cxx:94
structure use to store an object content
Definition STOFFOLEParser.hxx:109
OleContent(std::string const &dir, std::string const &base)
constructor
Definition STOFFOLEParser.hxx:111
bool m_isParsed
true if the data has been parsed
Definition STOFFOLEParser.hxx:170
bool isParsed() const
returns true if the object if parsed
Definition STOFFOLEParser.hxx:127
void setPosition(STOFFPosition const &pos)
set the image position
Definition STOFFOLEParser.hxx:142
void setParsed(bool flag=true)
sets the parsed flag
Definition STOFFOLEParser.hxx:132
STOFFPosition m_position
the image position (if known)
Definition STOFFOLEParser.hxx:172
librevenge::RVNGBinaryData m_imageData
the image content ( if known )
Definition STOFFOLEParser.hxx:174
std::string m_imageType
the image type ( if known)
Definition STOFFOLEParser.hxx:176
std::string m_dir
the directory
Definition STOFFOLEParser.hxx:166
STOFFPosition const & getPosition() const
return the image position
Definition STOFFOLEParser.hxx:137
std::string getOleName() const
returns the ole name
Definition STOFFOLEParser.hxx:121
void setImageData(librevenge::RVNGBinaryData const &data, std::string const &type)
sets the image data
Definition STOFFOLEParser.hxx:159
std::string getBaseName()
returns the base name
Definition STOFFOLEParser.hxx:116
std::string m_base
the base name
Definition STOFFOLEParser.hxx:168
bool getImageData(librevenge::RVNGBinaryData &data, std::string &type) const
returns the image data
Definition STOFFOLEParser.hxx:147
Internal: internal method to keep ole directory and their content.
Definition STOFFOLEParser.hxx:180
OleDirectory(STOFFInputStreamPtr input, std::string const &dir)
constructor
Definition STOFFOLEParser.hxx:182
bool m_parsed
a flag to know if the directory is parsed or not
Definition STOFFOLEParser.hxx:217
STOFFInputStreamPtr m_input
the main input
Definition STOFFOLEParser.hxx:203
STOFFDocument::Kind m_kind
the ole kind
Definition STOFFOLEParser.hxx:209
void addNewBase(std::string const &base)
add a new base file
Definition STOFFOLEParser.hxx:185
bool m_inUse
a flag to know if the directory is currently used
Definition STOFFOLEParser.hxx:219
std::vector< std::string > getUnparsedOles() const
returns the list of unknown ole
Definition STOFFOLEParser.hxx:193
bool m_hasCompObj
true if the directory contains a compobj object
Definition STOFFOLEParser.hxx:211
std::string m_clsName
the compobj CLSname
Definition STOFFOLEParser.hxx:213
std::string m_clipName
the compobj clipname
Definition STOFFOLEParser.hxx:215
std::string m_dir
the dir name
Definition STOFFOLEParser.hxx:205
std::vector< OleContent > m_contentList
the list of base name
Definition STOFFOLEParser.hxx:207

Generated on Wed Nov 29 2023 18:59:40 for libstaroffice by doxygen 1.9.8