HMWKParser.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 HMWK_PARSER
# define HMWK_PARSER
#include <iostream>
#include <string>
#include <vector>
#include <libwpd/libwpd.h>
#include "MWAWDebug.hxx"
#include "MWAWInputStream.hxx"
#include "MWAWParser.hxx"
namespace HMWKParserInternal
{
struct State;
class SubDocument;
}
struct HMWKZone {
HMWKZone(MWAWInputStreamPtr input, libmwaw::DebugFile &asciiFile);
HMWKZone(shared_ptr<libmwaw::DebugFile> asciiFile);
~HMWKZone();
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;
}
WPXBinaryData &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, HMWKZone const &zone);
libmwaw::DebugFile &ascii() {
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;
WPXBinaryData m_data;
libmwaw::DebugFile *m_asciiFile;
shared_ptr<libmwaw::DebugFile> m_asciiFilePtr;
private:
HMWKZone(HMWKZone const &orig);
HMWKZone &operator=(HMWKZone const &orig);
};
class HMWKGraph;
class HMWKText;
class HMWKParser : public MWAWParser
{
friend class HMWKGraph;
friend class HMWKText;
friend class HMWKParserInternal::SubDocument;
public:
HMWKParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
virtual ~HMWKParser();
bool checkHeader(MWAWHeader *header, bool strict=false);
// the main parse function
void parse(WPXDocumentInterface *documentInterface);
protected:
void init();
void createDocument(WPXDocumentInterface *documentInterface);
bool createZones();
Vec2f getPageLeftTop() const;
void newPage(int number);
// interface with the text parser
bool sendText(long id, long subId=0);
// interface with the graph parser
bool sendZone(long zId);
bool getColor(int colId, int patternId, MWAWColor &color) const;
//
// low level
//
bool readZonesList();
bool readZone(shared_ptr<HMWKZone> zone);
shared_ptr<HMWKZone> decodeZone(shared_ptr<HMWKZone> zone);
bool readFramesUnkn(shared_ptr<HMWKZone> zone);
bool readPrintInfo(HMWKZone &zone);
bool readZone6(shared_ptr<HMWKZone> zone);
bool readZone8(shared_ptr<HMWKZone> zone);
bool readZonea(shared_ptr<HMWKZone> zone);
bool readZoneb(HMWKZone &zone);
bool readZonec(shared_ptr<HMWKZone> zone);
protected:
//
// data
//
shared_ptr<HMWKParserInternal::State> m_state;
shared_ptr<HMWKGraph> m_graphParser;
shared_ptr<HMWKText> m_textParser;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
HMWKParser::m_textParser
shared_ptr< HMWKText > m_textParser
the text parser
Definition: HMWKParser.hxx:255
HMWKParser
the main class to read a HanMac Word-K file
Definition: HMWKParser.hxx:173
HMWKParser::readZonec
bool readZonec(shared_ptr< HMWKZone > zone)
try to read a unknown zone of type c
Definition: HMWKParser.cxx:871
MWAWHeader
a function used by MWAWDocument to store the version of document and the input
Definition: MWAWHeader.hxx:47
HMWKParser::getColor
bool getColor(int colId, int patternId, MWAWColor &color) const
returns the color associated with a pattern
Definition: HMWKParser.cxx:175
HMWKZone::m_extra
std::string m_extra
some extra data
Definition: HMWKParser.hxx:139
HMWKZone::m_subId
long m_subId
the zone subId
Definition: HMWKParser.hxx:133
MWAWParser.hxx
HMWKZone::m_input
MWAWInputStreamPtr m_input
the main input
Definition: HMWKParser.hxx:136
HMWKText
the main class to read the text part of HanMac Word file
Definition: HMWKText.hxx:61
libmwaw::DebugFile
an interface used to insert comment in a binary file, written in ascii form (if debug_with_files is n...
Definition: MWAWDebug.hxx:67
HMWKZone::m_asciiFile
libmwaw::DebugFile * m_asciiFile
the debug file
Definition: HMWKParser.hxx:155
HMWKParser::readZone8
bool readZone8(shared_ptr< HMWKZone > zone)
try to read a unknown zone of type 8
Definition: HMWKParser.cxx:736
HMWKZone::m_filePos
long m_filePos
the begin of the entry
Definition: HMWKParser.hxx:146
HMWKZone::name
std::string name() const
returns the zone name
Definition: HMWKParser.hxx:112
HMWKZone::m_parsed
bool m_parsed
true if the zone is sended
Definition: HMWKParser.hxx:142
HMWKParser::newPage
void newPage(int number)
adds a new page
Definition: HMWKParser.cxx:192
HMWKZone::getBinaryData
WPXBinaryData & getBinaryData()
returns a pointer to the binary data
Definition: HMWKParser.hxx:108
HMWKZone::~HMWKZone
~HMWKZone()
destructor
Definition: HMWKParser.cxx:1174
HMWKParser::readZonea
bool readZonea(shared_ptr< HMWKZone > zone)
try to read a unknown zone of type a
Definition: HMWKParser.cxx:769
HMWKGraph
the main class to read the graphic part of a HanMac Word file
Definition: HMWKGraph.hxx:77
MWAWColor
the class to store a color
Definition: libmwaw_internal.hxx:161
HMWKZone
Small class used to store the decoded zone of HMWKParser.
Definition: HMWKParser.hxx:58
HMWKParser::sendZone
bool sendZone(long zId)
send a zone
Definition: HMWKParser.cxx:168
HMWKParserInternal::SubDocument
Internal: the subdocument of a MWParser.
Definition: HMWKParser.cxx:84
HMWKParser::init
void init()
inits all internal variables
Definition: HMWKParser.cxx:146
HMWKParser::readPrintInfo
bool readPrintInfo(HMWKZone &zone)
try to read a printinfo zone (type 7)
Definition: HMWKParser.cxx:513
HMWKParser::parse
void parse(WPXDocumentInterface *documentInterface)
virtual function used to parse the input
Definition: HMWKParser.cxx:208
HMWKZone::valid
bool valid() const
returns true if the zone data exists
Definition: HMWKParser.hxx:80
HMWKParser::readZone
bool readZone(shared_ptr< HMWKZone > zone)
try to read a generic zone
Definition: HMWKParser.cxx:414
MWAWRSRCParserPtr
shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
a smart pointer of MWAWRSRCParser
Definition: libmwaw_internal.hxx:340
HMWKParser::~HMWKParser
virtual ~HMWKParser()
destructor
Definition: HMWKParser.cxx:142
HMWKZone::operator<<
friend std::ostream & operator<<(std::ostream &o, HMWKZone const &zone)
operator <<
Definition: HMWKParser.cxx:1180
HMWKZone::setFilePositions
void setFilePositions(long begPos, long endPos)
sets the begin/end file pos
Definition: HMWKParser.hxx:103
HMWKZone::m_type
int m_type
the type : 1(text), ....
Definition: HMWKParser.hxx:127
HMWKZone::HMWKZone
HMWKZone(MWAWInputStreamPtr input, libmwaw::DebugFile &asciiFile)
constructor given an input and an asciiFile
Definition: HMWKParser.cxx:1164
HMWKParser::m_graphParser
shared_ptr< HMWKGraph > m_graphParser
the graph parser
Definition: HMWKParser.hxx:252
HMWKZone::setFileBeginPos
void setFileBeginPos(long begPos)
sets the begin file pos
Definition: HMWKParser.hxx:95
HMWKZone::ascii
libmwaw::DebugFile & ascii()
returns the debug file
Definition: HMWKParser.hxx:122
HMWKZone::m_endFilePos
long m_endFilePos
the end of the entry
Definition: HMWKParser.hxx:149
HMWKZone::fileBeginPos
long fileBeginPos() const
returns the file begin position
Definition: HMWKParser.hxx:87
HMWKZone::fileEndPos
long fileEndPos() const
returns the file begin position
Definition: HMWKParser.hxx:91
HMWKZone::m_id
long m_id
the zone id
Definition: HMWKParser.hxx:130
HMWKParser::createDocument
void createDocument(WPXDocumentInterface *documentInterface)
creates the listener which will be associated to the document
Definition: HMWKParser.cxx:243
HMWKZone::setFileLength
void setFileLength(long len)
sets the file length
Definition: HMWKParser.hxx:99
MWAWInputStreamPtr
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:336
HMWKParser::readZoneb
bool readZoneb(HMWKZone &zone)
try to read a unknown zone of type b
Definition: HMWKParser.cxx:813
MWAWInputStream.hxx
MWAWDebug.hxx
HMWKParser::createZones
bool createZones()
finds the different objects zones
Definition: HMWKParser.cxx:290
HMWKParser::readZone6
bool readZone6(shared_ptr< HMWKZone > zone)
try to read a unknown zone of type 6
Definition: HMWKParser.cxx:692
HMWKZone::m_data
WPXBinaryData m_data
the storage (if needed)
Definition: HMWKParser.hxx:152
HMWKParser::HMWKParser
HMWKParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header)
constructor
Definition: HMWKParser.cxx:136
HMWKZone::length
long length() const
returns the zone size
Definition: HMWKParser.hxx:75
HMWKZone::end
long end() const
returns the last position in the input
Definition: HMWKParser.hxx:71
HMWKParser::checkHeader
bool checkHeader(MWAWHeader *header, bool strict=false)
checks if the document header is correct (or not)
Definition: HMWKParser.cxx:1061
HMWKParser::decodeZone
shared_ptr< HMWKZone > decodeZone(shared_ptr< HMWKZone > zone)
try to decode a zone
Definition: HMWKParser.cxx:954
HMWKZone::operator=
HMWKZone & operator=(HMWKZone const &orig)
MWAWParser
virtual class which defines the ancestor of all main zone parser
Definition: MWAWParser.hxx:87
HMWKZone::m_asciiFilePtr
shared_ptr< libmwaw::DebugFile > m_asciiFilePtr
the file pointer
Definition: HMWKParser.hxx:158
HMWKParser::readFramesUnkn
bool readFramesUnkn(shared_ptr< HMWKZone > zone)
try to read a zone storing a list of ?, frameType
Definition: HMWKParser.cxx:623
Vec2< float >
HMWKParser::getPageLeftTop
Vec2f getPageLeftTop() const
returns the page left top point ( in inches)
Definition: HMWKParser.cxx:183
HMWKParser::m_state
shared_ptr< HMWKParserInternal::State > m_state
the state
Definition: HMWKParser.hxx:249
HMWKParser::sendText
bool sendText(long id, long subId=0)
send a text zone (not implemented)
Definition: HMWKParser.cxx:163
HMWKParser::readZonesList
bool readZonesList()
try to read the zones list
Definition: HMWKParser.cxx:321
HMWKZone::begin
long begin() const
returns the first position in the input
Definition: HMWKParser.hxx:67