Krita Source Code Documentation
Loading...
Searching...
No Matches
HtmlWriter.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#include "HtmlWriter.h"
7
8#include <QDebug>
9#include <QIODevice>
10#include <QTextStream>
11
12#include <klocalizedstring.h>
13
14#include <KoShape.h>
15#include <KoShapeLayer.h>
16#include <KoShapeGroup.h>
17#include <KoSvgTextShape.h>
18
20
21#include <KisPortingUtils.h>
22
24 : m_toplevelShapes(toplevelShapes)
25{
26}
27
31
32bool HtmlWriter::save(QIODevice &outputDevice)
33{
34 if (m_toplevelShapes.isEmpty()) {
35 return false;
36 }
37
38 QTextStream htmlStream(&outputDevice);
40
41 // header
42 htmlStream << QLatin1String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
43 "\"http://www.w3.org/TR/REC-html40/strict.dtd\">"
44 "<html><head><meta name=\"Krita Svg Text\" />"
45 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>"
46 "</head>");
47 htmlStream.flush();
48 {
49 HtmlSavingContext savingContext(outputDevice);
50 saveShapes(m_toplevelShapes, savingContext);
51 }
52 htmlStream << "</html>";
53 htmlStream.flush();
54 return true;
55}
56
58{
59 return m_errors;
60}
61
63{
64 return m_warnings;
65}
66
68{
69 Q_FOREACH (KoShape *shape, shapes) {
70 KoShapeLayer *layer = dynamic_cast<KoShapeLayer*>(shape);
71 if (layer) {
72 m_errors << i18n("Saving KoShapeLayer to html is not implemented yet!");
73 } else {
74 KoShapeGroup *group = dynamic_cast<KoShapeGroup*>(shape);
75 if (group) {
76 m_errors << i18n("KoShapeGroup to html is not implemented yet!");
77 }
78 else {
79 KoSvgTextShape *svgTextShape = dynamic_cast<KoSvgTextShape*>(shape);
80 if (svgTextShape) {
81 if (!svgTextShape->saveHtml(savingContext)) {
82 m_errors << i18n("saving to html failed");
83 }
84 }
85 else {
86 m_errors << i18n("Cannot save %1 to html", shape->name());
87 }
88 }
89 }
90 }
91}
The HtmlSavingContext class provides context for saving a flake-based document to html.
QStringList m_warnings
Definition HtmlWriter.h:39
QStringList errors() const
virtual ~HtmlWriter()
bool save(QIODevice &outputDevice)
QStringList m_errors
Definition HtmlWriter.h:38
QList< KoShape * > m_toplevelShapes
Definition HtmlWriter.h:37
HtmlWriter(const QList< KoShape * > &toplevelShapes)
QStringList warnings() const
void saveShapes(const QList< KoShape * > shapes, HtmlSavingContext &savingContext)
QString name() const
Definition KoShape.cpp:1150
bool saveHtml(HtmlSavingContext &context)
void setUtf8OnStream(QTextStream &stream)