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
19
#include <
html/HtmlSavingContext.h
>
20
21
#include <
KisPortingUtils.h
>
22
23
HtmlWriter::HtmlWriter
(
const
QList<KoShape*>
&toplevelShapes)
24
: m_toplevelShapes(toplevelShapes)
25
{
26
}
27
28
HtmlWriter::~HtmlWriter
()
29
{
30
}
31
32
bool
HtmlWriter::save
(QIODevice &outputDevice)
33
{
34
if
(
m_toplevelShapes
.isEmpty()) {
35
return
false
;
36
}
37
38
QTextStream htmlStream(&outputDevice);
39
KisPortingUtils::setUtf8OnStream
(htmlStream);
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
57
QStringList
HtmlWriter::errors
()
const
58
{
59
return
m_errors
;
60
}
61
62
QStringList
HtmlWriter::warnings
()
const
63
{
64
return
m_warnings
;
65
}
66
67
void
HtmlWriter::saveShapes
(
const
QList<KoShape *>
shapes,
HtmlSavingContext
&savingContext)
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
}
HtmlSavingContext.h
HtmlWriter.h
KisPortingUtils.h
KoShapeGroup.h
KoShapeLayer.h
KoShape.h
KoSvgTextShape.h
HtmlSavingContext
The HtmlSavingContext class provides context for saving a flake-based document to html.
Definition
HtmlSavingContext.h:24
HtmlWriter::m_warnings
QStringList m_warnings
Definition
HtmlWriter.h:39
HtmlWriter::errors
QStringList errors() const
Definition
HtmlWriter.cpp:57
HtmlWriter::~HtmlWriter
virtual ~HtmlWriter()
Definition
HtmlWriter.cpp:28
HtmlWriter::save
bool save(QIODevice &outputDevice)
Definition
HtmlWriter.cpp:32
HtmlWriter::m_errors
QStringList m_errors
Definition
HtmlWriter.h:38
HtmlWriter::m_toplevelShapes
QList< KoShape * > m_toplevelShapes
Definition
HtmlWriter.h:37
HtmlWriter::HtmlWriter
HtmlWriter(const QList< KoShape * > &toplevelShapes)
Definition
HtmlWriter.cpp:23
HtmlWriter::warnings
QStringList warnings() const
Definition
HtmlWriter.cpp:62
HtmlWriter::saveShapes
void saveShapes(const QList< KoShape * > shapes, HtmlSavingContext &savingContext)
Definition
HtmlWriter.cpp:67
KoShapeGroup
Definition
KoShapeGroup.h:35
KoShapeLayer
Definition
KoShapeLayer.h:20
KoShape
Definition
KoShape.h:92
KoShape::name
QString name() const
Definition
KoShape.cpp:1150
KoSvgTextShape
Definition
KoSvgTextShape.h:29
KoSvgTextShape::saveHtml
bool saveHtml(HtmlSavingContext &context)
Definition
KoSvgTextShape.cpp:1357
QList
Definition
KisQStringListFwd.h:16
KisPortingUtils::setUtf8OnStream
void setUtf8OnStream(QTextStream &stream)
Definition
KisPortingUtils.h:18
libs
flake
html
HtmlWriter.cpp
Generated at
2025-11-04 02:30:02+01:00
from
Krita
branch
master
, commit
c9dde2e79561a8aea4a7e8d9ac99c98a7bac9e52