UBCFFSubsetAdaptor.h 5.53 KB
Newer Older
1 2 3
/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
Claudio Valerio's avatar
Claudio Valerio committed
4
 * the Free Software Foundation, either version 2 of the License, or
5 6 7 8 9 10 11 12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

16 17 18 19 20
#ifndef UBCFFSUBSETADAPTOR_H
#define UBCFFSUBSETADAPTOR_H

#include <QtXml>
#include <QString>
21
#include <QStack>
Ivan Ilin's avatar
Ivan Ilin committed
22 23
#include <QDomDocument>
#include <QHash>
24 25

class UBDocumentProxy;
26 27
class UBGraphicsScene;
class QSvgGenerator;
28
class UBGraphicsSvgItem;
29
class UBGraphicsPixmapItem;
30
class UBGraphicsItemDelegate;
31
class QTransform;
32
class QPainter;
33
class UBGraphicsItem;
Ivan Ilin's avatar
Ivan Ilin committed
34
class QGraphicsItem;
35 36
class QTextBlockFormat;
class QTextCharFormat;
Ivan Ilin's avatar
Ivan Ilin committed
37
class QTextCursor;
38

Ivan Ilin's avatar
Ivan Ilin committed
39

40 41 42 43
class UBCFFSubsetAdaptor
{
public:
    UBCFFSubsetAdaptor();
44
    static bool ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentProxy* pDocument);
45 46 47 48 49

private:
    class UBCFFSubsetReader
    {
    public:
50
        UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content);
51
        ~UBCFFSubsetReader();
52 53

        UBDocumentProxy *mProxy;
54
        QString pwdContent;
55 56 57 58 59 60

        bool parse();

    private:
        QString mTempFilePath;
        UBGraphicsScene *mCurrentScene;
61
        QRectF mCurrentSceneRect;
62 63
        QString mIndent;
        QRectF mViewBox;
64 65
        QRectF mViewPort;
        qreal mVBTransFactor;
66
        QPointF mViewBoxCenter;
67
        QSize mSize;
Ivan Ilin's avatar
Ivan Ilin committed
68
        QPointF mShiftVector;
69

Ivan Ilin's avatar
Ivan Ilin committed
70 71
    private:
        QDomDocument mDOMdoc;
72
        QDomNode mCurrentDOMElement;
73
        QHash<QString, UBGraphicsItem*> persistedItems;
Ivan Ilin's avatar
Ivan Ilin committed
74
        QDir mTmpFlashDir;
75

Ivan Ilin's avatar
Ivan Ilin committed
76
        bool hashElements();
77
        void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup);
Ivan Ilin's avatar
Ivan Ilin committed
78

79 80
        void hashSvg(QDomNode *parent, QString prefix = "");
        void hashSiblingIwbElements(QDomElement *parent, QDomElement *topGroup = 0);
Ivan Ilin's avatar
Ivan Ilin committed
81

82 83 84 85
        inline void parseSvgSectionAttr(const QDomElement &);
        bool parseSvgPage(const QDomElement &parent);
        bool parseSvgPageset(const QDomElement &parent);
        bool parseSvgElement(const QDomElement &parent);
Ivan Ilin's avatar
Ivan Ilin committed
86 87
        bool parseIwbMeta(const QDomElement &element);
        bool parseSvg(const QDomElement &svgSection);
88

Ivan Ilin's avatar
Ivan Ilin committed
89 90
        inline bool parseGSection(const QDomElement &element);
        inline bool parseSvgSwitchSection(const QDomElement &element);
91 92 93 94 95 96 97
        inline bool parseSvgRect(const QDomElement &element);
        inline bool parseSvgEllipse(const QDomElement &element);
        inline bool parseSvgPolygon(const QDomElement &element);
        inline bool parseSvgPolyline(const QDomElement &element);
        inline bool parseSvgText(const QDomElement &element);
        inline bool parseSvgTextarea(const QDomElement &element);
        inline bool parseSvgImage(const QDomElement &element);
Ivan Ilin's avatar
Ivan Ilin committed
98 99 100 101 102
        inline bool parseSvgFlash(const QDomElement &element);
        inline bool parseSvgAudio(const QDomElement &element);
        inline bool parseSvgVideo(const QDomElement &element);
        inline bool parseIwbGroup(QDomElement &parent);
        inline bool parseIwbElement(QDomElement &element);
Ivan Ilin's avatar
Ivan Ilin committed
103 104 105 106
        inline void parseTSpan(const QDomElement &parent, QPainter &painter
                               , qreal &curX, qreal &curY, qreal &width, qreal &height, qreal &linespacing, QRectF &lastDrawnTextBoundingRect
                               , qreal &fontSize, QColor &fontColor, QString &fontFamily, QString &fontStretch, bool &italic
                               , int &fontWeight, int &textAlign, QTransform &fontTransform);
Ivan Ilin's avatar
Ivan Ilin committed
107 108
        inline void parseTSpan(const QDomElement &element, QTextCursor &cursor
                               , QTextBlockFormat &blockFormat, QTextCharFormat &charFormat);
109
        inline void hashSceneItem(const QDomElement &element, UBGraphicsItem *item);
110 111

        // to kill
112
        inline void parseTextAttributes(const QDomElement &element, qreal &fontSize, QColor &fontColor,
113 114
                                 QString &fontFamily, QString &fontStretch, bool &italic,
                                 int &fontWeight, int &textAlign, QTransform &fontTransform);
115 116 117
        inline void parseTextAttributes(const QDomElement &element, QFont &font, QColor);
        inline void readTextBlockAttr(const QDomElement &element, QTextBlockFormat &format);
        inline void readTextCharAttr(const QDomElement &element, QTextCharFormat &format);
118

119 120 121 122 123
        //elements parsing methods
        bool parseDoc();

        bool createNewScene();
        bool persistCurrentScene();
124
        bool persistScenes();
125

Ivan Ilin's avatar
Ivan Ilin committed
126 127 128
//        helper methods
        void repositionSvgItem(QGraphicsItem *item, qreal width, qreal height,
                               qreal x, qreal y,
Ivan Ilin's avatar
Ivan Ilin committed
129
                               QTransform &transform);
130
        QColor colorFromString(const QString& clrString);
Ivan Ilin's avatar
Ivan Ilin committed
131
        QTransform transformFromString(const QString trString, QGraphicsItem *item = 0);
132
        bool getViewBoxDimenstions(const QString& viewBox);
133
        QSvgGenerator* createSvgGenerator(qreal width, qreal height);
134
        bool getTempFileName();
Ivan Ilin's avatar
Ivan Ilin committed
135 136
        inline bool strToBool(QString);
        bool createTempFlashPath();
137 138 139 140
    };
};

#endif // UBCFFSUBSETADAPTOR_H