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 <vector>
22 
23 namespace libqxp
24 {
25 
26 class QXPCollector;
27 class QXPHeader;
28 
29 class QXPParser
30 {
31  // disable copying
32  QXPParser(const QXPParser &other) = delete;
33  QXPParser &operator=(const QXPParser &other) = delete;
34 
35 public:
36  QXPParser(const std::shared_ptr<librevenge::RVNGInputStream> &input, librevenge::RVNGDrawingInterface *painter, const std::shared_ptr<QXPHeader> &header);
37  virtual ~QXPParser() = default;
38 
39  bool parse();
40 
41 protected:
42  const std::shared_ptr<librevenge::RVNGInputStream> m_input;
43  librevenge::RVNGDrawingInterface *m_painter;
44  const bool be; // big endian
45 
48 
49  std::map<unsigned, Color> m_colors;
50  std::map<int, std::string> m_fonts;
51  std::vector<std::shared_ptr<CharFormat>> m_charFormats;
52  std::vector<std::shared_ptr<ParagraphFormat>> m_paragraphFormats;
53  std::map<unsigned, LineStyle> m_lineStyles;
54  std::vector<Arrow> m_arrows;
55  std::deque<std::shared_ptr<HJ>> m_hjs;
56 
57  Color getColor(unsigned id, Color defaultColor = Color(0, 0, 0)) const;
58  const LineStyle *getLineStyle(unsigned id) const;
59  std::string getFont(int id, std::string defaultFont = "Arial") const;
60 
61  void convertCharFormatFlags(unsigned flags, CharFormat &format);
62  TabStopType convertTabStopType(unsigned type);
63 
64  virtual bool parseDocument(const std::shared_ptr<librevenge::RVNGInputStream> &docStream, QXPCollector &collector) = 0;
65  virtual bool parsePages(const std::shared_ptr<librevenge::RVNGInputStream> &stream, QXPCollector &collector) = 0;
66 
67  void skipRecord(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
68  void parseFonts(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
69  void parseHJs(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
70  void parseCharFormats(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
71  void parseCommonCharFormatProps(const std::shared_ptr<librevenge::RVNGInputStream> &stream, CharFormat &result);
72  void parseHJProps(const std::shared_ptr<librevenge::RVNGInputStream> &stream, HJ &result);
73  TabStop parseTabStop(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
74  void parseParagraphFormats(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
75 
76  virtual CharFormat parseCharFormat(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
77  virtual ParagraphFormat parseParagraphFormat(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
78  virtual std::shared_ptr<HJ> parseHJ(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
79 
80  void parseCollection(const std::shared_ptr<librevenge::RVNGInputStream>stream, std::function<void()> itemHandler);
81 
82  std::vector<PageSettings> parsePageSettings(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
83 
84  std::shared_ptr<Text> parseText(unsigned index, unsigned linkId, QXPCollector &collector);
85 
86  uint32_t readRecordEndOffset(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
87  uint8_t readColorComp(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
88  Rect readObjectBBox(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
89  Gradient readGradient(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const Color &color1);
90  HorizontalAlignment readHorAlign(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
91  VerticalAlignment readVertAlign(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
92  Point readYX(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
93  std::shared_ptr<ParagraphRule> readParagraphRule(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
94  uint8_t readParagraphFlags(const std::shared_ptr<librevenge::RVNGInputStream> &stream, bool &incrementalLeading, bool &ruleAbove, bool &ruleBelow);
95  uint8_t readObjectFlags(const std::shared_ptr<librevenge::RVNGInputStream> &stream, bool &noColor);
96  void setArrow(const unsigned index, Frame &frame) const;
97  void skipFileInfo(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
98 
99 private:
100  const std::shared_ptr<QXPHeader> m_header;
101 };
102 
103 }
104 
105 #endif // QXPPARSER_H_INCLUDED
106 
107 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
bool parse()
Definition: QXPParser.cpp:65
std::shared_ptr< Text > parseText(unsigned index, unsigned linkId, QXPCollector &collector)
Definition: QXPParser.cpp:291
virtual bool parsePages(const std::shared_ptr< librevenge::RVNGInputStream > &stream, QXPCollector &collector)=0
Definition: libqxp_utils.cpp:24
std::string getFont(int id, std::string defaultFont="Arial") const
Definition: QXPParser.cpp:105
QXPTextParser m_textParser
Definition: QXPParser.h:47
Rect readObjectBBox(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:317
Point readYX(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:420
void parseCollection(const std::shared_ptr< librevenge::RVNGInputStream >stream, std::function< void()> itemHandler)
Definition: QXPParser.cpp:233
Definition: QXPTextParser.h:28
Definition: QXPParser.h:29
std::vector< Arrow > m_arrows
Definition: QXPParser.h:54
std::vector< PageSettings > parsePageSettings(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:252
QXPBlockParser m_blockParser
Definition: QXPParser.h:46
void parseFonts(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:125
uint8_t readParagraphFlags(const std::shared_ptr< librevenge::RVNGInputStream > &stream, bool &incrementalLeading, bool &ruleAbove, bool &ruleBelow)
Definition: QXPParser.cpp:448
std::shared_ptr< ParagraphRule > readParagraphRule(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:428
std::map< int, std::string > m_fonts
Definition: QXPParser.h:50
Definition: QXPTypes.h:24
virtual ~QXPParser()=default
std::vector< std::shared_ptr< ParagraphFormat > > m_paragraphFormats
Definition: QXPParser.h:52
Gradient readGradient(const std::shared_ptr< librevenge::RVNGInputStream > &stream, const Color &color1)
Definition: QXPParser.cpp:327
VerticalAlignment
Definition: QXPTypes.h:200
librevenge::RVNGDrawingInterface * m_painter
Definition: QXPParser.h:43
const bool be
Definition: QXPParser.h:44
uint8_t readColorComp(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:312
HorizontalAlignment readHorAlign(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:380
void skipFileInfo(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:505
std::deque< std::shared_ptr< HJ > > m_hjs
Definition: QXPParser.h:55
virtual bool parseDocument(const std::shared_ptr< librevenge::RVNGInputStream > &docStream, QXPCollector &collector)=0
virtual std::shared_ptr< HJ > parseHJ(const std::shared_ptr< librevenge::RVNGInputStream > &stream)=0
Definition: QXPTypes.h:173
Color getColor(unsigned id, Color defaultColor=Color(0, 0, 0)) const
Definition: QXPParser.cpp:83
TabStopType
Definition: QXPTypes.h:208
std::vector< std::shared_ptr< CharFormat > > m_charFormats
Definition: QXPParser.h:51
const LineStyle * getLineStyle(unsigned id) const
Definition: QXPParser.cpp:94
void skipRecord(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:116
QXPParser(const QXPParser &other)=delete
const std::shared_ptr< QXPHeader > m_header
Definition: QXPParser.h:100
void parseHJs(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:153
const std::shared_ptr< librevenge::RVNGInputStream > m_input
Definition: QXPParser.h:42
uint32_t readRecordEndOffset(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:306
void setArrow(const unsigned index, Frame &frame) const
Definition: QXPParser.cpp:480
TabStopType convertTabStopType(unsigned type)
Definition: QXPParser.cpp:530
QXPParser & operator=(const QXPParser &other)=delete
Definition: QXPTypes.h:144
Definition: QXPTypes.h:97
Definition: QXPTypes.h:247
VerticalAlignment readVertAlign(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:401
uint8_t readObjectFlags(const std::shared_ptr< librevenge::RVNGInputStream > &stream, bool &noColor)
Definition: QXPParser.cpp:466
HorizontalAlignment
Definition: QXPTypes.h:191
Definition: QXPTypes.h:46
virtual CharFormat parseCharFormat(const std::shared_ptr< librevenge::RVNGInputStream > &stream)=0
Definition: QXPTypes.h:126
TabStop parseTabStop(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:194
void parseCharFormats(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:161
std::map< unsigned, LineStyle > m_lineStyles
Definition: QXPParser.h:53
void parseCommonCharFormatProps(const std::shared_ptr< librevenge::RVNGInputStream > &stream, CharFormat &result)
Definition: QXPParser.cpp:183
Definition: QXPTypes.h:216
void parseParagraphFormats(const std::shared_ptr< librevenge::RVNGInputStream > &stream)
Definition: QXPParser.cpp:224
void convertCharFormatFlags(unsigned flags, CharFormat &format)
Definition: QXPParser.cpp:514
void parseHJProps(const std::shared_ptr< librevenge::RVNGInputStream > &stream, HJ &result)
Definition: QXPParser.cpp:170
Definition: QXPTypes.h:68
std::map< unsigned, Color > m_colors
Definition: QXPParser.h:49
Definition: QXPTypes.h:344
virtual ParagraphFormat parseParagraphFormat(const std::shared_ptr< librevenge::RVNGInputStream > &stream)=0
Definition: QXPBlockParser.h:20
Definition: QXPCollector.h:27

Generated for libqxp by doxygen 1.8.13