| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 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 ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 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 |
#ifndef RAGTIME_5_DOCUMENT |
| 35 |
# define RAGTIME_5_DOCUMENT |
| 36 |
|
| 37 |
#include <map> |
| 38 |
#include <string> |
| 39 |
#include <set> |
| 40 |
#include <vector> |
| 41 |
|
| 42 |
#include "MWAWDebug.hxx" |
| 43 |
#include "MWAWInputStream.hxx" |
| 44 |
|
| 45 |
#include "MWAWParser.hxx" |
| 46 |
|
| 47 |
#include "RagTime5StructManager.hxx" |
| 48 |
#include "RagTime5ClusterManager.hxx" |
| 49 |
|
| 50 |
namespace RagTime5DocumentInternal |
| 51 |
{ |
| 52 |
struct DocInfoFieldParser; |
| 53 |
struct State; |
| 54 |
class SubDocument; |
| 55 |
} |
| 56 |
|
| 57 |
class RagTime5Chart; |
| 58 |
class RagTime5Formula; |
| 59 |
class RagTime5Graph; |
| 60 |
class RagTime5Layout; |
| 61 |
class RagTime5Parser; |
| 62 |
class RagTime5Pipeline; |
| 63 |
class RagTime5SSParser; |
| 64 |
class RagTime5Spreadsheet; |
| 65 |
class RagTime5StructManager; |
| 66 |
class RagTime5StyleManager; |
| 67 |
class RagTime5Text; |
| 68 |
class RagTime5Zone; |
| 69 |
class RagTime5ClusterManager; |
| 70 |
|
| 71 |
/** \brief the main class to read a RagTime v5 file |
| 72 |
* |
| 73 |
* |
| 74 |
* |
| 75 |
*/ |
| 76 |
class RagTime5Document |
| 77 |
{ |
| 78 |
friend class RagTime5Chart; |
| 79 |
friend class RagTime5Formula; |
| 80 |
friend class RagTime5Graph; |
| 81 |
friend class RagTime5Layout; |
| 82 |
friend class RagTime5Parser; |
| 83 |
friend class RagTime5Pipeline; |
| 84 |
friend class RagTime5Spreadsheet; |
| 85 |
friend class RagTime5SSParser; |
| 86 |
friend class RagTime5StructManager; |
| 87 |
friend class RagTime5Text; |
| 88 |
friend class RagTime5ClusterManager; |
| 89 |
friend struct RagTime5DocumentInternal::DocInfoFieldParser; |
| 90 |
friend class RagTime5StyleManager; |
| 91 |
friend class RagTime5DocumentInternal::SubDocument; |
| 92 |
|
| 93 |
public: |
| 94 |
//! constructor |
| 95 |
explicit RagTime5Document(MWAWParser &parser); |
| 96 |
//! destructor |
| 97 |
~RagTime5Document(); |
| 98 |
|
| 99 |
//! checks if the document header is correct (or not) |
| 100 |
bool checkHeader(MWAWHeader *header, bool strict=false); |
| 101 |
//! returns the main parser |
| 102 |
MWAWParser &getMainParser() |
| 103 |
{ |
| 104 |
return *m_parser; |
| 105 |
} |
| 106 |
|
| 107 |
protected: |
| 108 |
//! inits all internal variables |
| 109 |
void init(); |
| 110 |
|
| 111 |
// |
| 112 |
// interface |
| 113 |
// |
| 114 |
|
| 115 |
//! returns the document number of page |
| 116 |
int numPages() const; |
| 117 |
/** updates the page span list */ |
| 118 |
void updatePageSpanList(std::vector<MWAWPageSpan> &spanList); |
| 119 |
/** returns the document meta data */ |
| 120 |
librevenge::RVNGPropertyList getDocumentMetaData() const; |
| 121 |
//! returns the parser state |
| 122 |
MWAWParserStatePtr getParserState() |
| 123 |
{ |
| 124 |
return m_parserState; |
| 125 |
} |
| 126 |
//! returns the document version |
| 127 |
int version() const; |
| 128 |
//! sets the document version |
| 129 |
void setVersion(int vers); |
| 130 |
|
| 131 |
//! a DebugFile used to write what we recognize when we parse the document |
| 132 |
libmwaw::DebugFile &ascii() |
| 133 |
{ |
| 134 |
return getParserState()->m_asciiFile; |
| 135 |
} |
| 136 |
|
| 137 |
//! returns the zone corresponding to a data id (or 0) |
| 138 |
std::shared_ptr<RagTime5Zone> getDataZone(int dataId) const; |
| 139 |
/** returns the cluster type corresponding to zone id or C_Unknown (if the zone is not a cluster or was not parsed) */ |
| 140 |
RagTime5ClusterManager::Cluster::Type getClusterType(int zId) const; |
| 141 |
//! try to return the container's type corresponding to an id |
| 142 |
RagTime5ClusterManager::Cluster::Type getPipelineContainerType(int pipelineId) const; |
| 143 |
|
| 144 |
//! returns the cluster manager |
| 145 |
std::shared_ptr<RagTime5ClusterManager> getClusterManager(); |
| 146 |
//! returns the structure manager |
| 147 |
std::shared_ptr<RagTime5StructManager> getStructManager(); |
| 148 |
//! returns the style manager |
| 149 |
std::shared_ptr<RagTime5StyleManager> getStyleManager(); |
| 150 |
//! returns the formula parser |
| 151 |
std::shared_ptr<RagTime5Formula> getFormulaParser(); |
| 152 |
//! returns the graphic parser |
| 153 |
std::shared_ptr<RagTime5Graph> getGraphParser(); |
| 154 |
//! returns the spreadsheet parser |
| 155 |
std::shared_ptr<RagTime5Spreadsheet> getSpreadsheetParser(); |
| 156 |
|
| 157 |
//! try to read a button cluster (via the graphic manager) |
| 158 |
std::shared_ptr<RagTime5ClusterManager::Cluster> readButtonCluster(RagTime5Zone &zone, int zoneType); |
| 159 |
//! try to read a chart cluster (via the spreadsheet manager) |
| 160 |
std::shared_ptr<RagTime5ClusterManager::Cluster> readChartCluster(RagTime5Zone &zone, int zoneType); |
| 161 |
//! try to read a graphic cluster (via the graphic manager) |
| 162 |
std::shared_ptr<RagTime5ClusterManager::Cluster> readGraphicCluster(RagTime5Zone &zone, int zoneType); |
| 163 |
//! try to read a layout cluster (via the layout manager) |
| 164 |
std::shared_ptr<RagTime5ClusterManager::Cluster> readLayoutCluster(RagTime5Zone &zone, int zoneType); |
| 165 |
//! try to read a pipeline cluster (via the pipeline manager) |
| 166 |
std::shared_ptr<RagTime5ClusterManager::Cluster> readPipelineCluster(RagTime5Zone &zone, int zoneType); |
| 167 |
//! try to read a picture cluster (via the graphic manager) |
| 168 |
std::shared_ptr<RagTime5ClusterManager::Cluster> readPictureCluster(RagTime5Zone &zone, int zoneType); |
| 169 |
//! try to read a spreadsheet cluster (via the spreadsheet manager) |
| 170 |
std::shared_ptr<RagTime5ClusterManager::Cluster> readSpreadsheetCluster(RagTime5Zone &zone, int zoneType); |
| 171 |
//! try to read a text cluster (via the text manager) |
| 172 |
std::shared_ptr<RagTime5ClusterManager::Cluster> readTextCluster(RagTime5Zone &zone, int zoneType); |
| 173 |
|
| 174 |
//! try to send the different zones |
| 175 |
bool sendZones(MWAWListenerPtr listener); |
| 176 |
//! try to send the spreadsheet (assuming there is only one spreadsheet) |
| 177 |
bool sendSpreadsheet(MWAWListenerPtr listener); |
| 178 |
//! try to send a cluster zone (mainly unimplemented) |
| 179 |
bool send(int zoneId, MWAWListenerPtr listener, MWAWPosition const &pos, int partId=0, int cellId=0, double totalWidth=-1); |
| 180 |
//! try to send a button content as text |
| 181 |
bool sendButtonZoneAsText(MWAWListenerPtr listener, int buttonId); |
| 182 |
//! adds a new page |
| 183 |
void newPage(int number, bool softBreak); |
| 184 |
|
| 185 |
//! finds the different objects zones |
| 186 |
bool createZones(); |
| 187 |
//! try to find the list of zones (and stores them in a list) |
| 188 |
bool findZones(MWAWEntry const &entry); |
| 189 |
//! try to find the zone's kind |
| 190 |
bool findZonesKind(); |
| 191 |
//! try to update a zone: information + input |
| 192 |
bool updateZone(std::shared_ptr<RagTime5Zone> &zone); |
| 193 |
//! try to update a zone: create a new input if the zone is stored in different positions, ... |
| 194 |
bool updateZoneInput(RagTime5Zone &zone); |
| 195 |
//! try to read the zone data |
| 196 |
bool readZoneData(RagTime5Zone &zone); |
| 197 |
//! try to unpack a zone |
| 198 |
bool unpackZone(RagTime5Zone &zone, MWAWEntry const &entry, std::vector<unsigned char> &data); |
| 199 |
//! try to unpack a zone |
| 200 |
bool unpackZone(RagTime5Zone &zone); |
| 201 |
|
| 202 |
//! try to read the main zone info zone and the main cluster(and child) |
| 203 |
bool useMainZoneInfoData(); |
| 204 |
//! try to parse the zoneInfo child |
| 205 |
bool parseMainZoneInfoData(RagTime5Zone const &zone); |
| 206 |
|
| 207 |
//! check if the document is a spreadsheet |
| 208 |
bool checkIsSpreadsheet(); |
| 209 |
|
| 210 |
//! try to read a cluster zone |
| 211 |
bool readClusterZone(RagTime5Zone &zone, int type=-1); |
| 212 |
//! try to read a cluster link zone |
| 213 |
bool readClusterLinkList(RagTime5Zone &zone, |
| 214 |
RagTime5ClusterManager::Link const &link, |
| 215 |
std::vector<RagTime5StructManager::ZoneLink> &listLinks); |
| 216 |
//! try to read a cluster list link zone |
| 217 |
bool readClusterLinkList(RagTime5ClusterManager::Link const &link, |
| 218 |
std::vector<RagTime5StructManager::ZoneLink> &list, std::string const &name=""); |
| 219 |
|
| 220 |
//! try to read a string zone ( zone with id1=21,id2=23:24) |
| 221 |
bool readString(RagTime5Zone &zone, std::string &string); |
| 222 |
//! try to read a unicode string zone |
| 223 |
bool readUnicodeString(RagTime5Zone &zone, std::string const &what=""); |
| 224 |
//! try to read a int/long zone data |
| 225 |
bool readLongListWithSize(int dataId, int fSz, std::vector<long> &list, std::string const &zoneName=""); |
| 226 |
//! try to read a positions zone in data |
| 227 |
bool readPositions(int posId, std::vector<long> &listPosition); |
| 228 |
//! try to read/get the list of long of a L_LongList |
| 229 |
bool readLongList(RagTime5ClusterManager::Link const &link, std::vector<long> &list); |
| 230 |
//! try to read a list of unicode string zone |
| 231 |
bool readUnicodeStringList(RagTime5ClusterManager::NameLink const &link, std::map<int, librevenge::RVNGString> &idToStringMap); |
| 232 |
|
| 233 |
//! try to read the document version zone |
| 234 |
bool readDocumentVersion(RagTime5Zone &zone); |
| 235 |
//! try to read the main cluster |
| 236 |
bool readClusterRootData(RagTime5ClusterManager::ClusterRoot &cluster); |
| 237 |
//! try to read the main doc info cluster data |
| 238 |
bool readDocInfoClusterData(RagTime5Zone &zone, MWAWEntry const &entry); |
| 239 |
//! try to read a script comment zone |
| 240 |
bool readScriptComment(RagTime5Zone &zone); |
| 241 |
//! try to read the cluster with contains main graphic object properties |
| 242 |
bool readClusterGProp(RagTime5ClusterManager::Cluster &cluster); |
| 243 |
//! try to read the unknown clusterC data |
| 244 |
bool readUnknownClusterCData(RagTime5ClusterManager::Cluster const &cluster); |
| 245 |
|
| 246 |
//! try to read a structured zone |
| 247 |
bool readStructZone(RagTime5ClusterManager::Link const &link, RagTime5StructManager::FieldParser &parser, int headerSz, RagTime5ClusterManager::NameLink *nameLink=nullptr); |
| 248 |
//! try to read a data in a structured zone |
| 249 |
bool readStructData(RagTime5Zone &zone, long endPos, int n, int headerSz, |
| 250 |
RagTime5StructManager::FieldParser &parser, librevenge::RVNGString const &dataName); |
| 251 |
|
| 252 |
//! try to read a list zone |
| 253 |
bool readListZone(RagTime5ClusterManager::Link const &link); |
| 254 |
//! try to read a list zone |
| 255 |
bool readListZone(RagTime5ClusterManager::Link const &link, RagTime5StructManager::DataParser &parser); |
| 256 |
//! try to read a fixed size zone |
| 257 |
bool readFixedSizeZone(RagTime5ClusterManager::Link const &link, std::string const &name); |
| 258 |
//! try to read a fixed size zone |
| 259 |
bool readFixedSizeZone(RagTime5ClusterManager::Link const &link, RagTime5StructManager::DataParser &parser); |
| 260 |
|
| 261 |
//! try to read a cluster child list |
| 262 |
bool readChildList(RagTime5ClusterManager::Link const &link, std::vector<RagTime5StructManager::ZoneLink> &childList, bool findN=false); |
| 263 |
//! check a cluster list |
| 264 |
bool checkClusterList(std::vector<RagTime5StructManager::ZoneLink> const &list); |
| 265 |
//! check a cluster list |
| 266 |
bool checkClusterList(std::vector<int> const &list); |
| 267 |
//! flush unsent zone (debugging function) |
| 268 |
void flushExtra(MWAWListenerPtr listener, bool onlyCheck=false); |
| 269 |
|
| 270 |
protected: |
| 271 |
// |
| 272 |
// data |
| 273 |
// |
| 274 |
//! the main parser |
| 275 |
MWAWParser *m_parser; |
| 276 |
//! the parser state |
| 277 |
std::shared_ptr<MWAWParserState> m_parserState; |
| 278 |
//! the state |
| 279 |
std::shared_ptr<RagTime5DocumentInternal::State> m_state; |
| 280 |
//! the chart manager |
| 281 |
std::shared_ptr<RagTime5Chart> m_chartParser; |
| 282 |
//! the formula manager |
| 283 |
std::shared_ptr<RagTime5Formula> m_formulaParser; |
| 284 |
//! the graph manager |
| 285 |
std::shared_ptr<RagTime5Graph> m_graphParser; |
| 286 |
//! the layout manager |
| 287 |
std::shared_ptr<RagTime5Layout> m_layoutParser; |
| 288 |
//! the pipeline manager |
| 289 |
std::shared_ptr<RagTime5Pipeline> m_pipelineParser; |
| 290 |
//! the spreadsheet manager |
| 291 |
std::shared_ptr<RagTime5Spreadsheet> m_spreadsheetParser; |
| 292 |
//! the text manager |
| 293 |
std::shared_ptr<RagTime5Text> m_textParser; |
| 294 |
|
| 295 |
//! the cluster manager |
| 296 |
std::shared_ptr<RagTime5ClusterManager> m_clusterManager; |
| 297 |
//! the structure manager |
| 298 |
std::shared_ptr<RagTime5StructManager> m_structManager; |
| 299 |
//! the style manager |
| 300 |
std::shared_ptr<RagTime5StyleManager> m_styleManager; |
| 301 |
|
| 302 |
// |
| 303 |
// the callback |
| 304 |
// |
| 305 |
|
| 306 |
/** callback used to send a page break */ |
| 307 |
typedef void (MWAWParser::* NewPage)(int page, bool softBreak); |
| 308 |
//! callback used to send a footnote |
| 309 |
typedef void (MWAWParser::* SendFootnote)(int zoneId); |
| 310 |
|
| 311 |
/** the new page callback */ |
| 312 |
NewPage m_newPage; |
| 313 |
/** the send footnote callback */ |
| 314 |
SendFootnote m_sendFootnote; |
| 315 |
private: |
| 316 |
RagTime5Document(RagTime5Document const &)=delete; |
| 317 |
RagTime5Document &operator=(RagTime5Document const &)=delete; |
| 318 |
|
| 319 |
}; |
| 320 |
#endif |
| 321 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |