QXP4Parser.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libqxp project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef QXP4PARSER_H_INCLUDED
00011 #define QXP4PARSER_H_INCLUDED
00012 
00013 #include "QXPParser.h"
00014 #include <vector>
00015 
00016 namespace libqxp
00017 {
00018 
00019 class QXP4Deobfuscator;
00020 class QXP4Header;
00021 
00022 class QXP4Parser : public QXPParser
00023 {
00024 public:
00025   QXP4Parser(const std::shared_ptr<librevenge::RVNGInputStream> &input, librevenge::RVNGDrawingInterface *painter, const std::shared_ptr<QXP4Header> &header);
00026 
00027   enum class ShapeType
00028   {
00029     UNKNOWN,
00030     LINE,
00031     ORTHOGONAL_LINE,
00032     BEZIER_LINE,
00033     RECTANGLE,
00034     ROUNDED_RECTANGLE,
00035     CONCAVE_RECTANGLE,
00036     BEVELED_RECTANGLE,
00037     OVAL,
00038     BEZIER_BOX
00039   };
00040 
00041   struct ObjectHeader
00042   {
00043     boost::optional<Color> fillColor;
00044     Color color;
00045 
00046     unsigned contentIndex;
00047     unsigned linkId;
00048     unsigned oleId;
00049     unsigned gradientId;
00050 
00051     double rotation;
00052     double skew;
00053 
00054     bool hflip;
00055     bool vflip;
00056 
00057     ContentType contentType;
00058     ShapeType shapeType;
00059 
00060     BoxType boxType;
00061     CornerType cornerType;
00062 
00063     ObjectHeader()
00064       : fillColor(), color(), contentIndex(0), linkId(0), oleId(0), gradientId(0),
00065         rotation(0), skew(0), hflip(false), vflip(false),
00066         contentType(ContentType::UNKNOWN), shapeType(ShapeType::UNKNOWN),
00067         boxType(BoxType::UNKNOWN), cornerType(CornerType::DEFAULT)
00068     { }
00069   };
00070 
00071 private:
00072   struct ColorBlockSpec
00073   {
00074     unsigned offset;
00075     unsigned padding;
00076 
00077     ColorBlockSpec()
00078       : offset(0), padding(0)
00079     { }
00080   };
00081 
00082   const std::shared_ptr<QXP4Header> m_header;
00083 
00084   std::vector<std::vector<TabStop>> m_paragraphTabStops;
00085 
00086   bool parseDocument(const std::shared_ptr<librevenge::RVNGInputStream> &docStream, QXPCollector &collector) override;
00087   bool parsePages(const std::shared_ptr<librevenge::RVNGInputStream> &stream, QXPCollector &collector) override;
00088 
00089   void parseColors(const std::shared_ptr<librevenge::RVNGInputStream> &docStream);
00090   ColorBlockSpec parseColorBlockSpec(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00091   void parseColor(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const std::vector<ColorBlockSpec> &blocks);
00092   void skipParagraphStylesheets(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00093   CharFormat parseCharFormat(const std::shared_ptr<librevenge::RVNGInputStream> &stream) override;
00094   void parseLineStyles(const std::shared_ptr<librevenge::RVNGInputStream> &docStream);
00095   void skipTemplates(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00096   void parseTabStops(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00097   ParagraphFormat parseParagraphFormat(const std::shared_ptr<librevenge::RVNGInputStream> &stream) override;
00098   std::shared_ptr<HJ> parseHJ(const std::shared_ptr<librevenge::RVNGInputStream> &stream) override;
00099 
00100   Page parsePage(const std::shared_ptr<librevenge::RVNGInputStream> &stream, QXP4Deobfuscator &deobfuscate);
00101 
00102   void parseObject(const std::shared_ptr<librevenge::RVNGInputStream> &stream, QXP4Deobfuscator &deobfuscate, QXPCollector &collector, const Page &page, unsigned index);
00103   ObjectHeader parseObjectHeader(const std::shared_ptr<librevenge::RVNGInputStream> &stream, QXP4Deobfuscator &deobfuscate);
00104   void parseLine(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector);
00105   void parseBezierLine(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector);
00106   void parseBezierEmptyBox(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector);
00107   void parseEmptyBox(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector);
00108   void parseBezierPictureBox(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector);
00109   void parsePictureBox(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector);
00110   void parseLineText(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector);
00111   void parseBezierText(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector);
00112   void parseBezierTextBox(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector);
00113   void parseTextBox(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector);
00114   void parseGroup(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, QXPCollector &collector, const Page &page, unsigned index);
00115 
00116   Frame readFrame(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00117   bool readRunaround(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00118   void readLinkedTextSettings(const std::shared_ptr<librevenge::RVNGInputStream> &stream, LinkedTextSettings &settings);
00119   void readTextSettings(const std::shared_ptr<librevenge::RVNGInputStream> &stream, TextSettings &settings);
00120   void readTextPathSettings(const std::shared_ptr<librevenge::RVNGInputStream> &stream, TextPathSettings &settings);
00121   void readOleObject(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00122   void readPictureSettings(const std::shared_ptr<librevenge::RVNGInputStream> &stream, std::shared_ptr<PictureBox> &picturebox);
00123   void readImageData(const std::shared_ptr<librevenge::RVNGInputStream> &stream);
00124   void readBezierData(const std::shared_ptr<librevenge::RVNGInputStream> &stream, std::vector<CurveComponent> &curveComponents, Rect &bbox);
00125   void skipTextObjectEnd(const std::shared_ptr<librevenge::RVNGInputStream> &stream, const ObjectHeader &header, const LinkedTextSettings &linkedTextSettings);
00126 };
00127 
00128 }
00129 
00130 #endif // QXP4PARSER_H_INCLUDED
00131 
00132 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */