Debian Codegraph @

src/lib/QXPParser.h

raw
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
47 QXPBlockParser m_blockParser;
48 QXPTextParser m_textParser;
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: */