| 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 ([email protected]) |
| 11 | * Copyright (C) 2006, 2007 Andrew Ziem |
| 12 | * Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 13 | * Copyright (C) 2004 Marc Maurer ([email protected]) |
| 14 | * Copyright (C) 2003-2005 William Lachance ([email protected]) |
| 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 | |
| 82 | /** \brief a class used to parse some basic oles |
| 83 | Tries to read the different ole parts and stores their contents in form of picture. |
| 84 | */ |
| 85 | class WPSOLEParser |
| 86 | { |
| 87 | public: |
| 88 | /** constructor |
| 89 | \param mainName name of the main ole, we must avoid to parse */ |
| 90 | WPSOLEParser(const std::string &mainName, |
| 91 | libwps_tools_win::Font::Type fontType, |
| 92 | std::function<int(std::string const &)> const &dirToIdFunc=getIdFromDirectory); |
| 93 | |
| 94 | /** destructor */ |
| 95 | ~WPSOLEParser(); |
| 96 | |
| 97 | /** tries to parse basic OLE (excepted mainName) |
| 98 | \return false if fileInput is not an Ole file */ |
| 99 | bool parse(RVNGInputStreamPtr fileInput); |
| 100 | /** update the meta data, using information find in SummaryInformation */ |
| 101 | void updateMetaData(librevenge::RVNGPropertyList &metaData) const; |
| 102 | |
| 103 | //! returns the list of unknown ole |
| 104 | std::vector<std::string> const &getNotParse() const; |
| 105 | //! returns the list of data positions which have been read |
| 106 | std::map<int,WPSEmbeddedObject> const &getObjectsMap() const; |
| 107 | |
| 108 | protected: |
| 109 | //! the summary information and the doc summary information |
| 110 | bool readSummaryInformation(RVNGInputStreamPtr input, std::string const &oleName, |
| 111 | librevenge::RVNGPropertyList &pList, |
| 112 | libwps::DebugFile &ascii) const; |
| 113 | //! try to read a summary property |
| 114 | bool readSummaryProperty(RVNGInputStreamPtr input, long endPos, int type, |
| 115 | libwps::DebugFile &ascii, libwps::DebugStream &f) const; |
| 116 | //! try to read a summary property: type 1e |
| 117 | bool readSummaryPropertyString(RVNGInputStreamPtr input, long endPos, int type, librevenge::RVNGString &string, |
| 118 | libwps::DebugStream &f) const; |
| 119 | //! try to read a summary property: type 2,3,9,12, |
| 120 | static bool readSummaryPropertyLong(RVNGInputStreamPtr input, long endPos, int type, long &value, |
| 121 | libwps::DebugStream &f); |
| 122 | |
| 123 | //! the "Ole" small structure : unknown contain |
| 124 | static bool readOle(RVNGInputStreamPtr &ip, std::string const &oleName, |
| 125 | libwps::DebugFile &ascii); |
| 126 | //! the "MM" small structure : seems to contain the file versions |
| 127 | static bool readMM(RVNGInputStreamPtr &input, std::string const &oleName, |
| 128 | libwps::DebugFile &ascii); |
| 129 | //! the "ObjInfo" small structure : seems to contain 3 ints=0,3,4 |
| 130 | static bool readObjInfo(RVNGInputStreamPtr &input, std::string const &oleName, |
| 131 | libwps::DebugFile &ascii); |
| 132 | //! the "CompObj" contains : UserType,ClipName,ProgIdName |
| 133 | bool readCompObj(RVNGInputStreamPtr &ip, std::string const &oleName, |
| 134 | libwps::DebugFile &ascii); |
| 135 | |
| 136 | /** the OlePres001 seems to contain standart picture file and size */ |
| 137 | static bool isOlePres(RVNGInputStreamPtr &ip, std::string const &oleName); |
| 138 | /** extracts the picture of OlePres001 if it is possible */ |
| 139 | static bool readOlePres(RVNGInputStreamPtr &ip, WPSEmbeddedObject &obj, libwps::DebugFile &ascii); |
| 140 | |
| 141 | //! theOle10Native : basic Windows' picture, with no size |
| 142 | static bool isOle10Native(RVNGInputStreamPtr &ip, std::string const &oleName); |
| 143 | /** extracts the picture if it is possible */ |
| 144 | static bool readOle10Native(RVNGInputStreamPtr &ip, WPSEmbeddedObject &obj, libwps::DebugFile &ascii); |
| 145 | |
| 146 | /** \brief the Contents : in general a picture : a PNG, an JPEG, a basic metafile, |
| 147 | * I find also a Word art picture, which are not sucefully read |
| 148 | */ |
| 149 | static bool readContents(RVNGInputStreamPtr &input, std::string const &oleName, |
| 150 | WPSEmbeddedObject &obj, libwps::DebugFile &ascii); |
| 151 | |
| 152 | /** the CONTENTS : seems to store a header size, the header |
| 153 | * and then a object in EMF (with the same header)... |
| 154 | * \note I only find such lib in 2 files, so the parsing may be incomplete |
| 155 | * and many such Ole rejected |
| 156 | */ |
| 157 | static bool readCONTENTS(RVNGInputStreamPtr &input, std::string const &oleName, |
| 158 | WPSEmbeddedObject &obj, libwps::DebugFile &ascii); |
| 159 | |
| 160 | //! the "MN0" small structure : can contains a WKS file... |
| 161 | static bool readMN0AndCheckWKS(RVNGInputStreamPtr &input, std::string const &oleName, |
| 162 | WPSEmbeddedObject &obj, libwps::DebugFile &ascii); |
| 163 | |
| 164 | /** the default function which uses the last integer of dirName to return the final id, |
| 165 | ie. it converts "MatOST/MatadorObject1", "Object 1" in 1*/ |
| 166 | static int getIdFromDirectory(std::string const &dirName); |
| 167 | |
| 168 | //! if filled, does not parse content with this name |
| 169 | std::string m_avoidOLE; |
| 170 | //! the main state |
| 171 | std::shared_ptr<WPSOLEParserInternal::State> m_state; |
| 172 | }; |
| 173 | |
| 174 | #endif |
| 175 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |