| 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 |
/* |
| 35 |
* Parser to convert FullWrite document |
| 36 |
* |
| 37 |
*/ |
| 38 |
#ifndef FULL_WRT_PARSER |
| 39 |
# define FULL_WRT_PARSER |
| 40 |
|
| 41 |
#include <list> |
| 42 |
#include <string> |
| 43 |
#include <vector> |
| 44 |
|
| 45 |
#include <librevenge/librevenge.h> |
| 46 |
|
| 47 |
#include "MWAWInputStream.hxx" |
| 48 |
|
| 49 |
#include "FullWrtStruct.hxx" |
| 50 |
#include "MWAWParser.hxx" |
| 51 |
|
| 52 |
namespace FullWrtParserInternal |
| 53 |
{ |
| 54 |
struct State; |
| 55 |
class SubDocument; |
| 56 |
} |
| 57 |
|
| 58 |
class FullWrtGraph; |
| 59 |
class FullWrtText; |
| 60 |
|
| 61 |
/** \brief the main class to read a FullWrite file |
| 62 |
* |
| 63 |
* |
| 64 |
* |
| 65 |
*/ |
| 66 |
class FullWrtParser final : public MWAWTextParser |
| 67 |
{ |
| 68 |
friend class FullWrtGraph; |
| 69 |
friend class FullWrtText; |
| 70 |
friend class FullWrtParserInternal::SubDocument; |
| 71 |
|
| 72 |
public: |
| 73 |
//! constructor |
| 74 |
FullWrtParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 75 |
//! destructor |
| 76 |
~FullWrtParser() final; |
| 77 |
|
| 78 |
//! checks if the document header is correct (or not) |
| 79 |
bool checkHeader(MWAWHeader *header, bool strict=false) final; |
| 80 |
|
| 81 |
// the main parse function |
| 82 |
void parse(librevenge::RVNGTextInterface *documentInterface) final; |
| 83 |
|
| 84 |
protected: |
| 85 |
//! inits all internal variables |
| 86 |
void init(); |
| 87 |
|
| 88 |
//! creates the listener which will be associated to the document |
| 89 |
void createDocument(librevenge::RVNGTextInterface *documentInterface); |
| 90 |
|
| 91 |
//! finds the different objects zones |
| 92 |
bool createZones(); |
| 93 |
|
| 94 |
//! create the file zone ( first step of create zones) |
| 95 |
bool createFileZones(); |
| 96 |
|
| 97 |
//! adds a new page |
| 98 |
void newPage(int number); |
| 99 |
|
| 100 |
//! find the last position of the document and read data |
| 101 |
bool readDocPosition(); |
| 102 |
|
| 103 |
//! try to read the file zones main flags |
| 104 |
bool readFileZoneFlags(FullWrtStruct::EntryPtr zone); |
| 105 |
|
| 106 |
//! try to read the file zones position |
| 107 |
bool readFileZonePos(FullWrtStruct::EntryPtr zone); |
| 108 |
|
| 109 |
//! try to read the zone containing the data of each doc zone (ie. Zone0) |
| 110 |
bool readDocZoneData(FullWrtStruct::EntryPtr zone); |
| 111 |
|
| 112 |
//! try to read the zone which stores the structure of zone0, ... (ie. Zone1) |
| 113 |
bool readDocZoneStruct(FullWrtStruct::EntryPtr zone); |
| 114 |
|
| 115 |
//! try to read zone2, a zone which stores the document information zone, ... |
| 116 |
bool readDocInfo(FullWrtStruct::EntryPtr zone); |
| 117 |
|
| 118 |
//! try to read the end of zone2 (only v2) ? |
| 119 |
bool readEndDocInfo(FullWrtStruct::EntryPtr zone); |
| 120 |
|
| 121 |
//! try to read the list of citation (at the end of doc info) |
| 122 |
bool readCitationDocInfo(FullWrtStruct::EntryPtr zone); |
| 123 |
|
| 124 |
//! try read the print info zone |
| 125 |
bool readPrintInfo(FullWrtStruct::EntryPtr zone); |
| 126 |
|
| 127 |
// |
| 128 |
// interface to the graph parser |
| 129 |
// |
| 130 |
|
| 131 |
//! returns the page left top point ( in inches) |
| 132 |
MWAWVec2f getPageLeftTop() const; |
| 133 |
//! try to return a border corresponding to an id |
| 134 |
bool getBorder(int bId, FullWrtStruct::Border &border) const; |
| 135 |
|
| 136 |
// |
| 137 |
// interface to the text parser |
| 138 |
// |
| 139 |
|
| 140 |
//! try to send a footnote/endnote entry |
| 141 |
void sendText(int docId, libmwaw::SubDocumentType type, MWAWNote::Type which=MWAWNote::FootNote); |
| 142 |
//! try to send a graphic |
| 143 |
void sendGraphic(int docId); |
| 144 |
//! try to send a variable, in pratice do nothing |
| 145 |
void sendVariable(int docId); |
| 146 |
//! try to send a reference, in pratice do nothing |
| 147 |
void sendReference(int docId); |
| 148 |
//! ask the text parser to send a zone |
| 149 |
bool send(int fileId, MWAWColor fontColor=MWAWColor::black()); |
| 150 |
|
| 151 |
// |
| 152 |
// interface ( mainly debugging function) |
| 153 |
// |
| 154 |
|
| 155 |
//! returns the number of zone struct |
| 156 |
int getNumDocZoneStruct() const; |
| 157 |
/** returns a the type of a document zone ( mainly used for debugging) */ |
| 158 |
std::string getDocumentTypeName(int zId) const; |
| 159 |
|
| 160 |
// |
| 161 |
// low level |
| 162 |
// |
| 163 |
|
| 164 |
//! try to read the reference data |
| 165 |
bool readReferenceData(FullWrtStruct::EntryPtr zone); |
| 166 |
//! try to read the data of a zone which begins with a generic header |
| 167 |
bool readGenericDocData(FullWrtStruct::EntryPtr zone, FullWrtStruct::ZoneHeader &doc); |
| 168 |
|
| 169 |
protected: |
| 170 |
// |
| 171 |
// data |
| 172 |
// |
| 173 |
//! the state |
| 174 |
std::shared_ptr<FullWrtParserInternal::State> m_state; |
| 175 |
|
| 176 |
//! the graph parser |
| 177 |
std::shared_ptr<FullWrtGraph> m_graphParser; |
| 178 |
//! the text parser |
| 179 |
std::shared_ptr<FullWrtText> m_textParser; |
| 180 |
}; |
| 181 |
#endif |
| 182 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |