~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to filters/words/epub/OdtHtmlConverter.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 /* This file is part of the KDE project
 
2
   Copyright (C) 2012 Inge Wallin            <inge@lysator.liu.se>
 
3
   Copyright (C) 2012 Mojtaba Shahi Senobari <mojtaba.shahi3000@gmail.com>
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#ifndef ODTHTMLCONVERTER_H
 
22
#define ODTHTMLCONVERTER_H
 
23
 
 
24
#include <QHash>
 
25
#include <QString>
 
26
#include <QList>
 
27
 
 
28
#include <KoXmlReader.h>
 
29
#include <KoFilter.h>
 
30
 
 
31
class QByteArray;
 
32
class QSizeF;
 
33
class QStringList;
 
34
class KoXmlWriter;
 
35
class KoStore;
 
36
class FileCollector;
 
37
 
 
38
 
 
39
struct StyleInfo {
 
40
    StyleInfo();
 
41
 
 
42
    QString family;
 
43
    QString parent;
 
44
    bool isDefaultStyle;
 
45
 
 
46
    int  defaultOutlineLevel;
 
47
    bool shouldBreakChapter;
 
48
    bool inUse;
 
49
 
 
50
    QHash<QString, QString> attributes;
 
51
};
 
52
 
 
53
 
 
54
class OdtHtmlConverter
 
55
{
 
56
 public:
 
57
    struct ConversionOptions {
 
58
        bool  stylesInCssFile;  // True if the css should go into a separate file
 
59
        bool  doBreakIntoChapters; // True if the output should be broken into chapters.
 
60
        bool  useMobiConventions;  // True if Mobi is using the convention.
 
61
                                   // to handle img tag and for handle indention
 
62
                                   // and dont write meta and link tag in html head.
 
63
    };
 
64
 
 
65
    OdtHtmlConverter();
 
66
    ~OdtHtmlConverter();
 
67
 
 
68
    KoFilter::ConversionStatus convertContent(KoStore *odfStore, QHash<QString, QString> &metaData,
 
69
                                              ConversionOptions *options,
 
70
                                              FileCollector *collector,
 
71
                                              // Out parameters:
 
72
                                              QHash<QString, QSizeF> &images);
 
73
 
 
74
 private:
 
75
 
 
76
    // Helper functions to create the html contents.
 
77
    void beginHtmlFile(QHash<QString, QString> &metaData);
 
78
    void endHtmlFile();
 
79
    void createHtmlHead(KoXmlWriter *writer, QHash<QString, QString> &metaData);
 
80
 
 
81
 
 
82
    // All handleTag*() are named after the tag in the ODF that they handle.
 
83
    void handleInsideElementsTag(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
84
    void handleTagP(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
85
    void handleTagH(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
86
    void handleTagSpan(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
87
    void handleCharacterData(KoXmlNode &node, KoXmlWriter *htmlWriter);
 
88
 
 
89
    void handleTagTable(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
90
 
 
91
    void handleTagA(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
92
 
 
93
    void handleTagPageBreak(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
94
    void handleTagList(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
95
 
 
96
    void handleTagFrame(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
97
 
 
98
    void handleTagTab(KoXmlWriter *htmlWriter);
 
99
    void handleTagTableOfContent(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
100
    void handleTagTableOfContentBody(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
101
 
 
102
    void handleTagLineBreak(KoXmlWriter *htmlWriter);
 
103
    void handleTagBookMark(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
104
    void handleTagBookMarkStart(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
105
    void handleTagBookMarkEnd(KoXmlWriter *htmlWriter);
 
106
 
 
107
    void handleUnknownTags(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
108
    void handleTagNote(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
 
109
 
 
110
    void collectInternalLinksInfo(KoXmlElement &currentElement, int &chapter);
 
111
 
 
112
    void writeFootNotes(KoXmlWriter *htmlWriter);
 
113
    void writeEndNotes(KoXmlWriter *htmlWriter);
 
114
 
 
115
    KoFilter::ConversionStatus collectStyles(KoStore *odfStore, QHash<QString, StyleInfo*> &styles);
 
116
    void collectStyleSet(KoXmlNode &stylesNode, QHash<QString, StyleInfo*> &styles);
 
117
    void collectStyleAttributes(KoXmlElement &propertiesElement, StyleInfo *styleInfo);
 
118
 
 
119
    void fixStyleTree(QHash<QString, StyleInfo*> &styles);
 
120
 
 
121
    KoFilter::ConversionStatus createCSS(QHash<QString, StyleInfo*> &styles,
 
122
                                         QByteArray &cssContent);
 
123
    void flattenStyles(QHash<QString, StyleInfo*> &styles);
 
124
    void flattenStyle(const QString &styleName, QHash<QString, StyleInfo*> &styles,
 
125
                      QSet<QString> &doneStyles);
 
126
 
 
127
 
 
128
 private:
 
129
    FileCollector *m_collector;
 
130
 
 
131
    // Some variables used while creating the HTML contents.
 
132
    QByteArray   m_cssContent;
 
133
    QByteArray   m_htmlContent;
 
134
    QBuffer     *m_outBuf;
 
135
    KoXmlWriter *m_htmlWriter;
 
136
 
 
137
    // Options for the conversion process
 
138
    // FIXME: This should go into an Options struct together with some
 
139
    //        others from FileConversion.h.
 
140
    ConversionOptions  *m_options;
 
141
 
 
142
    QHash<QString, StyleInfo*> m_styles;
 
143
 
 
144
    // The number of the current chapter during the conversion.
 
145
    int m_currentChapter;
 
146
 
 
147
    // A list of images and their sizes. This list is collected during
 
148
    // the conversion and returned from convertContent() using an
 
149
    // outparameter.
 
150
    //
 
151
    // The format is QHash<name, size>
 
152
    // where
 
153
    //    name   is the name of the picture inside the ODT file
 
154
    //    size   is the size in points.
 
155
    //
 
156
    QHash<QString, QSizeF>  m_images;
 
157
 
 
158
    // Internal links have to be done in a two pass fashion.
 
159
    //
 
160
    // The first pass just quickly steps through the content and
 
161
    // collects the anchors in linksInfo. The second pass is the
 
162
    // actual conversion where linksInfo is used to create the
 
163
    // links. The reason we have to do it like this is that the
 
164
    // contents is split up into chapters and we have to know when we
 
165
    // write the href which file (chapter) the anchor is in.
 
166
    //
 
167
    // The format is QHash<name, filename>
 
168
    // where
 
169
    //    name      is a unique name for this anchor
 
170
    //    filename  is the filename where it occurs. example: "chapter3.xhtml"
 
171
    //
 
172
    QHash<QString, QString> m_linksInfo;
 
173
 
 
174
    // Footnotes are collected while parsing a chapter and written at
 
175
    // the end of a chapter. Endnotes are collected while parsing all
 
176
    // chapters and are written into its own file at the end of the book.
 
177
    //
 
178
    // The format is QHash<id, noteElement>
 
179
    // where
 
180
    //    id          is a unique name for this footnote
 
181
    //    noteElement is the KoXmlElement that contains the body of the note
 
182
    //
 
183
    QHash<QString, KoXmlElement> m_footNotes;
 
184
    QHash<QString, KoXmlElement> m_endNotes;
 
185
 
 
186
    // specifice valuse for mobi.
 
187
 
 
188
    // The format is QHash<QString source, int index>
 
189
    // In mobi we save images with index and as we can have repeated
 
190
    // images we need a hash.
 
191
    // e.g img tag format in mobi <img recindex="0004">
 
192
    QHash<QString, int> m_imagesIndex;
 
193
 
 
194
    int m_imgIndex;
 
195
 
 
196
    // In mobi we dont need indentation.
 
197
    bool m_doIndent;
 
198
 
 
199
    // Format: QHash<Qstring anchor, qint64 anchor position>
 
200
    QHash<QString, qint64> m_mobiInternalLinks;
 
201
 
 
202
    //
 
203
 
 
204
};
 
205
 
 
206
#endif // ODTHTMLCONVERTER_H