HanMacWrdKParser.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 -*- */
/* libmwaw
* 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.
*/
/*
* Parser to convert HanMac Word-K document
*/
#ifndef HAN_MAC_WRD_K_PARSER
# define HAN_MAC_WRD_K_PARSER
#include <iostream>
#include <string>
#include <vector>
#include <librevenge/librevenge.h>
#include "MWAWDebug.hxx"
#include "MWAWInputStream.hxx"
#include "MWAWParser.hxx"
namespace HanMacWrdKParserInternal
{
struct State;
class SubDocument;
}
struct HanMacWrdKZone {
HanMacWrdKZone(MWAWInputStreamPtr const &input, libmwaw::DebugFile &asciiFile);
explicit HanMacWrdKZone(std::shared_ptr<libmwaw::DebugFile> const &asciiFile);
~HanMacWrdKZone();
long begin() const
{
return m_asciiFilePtr ? 0 : m_filePos;
}
long end() const
{
return m_asciiFilePtr ? long(m_data.size()) : m_endFilePos;
}
long length() const
{
if (m_asciiFilePtr) return long(m_data.size());
return m_endFilePos-m_filePos;
}
bool valid() const
{
return length() > 0;
}
// function to define the zone in the original file
long fileBeginPos() const
{
return m_filePos;
}
long fileEndPos() const
{
return m_endFilePos;
}
void setFileBeginPos(long begPos)
{
m_filePos = m_endFilePos = begPos;
}
void setFileLength(long len)
{
m_endFilePos = m_filePos+len;
}
void setFilePositions(long begPos, long endPos)
{
m_filePos = begPos;
m_endFilePos = endPos;
}
librevenge::RVNGBinaryData &getBinaryData()
{
return m_data;
}
std::string name() const
{
return name(m_type);
}
static std::string name(int type);
friend std::ostream &operator<<(std::ostream &o, HanMacWrdKZone const &zone);
libmwaw::DebugFile &ascii() const
{
return *m_asciiFile;
}
int m_type;
long m_id;
long m_subId;
MWAWInputStreamPtr m_input;
std::string m_extra;
mutable bool m_parsed;
protected:
long m_filePos;
long m_endFilePos;
librevenge::RVNGBinaryData m_data;
libmwaw::DebugFile *m_asciiFile;
std::shared_ptr<libmwaw::DebugFile> m_asciiFilePtr;
private:
HanMacWrdKZone(HanMacWrdKZone const &orig) = delete;
HanMacWrdKZone &operator=(HanMacWrdKZone const &orig) = delete;
};
class HanMacWrdKGraph;
class HanMacWrdKText;
class HanMacWrdKParser final : public MWAWTextParser
{
friend class HanMacWrdKGraph;
friend class HanMacWrdKText;
friend class HanMacWrdKParserInternal::SubDocument;
public:
HanMacWrdKParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
~HanMacWrdKParser() final;
bool checkHeader(MWAWHeader *header, bool strict=false) final;
// the main parse function
void parse(librevenge::RVNGTextInterface *documentInterface) final;
protected:
void init();
void createDocument(librevenge::RVNGTextInterface *documentInterface);
bool createZones();
MWAWVec2f getPageLeftTop() const;
void newPage(int number);
// interface with the text parser
bool sendText(long id, long subId, MWAWListenerPtr listener=MWAWListenerPtr());
bool canSendTextAsGraphic(long id, long subId);
// interface with the graph parser
bool sendZone(long zId);
bool getColor(int colId, int patternId, MWAWColor &color) const;
//
// low level
//
bool readZonesList();
bool readZone(std::shared_ptr<HanMacWrdKZone> zone);
std::shared_ptr<HanMacWrdKZone> decodeZone(std::shared_ptr<HanMacWrdKZone> zone);
bool readFramesUnkn(std::shared_ptr<HanMacWrdKZone> zone);
bool readPrintInfo(HanMacWrdKZone &zone);
bool readZone6(std::shared_ptr<HanMacWrdKZone> zone);
bool readZone8(std::shared_ptr<HanMacWrdKZone> zone);
bool readZonea(std::shared_ptr<HanMacWrdKZone> zone);
bool readZoneb(HanMacWrdKZone &zone);
bool readZonec(std::shared_ptr<HanMacWrdKZone> zone);
protected:
//
// data
//
std::shared_ptr<HanMacWrdKParserInternal::State> m_state;
std::shared_ptr<HanMacWrdKGraph> m_graphParser;
std::shared_ptr<HanMacWrdKText> m_textParser;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWDebug.hxx
MWAWInputStream.hxx
MWAWParser.hxx
HanMacWrdKGraph
the main class to read the graphic part of a HanMac Word file
Definition HanMacWrdKGraph.hxx:78
HanMacWrdKParserInternal::SubDocument
Internal: the subdocument of a HanMacWrdKParser.
Definition HanMacWrdKParser.cxx:91
HanMacWrdKParser::~HanMacWrdKParser
~HanMacWrdKParser() final
destructor
Definition HanMacWrdKParser.cxx:151
HanMacWrdKParser::readZone8
bool readZone8(std::shared_ptr< HanMacWrdKZone > zone)
try to read a unknown zone of type 8
Definition HanMacWrdKParser.cxx:754
HanMacWrdKParser::decodeZone
std::shared_ptr< HanMacWrdKZone > decodeZone(std::shared_ptr< HanMacWrdKZone > zone)
try to decode a zone
Definition HanMacWrdKParser.cxx:971
HanMacWrdKParser::init
void init()
inits all internal variables
Definition HanMacWrdKParser.cxx:155
HanMacWrdKParser::parse
void parse(librevenge::RVNGTextInterface *documentInterface) final
virtual function used to parse the input
Definition HanMacWrdKParser.cxx:222
HanMacWrdKParser::sendText
bool sendText(long id, long subId, MWAWListenerPtr listener=MWAWListenerPtr())
send a text zone
Definition HanMacWrdKParser.cxx:172
HanMacWrdKParser::HanMacWrdKText
friend class HanMacWrdKText
Definition HanMacWrdKParser.hxx:188
HanMacWrdKParser::readZonesList
bool readZonesList()
try to read the zones list
Definition HanMacWrdKParser.cxx:336
HanMacWrdKParser::m_state
std::shared_ptr< HanMacWrdKParserInternal::State > m_state
the state
Definition HanMacWrdKParser.hxx:264
HanMacWrdKParser::checkHeader
bool checkHeader(MWAWHeader *header, bool strict=false) final
checks if the document header is correct (or not)
Definition HanMacWrdKParser.cxx:1082
HanMacWrdKParser::HanMacWrdKGraph
friend class HanMacWrdKGraph
Definition HanMacWrdKParser.hxx:187
HanMacWrdKParser::readPrintInfo
bool readPrintInfo(HanMacWrdKZone &zone)
try to read a printinfo zone (type 7)
Definition HanMacWrdKParser.cxx:530
HanMacWrdKParser::getColor
bool getColor(int colId, int patternId, MWAWColor &color) const
returns the color associated with a pattern
Definition HanMacWrdKParser.cxx:189
HanMacWrdKParser::readFramesUnkn
bool readFramesUnkn(std::shared_ptr< HanMacWrdKZone > zone)
try to read a zone storing a list of ?
Definition HanMacWrdKParser.cxx:641
HanMacWrdKParser::HanMacWrdKParser
HanMacWrdKParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
constructor
Definition HanMacWrdKParser.cxx:142
HanMacWrdKParser::getPageLeftTop
MWAWVec2f getPageLeftTop() const
returns the page left top point ( in inches)
Definition HanMacWrdKParser.cxx:197
HanMacWrdKParser::readZone6
bool readZone6(std::shared_ptr< HanMacWrdKZone > zone)
try to read a unknown zone of type 6
Definition HanMacWrdKParser.cxx:710
HanMacWrdKParser::createDocument
void createDocument(librevenge::RVNGTextInterface *documentInterface)
creates the listener which will be associated to the document
Definition HanMacWrdKParser.cxx:258
HanMacWrdKParser::createZones
bool createZones()
finds the different objects zones
Definition HanMacWrdKParser.cxx:305
HanMacWrdKParser::readZonec
bool readZonec(std::shared_ptr< HanMacWrdKZone > zone)
try to read a unknown zone of type c
Definition HanMacWrdKParser.cxx:889
HanMacWrdKParser::m_textParser
std::shared_ptr< HanMacWrdKText > m_textParser
the text parser
Definition HanMacWrdKParser.hxx:270
HanMacWrdKParser::newPage
void newPage(int number)
adds a new page
Definition HanMacWrdKParser.cxx:206
HanMacWrdKParser::readZonea
bool readZonea(std::shared_ptr< HanMacWrdKZone > zone)
try to read a unknown zone of type a
Definition HanMacWrdKParser.cxx:787
HanMacWrdKParser::canSendTextAsGraphic
bool canSendTextAsGraphic(long id, long subId)
check if we can send a textzone as graphic
Definition HanMacWrdKParser.cxx:177
HanMacWrdKParser::readZoneb
bool readZoneb(HanMacWrdKZone &zone)
try to read a unknown zone of type b
Definition HanMacWrdKParser.cxx:831
HanMacWrdKParser::sendZone
bool sendZone(long zId)
send a zone
Definition HanMacWrdKParser.cxx:182
HanMacWrdKParser::m_graphParser
std::shared_ptr< HanMacWrdKGraph > m_graphParser
the graph parser
Definition HanMacWrdKParser.hxx:267
HanMacWrdKParser::readZone
bool readZone(std::shared_ptr< HanMacWrdKZone > zone)
try to read a generic zone
Definition HanMacWrdKParser.cxx:430
HanMacWrdKText
the main class to read the text part of HanMac Word file
Definition HanMacWrdKText.hxx:62
MWAWHeader
a function used by MWAWDocument to store the version of document
Definition MWAWHeader.hxx:57
MWAWTextParser::MWAWTextParser
MWAWTextParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
constructor (protected)
Definition MWAWParser.hxx:307
libmwaw::DebugFile
Definition MWAWDebug.hxx:66
MWAWRSRCParserPtr
std::shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
a smart pointer of MWAWRSRCParser
Definition libmwaw_internal.hxx:561
MWAWListenerPtr
std::shared_ptr< MWAWListener > MWAWListenerPtr
a smart pointer of MWAWListener
Definition libmwaw_internal.hxx:553
MWAWVec2f
MWAWVec2< float > MWAWVec2f
MWAWVec2 of float.
Definition libmwaw_internal.hxx:842
MWAWInputStreamPtr
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition libmwaw_internal.hxx:551
HanMacWrdKParserInternal
Internal: the structures of a HanMacWrdKParser.
Definition HanMacWrdKParser.cxx:63
librevenge
Definition MWAWDocument.hxx:57
HanMacWrdKParserInternal::State
Internal: the state of a HanMacWrdKParser.
Definition HanMacWrdKParser.cxx:66
HanMacWrdKZone
Small class used to store the decoded zone of HanMacWrdKParser.
Definition HanMacWrdKParser.hxx:58
HanMacWrdKZone::m_endFilePos
long m_endFilePos
the end of the entry
Definition HanMacWrdKParser.hxx:161
HanMacWrdKZone::m_data
librevenge::RVNGBinaryData m_data
the storage (if needed)
Definition HanMacWrdKParser.hxx:164
HanMacWrdKZone::HanMacWrdKZone
HanMacWrdKZone(HanMacWrdKZone const &orig)=delete
HanMacWrdKZone::fileEndPos
long fileEndPos() const
returns the file begin position
Definition HanMacWrdKParser.hxx:96
HanMacWrdKZone::begin
long begin() const
returns the first position in the input
Definition HanMacWrdKParser.hxx:67
HanMacWrdKZone::ascii
libmwaw::DebugFile & ascii() const
returns the debug file
Definition HanMacWrdKParser.hxx:133
HanMacWrdKZone::m_parsed
bool m_parsed
true if the zone is sended
Definition HanMacWrdKParser.hxx:154
HanMacWrdKZone::name
std::string name() const
returns the zone name
Definition HanMacWrdKParser.hxx:122
HanMacWrdKZone::m_type
int m_type
the type : 1(text), ....
Definition HanMacWrdKParser.hxx:139
HanMacWrdKZone::~HanMacWrdKZone
~HanMacWrdKZone()
destructor
Definition HanMacWrdKParser.cxx:1215
HanMacWrdKZone::setFileBeginPos
void setFileBeginPos(long begPos)
sets the begin file pos
Definition HanMacWrdKParser.hxx:101
HanMacWrdKZone::valid
bool valid() const
returns true if the zone data exists
Definition HanMacWrdKParser.hxx:83
HanMacWrdKZone::m_asciiFilePtr
std::shared_ptr< libmwaw::DebugFile > m_asciiFilePtr
the file pointer
Definition HanMacWrdKParser.hxx:170
HanMacWrdKZone::m_asciiFile
libmwaw::DebugFile * m_asciiFile
the debug file
Definition HanMacWrdKParser.hxx:167
HanMacWrdKZone::setFilePositions
void setFilePositions(long begPos, long endPos)
sets the begin/end file pos
Definition HanMacWrdKParser.hxx:111
HanMacWrdKZone::operator=
HanMacWrdKZone & operator=(HanMacWrdKZone const &orig)=delete
HanMacWrdKZone::length
long length() const
returns the zone size
Definition HanMacWrdKParser.hxx:77
HanMacWrdKZone::m_filePos
long m_filePos
the begin of the entry
Definition HanMacWrdKParser.hxx:158
HanMacWrdKZone::HanMacWrdKZone
HanMacWrdKZone(MWAWInputStreamPtr const &input, libmwaw::DebugFile &asciiFile)
constructor given an input and an asciiFile
Definition HanMacWrdKParser.cxx:1185
HanMacWrdKZone::end
long end() const
returns the last position in the input
Definition HanMacWrdKParser.hxx:72
HanMacWrdKZone::fileBeginPos
long fileBeginPos() const
returns the file begin position
Definition HanMacWrdKParser.hxx:91
HanMacWrdKZone::m_extra
std::string m_extra
some extra data
Definition HanMacWrdKParser.hxx:151
HanMacWrdKZone::m_id
long m_id
the zone id
Definition HanMacWrdKParser.hxx:142
HanMacWrdKZone::m_subId
long m_subId
the zone subId
Definition HanMacWrdKParser.hxx:145
HanMacWrdKZone::operator<<
friend std::ostream & operator<<(std::ostream &o, HanMacWrdKZone const &zone)
operator <<
Definition HanMacWrdKParser.cxx:1221
HanMacWrdKZone::setFileLength
void setFileLength(long len)
sets the file length
Definition HanMacWrdKParser.hxx:106
HanMacWrdKZone::m_input
MWAWInputStreamPtr m_input
the main input
Definition HanMacWrdKParser.hxx:148
HanMacWrdKZone::getBinaryData
librevenge::RVNGBinaryData & getBinaryData()
returns a pointer to the binary data
Definition HanMacWrdKParser.hxx:117
MWAWColor
the class to store a color
Definition libmwaw_internal.hxx:192