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>
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.
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.
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.
21
#ifndef ODTHTMLCONVERTER_H
22
#define ODTHTMLCONVERTER_H
28
#include <KoXmlReader.h>
46
int defaultOutlineLevel;
47
bool shouldBreakChapter;
50
QHash<QString, QString> attributes;
54
class OdtHtmlConverter
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.
68
KoFilter::ConversionStatus convertContent(KoStore *odfStore, QHash<QString, QString> &metaData,
69
ConversionOptions *options,
70
FileCollector *collector,
72
QHash<QString, QSizeF> &images);
76
// Helper functions to create the html contents.
77
void beginHtmlFile(QHash<QString, QString> &metaData);
79
void createHtmlHead(KoXmlWriter *writer, QHash<QString, QString> &metaData);
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);
89
void handleTagTable(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
91
void handleTagA(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
93
void handleTagPageBreak(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
94
void handleTagList(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
96
void handleTagFrame(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
98
void handleTagTab(KoXmlWriter *htmlWriter);
99
void handleTagTableOfContent(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
100
void handleTagTableOfContentBody(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
102
void handleTagLineBreak(KoXmlWriter *htmlWriter);
103
void handleTagBookMark(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
104
void handleTagBookMarkStart(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
105
void handleTagBookMarkEnd(KoXmlWriter *htmlWriter);
107
void handleUnknownTags(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
108
void handleTagNote(KoXmlElement &nodeElement, KoXmlWriter *htmlWriter);
110
void collectInternalLinksInfo(KoXmlElement ¤tElement, int &chapter);
112
void writeFootNotes(KoXmlWriter *htmlWriter);
113
void writeEndNotes(KoXmlWriter *htmlWriter);
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);
119
void fixStyleTree(QHash<QString, StyleInfo*> &styles);
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);
129
FileCollector *m_collector;
131
// Some variables used while creating the HTML contents.
132
QByteArray m_cssContent;
133
QByteArray m_htmlContent;
135
KoXmlWriter *m_htmlWriter;
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;
142
QHash<QString, StyleInfo*> m_styles;
144
// The number of the current chapter during the conversion.
145
int m_currentChapter;
147
// A list of images and their sizes. This list is collected during
148
// the conversion and returned from convertContent() using an
151
// The format is QHash<name, size>
153
// name is the name of the picture inside the ODT file
154
// size is the size in points.
156
QHash<QString, QSizeF> m_images;
158
// Internal links have to be done in a two pass fashion.
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.
167
// The format is QHash<name, filename>
169
// name is a unique name for this anchor
170
// filename is the filename where it occurs. example: "chapter3.xhtml"
172
QHash<QString, QString> m_linksInfo;
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.
178
// The format is QHash<id, noteElement>
180
// id is a unique name for this footnote
181
// noteElement is the KoXmlElement that contains the body of the note
183
QHash<QString, KoXmlElement> m_footNotes;
184
QHash<QString, KoXmlElement> m_endNotes;
186
// specifice valuse for mobi.
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;
196
// In mobi we dont need indentation.
199
// Format: QHash<Qstring anchor, qint64 anchor position>
200
QHash<QString, qint64> m_mobiInternalLinks;
206
#endif // ODTHTMLCONVERTER_H