1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTEXTODFWRITER_H
5#define QTEXTODFWRITER_H
6
7#include <QtGui/private/qtguiglobal_p.h>
8
9#ifndef QT_NO_TEXTODFWRITER
10
11//
12// W A R N I N G
13// -------------
14//
15// This file is not part of the Qt API. It exists purely as an
16// implementation detail. This header file may change from version to
17// version without notice, or even be removed.
18//
19// We mean it.
20//
21
22#include <QtCore/qhash.h>
23#include <QtCore/qlist.h>
24#include <QtCore/qset.h>
25#include <QtCore/qstack.h>
26#include <QtCore/QXmlStreamWriter>
27
28#include "qtextdocument_p.h"
29#include "qtextdocumentwriter.h"
30
31QT_BEGIN_NAMESPACE
32
33class QTextDocumentPrivate;
34class QTextCursor;
35class QTextBlock;
36class QIODevice;
37class QXmlStreamWriter;
38class QTextOdfWriterPrivate;
39class QTextBlockFormat;
40class QTextCharFormat;
41class QTextListFormat;
42class QTextFrameFormat;
43class QTextTableCellFormat;
44class QTextFrame;
45class QTextFragment;
46class QOutputStrategy;
47
48class Q_AUTOTEST_EXPORT QTextOdfWriter {
49public:
50 QTextOdfWriter(const QTextDocument &document, QIODevice *device);
51 bool writeAll();
52
53 void setCreateArchive(bool on) { m_createArchive = on; }
54 bool createArchive() const { return m_createArchive; }
55
56 void writeBlock(QXmlStreamWriter &writer, const QTextBlock &block);
57 void writeFormats(QXmlStreamWriter &writer, const QSet<int> &formatIds) const;
58 void writeBlockFormat(QXmlStreamWriter &writer, QTextBlockFormat format, int formatIndex) const;
59 void writeCharacterFormat(QXmlStreamWriter &writer, QTextCharFormat format, int formatIndex) const;
60 void writeListFormat(QXmlStreamWriter &writer, QTextListFormat format, int formatIndex) const;
61 void writeFrameFormat(QXmlStreamWriter &writer, QTextFrameFormat format, int formatIndex) const;
62 void writeTableFormat(QXmlStreamWriter &writer, QTextTableFormat format, int formatIndex) const;
63 void writeTableCellFormat(QXmlStreamWriter &writer, QTextTableCellFormat format,
64 int formatIndex, QList<QTextFormat> &styles) const;
65 void writeFrame(QXmlStreamWriter &writer, const QTextFrame *frame);
66 void writeInlineCharacter(QXmlStreamWriter &writer, const QTextFragment &fragment) const;
67
68 const QString officeNS, textNS, styleNS, foNS, tableNS, drawNS, xlinkNS, svgNS;
69 const int defaultImageResolution = 11811; // 11811 dots per meter = (about) 300 dpi
70
71protected:
72 void tableCellStyleElement(QXmlStreamWriter &writer, const int &formatIndex,
73 const QTextTableCellFormat &format,
74 bool hasBorder, int tableId = 0,
75 const QTextTableFormat tableFormatTmp = QTextTableFormat()) const;
76
77private:
78 const QTextDocument *m_document;
79 QIODevice *m_device;
80
81 QOutputStrategy *m_strategy;
82 bool m_createArchive;
83
84 QStack<QTextList *> m_listStack;
85
86 QHash<int, QList<int>> m_cellFormatsInTablesWithBorders;
87 QSet<int> m_tableFormatsWithBorders;
88 mutable QSet<int> m_tableFormatsWithColWidthConstraints;
89};
90
91QT_END_NAMESPACE
92
93#endif // QT_NO_TEXTODFWRITER
94#endif // QTEXTODFWRITER_H
95

source code of qtbase/src/gui/text/qtextodfwriter_p.h