QXPParser.h
Go to the documentation of this file.
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* This file is part of the libqxp project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef QXPPARSER_H_INCLUDED
#define QXPPARSER_H_INCLUDED
#include "libqxp_utils.h"
#include "QXPBlockParser.h"
#include "QXPTextParser.h"
#include "QXPTypes.h"
#include <deque>
#include <functional>
#include <map>
#include <set>
#include <vector>
namespace libqxp
{
class QXPCollector;
class QXPHeader;
class QXPParser
{
// disable copying
QXPParser(const QXPParser &other) = delete;
QXPParser &operator=(const QXPParser &other) = delete;
public:
QXPParser(const std::shared_ptr<librevenge::RVNGInputStream> &input, librevenge::RVNGDrawingInterface *painter, const std::shared_ptr<QXPHeader> &header);
virtual ~QXPParser() = default;
bool parse();
protected:
const std::shared_ptr<librevenge::RVNGInputStream> m_input;
librevenge::RVNGDrawingInterface *m_painter;
const bool be; // big endian
QXPBlockParser m_blockParser;
QXPTextParser m_textParser;
std::map<unsigned, Color> m_colors;
std::map<int, std::string> m_fonts;
std::vector<std::shared_ptr<CharFormat>> m_charFormats;
std::vector<std::shared_ptr<ParagraphFormat>> m_paragraphFormats;
std::map<unsigned, LineStyle> m_lineStyles;
std::vector<Arrow> m_arrows;
std::deque<std::shared_ptr<HJ>> m_hjs;
std::set<unsigned> m_groupObjects;
Color getColor(unsigned id, Color defaultColor = Color(0, 0, 0)) const;
const LineStyle *getLineStyle(unsigned id) const;
std::string getFont(int id, std::string defaultFont = "Arial") const;
void convertCharFormatFlags(unsigned flags, CharFormat &format);
TabStopType convertTabStopType(unsigned type);
virtual bool parseDocument(const std::shared_ptr<librevenge::RVNGInputStream> &docStream, QXPCollector &collector) = 0;
virtual bool parsePages(const std::shared_ptr<librevenge::RVNGInputStream> &stream, QXPCollector &collector) = 0;
void skipRecord(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
void parseFonts(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
void parseHJs(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
void parseCharFormats(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
void parseCommonCharFormatProps(const std::shared_ptr<librevenge::RVNGInputStream> &stream, CharFormat &result);
void parseHJProps(const std::shared_ptr<librevenge::RVNGInputStream> &stream, HJ &result);
TabStop parseTabStop(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
void parseParagraphFormats(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
virtual CharFormat parseCharFormat(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
virtual ParagraphFormat parseParagraphFormat(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
virtual std::shared_ptr<HJ> parseHJ(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
void parseCollection(const std::shared_ptr<librevenge::RVNGInputStream>stream, std::function<void()> itemHandler);
std::vector<PageSettings> parsePageSettings(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
std::shared_ptr<Text> parseText(unsigned index, unsigned linkId, QXPCollector &collector);
uint32_t readRecordEndOffset(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
uint8_t readColorComp(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
Rect readObjectBBox(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
Gradient readGradient(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const Color &color1);
HorizontalAlignment readHorAlign(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
VerticalAlignment readVertAlign(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
Point readYX(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
std::shared_ptr<ParagraphRule> readParagraphRule(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
uint8_t readParagraphFlags(const std::shared_ptr<librevenge::RVNGInputStream> &stream, bool &incrementalLeading, bool &ruleAbove, bool &ruleBelow);
uint8_t readObjectFlags(const std::shared_ptr<librevenge::RVNGInputStream> &stream, bool &noColor);
void readGroupElements(const std::shared_ptr<librevenge::RVNGInputStream> &stream, unsigned count, unsigned objectsCount, unsigned index, std::vector<unsigned> &elements);
void setArrow(const unsigned index, Frame &frame) const;
void skipFileInfo(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
private:
const std::shared_ptr<QXPHeader> m_header;
};
}
#endif // QXPPARSER_H_INCLUDED
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
QXPBlockParser.h
QXPTextParser.h
QXPTypes.h
libqxp::QXPBlockParser
Definition QXPBlockParser.h:21
libqxp::QXPCollector
Definition QXPCollector.h:28
libqxp::QXPHeader
Definition QXPHeader.h:41
libqxp::QXPParser::m_fonts
std::map< int, std::string > m_fonts
Definition QXPParser.h:51
libqxp::QXPParser::readObjectBBox
Rect readObjectBBox(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:329
libqxp::QXPParser::m_textParser
QXPTextParser m_textParser
Definition QXPParser.h:48
libqxp::QXPParser::m_input
const std::shared_ptr< librevenge::RVNGInputStream > m_input
Definition QXPParser.h:43
libqxp::QXPParser::m_hjs
std::deque< std::shared_ptr< HJ > > m_hjs
Definition QXPParser.h:56
libqxp::QXPParser::readParagraphRule
std::shared_ptr< ParagraphRule > readParagraphRule(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:440
libqxp::QXPParser::readColorComp
uint8_t readColorComp(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:324
libqxp::QXPParser::parseHJ
virtual std::shared_ptr< HJ > parseHJ(const std::shared_ptr< librevenge::RVNGInputStream > &stream)=0
libqxp::QXPParser::skipRecord
void skipRecord(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:116
libqxp::QXPParser::convertTabStopType
TabStopType convertTabStopType(unsigned type)
Definition QXPParser.cpp:542
libqxp::QXPParser::readGroupElements
void readGroupElements(const std::shared_ptr< librevenge::RVNGInputStream > &stream, unsigned count, unsigned objectsCount, unsigned index, std::vector< unsigned > &elements)
Definition QXPParser.cpp:560
libqxp::QXPParser::readVertAlign
VerticalAlignment readVertAlign(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:413
libqxp::QXPParser::skipFileInfo
void skipFileInfo(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:517
libqxp::QXPParser::getColor
Color getColor(unsigned id, Color defaultColor=Color(0, 0, 0)) const
Definition QXPParser.cpp:83
libqxp::QXPParser::parseParagraphFormat
virtual ParagraphFormat parseParagraphFormat(const std::shared_ptr< librevenge::RVNGInputStream > &stream)=0
libqxp::QXPParser::convertCharFormatFlags
void convertCharFormatFlags(unsigned flags, CharFormat &format)
Definition QXPParser.cpp:526
libqxp::QXPParser::m_header
const std::shared_ptr< QXPHeader > m_header
Definition QXPParser.h:104
libqxp::QXPParser::getFont
std::string getFont(int id, std::string defaultFont="Arial") const
Definition QXPParser.cpp:105
libqxp::QXPParser::readGradient
Gradient readGradient(const std::shared_ptr< librevenge::RVNGInputStream > &stream, const Color &color1)
Definition QXPParser.cpp:339
libqxp::QXPParser::m_lineStyles
std::map< unsigned, LineStyle > m_lineStyles
Definition QXPParser.h:54
libqxp::QXPParser::parseCollection
void parseCollection(const std::shared_ptr< librevenge::RVNGInputStream >stream, std::function< void()> itemHandler)
Definition QXPParser.cpp:239
libqxp::QXPParser::m_colors
std::map< unsigned, Color > m_colors
Definition QXPParser.h:50
libqxp::QXPParser::m_charFormats
std::vector< std::shared_ptr< CharFormat > > m_charFormats
Definition QXPParser.h:52
libqxp::QXPParser::parseCharFormat
virtual CharFormat parseCharFormat(const std::shared_ptr< librevenge::RVNGInputStream > &stream)=0
libqxp::QXPParser::setArrow
void setArrow(const unsigned index, Frame &frame) const
Definition QXPParser.cpp:492
libqxp::QXPParser::parsePages
virtual bool parsePages(const std::shared_ptr< librevenge::RVNGInputStream > &stream, QXPCollector &collector)=0
libqxp::QXPParser::~QXPParser
virtual ~QXPParser()=default
libqxp::QXPParser::parseFonts
void parseFonts(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:125
libqxp::QXPParser::parseParagraphFormats
void parseParagraphFormats(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:230
libqxp::QXPParser::parseCommonCharFormatProps
void parseCommonCharFormatProps(const std::shared_ptr< librevenge::RVNGInputStream > &stream, CharFormat &result)
Definition QXPParser.cpp:189
libqxp::QXPParser::parseTabStop
TabStop parseTabStop(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:200
libqxp::QXPParser::readRecordEndOffset
uint32_t readRecordEndOffset(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:318
libqxp::QXPParser::parseCharFormats
void parseCharFormats(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:167
libqxp::QXPParser::parse
bool parse()
Definition QXPParser.cpp:65
libqxp::QXPParser::readParagraphFlags
uint8_t readParagraphFlags(const std::shared_ptr< librevenge::RVNGInputStream > &stream, bool &incrementalLeading, bool &ruleAbove, bool &ruleBelow)
Definition QXPParser.cpp:460
libqxp::QXPParser::parseHJProps
void parseHJProps(const std::shared_ptr< librevenge::RVNGInputStream > &stream, HJ &result)
Definition QXPParser.cpp:176
libqxp::QXPParser::m_arrows
std::vector< Arrow > m_arrows
Definition QXPParser.h:55
libqxp::QXPParser::parsePageSettings
std::vector< PageSettings > parsePageSettings(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:264
libqxp::QXPParser::parseText
std::shared_ptr< Text > parseText(unsigned index, unsigned linkId, QXPCollector &collector)
Definition QXPParser.cpp:303
libqxp::QXPParser::readYX
Point readYX(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:432
libqxp::QXPParser::operator=
QXPParser & operator=(const QXPParser &other)=delete
libqxp::QXPParser::getLineStyle
const LineStyle * getLineStyle(unsigned id) const
Definition QXPParser.cpp:94
libqxp::QXPParser::m_paragraphFormats
std::vector< std::shared_ptr< ParagraphFormat > > m_paragraphFormats
Definition QXPParser.h:53
libqxp::QXPParser::readHorAlign
HorizontalAlignment readHorAlign(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:392
libqxp::QXPParser::be
const bool be
Definition QXPParser.h:45
libqxp::QXPParser::m_painter
librevenge::RVNGDrawingInterface * m_painter
Definition QXPParser.h:44
libqxp::QXPParser::readObjectFlags
uint8_t readObjectFlags(const std::shared_ptr< librevenge::RVNGInputStream > &stream, bool &noColor)
Definition QXPParser.cpp:478
libqxp::QXPParser::m_groupObjects
std::set< unsigned > m_groupObjects
Definition QXPParser.h:58
libqxp::QXPParser::m_blockParser
QXPBlockParser m_blockParser
Definition QXPParser.h:47
libqxp::QXPParser::QXPParser
QXPParser(const QXPParser &other)=delete
libqxp::QXPParser::parseHJs
void parseHJs(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition QXPParser.cpp:159
libqxp::QXPParser::parseDocument
virtual bool parseDocument(const std::shared_ptr< librevenge::RVNGInputStream > &docStream, QXPCollector &collector)=0
libqxp::QXPTextParser
Definition QXPTextParser.h:29
libqxp_utils.h
libqxp
Definition libqxp_utils.cpp:25
libqxp::VerticalAlignment
VerticalAlignment
Definition QXPTypes.h:201
libqxp::HorizontalAlignment
HorizontalAlignment
Definition QXPTypes.h:192
libqxp::TabStopType
TabStopType
Definition QXPTypes.h:209
libqxp::CharFormat
Definition QXPTypes.h:145
libqxp::Color
Definition QXPTypes.h:69
libqxp::Frame
Definition QXPTypes.h:345
libqxp::Gradient
Definition QXPTypes.h:98
libqxp::HJ
Definition QXPTypes.h:174
libqxp::LineStyle
Definition QXPTypes.h:127
libqxp::ParagraphFormat
Definition QXPTypes.h:248
libqxp::Point
Definition QXPTypes.h:25
libqxp::Rect
Definition QXPTypes.h:47
libqxp::TabStop
Definition QXPTypes.h:217