QXPParser.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  * This file is part of the libqxp project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef QXPPARSER_H_INCLUDED
11 #define QXPPARSER_H_INCLUDED
12 
13 #include "libqxp_utils.h"
14 #include "QXPBlockParser.h"
15 #include "QXPTextParser.h"
16 #include "QXPTypes.h"
17 
18 #include <deque>
19 #include <functional>
20 #include <map>
21 #include <set>
22 #include <vector>
23 
24 namespace libqxp
25 {
26 
27 class QXPCollector;
28 class QXPHeader;
29 
30 class QXPParser
31 {
32  // disable copying
33  QXPParser(const QXPParser &other) = delete;
34  QXPParser &operator=(const QXPParser &other) = delete;
35 
36 public:
37  QXPParser(const std::shared_ptr<librevenge::RVNGInputStream> &input, librevenge::RVNGDrawingInterface *painter, const std::shared_ptr<QXPHeader> &header);
38  virtual ~QXPParser() = default;
39 
40  bool parse();
41 
42 protected:
43  const std::shared_ptr<librevenge::RVNGInputStream> m_input;
44  librevenge::RVNGDrawingInterface *m_painter;
45  const bool be; // big endian
46 
49 
50  std::map<unsigned, Color> m_colors;
51  std::map<int, std::string> m_fonts;
52  std::vector<std::shared_ptr<CharFormat>> m_charFormats;
53  std::vector<std::shared_ptr<ParagraphFormat>> m_paragraphFormats;
54  std::map<unsigned, LineStyle> m_lineStyles;
55  std::vector<Arrow> m_arrows;
56  std::deque<std::shared_ptr<HJ>> m_hjs;
57 
58  std::set<unsigned> m_groupObjects;
59 
60  Color getColor(unsigned id, Color defaultColor = Color(0, 0, 0)) const;
61  const LineStyle *getLineStyle(unsigned id) const;
62  std::string getFont(int id, std::string defaultFont = "Arial") const;
63 
64  void convertCharFormatFlags(unsigned flags, CharFormat &format);
65  TabStopType convertTabStopType(unsigned type);
66 
67  virtual bool parseDocument(const std::shared_ptr<librevenge::RVNGInputStream> &docStream, QXPCollector &collector) = 0;
68  virtual bool parsePages(const std::shared_ptr<librevenge::RVNGInputStream> &stream, QXPCollector &collector) = 0;
69 
70  void skipRecord(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
71  void parseFonts(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
72  void parseHJs(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
73  void parseCharFormats(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
74  void parseCommonCharFormatProps(const std::shared_ptr<librevenge::RVNGInputStream> &stream, CharFormat &result);
75  void parseHJProps(const std::shared_ptr<librevenge::RVNGInputStream> &stream, HJ &result);
76  TabStop parseTabStop(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
77  void parseParagraphFormats(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
78 
79  virtual CharFormat parseCharFormat(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
80  virtual ParagraphFormat parseParagraphFormat(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
81  virtual std::shared_ptr<HJ> parseHJ(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
82 
83  void parseCollection(const std::shared_ptr<librevenge::RVNGInputStream>stream, std::function<void()> itemHandler);
84 
85  std::vector<PageSettings> parsePageSettings(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
86 
87  std::shared_ptr<Text> parseText(unsigned index, unsigned linkId, QXPCollector &collector);
88 
89  uint32_t readRecordEndOffset(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
90  uint8_t readColorComp(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
91  Rect readObjectBBox(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
92  Gradient readGradient(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const Color &color1);
93  HorizontalAlignment readHorAlign(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
94  VerticalAlignment readVertAlign(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
95  Point readYX(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
96  std::shared_ptr<ParagraphRule> readParagraphRule(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
97  uint8_t readParagraphFlags(const std::shared_ptr<librevenge::RVNGInputStream> &stream, bool &incrementalLeading, bool &ruleAbove, bool &ruleBelow);
98  uint8_t readObjectFlags(const std::shared_ptr<librevenge::RVNGInputStream> &stream, bool &noColor);
99  void readGroupElements(const std::shared_ptr<librevenge::RVNGInputStream> &stream, unsigned count, unsigned objectsCount, unsigned index, std::vector<unsigned> &elements);
100  void setArrow(const unsigned index, Frame &frame) const;
101  void skipFileInfo(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
102 
103 private:
104  const std::shared_ptr<QXPHeader> m_header;
105 };
106 
107 }
108 
109 #endif // QXPPARSER_H_INCLUDED
110 
111 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libqxp::Color
Definition: QXPTypes.h:68
libqxp::HJ::maxInRow
unsigned maxInRow
Definition: QXPTypes.h:187
libqxp::VerticalAlignment
VerticalAlignment
Definition: QXPTypes.h:200
libqxp::QXPParser::m_fonts
std::map< int, std::string > m_fonts
Definition: QXPParser.h:51
libqxp::CharFormat::superior
bool superior
Definition: QXPTypes.h:157
libqxp::QXPParser::QXPParser
QXPParser(const QXPParser &other)=delete
libqxp::QXPContentCollector
Definition: QXPContentCollector.h:26
libqxp::CharFormat::wordUnderline
bool wordUnderline
Definition: QXPTypes.h:161
libqxp::readU16
uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:111
libqxp::CharFormat::underline
bool underline
Definition: QXPTypes.h:152
libqxp::QXPParser::getColor
Color getColor(unsigned id, Color defaultColor=Color(0, 0, 0)) const
Definition: QXPParser.cpp:83
libqxp::CharFormat::superscript
bool superscript
Definition: QXPTypes.h:155
libqxp::QXPParser::be
const bool be
Definition: QXPParser.h:45
libqxp::QXPParser::readRecordEndOffset
uint32_t readRecordEndOffset(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:318
libqxp::QXPParser::readColorComp
uint8_t readColorComp(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:324
libqxp::TabStop::type
TabStopType type
Definition: QXPTypes.h:218
libqxp::QXPParser::parsePages
virtual bool parsePages(const std::shared_ptr< librevenge::RVNGInputStream > &stream, QXPCollector &collector)=0
libqxp::GradientType::CIRCULAR
libqxp::QXP_4
Definition: QXPHeader.h:29
libqxp::QXPContentCollector::endDocument
void endDocument() override
Definition: QXPContentCollector.cpp:320
libqxp
Definition: libqxp_utils.cpp:24
libqxp::QXPParser::getFont
std::string getFont(int id, std::string defaultFont="Arial") const
Definition: QXPParser.cpp:105
libqxp::CharFormat::smallCaps
bool smallCaps
Definition: QXPTypes.h:160
libqxp::QXPParser::readObjectFlags
uint8_t readObjectFlags(const std::shared_ptr< librevenge::RVNGInputStream > &stream, bool &noColor)
Definition: QXPParser.cpp:478
libqxp::HorizontalAlignment::RIGHT
libqxp::QXPParser::m_paragraphFormats
std::vector< std::shared_ptr< ParagraphFormat > > m_paragraphFormats
Definition: QXPParser.h:53
libqxp::HJ::hyphenate
bool hyphenate
Definition: QXPTypes.h:184
libqxp::QXPParser::skipRecord
void skipRecord(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:116
libqxp::QXPParser::m_charFormats
std::vector< std::shared_ptr< CharFormat > > m_charFormats
Definition: QXPParser.h:52
libqxp::LineJoinType::MITER
libqxp::QXPParser
Definition: QXPParser.h:30
libqxp::Frame
Definition: QXPTypes.h:344
libqxp::HorizontalAlignment::JUSTIFIED
libqxp::readFloat16
double readFloat16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:169
libqxp::QXPParser::parseTabStop
TabStop parseTabStop(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:200
libqxp::QXPParser::setArrow
void setArrow(const unsigned index, Frame &frame) const
Definition: QXPParser.cpp:492
libqxp::QXPParser::m_painter
librevenge::RVNGDrawingInterface * m_painter
Definition: QXPParser.h:44
libqxp::readS16
int16_t readS16(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:159
libqxp::QXPParser::m_input
const std::shared_ptr< librevenge::RVNGInputStream > m_input
Definition: QXPParser.h:43
libqxp::seek
void seek(librevenge::RVNGInputStream *const input, const unsigned long pos)
Definition: libqxp_utils.cpp:241
libqxp::readPlatformString
std::string readPlatformString(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:229
libqxp::HorizontalAlignment::LEFT
libqxp::QXPParser::m_arrows
std::vector< Arrow > m_arrows
Definition: QXPParser.h:55
libqxp::Gradient::color1
Color color1
Definition: QXPTypes.h:100
libqxp::GradientType::MIDLINEAR
libqxp::QXPCollector
Definition: QXPCollector.h:27
libqxp_utils.h
libqxp::Frame::endArrow
const Arrow * endArrow
Definition: QXPTypes.h:351
libqxp::TabStop::position
double position
Definition: QXPTypes.h:219
libqxp::QXPParser::parseFonts
void parseFonts(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:125
libqxp::CharFormat::outline
bool outline
Definition: QXPTypes.h:153
libqxp::QXPParser::parseCharFormat
virtual CharFormat parseCharFormat(const std::shared_ptr< librevenge::RVNGInputStream > &stream)=0
libqxp::LineCapType::BUTT
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::getLineStyle
const LineStyle * getLineStyle(unsigned id) const
Definition: QXPParser.cpp:94
libqxp::QXPParser::readVertAlign
VerticalAlignment readVertAlign(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:413
libqxp::QXPParser::parseParagraphFormats
void parseParagraphFormats(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:230
libqxp::HorizontalAlignment::FORCED
libqxp::QXPParser::readYX
Point readYX(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:432
QXPBlockParser.h
libqxp::LineCapType::ROUND
libqxp::readU32
uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:127
libqxp::Frame::startArrow
const Arrow * startArrow
Definition: QXPTypes.h:350
libqxp::QXPParser::m_hjs
std::deque< std::shared_ptr< HJ > > m_hjs
Definition: QXPParser.h:56
libqxp::QXPTextParser::parseText
std::shared_ptr< Text > parseText(unsigned index, const std::vector< std::shared_ptr< CharFormat >> &charFormats, const std::vector< std::shared_ptr< ParagraphFormat >> &paragraphFormats)
Definition: QXPTextParser.cpp:64
libqxp::HorizontalAlignment
HorizontalAlignment
Definition: QXPTypes.h:191
libqxp::CharFormat::fontName
librevenge::RVNGString fontName
Definition: QXPTypes.h:146
libqxp::readFraction
double readFraction(librevenge::RVNGInputStream *input, bool bigEndian)
Definition: libqxp_utils.cpp:174
QXP_DEBUG_MSG
#define QXP_DEBUG_MSG(M)
Definition: libqxp_utils.h:53
libqxp::QXPParser::m_blockParser
QXPBlockParser m_blockParser
Definition: QXPParser.h:47
libqxp::TabStop
Definition: QXPTypes.h:216
libqxp::GradientType::LINEAR
QXP_FALLTHROUGH
#define QXP_FALLTHROUGH
Definition: libqxp_utils.h:40
libqxp::QXPCollector::collectText
virtual void collectText(const std::shared_ptr< Text > &, const unsigned)
Definition: QXPCollector.h:51
libqxp::QXPParser::readParagraphFlags
uint8_t readParagraphFlags(const std::shared_ptr< librevenge::RVNGInputStream > &stream, bool &incrementalLeading, bool &ruleAbove, bool &ruleBelow)
Definition: QXPParser.cpp:460
libqxp::CharFormat
Definition: QXPTypes.h:144
libqxp::Rect::top
double top
Definition: QXPTypes.h:48
libqxp::QXPParser::~QXPParser
virtual ~QXPParser()=default
libqxp::CharFormat::subscript
bool subscript
Definition: QXPTypes.h:156
libqxp::QXPParser::readParagraphRule
std::shared_ptr< ParagraphRule > readParagraphRule(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:440
libqxp::Gradient::color2
Color color2
Definition: QXPTypes.h:101
libqxp::LineStyle
Definition: QXPTypes.h:126
libqxp::QXPParser::readGradient
Gradient readGradient(const std::shared_ptr< librevenge::RVNGInputStream > &stream, const Color &color1)
Definition: QXPParser.cpp:339
libqxp::Point::x
double x
Definition: QXPTypes.h:26
libqxp::CharFormat::shadow
bool shadow
Definition: QXPTypes.h:154
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::TabStopType::ALIGN
libqxp::CharFormat::italic
bool italic
Definition: QXPTypes.h:151
libqxp::HorizontalAlignment::CENTER
libqxp::CharFormat::bold
bool bold
Definition: QXPTypes.h:150
libqxp::Point
Definition: QXPTypes.h:24
libqxp::QXPParser::parseText
std::shared_ptr< Text > parseText(unsigned index, unsigned linkId, QXPCollector &collector)
Definition: QXPParser.cpp:303
libqxp::QXPParser::parseCollection
void parseCollection(const std::shared_ptr< librevenge::RVNGInputStream >stream, std::function< void()> itemHandler)
Definition: QXPParser.cpp:239
libqxp::TabStop::fillChar
librevenge::RVNGString fillChar
Definition: QXPTypes.h:220
libqxp::Rect::right
double right
Definition: QXPTypes.h:49
QXPTypes.h
libqxp::Rect
Definition: QXPTypes.h:46
libqxp::HJ::singleWordJustify
bool singleWordJustify
Definition: QXPTypes.h:188
libqxp::readU8
uint8_t readU8(librevenge::RVNGInputStream *input, bool)
Definition: libqxp_utils.cpp:99
libqxp::QXPParser::skipFileInfo
void skipFileInfo(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:517
libqxp::QXPParser::m_colors
std::map< unsigned, Color > m_colors
Definition: QXPParser.h:50
libqxp::QXPParser::parseHJ
virtual std::shared_ptr< HJ > parseHJ(const std::shared_ptr< librevenge::RVNGInputStream > &stream)=0
libqxp::GradientType::RECTANGULAR
libqxp::QXPParser::readHorAlign
HorizontalAlignment readHorAlign(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:392
libqxp::HJ
Definition: QXPTypes.h:173
libqxp::HJ::minAfter
unsigned minAfter
Definition: QXPTypes.h:186
libqxp::GradientType::FULLCIRCULAR
libqxp::Color::applyShade
Color applyShade(double shade) const
Definition: QXPTypes.cpp:105
libqxp::QXPBlockParser
Definition: QXPBlockParser.h:20
libqxp::TabStopType
TabStopType
Definition: QXPTypes.h:208
libqxp::QXPParser::convertTabStopType
TabStopType convertTabStopType(unsigned type)
Definition: QXPParser.cpp:542
libqxp::CharFormat::allCaps
bool allCaps
Definition: QXPTypes.h:159
QXPContentCollector.h
libqxp::CharFormat::fontSize
double fontSize
Definition: QXPTypes.h:147
libqxp::QXPContentCollector::startDocument
void startDocument() override
Definition: QXPContentCollector.cpp:310
libqxp::HJ::minBefore
unsigned minBefore
Definition: QXPTypes.h:185
libqxp::Rect::bottom
double bottom
Definition: QXPTypes.h:50
libqxp::QXPTextParser
Definition: QXPTextParser.h:28
libqxp::TabStop::alignChar
librevenge::RVNGString alignChar
Definition: QXPTypes.h:221
libqxp::QXPBlockParser::getChain
std::shared_ptr< librevenge::RVNGInputStream > getChain(const uint32_t index)
Definition: QXPBlockParser.cpp:69
libqxp::QXPParser::parseCommonCharFormatProps
void parseCommonCharFormatProps(const std::shared_ptr< librevenge::RVNGInputStream > &stream, CharFormat &result)
Definition: QXPParser.cpp:189
libqxp::QXPParser::operator=
QXPParser & operator=(const QXPParser &other)=delete
libqxp::QXPParser::parse
bool parse()
Definition: QXPParser.cpp:65
libqxp::ParagraphFormat
Definition: QXPTypes.h:247
libqxp::Rect::left
double left
Definition: QXPTypes.h:51
libqxp::GradientType::DIAMOND
libqxp::skip
void skip(librevenge::RVNGInputStream *input, unsigned long numBytes)
Definition: libqxp_utils.cpp:234
QXPParser.h
libqxp::QXPParser::parseHJProps
void parseHJProps(const std::shared_ptr< librevenge::RVNGInputStream > &stream, HJ &result)
Definition: QXPParser.cpp:176
libqxp::QXPParser::parseDocument
virtual bool parseDocument(const std::shared_ptr< librevenge::RVNGInputStream > &docStream, QXPCollector &collector)=0
libqxp::CharFormat::strike
bool strike
Definition: QXPTypes.h:158
libqxp::ParseError
Definition: libqxp_utils.h:142
libqxp::QXPParser::parseParagraphFormat
virtual ParagraphFormat parseParagraphFormat(const std::shared_ptr< librevenge::RVNGInputStream > &stream)=0
libqxp::QXPParser::m_groupObjects
std::set< unsigned > m_groupObjects
Definition: QXPParser.h:58
libqxp::QXPParser::parseHJs
void parseHJs(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:159
libqxp::Point::y
double y
Definition: QXPTypes.h:27
libqxp::Gradient::angle
double angle
Definition: QXPTypes.h:102
libqxp::QXPParser::parsePageSettings
std::vector< PageSettings > parsePageSettings(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:264
libqxp::Gradient::type
GradientType type
Definition: QXPTypes.h:99
QXPTextParser.h
libqxp::Arrow
Definition: QXPTypes.h:333
QXPHeader.h
libqxp::VerticalAlignment::BOTTOM
libqxp::QXPParser::m_header
const std::shared_ptr< QXPHeader > m_header
Definition: QXPParser.h:104
libqxp::Gradient
Definition: QXPTypes.h:97
libqxp::getRemainingLength
unsigned long getRemainingLength(librevenge::RVNGInputStream *const input)
Definition: libqxp_utils.cpp:259
libqxp::QXPParser::convertCharFormatFlags
void convertCharFormatFlags(unsigned flags, CharFormat &format)
Definition: QXPParser.cpp:526
libqxp::QXPParser::parseCharFormats
void parseCharFormats(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:167
libqxp::QXPParser::m_lineStyles
std::map< unsigned, LineStyle > m_lineStyles
Definition: QXPParser.h:54
libqxp::VerticalAlignment::TOP

Generated for libqxp by doxygen 1.8.16