| 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 HanMac Word-K document |
| 36 |
*/ |
| 37 |
#ifndef HAN_MAC_WRD_K_PARSER |
| 38 |
# define HAN_MAC_WRD_K_PARSER |
| 39 |
|
| 40 |
#include <iostream> |
| 41 |
#include <string> |
| 42 |
#include <vector> |
| 43 |
|
| 44 |
#include <librevenge/librevenge.h> |
| 45 |
|
| 46 |
#include "MWAWDebug.hxx" |
| 47 |
#include "MWAWInputStream.hxx" |
| 48 |
|
| 49 |
#include "MWAWParser.hxx" |
| 50 |
|
| 51 |
namespace HanMacWrdKParserInternal |
| 52 |
{ |
| 53 |
struct State; |
| 54 |
class SubDocument; |
| 55 |
} |
| 56 |
|
| 57 |
//! Small class used to store the decoded zone of HanMacWrdKParser |
| 58 |
struct HanMacWrdKZone { |
| 59 |
//! constructor given an input and an asciiFile |
| 60 |
HanMacWrdKZone(MWAWInputStreamPtr const &input, libmwaw::DebugFile &asciiFile); |
| 61 |
//! constructor given an asciiFile (used for compressed zone) |
| 62 |
explicit HanMacWrdKZone(std::shared_ptr<libmwaw::DebugFile> const &asciiFile); |
| 63 |
//! destructor |
| 64 |
~HanMacWrdKZone(); |
| 65 |
|
| 66 |
//! returns the first position in the input |
| 67 |
long begin() const |
| 68 |
{ |
| 69 |
return m_asciiFilePtr ? 0 : m_filePos; |
| 70 |
} |
| 71 |
//! returns the last position in the input |
| 72 |
long end() const |
| 73 |
{ |
| 74 |
return m_asciiFilePtr ? long(m_data.size()) : m_endFilePos; |
| 75 |
} |
| 76 |
//! returns the zone size |
| 77 |
long length() const |
| 78 |
{ |
| 79 |
if (m_asciiFilePtr) return long(m_data.size()); |
| 80 |
return m_endFilePos-m_filePos; |
| 81 |
} |
| 82 |
//! returns true if the zone data exists |
| 83 |
bool valid() const |
| 84 |
{ |
| 85 |
return length() > 0; |
| 86 |
} |
| 87 |
|
| 88 |
// function to define the zone in the original file |
| 89 |
|
| 90 |
//! returns the file begin position |
| 91 |
long fileBeginPos() const |
| 92 |
{ |
| 93 |
return m_filePos; |
| 94 |
} |
| 95 |
//! returns the file begin position |
| 96 |
long fileEndPos() const |
| 97 |
{ |
| 98 |
return m_endFilePos; |
| 99 |
} |
| 100 |
//! sets the begin file pos |
| 101 |
void setFileBeginPos(long begPos) |
| 102 |
{ |
| 103 |
m_filePos = m_endFilePos = begPos; |
| 104 |
} |
| 105 |
//! sets the file length |
| 106 |
void setFileLength(long len) |
| 107 |
{ |
| 108 |
m_endFilePos = m_filePos+len; |
| 109 |
} |
| 110 |
//! sets the begin/end file pos |
| 111 |
void setFilePositions(long begPos, long endPos) |
| 112 |
{ |
| 113 |
m_filePos = begPos; |
| 114 |
m_endFilePos = endPos; |
| 115 |
} |
| 116 |
//! returns a pointer to the binary data |
| 117 |
librevenge::RVNGBinaryData &getBinaryData() |
| 118 |
{ |
| 119 |
return m_data; |
| 120 |
} |
| 121 |
//! returns the zone name |
| 122 |
std::string name() const |
| 123 |
{ |
| 124 |
return name(m_type); |
| 125 |
} |
| 126 |
//! returns the zone name |
| 127 |
static std::string name(int type); |
| 128 |
|
| 129 |
//! operator << |
| 130 |
friend std::ostream &operator<<(std::ostream &o, HanMacWrdKZone const &zone); |
| 131 |
|
| 132 |
//! returns the debug file |
| 133 |
libmwaw::DebugFile &ascii() const |
| 134 |
{ |
| 135 |
return *m_asciiFile; |
| 136 |
} |
| 137 |
|
| 138 |
//! the type : 1(text), .... |
| 139 |
int m_type; |
| 140 |
|
| 141 |
//! the zone id |
| 142 |
long m_id; |
| 143 |
|
| 144 |
//! the zone subId |
| 145 |
long m_subId; |
| 146 |
|
| 147 |
//! the main input |
| 148 |
MWAWInputStreamPtr m_input; |
| 149 |
|
| 150 |
//! some extra data |
| 151 |
std::string m_extra; |
| 152 |
|
| 153 |
//! true if the zone is sended |
| 154 |
mutable bool m_parsed; |
| 155 |
|
| 156 |
protected: |
| 157 |
//! the begin of the entry |
| 158 |
long m_filePos; |
| 159 |
|
| 160 |
//! the end of the entry |
| 161 |
long m_endFilePos; |
| 162 |
|
| 163 |
//! the storage (if needed) |
| 164 |
librevenge::RVNGBinaryData m_data; |
| 165 |
|
| 166 |
//! the debug file |
| 167 |
libmwaw::DebugFile *m_asciiFile; |
| 168 |
|
| 169 |
//! the file pointer |
| 170 |
std::shared_ptr<libmwaw::DebugFile> m_asciiFilePtr; |
| 171 |
|
| 172 |
private: |
| 173 |
HanMacWrdKZone(HanMacWrdKZone const &orig) = delete; |
| 174 |
HanMacWrdKZone &operator=(HanMacWrdKZone const &orig) = delete; |
| 175 |
}; |
| 176 |
|
| 177 |
class HanMacWrdKGraph; |
| 178 |
class HanMacWrdKText; |
| 179 |
|
| 180 |
/** \brief the main class to read a HanMac Word-K file |
| 181 |
* |
| 182 |
* |
| 183 |
* |
| 184 |
*/ |
| 185 |
class HanMacWrdKParser final : public MWAWTextParser |
| 186 |
{ |
| 187 |
friend class HanMacWrdKGraph; |
| 188 |
friend class HanMacWrdKText; |
| 189 |
friend class HanMacWrdKParserInternal::SubDocument; |
| 190 |
|
| 191 |
public: |
| 192 |
//! constructor |
| 193 |
HanMacWrdKParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 194 |
//! destructor |
| 195 |
~HanMacWrdKParser() final; |
| 196 |
|
| 197 |
//! checks if the document header is correct (or not) |
| 198 |
bool checkHeader(MWAWHeader *header, bool strict=false) final; |
| 199 |
|
| 200 |
// the main parse function |
| 201 |
void parse(librevenge::RVNGTextInterface *documentInterface) final; |
| 202 |
|
| 203 |
protected: |
| 204 |
//! inits all internal variables |
| 205 |
void init(); |
| 206 |
|
| 207 |
//! creates the listener which will be associated to the document |
| 208 |
void createDocument(librevenge::RVNGTextInterface *documentInterface); |
| 209 |
|
| 210 |
//! finds the different objects zones |
| 211 |
bool createZones(); |
| 212 |
|
| 213 |
//! returns the page left top point ( in inches) |
| 214 |
MWAWVec2f getPageLeftTop() const; |
| 215 |
|
| 216 |
//! adds a new page |
| 217 |
void newPage(int number); |
| 218 |
|
| 219 |
// interface with the text parser |
| 220 |
|
| 221 |
//! send a text zone |
| 222 |
bool sendText(long id, long subId, MWAWListenerPtr listener=MWAWListenerPtr()); |
| 223 |
|
| 224 |
//! check if we can send a textzone as graphic |
| 225 |
bool canSendTextAsGraphic(long id, long subId); |
| 226 |
|
| 227 |
// interface with the graph parser |
| 228 |
|
| 229 |
//! send a zone |
| 230 |
bool sendZone(long zId); |
| 231 |
//! returns the color associated with a pattern |
| 232 |
bool getColor(int colId, int patternId, MWAWColor &color) const; |
| 233 |
|
| 234 |
// |
| 235 |
// low level |
| 236 |
// |
| 237 |
|
| 238 |
/** try to read the zones list */ |
| 239 |
bool readZonesList(); |
| 240 |
/** try to read a generic zone */ |
| 241 |
bool readZone(std::shared_ptr<HanMacWrdKZone> zone); |
| 242 |
/** try to decode a zone */ |
| 243 |
std::shared_ptr<HanMacWrdKZone> decodeZone(std::shared_ptr<HanMacWrdKZone> zone); |
| 244 |
/** try to read a zone storing a list of ?, frameType*/ |
| 245 |
bool readFramesUnkn(std::shared_ptr<HanMacWrdKZone> zone); |
| 246 |
/** try to read a printinfo zone (type 7)*/ |
| 247 |
bool readPrintInfo(HanMacWrdKZone &zone); |
| 248 |
/** try to read a unknown zone of type 6*/ |
| 249 |
bool readZone6(std::shared_ptr<HanMacWrdKZone> zone); |
| 250 |
/** try to read a unknown zone of type 8*/ |
| 251 |
bool readZone8(std::shared_ptr<HanMacWrdKZone> zone); |
| 252 |
/** try to read a unknown zone of type a*/ |
| 253 |
bool readZonea(std::shared_ptr<HanMacWrdKZone> zone); |
| 254 |
/** try to read a unknown zone of type b*/ |
| 255 |
bool readZoneb(HanMacWrdKZone &zone); |
| 256 |
/** try to read a unknown zone of type c*/ |
| 257 |
bool readZonec(std::shared_ptr<HanMacWrdKZone> zone); |
| 258 |
|
| 259 |
protected: |
| 260 |
// |
| 261 |
// data |
| 262 |
// |
| 263 |
//! the state |
| 264 |
std::shared_ptr<HanMacWrdKParserInternal::State> m_state; |
| 265 |
|
| 266 |
//! the graph parser |
| 267 |
std::shared_ptr<HanMacWrdKGraph> m_graphParser; |
| 268 |
|
| 269 |
//! the text parser |
| 270 |
std::shared_ptr<HanMacWrdKText> m_textParser; |
| 271 |
}; |
| 272 |
#endif |
| 273 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |