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 | |
31 | QT_BEGIN_NAMESPACE |
32 | |
33 | class QTextDocumentPrivate; |
34 | class QTextCursor; |
35 | class QTextBlock; |
36 | class QIODevice; |
37 | class QXmlStreamWriter; |
38 | class QTextOdfWriterPrivate; |
39 | class QTextBlockFormat; |
40 | class QTextCharFormat; |
41 | class QTextListFormat; |
42 | class QTextFrameFormat; |
43 | class QTextTableCellFormat; |
44 | class QTextFrame; |
45 | class QTextFragment; |
46 | class QOutputStrategy; |
47 | |
48 | class Q_AUTOTEST_EXPORT QTextOdfWriter { |
49 | public: |
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 | |
71 | protected: |
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 | |
77 | private: |
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 | |
91 | QT_END_NAMESPACE |
92 | |
93 | #endif // QT_NO_TEXTODFWRITER |
94 | #endif // QTEXTODFWRITER_H |
95 | |