MRWParser.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 Mariner Write document
*/
#ifndef MRW_PARSER
# define MRW_PARSER
#include <iostream>
#include <string>
#include <vector>
#include <libwpd/libwpd.h>
class WPXBinaryData;
#include "MWAWDebug.hxx"
#include "MWAWEntry.hxx"
#include "MWAWInputStream.hxx"
#include "MWAWParser.hxx"
namespace MRWParserInternal
{
struct State;
class SubDocument;
}
class MRWGraph;
class MRWText;
struct MRWEntry : public MWAWEntry {
MRWEntry() : MWAWEntry(), m_fileType(0), m_N(0), m_value(0) {
}
std::string name() const;
friend std::ostream &operator<< (std::ostream &o, MRWEntry const &ent) {
if (ent.m_N || ent.m_value || ent.m_extra.length()) {
o << "[";
if (ent.m_N) o << "N=" << ent.m_N << ",";
if (ent.m_value) o << "unkn=" << ent.m_value << ",";
if (ent.m_extra.length()) o << ent.m_extra;
o << "],";
}
return o;
}
int m_fileType;
int m_N;
int m_value;
};
struct MRWStruct {
MRWStruct() : m_filePos(-1), m_pos(), m_type(-1), m_data() {
}
friend std::ostream &operator<<(std::ostream &o, MRWStruct const &dt);
int numValues() const {
return int(m_data.size());
}
bool isBasic() const {
return (m_type==1 || m_type==2) && m_data.size()<=1;
}
long value(int i) const;
long m_filePos;
MWAWEntry m_pos;
int m_type;
std::vector<long> m_data;
};
class MRWParser : public MWAWParser
{
friend class MRWGraph;
friend class MRWText;
friend class MRWParserInternal::SubDocument;
public:
MRWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header);
virtual ~MRWParser();
bool checkHeader(MWAWHeader *header, bool strict=false);
// the main parse function
void parse(WPXDocumentInterface *documentInterface);
protected:
void init();
void createDocument(WPXDocumentInterface *documentInterface);
bool createZones();
bool readZone(int &actZone, bool onlyTest=false);
Vec2f getPageLeftTop() const;
MWAWSection getSection(int zoneId) const;
void newPage(int number);
// interface with the text parser
int getZoneId(uint32_t fileId, bool &endNote);
void sendText(int zoneId);
// interface with the graph parser
float getPatternPercent(int id) const;
void sendToken(int zoneId, long tokenId, MWAWFont const &actFont);
//
// low level
//
bool readEntryHeader(MRWEntry &entry);
bool decodeZone(std::vector<MRWStruct> &dataList, long numData=999999);
bool readSeparator(MRWEntry const &entry);
bool readZoneDim(MRWEntry const &entry, int zoneId);
bool readZoneHeader(MRWEntry const &entry, int zoneId, bool onlyTest);
bool readZoneb(MRWEntry const &entry, int zoneId);
bool readZonec(MRWEntry const &entry, int zoneId);
bool readZone13(MRWEntry const &entry, int zoneId);
bool readDocInfo(MRWEntry const &entry, int zoneId);
bool readPrintInfo(MRWEntry const &entry);
bool readCPRT(MRWEntry const &entry);
bool readNumbersString(int num, std::vector<long> &res);
protected:
//
// data
//
shared_ptr<MRWParserInternal::State> m_state;
bool m_pageMarginsSpanSet;
shared_ptr<MRWGraph> m_graphParser;
shared_ptr<MRWText> m_textParser;
};
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MRWParser::createZones
bool createZones()
finds the different objects zones
Definition: MRWParser.cxx:444
MRWParser::readNumbersString
bool readNumbersString(int num, std::vector< long > &res)
try to read a number or a list of number entries
Definition: MRWParser.cxx:1343
MWAWHeader
a function used by MWAWDocument to store the version of document and the input
Definition: MWAWHeader.hxx:47
MRWParser::getZoneId
int getZoneId(uint32_t fileId, bool &endNote)
return a zoneid corresponding to a fileId (or -1) and set the endnote flag
Definition: MRWParser.cxx:285
MRWParser
the main class to read a Mariner Write file
Definition: MRWParser.hxx:121
MRWParser::parse
void parse(WPXDocumentInterface *documentInterface)
virtual function used to parse the input
Definition: MRWParser.cxx:322
MRWParser::MRWParser
MRWParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header)
constructor
Definition: MRWParser.cxx:226
MWAWParser.hxx
MRWStruct::numValues
int numValues() const
returns the number of values
Definition: MRWParser.hxx:97
MWAWEntry.hxx
MRWParser::readZoneDim
bool readZoneDim(MRWEntry const &entry, int zoneId)
try to read the zone dimension ( normal and with margin )
Definition: MRWParser.cxx:821
MRWStruct::isBasic
bool isBasic() const
returns true if this corresponds to a simple container
Definition: MRWParser.hxx:101
MRWParser::checkHeader
bool checkHeader(MWAWHeader *header, bool strict=false)
checks if the document header is correct (or not)
Definition: MRWParser.cxx:1466
MRWStruct::m_data
std::vector< long > m_data
the data block
Definition: MRWParser.hxx:113
MRWParser::createDocument
void createDocument(WPXDocumentInterface *documentInterface)
creates the listener which will be associated to the document
Definition: MRWParser.cxx:358
MRWParser::getSection
MWAWSection getSection(int zoneId) const
returns the section information corresponding to a zone
Definition: MRWParser.cxx:259
MRWParser::readZonec
bool readZonec(MRWEntry const &entry, int zoneId)
try to read a unknown zone of 9 int
Definition: MRWParser.cxx:1091
MRWParser::readEntryHeader
bool readEntryHeader(MRWEntry &entry)
try to read an entry header
Definition: MRWParser.cxx:1318
MRWParser::readZoneHeader
bool readZoneHeader(MRWEntry const &entry, int zoneId, bool onlyTest)
try to read the zone header
Definition: MRWParser.cxx:618
MRWGraph
the main class to read the graphic part of a Mariner Write file
Definition: MRWGraph.hxx:68
MRWEntry::operator<<
friend std::ostream & operator<<(std::ostream &o, MRWEntry const &ent)
operator<<
Definition: MRWParser.hxx:71
MRWStruct::operator<<
friend std::ostream & operator<<(std::ostream &o, MRWStruct const &dt)
operator<<
Definition: MRWParser.cxx:1559
MRWParser::readZone13
bool readZone13(MRWEntry const &entry, int zoneId)
try to read a unknown zone of 23 int
Definition: MRWParser.cxx:1138
MRWParser::~MRWParser
virtual ~MRWParser()
destructor
Definition: MRWParser.cxx:232
MWAWRSRCParserPtr
shared_ptr< MWAWRSRCParser > MWAWRSRCParserPtr
a smart pointer of MWAWRSRCParser
Definition: libmwaw_internal.hxx:340
MRWParser::newPage
void newPage(int number)
adds a new page
Definition: MRWParser.cxx:269
MRWParser::readCPRT
bool readCPRT(MRWEntry const &entry)
try to read a xml printinfo zone
Definition: MRWParser.cxx:1233
MRWStruct::value
long value(int i) const
returns the ith value (or 0 if it does not exists )
Definition: MRWParser.cxx:1549
MRWParser::readDocInfo
bool readDocInfo(MRWEntry const &entry, int zoneId)
try to read the doc info zone
Definition: MRWParser.cxx:901
MRWParser::m_pageMarginsSpanSet
bool m_pageMarginsSpanSet
a flag to know if page margins span are set
Definition: MRWParser.hxx:211
MRWEntry::MRWEntry
MRWEntry()
constructor
Definition: MRWParser.hxx:66
MRWStruct::m_type
int m_type
the data type
Definition: MRWParser.hxx:111
MRWEntry::name
std::string name() const
returns the entry name;
Definition: MRWParser.cxx:1496
MWAWEntry::m_extra
std::string m_extra
an extra string
Definition: MWAWEntry.hxx:172
MRWParser::readZone
bool readZone(int &actZone, bool onlyTest=false)
try to read a zone
Definition: MRWParser.cxx:456
MRWEntry
a entry to store a zone structure
Definition: MRWParser.hxx:64
MRWParser::decodeZone
bool decodeZone(std::vector< MRWStruct > &dataList, long numData=999999)
try to decode a zone
Definition: MRWParser.cxx:1401
MRWEntry::m_N
int m_N
the number of value
Definition: MRWParser.hxx:84
MWAWSection
a class which stores section properties
Definition: MWAWSection.hxx:45
MRWEntry::m_fileType
int m_fileType
the entry type
Definition: MRWParser.hxx:82
MWAWInputStreamPtr
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:336
MRWStruct::m_pos
MWAWEntry m_pos
the file data position (for type=0 data )
Definition: MRWParser.hxx:109
MRWEntry::m_value
int m_value
a unknown value
Definition: MRWParser.hxx:86
MWAWInputStream.hxx
MWAWDebug.hxx
MRWParser::m_graphParser
shared_ptr< MRWGraph > m_graphParser
the graph parser
Definition: MRWParser.hxx:214
MRWParser::sendToken
void sendToken(int zoneId, long tokenId, MWAWFont const &actFont)
ask the graph parser to send a token
Definition: MRWParser.cxx:311
MRWParser::getPageLeftTop
Vec2f getPageLeftTop() const
returns the page left top point ( in inches)
Definition: MRWParser.cxx:253
MRWParser::readSeparator
bool readSeparator(MRWEntry const &entry)
try to read the separator of differents part
Definition: MRWParser.cxx:589
MRWParser::m_state
shared_ptr< MRWParserInternal::State > m_state
the state
Definition: MRWParser.hxx:208
MRWParser::sendText
void sendText(int zoneId)
ask the text parser to send a zone
Definition: MRWParser.cxx:298
MWAWParser
virtual class which defines the ancestor of all main zone parser
Definition: MWAWParser.hxx:87
MWAWEntry
basic class to store an entry in a file This contained :
Definition: MWAWEntry.hxx:46
MRWText
the main class to read the text part of Mariner Write file
Definition: MRWText.hxx:60
MRWParser::getPatternPercent
float getPatternPercent(int id) const
return the pattern percent which corresponds to an id (or -1)
Definition: MRWParser.cxx:306
Vec2< float >
MRWStruct::MRWStruct
MRWStruct()
constructor
Definition: MRWParser.hxx:92
MRWParser::init
void init()
inits all internal variables
Definition: MRWParser.cxx:236
MRWParser::m_textParser
shared_ptr< MRWText > m_textParser
the text parser
Definition: MRWParser.hxx:217
MRWStruct
Internal: a struct used to read some field.
Definition: MRWParser.hxx:90
MRWParser::readZoneb
bool readZoneb(MRWEntry const &entry, int zoneId)
try to read a unknown zone : one by separator?, borderdim?
Definition: MRWParser.cxx:1051
MRWParserInternal::SubDocument
Internal: the subdocument of a MWParser.
Definition: MRWParser.cxx:179
MRWStruct::m_filePos
long m_filePos
the file position where the field description begin
Definition: MRWParser.hxx:107
MRWParser::readPrintInfo
bool readPrintInfo(MRWEntry const &entry)
try to read a printinfo zone
Definition: MRWParser.cxx:1259