Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef QXPPARSER_H_INCLUDED
00011 #define QXPPARSER_H_INCLUDED
00012
00013 #include "libqxp_utils.h"
00014 #include "QXPBlockParser.h"
00015 #include "QXPTextParser.h"
00016 #include "QXPTypes.h"
00017
00018 #include <deque>
00019 #include <functional>
00020 #include <map>
00021 #include <set>
00022 #include <vector>
00023
00024 namespace libqxp
00025 {
00026
00027 class QXPCollector;
00028 class QXPHeader;
00029
00030 class QXPParser
00031 {
00032
00033 QXPParser(const QXPParser &other) = delete;
00034 QXPParser &operator=(const QXPParser &other) = delete;
00035
00036 public:
00037 QXPParser(const std::shared_ptr<librevenge::RVNGInputStream> &input, librevenge::RVNGDrawingInterface *painter, const std::shared_ptr<QXPHeader> &header);
00038 virtual ~QXPParser() = default;
00039
00040 bool parse();
00041
00042 protected:
00043 const std::shared_ptr<librevenge::RVNGInputStream> m_input;
00044 librevenge::RVNGDrawingInterface *m_painter;
00045 const bool be;
00046
00047 QXPBlockParser m_blockParser;
00048 QXPTextParser m_textParser;
00049
00050 std::map<unsigned, Color> m_colors;
00051 std::map<int, std::string> m_fonts;
00052 std::vector<std::shared_ptr<CharFormat>> m_charFormats;
00053 std::vector<std::shared_ptr<ParagraphFormat>> m_paragraphFormats;
00054 std::map<unsigned, LineStyle> m_lineStyles;
00055 std::vector<Arrow> m_arrows;
00056 std::deque<std::shared_ptr<HJ>> m_hjs;
00057
00058 std::set<unsigned> m_groupObjects;
00059
00060 Color getColor(unsigned id, Color defaultColor = Color(0, 0, 0)) const;
00061 const LineStyle *getLineStyle(unsigned id) const;
00062 std::string getFont(int id, std::string defaultFont = "Arial") const;
00063
00064 void convertCharFormatFlags(unsigned flags, CharFormat &format);
00065 TabStopType convertTabStopType(unsigned type);
00066
00067 virtual bool parseDocument(const std::shared_ptr<librevenge::RVNGInputStream> &docStream, QXPCollector &collector) = 0;
00068 virtual bool parsePages(const std::shared_ptr<librevenge::RVNGInputStream> &stream, QXPCollector &collector) = 0;
00069
00070 void skipRecord(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00071 void parseFonts(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00072 void parseHJs(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00073 void parseCharFormats(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00074 void parseCommonCharFormatProps(const std::shared_ptr<librevenge::RVNGInputStream> &stream, CharFormat &result);
00075 void parseHJProps(const std::shared_ptr<librevenge::RVNGInputStream> &stream, HJ &result);
00076 TabStop parseTabStop(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00077 void parseParagraphFormats(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00078
00079 virtual CharFormat parseCharFormat(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
00080 virtual ParagraphFormat parseParagraphFormat(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
00081 virtual std::shared_ptr<HJ> parseHJ(const std::shared_ptr<librevenge::RVNGInputStream> &stream) = 0;
00082
00083 void parseCollection(const std::shared_ptr<librevenge::RVNGInputStream>stream, std::function<void()> itemHandler);
00084
00085 std::vector<PageSettings> parsePageSettings(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00086
00087 std::shared_ptr<Text> parseText(unsigned index, unsigned linkId, QXPCollector &collector);
00088
00089 uint32_t readRecordEndOffset(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00090 uint8_t readColorComp(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00091 Rect readObjectBBox(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00092 Gradient readGradient(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const Color &color1);
00093 HorizontalAlignment readHorAlign(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00094 VerticalAlignment readVertAlign(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00095 Point readYX(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00096 std::shared_ptr<ParagraphRule> readParagraphRule(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00097 uint8_t readParagraphFlags(const std::shared_ptr<librevenge::RVNGInputStream> &stream, bool &incrementalLeading, bool &ruleAbove, bool &ruleBelow);
00098 uint8_t readObjectFlags(const std::shared_ptr<librevenge::RVNGInputStream> &stream, bool &noColor);
00099 void readGroupElements(const std::shared_ptr<librevenge::RVNGInputStream> &stream, unsigned count, unsigned objectsCount, unsigned index, std::vector<unsigned> &elements);
00100 void setArrow(const unsigned index, Frame &frame) const;
00101 void skipFileInfo(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00102
00103 private:
00104 const std::shared_ptr<QXPHeader> m_header;
00105 };
00106
00107 }
00108
00109 #endif // QXPPARSER_H_INCLUDED
00110
00111