STOFFOLEParser.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libstaroffice
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
/*
* freely inspired from istorage :
* ------------------------------------------------------------
* Generic OLE Zones furnished with a copy of the file header
*
* Compound Storage (32 bit version)
* Storage implementation
*
* This file contains the compound file implementation
* of the storage interface.
*
* Copyright 1999 Francis Beaudet
* Copyright 1999 Sylvain St-Germain
* Copyright 1999 Thuy Nguyen
* Copyright 2005 Mike McCormack
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* ------------------------------------------------------------
*/
#ifndef STOFF_OLE_PARSER_H
#define STOFF_OLE_PARSER_H
#include <string>
#include <vector>
#include <librevenge-stream/librevenge-stream.h>
#include <libstaroffice/STOFFDocument.hxx>
#include "libstaroffice_internal.hxx"
#include "STOFFPosition.hxx"
#include "STOFFDebug.hxx"
namespace STOFFOLEParserInternal
{
struct State;
}
class STOFFOLEParser
{
public:
struct OleDirectory;
STOFFOLEParser();
~STOFFOLEParser();
bool parse(STOFFInputStreamPtr fileInput);
std::vector<std::shared_ptr<OleDirectory> > &getDirectoryList();
std::shared_ptr<OleDirectory> getDirectory(std::string const &dir);
bool getCompObjName(STOFFInputStreamPtr fileInput, std::string &programName);
struct OleContent {
OleContent(std::string const &dir, std::string const &base)
: m_dir(dir)
, m_base(base)
, m_isParsed(false)
, m_position()
, m_imageData()
, m_imageType("")
{
}
std::string getBaseName()
{
return m_base;
}
std::string getOleName() const
{
if (m_dir.empty()) return m_base;
return m_dir+"/"+m_base;
}
bool isParsed() const
{
return m_isParsed;
}
void setParsed(bool flag=true)
{
m_isParsed=flag;
}
STOFFPosition const &getPosition() const
{
return m_position;
}
void setPosition(STOFFPosition const &pos)
{
m_position=pos;
}
bool getImageData(librevenge::RVNGBinaryData &data, std::string &type) const
{
if (m_imageData.empty()) {
data.clear();
type="";
return false;
}
data=m_imageData;
type=m_imageType;
return true;
}
void setImageData(librevenge::RVNGBinaryData const &data, std::string const &type)
{
m_imageData=data;
m_imageType=type;
}
protected:
std::string m_dir;
std::string m_base;
bool m_isParsed;
STOFFPosition m_position;
librevenge::RVNGBinaryData m_imageData;
std::string m_imageType;
};
struct OleDirectory {
OleDirectory(STOFFInputStreamPtr &input, std::string const &dir)
: m_input(input)
, m_dir(dir)
, m_contentList()
, m_kind(STOFFDocument::STOFF_K_UNKNOWN)
, m_hasCompObj(false)
, m_clsName("")
, m_clipName("")
, m_parsed(false)
, m_inUse(false) { }
void addNewBase(std::string const &base)
{
if (base=="CompObj")
m_hasCompObj=true;
else
m_contentList.push_back(OleContent(m_dir,base));
}
std::vector<std::string> getUnparsedOles() const
{
std::vector<std::string> res;
for (auto const &c : m_contentList) {
if (c.isParsed()) continue;
res.push_back(c.getOleName());
}
return res;
}
STOFFInputStreamPtr m_input;
std::string m_dir;
std::vector<OleContent> m_contentList;
STOFFDocument::Kind m_kind;
bool m_hasCompObj;
std::string m_clsName;
std::string m_clipName;
bool m_parsed;
mutable bool m_inUse;
};
protected:
static bool readSummaryInformation(STOFFInputStreamPtr input, std::string const &oleName,
libstoff::DebugFile &ascii);
bool readCompObj(STOFFInputStreamPtr ip, OleDirectory &directory);
static bool readOle(STOFFInputStreamPtr ip, std::string const &oleName,
libstoff::DebugFile &ascii);
static bool readObjInfo(STOFFInputStreamPtr input, std::string const &oleName,
libstoff::DebugFile &ascii);
static bool isOlePres(STOFFInputStreamPtr ip, std::string const &oleName);
static bool readOlePres(STOFFInputStreamPtr ip, OleContent &content);
static bool isOle10Native(STOFFInputStreamPtr ip, std::string const &oleName);
static bool readOle10Native(STOFFInputStreamPtr ip, OleContent &content);
bool readContents(STOFFInputStreamPtr input, OleContent &content);
bool readCONTENTS(STOFFInputStreamPtr input, OleContent &content);
protected:
//
// data
//
std::shared_ptr<STOFFOLEParserInternal::State> m_state;
};
#endif
// 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::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
STOFFOLEParserInternal::State
the state of a STOFFOLEParser
Definition STOFFOLEParser.cxx:96
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