| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextodfwriter.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include <qglobal.h> | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | #ifndef QT_NO_TEXTODFWRITER | - | ||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | #include "qtextodfwriter_p.h" | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include <QImageWriter> | - | ||||||||||||||||||
| 41 | #include <QTextListFormat> | - | ||||||||||||||||||
| 42 | #include <QTextList> | - | ||||||||||||||||||
| 43 | #include <QBuffer> | - | ||||||||||||||||||
| 44 | #include <QUrl> | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | #include "qtextdocument_p.h" | - | ||||||||||||||||||
| 47 | #include "qtexttable.h" | - | ||||||||||||||||||
| 48 | #include "qtextcursor.h" | - | ||||||||||||||||||
| 49 | #include "qtextimagehandler_p.h" | - | ||||||||||||||||||
| 50 | #include "qzipwriter_p.h" | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | #include <QDebug> | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | /// Convert pixels to postscript point units | - | ||||||||||||||||||
| 57 | static QString pixelToPoint(qreal pixels) | - | ||||||||||||||||||
| 58 | { | - | ||||||||||||||||||
| 59 | // we hardcode 96 DPI, we do the same in the ODF importer to have a perfect roundtrip. | - | ||||||||||||||||||
| 60 | return QString::number(pixels * 72 / 96) + QString::fromLatin1("pt"); never executed: return QString::number(pixels * 72 / 96) + QString::fromLatin1("pt"); | 0 | ||||||||||||||||||
| 61 | } | - | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | // strategies | - | ||||||||||||||||||
| 64 | class QOutputStrategy { | - | ||||||||||||||||||
| 65 | public: | - | ||||||||||||||||||
| 66 | QOutputStrategy() : contentStream(0), counter(1) { } never executed: end of block | 0 | ||||||||||||||||||
| 67 | virtual ~QOutputStrategy() {} | - | ||||||||||||||||||
| 68 | virtual void addFile(const QString &fileName, const QString &mimeType, const QByteArray &bytes) = 0; | - | ||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | QString createUniqueImageName() | - | ||||||||||||||||||
| 71 | { | - | ||||||||||||||||||
| 72 | return QString::fromLatin1("Pictures/Picture%1").arg(counter++); never executed: return QString::fromLatin1("Pictures/Picture%1").arg(counter++); | 0 | ||||||||||||||||||
| 73 | } | - | ||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | QIODevice *contentStream; | - | ||||||||||||||||||
| 76 | int counter; | - | ||||||||||||||||||
| 77 | }; | - | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | class QXmlStreamStrategy : public QOutputStrategy { | - | ||||||||||||||||||
| 80 | public: | - | ||||||||||||||||||
| 81 | QXmlStreamStrategy(QIODevice *device) | - | ||||||||||||||||||
| 82 | { | - | ||||||||||||||||||
| 83 | contentStream = device; | - | ||||||||||||||||||
| 84 | } never executed: end of block | 0 | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | virtual ~QXmlStreamStrategy() | - | ||||||||||||||||||
| 87 | { | - | ||||||||||||||||||
| 88 | if (contentStream)
| 0 | ||||||||||||||||||
| 89 | contentStream->close(); never executed: contentStream->close(); | 0 | ||||||||||||||||||
| 90 | } never executed: end of block | 0 | ||||||||||||||||||
| 91 | virtual void addFile(const QString &, const QString &, const QByteArray &) Q_DECL_OVERRIDE | - | ||||||||||||||||||
| 92 | { | - | ||||||||||||||||||
| 93 | // we ignore this... | - | ||||||||||||||||||
| 94 | } | - | ||||||||||||||||||
| 95 | }; | - | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | class QZipStreamStrategy : public QOutputStrategy { | - | ||||||||||||||||||
| 98 | public: | - | ||||||||||||||||||
| 99 | QZipStreamStrategy(QIODevice *device) | - | ||||||||||||||||||
| 100 | : zip(device), | - | ||||||||||||||||||
| 101 | manifestWriter(&manifest) | - | ||||||||||||||||||
| 102 | { | - | ||||||||||||||||||
| 103 | QByteArray mime("application/vnd.oasis.opendocument.text"); | - | ||||||||||||||||||
| 104 | zip.setCompressionPolicy(QZipWriter::NeverCompress); | - | ||||||||||||||||||
| 105 | zip.addFile(QString::fromLatin1("mimetype"), mime); // for mime-magick | - | ||||||||||||||||||
| 106 | zip.setCompressionPolicy(QZipWriter::AutoCompress); | - | ||||||||||||||||||
| 107 | contentStream = &content; | - | ||||||||||||||||||
| 108 | content.open(QIODevice::WriteOnly); | - | ||||||||||||||||||
| 109 | manifest.open(QIODevice::WriteOnly); | - | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | manifestNS = QString::fromLatin1("urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"); | - | ||||||||||||||||||
| 112 | // prettyfy | - | ||||||||||||||||||
| 113 | manifestWriter.setAutoFormatting(true); | - | ||||||||||||||||||
| 114 | manifestWriter.setAutoFormattingIndent(1); | - | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | manifestWriter.writeNamespace(manifestNS, QString::fromLatin1("manifest")); | - | ||||||||||||||||||
| 117 | manifestWriter.writeStartDocument(); | - | ||||||||||||||||||
| 118 | manifestWriter.writeStartElement(manifestNS, QString::fromLatin1("manifest")); | - | ||||||||||||||||||
| 119 | manifestWriter.writeAttribute(manifestNS, QString::fromLatin1("version"), QString::fromLatin1("1.2")); | - | ||||||||||||||||||
| 120 | addFile(QString::fromLatin1("/"), QString::fromLatin1("application/vnd.oasis.opendocument.text")); | - | ||||||||||||||||||
| 121 | addFile(QString::fromLatin1("content.xml"), QString::fromLatin1("text/xml")); | - | ||||||||||||||||||
| 122 | } never executed: end of block | 0 | ||||||||||||||||||
| 123 | - | |||||||||||||||||||
| 124 | ~QZipStreamStrategy() | - | ||||||||||||||||||
| 125 | { | - | ||||||||||||||||||
| 126 | manifestWriter.writeEndDocument(); | - | ||||||||||||||||||
| 127 | manifest.close(); | - | ||||||||||||||||||
| 128 | zip.addFile(QString::fromLatin1("META-INF/manifest.xml"), &manifest); | - | ||||||||||||||||||
| 129 | content.close(); | - | ||||||||||||||||||
| 130 | zip.addFile(QString::fromLatin1("content.xml"), &content); | - | ||||||||||||||||||
| 131 | zip.close(); | - | ||||||||||||||||||
| 132 | } never executed: end of block | 0 | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | virtual void addFile(const QString &fileName, const QString &mimeType, const QByteArray &bytes) Q_DECL_OVERRIDE | - | ||||||||||||||||||
| 135 | { | - | ||||||||||||||||||
| 136 | zip.addFile(fileName, bytes); | - | ||||||||||||||||||
| 137 | addFile(fileName, mimeType); | - | ||||||||||||||||||
| 138 | } never executed: end of block | 0 | ||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | private: | - | ||||||||||||||||||
| 141 | void addFile(const QString &fileName, const QString &mimeType) | - | ||||||||||||||||||
| 142 | { | - | ||||||||||||||||||
| 143 | manifestWriter.writeEmptyElement(manifestNS, QString::fromLatin1("file-entry")); | - | ||||||||||||||||||
| 144 | manifestWriter.writeAttribute(manifestNS, QString::fromLatin1("media-type"), mimeType); | - | ||||||||||||||||||
| 145 | manifestWriter.writeAttribute(manifestNS, QString::fromLatin1("full-path"), fileName); | - | ||||||||||||||||||
| 146 | } never executed: end of block | 0 | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | QBuffer content; | - | ||||||||||||||||||
| 149 | QBuffer manifest; | - | ||||||||||||||||||
| 150 | QZipWriter zip; | - | ||||||||||||||||||
| 151 | QXmlStreamWriter manifestWriter; | - | ||||||||||||||||||
| 152 | QString manifestNS; | - | ||||||||||||||||||
| 153 | }; | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | static QString bulletChar(QTextListFormat::Style style) | - | ||||||||||||||||||
| 156 | { | - | ||||||||||||||||||
| 157 | switch(style) { | - | ||||||||||||||||||
| 158 | case QTextListFormat::ListDisc: never executed: case QTextListFormat::ListDisc: | 0 | ||||||||||||||||||
| 159 | return QChar(0x25cf); // bullet character never executed: return QChar(0x25cf); | 0 | ||||||||||||||||||
| 160 | case QTextListFormat::ListCircle: never executed: case QTextListFormat::ListCircle: | 0 | ||||||||||||||||||
| 161 | return QChar(0x25cb); // white circle never executed: return QChar(0x25cb); | 0 | ||||||||||||||||||
| 162 | case QTextListFormat::ListSquare: never executed: case QTextListFormat::ListSquare: | 0 | ||||||||||||||||||
| 163 | return QChar(0x25a1); // white square never executed: return QChar(0x25a1); | 0 | ||||||||||||||||||
| 164 | case QTextListFormat::ListDecimal: never executed: case QTextListFormat::ListDecimal: | 0 | ||||||||||||||||||
| 165 | return QString::fromLatin1("1"); never executed: return QString::fromLatin1("1"); | 0 | ||||||||||||||||||
| 166 | case QTextListFormat::ListLowerAlpha: never executed: case QTextListFormat::ListLowerAlpha: | 0 | ||||||||||||||||||
| 167 | return QString::fromLatin1("a"); never executed: return QString::fromLatin1("a"); | 0 | ||||||||||||||||||
| 168 | case QTextListFormat::ListUpperAlpha: never executed: case QTextListFormat::ListUpperAlpha: | 0 | ||||||||||||||||||
| 169 | return QString::fromLatin1("A"); never executed: return QString::fromLatin1("A"); | 0 | ||||||||||||||||||
| 170 | case QTextListFormat::ListLowerRoman: never executed: case QTextListFormat::ListLowerRoman: | 0 | ||||||||||||||||||
| 171 | return QString::fromLatin1("i"); never executed: return QString::fromLatin1("i"); | 0 | ||||||||||||||||||
| 172 | case QTextListFormat::ListUpperRoman: never executed: case QTextListFormat::ListUpperRoman: | 0 | ||||||||||||||||||
| 173 | return QString::fromLatin1("I"); never executed: return QString::fromLatin1("I"); | 0 | ||||||||||||||||||
| 174 | default: never executed: default: | 0 | ||||||||||||||||||
| 175 | case QTextListFormat::ListStyleUndefined: never executed: case QTextListFormat::ListStyleUndefined: | 0 | ||||||||||||||||||
| 176 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
| 177 | } | - | ||||||||||||||||||
| 178 | } | - | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | void QTextOdfWriter::writeFrame(QXmlStreamWriter &writer, const QTextFrame *frame) | - | ||||||||||||||||||
| 181 | { | - | ||||||||||||||||||
| 182 | Q_ASSERT(frame); | - | ||||||||||||||||||
| 183 | const QTextTable *table = qobject_cast<const QTextTable*> (frame); | - | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | if (table) { // Start a table.
| 0 | ||||||||||||||||||
| 186 | writer.writeStartElement(tableNS, QString::fromLatin1("table")); | - | ||||||||||||||||||
| 187 | writer.writeEmptyElement(tableNS, QString::fromLatin1("table-column")); | - | ||||||||||||||||||
| 188 | writer.writeAttribute(tableNS, QString::fromLatin1("number-columns-repeated"), QString::number(table->columns())); | - | ||||||||||||||||||
| 189 | } else if (frame->document() && frame->document()->rootFrame() != frame) { // start a section never executed: end of block
| 0 | ||||||||||||||||||
| 190 | writer.writeStartElement(textNS, QString::fromLatin1("section")); | - | ||||||||||||||||||
| 191 | } never executed: end of block | 0 | ||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | QTextFrame::iterator iterator = frame->begin(); | - | ||||||||||||||||||
| 194 | QTextFrame *child = 0; | - | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | int tableRow = -1; | - | ||||||||||||||||||
| 197 | while (! iterator.atEnd()) {
| 0 | ||||||||||||||||||
| 198 | if (iterator.currentFrame() && child != iterator.currentFrame())
| 0 | ||||||||||||||||||
| 199 | writeFrame(writer, iterator.currentFrame()); never executed: writeFrame(writer, iterator.currentFrame()); | 0 | ||||||||||||||||||
| 200 | else { // no frame, its a block | - | ||||||||||||||||||
| 201 | QTextBlock block = iterator.currentBlock(); | - | ||||||||||||||||||
| 202 | if (table) {
| 0 | ||||||||||||||||||
| 203 | QTextTableCell cell = table->cellAt(block.position()); | - | ||||||||||||||||||
| 204 | if (tableRow < cell.row()) {
| 0 | ||||||||||||||||||
| 205 | if (tableRow >= 0)
| 0 | ||||||||||||||||||
| 206 | writer.writeEndElement(); // close table row never executed: writer.writeEndElement(); | 0 | ||||||||||||||||||
| 207 | tableRow = cell.row(); | - | ||||||||||||||||||
| 208 | writer.writeStartElement(tableNS, QString::fromLatin1("table-row")); | - | ||||||||||||||||||
| 209 | } never executed: end of block | 0 | ||||||||||||||||||
| 210 | writer.writeStartElement(tableNS, QString::fromLatin1("table-cell")); | - | ||||||||||||||||||
| 211 | if (cell.columnSpan() > 1)
| 0 | ||||||||||||||||||
| 212 | writer.writeAttribute(tableNS, QString::fromLatin1("number-columns-spanned"), QString::number(cell.columnSpan())); never executed: writer.writeAttribute(tableNS, QString::fromLatin1("number-columns-spanned"), QString::number(cell.columnSpan())); | 0 | ||||||||||||||||||
| 213 | if (cell.rowSpan() > 1)
| 0 | ||||||||||||||||||
| 214 | writer.writeAttribute(tableNS, QString::fromLatin1("number-rows-spanned"), QString::number(cell.rowSpan())); never executed: writer.writeAttribute(tableNS, QString::fromLatin1("number-rows-spanned"), QString::number(cell.rowSpan())); | 0 | ||||||||||||||||||
| 215 | if (cell.format().isTableCellFormat()) {
| 0 | ||||||||||||||||||
| 216 | writer.writeAttribute(tableNS, QString::fromLatin1("style-name"), QString::fromLatin1("T%1").arg(cell.tableCellFormatIndex())); | - | ||||||||||||||||||
| 217 | } never executed: end of block | 0 | ||||||||||||||||||
| 218 | } never executed: end of block | 0 | ||||||||||||||||||
| 219 | writeBlock(writer, block); | - | ||||||||||||||||||
| 220 | if (table)
| 0 | ||||||||||||||||||
| 221 | writer.writeEndElement(); // table-cell never executed: writer.writeEndElement(); | 0 | ||||||||||||||||||
| 222 | } never executed: end of block | 0 | ||||||||||||||||||
| 223 | child = iterator.currentFrame(); | - | ||||||||||||||||||
| 224 | ++iterator; | - | ||||||||||||||||||
| 225 | } never executed: end of block | 0 | ||||||||||||||||||
| 226 | if (tableRow >= 0)
| 0 | ||||||||||||||||||
| 227 | writer.writeEndElement(); // close table-row never executed: writer.writeEndElement(); | 0 | ||||||||||||||||||
| 228 | - | |||||||||||||||||||
| 229 | if (table || (frame->document() && frame->document()->rootFrame() != frame))
| 0 | ||||||||||||||||||
| 230 | writer.writeEndElement(); // close table or section element never executed: writer.writeEndElement(); | 0 | ||||||||||||||||||
| 231 | } never executed: end of block | 0 | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &block) | - | ||||||||||||||||||
| 234 | { | - | ||||||||||||||||||
| 235 | if (block.textList()) { // its a list-item
| 0 | ||||||||||||||||||
| 236 | const int listLevel = block.textList()->format().indent(); | - | ||||||||||||||||||
| 237 | if (m_listStack.isEmpty() || m_listStack.top() != block.textList()) {
| 0 | ||||||||||||||||||
| 238 | // not the same list we were in. | - | ||||||||||||||||||
| 239 | while (m_listStack.count() >= listLevel && !m_listStack.isEmpty() && m_listStack.top() != block.textList() ) { // we need to close tags
| 0 | ||||||||||||||||||
| 240 | m_listStack.pop(); | - | ||||||||||||||||||
| 241 | writer.writeEndElement(); // list | - | ||||||||||||||||||
| 242 | if (m_listStack.count())
| 0 | ||||||||||||||||||
| 243 | writer.writeEndElement(); // list-item never executed: writer.writeEndElement(); | 0 | ||||||||||||||||||
| 244 | } never executed: end of block | 0 | ||||||||||||||||||
| 245 | while (m_listStack.count() < listLevel) {
| 0 | ||||||||||||||||||
| 246 | if (m_listStack.count())
| 0 | ||||||||||||||||||
| 247 | writer.writeStartElement(textNS, QString::fromLatin1("list-item")); never executed: writer.writeStartElement(textNS, QString::fromLatin1("list-item")); | 0 | ||||||||||||||||||
| 248 | writer.writeStartElement(textNS, QString::fromLatin1("list")); | - | ||||||||||||||||||
| 249 | if (m_listStack.count() == listLevel - 1) {
| 0 | ||||||||||||||||||
| 250 | m_listStack.push(block.textList()); | - | ||||||||||||||||||
| 251 | writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("L%1") | - | ||||||||||||||||||
| 252 | .arg(block.textList()->formatIndex())); | - | ||||||||||||||||||
| 253 | } never executed: end of block | 0 | ||||||||||||||||||
| 254 | else { | - | ||||||||||||||||||
| 255 | m_listStack.push(0); | - | ||||||||||||||||||
| 256 | } never executed: end of block | 0 | ||||||||||||||||||
| 257 | } | - | ||||||||||||||||||
| 258 | } never executed: end of block | 0 | ||||||||||||||||||
| 259 | writer.writeStartElement(textNS, QString::fromLatin1("list-item")); | - | ||||||||||||||||||
| 260 | } never executed: end of block | 0 | ||||||||||||||||||
| 261 | else { | - | ||||||||||||||||||
| 262 | while (! m_listStack.isEmpty()) {
| 0 | ||||||||||||||||||
| 263 | m_listStack.pop(); | - | ||||||||||||||||||
| 264 | writer.writeEndElement(); // list | - | ||||||||||||||||||
| 265 | if (m_listStack.count())
| 0 | ||||||||||||||||||
| 266 | writer.writeEndElement(); // list-item never executed: writer.writeEndElement(); | 0 | ||||||||||||||||||
| 267 | } never executed: end of block | 0 | ||||||||||||||||||
| 268 | } never executed: end of block | 0 | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | if (block.length() == 1) { // only a linefeed
| 0 | ||||||||||||||||||
| 271 | writer.writeEmptyElement(textNS, QString::fromLatin1("p")); | - | ||||||||||||||||||
| 272 | writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("p%1") | - | ||||||||||||||||||
| 273 | .arg(block.blockFormatIndex())); | - | ||||||||||||||||||
| 274 | if (block.textList())
| 0 | ||||||||||||||||||
| 275 | writer.writeEndElement(); // numbered-paragraph never executed: writer.writeEndElement(); | 0 | ||||||||||||||||||
| 276 | return; never executed: return; | 0 | ||||||||||||||||||
| 277 | } | - | ||||||||||||||||||
| 278 | writer.writeStartElement(textNS, QString::fromLatin1("p")); | - | ||||||||||||||||||
| 279 | writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("p%1") | - | ||||||||||||||||||
| 280 | .arg(block.blockFormatIndex())); | - | ||||||||||||||||||
| 281 | for (QTextBlock::Iterator frag = block.begin(); !frag.atEnd(); ++frag) {
| 0 | ||||||||||||||||||
| 282 | bool isHyperlink = frag.fragment().charFormat().hasProperty(QTextFormat::AnchorHref); | - | ||||||||||||||||||
| 283 | if (isHyperlink) {
| 0 | ||||||||||||||||||
| 284 | QString value = frag.fragment().charFormat().property(QTextFormat::AnchorHref).toString(); | - | ||||||||||||||||||
| 285 | writer.writeStartElement(textNS, QString::fromLatin1("a")); | - | ||||||||||||||||||
| 286 | writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), value); | - | ||||||||||||||||||
| 287 | } never executed: end of block | 0 | ||||||||||||||||||
| 288 | writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed in front of it. | - | ||||||||||||||||||
| 289 | writer.writeStartElement(textNS, QString::fromLatin1("span")); | - | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | QString fragmentText = frag.fragment().text(); | - | ||||||||||||||||||
| 292 | if (fragmentText.length() == 1 && fragmentText[0] == 0xFFFC) { // its an inline character.
| 0 | ||||||||||||||||||
| 293 | writeInlineCharacter(writer, frag.fragment()); | - | ||||||||||||||||||
| 294 | writer.writeEndElement(); // span | - | ||||||||||||||||||
| 295 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 296 | } | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("c%1") | - | ||||||||||||||||||
| 299 | .arg(frag.fragment().charFormatIndex())); | - | ||||||||||||||||||
| 300 | bool escapeNextSpace = true; | - | ||||||||||||||||||
| 301 | int precedingSpaces = 0; | - | ||||||||||||||||||
| 302 | int exportedIndex = 0; | - | ||||||||||||||||||
| 303 | for (int i=0; i <= fragmentText.count(); ++i) {
| 0 | ||||||||||||||||||
| 304 | QChar character = fragmentText[i]; | - | ||||||||||||||||||
| 305 | bool isSpace = character.unicode() == ' '; | - | ||||||||||||||||||
| 306 | - | |||||||||||||||||||
| 307 | // find more than one space. -> <text:s text:c="2" /> | - | ||||||||||||||||||
| 308 | if (!isSpace && escapeNextSpace && precedingSpaces > 1) {
| 0 | ||||||||||||||||||
| 309 | const bool startParag = exportedIndex == 0 && i == precedingSpaces;
| 0 | ||||||||||||||||||
| 310 | if (!startParag)
| 0 | ||||||||||||||||||
| 311 | writer.writeCharacters(fragmentText.mid(exportedIndex, i - precedingSpaces + 1 - exportedIndex)); never executed: writer.writeCharacters(fragmentText.mid(exportedIndex, i - precedingSpaces + 1 - exportedIndex)); | 0 | ||||||||||||||||||
| 312 | writer.writeEmptyElement(textNS, QString::fromLatin1("s")); | - | ||||||||||||||||||
| 313 | const int count = precedingSpaces - (startParag?0:1);
| 0 | ||||||||||||||||||
| 314 | if (count > 1)
| 0 | ||||||||||||||||||
| 315 | writer.writeAttribute(textNS, QString::fromLatin1("c"), QString::number(count)); never executed: writer.writeAttribute(textNS, QString::fromLatin1("c"), QString::number(count)); | 0 | ||||||||||||||||||
| 316 | precedingSpaces = 0; | - | ||||||||||||||||||
| 317 | exportedIndex = i; | - | ||||||||||||||||||
| 318 | } never executed: end of block | 0 | ||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | if (i < fragmentText.count()) {
| 0 | ||||||||||||||||||
| 321 | if (character.unicode() == 0x2028) { // soft-return
| 0 | ||||||||||||||||||
| 322 | //if (exportedIndex < i) | - | ||||||||||||||||||
| 323 | writer.writeCharacters(fragmentText.mid(exportedIndex, i - exportedIndex)); | - | ||||||||||||||||||
| 324 | writer.writeEmptyElement(textNS, QString::fromLatin1("line-break")); | - | ||||||||||||||||||
| 325 | exportedIndex = i+1; | - | ||||||||||||||||||
| 326 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 327 | } else if (character.unicode() == '\t') { // Tab
| 0 | ||||||||||||||||||
| 328 | //if (exportedIndex < i) | - | ||||||||||||||||||
| 329 | writer.writeCharacters(fragmentText.mid(exportedIndex, i - exportedIndex)); | - | ||||||||||||||||||
| 330 | writer.writeEmptyElement(textNS, QString::fromLatin1("tab")); | - | ||||||||||||||||||
| 331 | exportedIndex = i+1; | - | ||||||||||||||||||
| 332 | precedingSpaces = 0; | - | ||||||||||||||||||
| 333 | } else if (isSpace) { never executed: end of block
| 0 | ||||||||||||||||||
| 334 | ++precedingSpaces; | - | ||||||||||||||||||
| 335 | escapeNextSpace = true; | - | ||||||||||||||||||
| 336 | } else if (!isSpace) { never executed: end of block
| 0 | ||||||||||||||||||
| 337 | precedingSpaces = 0; | - | ||||||||||||||||||
| 338 | } never executed: end of block | 0 | ||||||||||||||||||
| 339 | } never executed: end of block | 0 | ||||||||||||||||||
| 340 | } never executed: end of block | 0 | ||||||||||||||||||
| 341 | - | |||||||||||||||||||
| 342 | writer.writeCharacters(fragmentText.mid(exportedIndex)); | - | ||||||||||||||||||
| 343 | writer.writeEndElement(); // span | - | ||||||||||||||||||
| 344 | writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed behind it. | - | ||||||||||||||||||
| 345 | if (isHyperlink)
| 0 | ||||||||||||||||||
| 346 | writer.writeEndElement(); // a never executed: writer.writeEndElement(); | 0 | ||||||||||||||||||
| 347 | } never executed: end of block | 0 | ||||||||||||||||||
| 348 | writer.writeCharacters(QString()); // Trick to make sure that the span gets no linefeed behind it. | - | ||||||||||||||||||
| 349 | writer.writeEndElement(); // p | - | ||||||||||||||||||
| 350 | if (block.textList())
| 0 | ||||||||||||||||||
| 351 | writer.writeEndElement(); // list-item never executed: writer.writeEndElement(); | 0 | ||||||||||||||||||
| 352 | } never executed: end of block | 0 | ||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextFragment &fragment) const | - | ||||||||||||||||||
| 355 | { | - | ||||||||||||||||||
| 356 | writer.writeStartElement(drawNS, QString::fromLatin1("frame")); | - | ||||||||||||||||||
| 357 | if (m_strategy == 0) {
| 0 | ||||||||||||||||||
| 358 | // don't do anything. | - | ||||||||||||||||||
| 359 | } never executed: end of block | 0 | ||||||||||||||||||
| 360 | else if (fragment.charFormat().isImageFormat()) {
| 0 | ||||||||||||||||||
| 361 | QTextImageFormat imageFormat = fragment.charFormat().toImageFormat(); | - | ||||||||||||||||||
| 362 | writer.writeAttribute(drawNS, QString::fromLatin1("name"), imageFormat.name()); | - | ||||||||||||||||||
| 363 | - | |||||||||||||||||||
| 364 | // vvv Copy pasted mostly from Qt ================= | - | ||||||||||||||||||
| 365 | QImage image; | - | ||||||||||||||||||
| 366 | QString name = imageFormat.name(); | - | ||||||||||||||||||
| 367 | if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
| 0 | ||||||||||||||||||
| 368 | name.prepend(QLatin1String("qrc")); never executed: name.prepend(QLatin1String("qrc")); | 0 | ||||||||||||||||||
| 369 | QUrl url = QUrl(name); | - | ||||||||||||||||||
| 370 | const QVariant data = m_document->resource(QTextDocument::ImageResource, url); | - | ||||||||||||||||||
| 371 | if (data.type() == QVariant::Image) {
| 0 | ||||||||||||||||||
| 372 | image = qvariant_cast<QImage>(data); | - | ||||||||||||||||||
| 373 | } else if (data.type() == QVariant::ByteArray) { never executed: end of block
| 0 | ||||||||||||||||||
| 374 | image.loadFromData(data.toByteArray()); | - | ||||||||||||||||||
| 375 | } never executed: end of block | 0 | ||||||||||||||||||
| 376 | - | |||||||||||||||||||
| 377 | if (image.isNull()) {
| 0 | ||||||||||||||||||
| 378 | QString context; | - | ||||||||||||||||||
| 379 | if (image.isNull()) { // try direct loading
| 0 | ||||||||||||||||||
| 380 | name = imageFormat.name(); // remove qrc:/ prefix again | - | ||||||||||||||||||
| 381 | image.load(name); | - | ||||||||||||||||||
| 382 | } never executed: end of block | 0 | ||||||||||||||||||
| 383 | } never executed: end of block | 0 | ||||||||||||||||||
| 384 | - | |||||||||||||||||||
| 385 | // ^^^ Copy pasted mostly from Qt ================= | - | ||||||||||||||||||
| 386 | if (! image.isNull()) {
| 0 | ||||||||||||||||||
| 387 | QBuffer imageBytes; | - | ||||||||||||||||||
| 388 | QImageWriter imageWriter(&imageBytes, "png"); | - | ||||||||||||||||||
| 389 | imageWriter.write(image); | - | ||||||||||||||||||
| 390 | QString filename = m_strategy->createUniqueImageName(); | - | ||||||||||||||||||
| 391 | m_strategy->addFile(filename, QString::fromLatin1("image/png"), imageBytes.data()); | - | ||||||||||||||||||
| 392 | - | |||||||||||||||||||
| 393 | // get the width/height from the format. | - | ||||||||||||||||||
| 394 | qreal width = (imageFormat.hasProperty(QTextFormat::ImageWidth)) ? imageFormat.width() : image.width();
| 0 | ||||||||||||||||||
| 395 | writer.writeAttribute(svgNS, QString::fromLatin1("width"), pixelToPoint(width)); | - | ||||||||||||||||||
| 396 | qreal height = (imageFormat.hasProperty(QTextFormat::ImageHeight)) ? imageFormat.height() : image.height();
| 0 | ||||||||||||||||||
| 397 | writer.writeAttribute(svgNS, QString::fromLatin1("height"), pixelToPoint(height)); | - | ||||||||||||||||||
| 398 | - | |||||||||||||||||||
| 399 | writer.writeStartElement(drawNS, QString::fromLatin1("image")); | - | ||||||||||||||||||
| 400 | writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), filename); | - | ||||||||||||||||||
| 401 | writer.writeEndElement(); // image | - | ||||||||||||||||||
| 402 | } never executed: end of block | 0 | ||||||||||||||||||
| 403 | } never executed: end of block | 0 | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | writer.writeEndElement(); // frame | - | ||||||||||||||||||
| 406 | } never executed: end of block | 0 | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | void QTextOdfWriter::writeFormats(QXmlStreamWriter &writer, const QSet<int> &formats) const | - | ||||||||||||||||||
| 409 | { | - | ||||||||||||||||||
| 410 | writer.writeStartElement(officeNS, QString::fromLatin1("automatic-styles")); | - | ||||||||||||||||||
| 411 | QVector<QTextFormat> allStyles = m_document->allFormats(); | - | ||||||||||||||||||
| 412 | QSetIterator<int> formatId(formats); | - | ||||||||||||||||||
| 413 | while(formatId.hasNext()) {
| 0 | ||||||||||||||||||
| 414 | int formatIndex = formatId.next(); | - | ||||||||||||||||||
| 415 | QTextFormat textFormat = allStyles.at(formatIndex); | - | ||||||||||||||||||
| 416 | switch (textFormat.type()) { | - | ||||||||||||||||||
| 417 | case QTextFormat::CharFormat: never executed: case QTextFormat::CharFormat: | 0 | ||||||||||||||||||
| 418 | if (textFormat.isTableCellFormat())
| 0 | ||||||||||||||||||
| 419 | writeTableCellFormat(writer, textFormat.toTableCellFormat(), formatIndex); never executed: writeTableCellFormat(writer, textFormat.toTableCellFormat(), formatIndex); | 0 | ||||||||||||||||||
| 420 | else | - | ||||||||||||||||||
| 421 | writeCharacterFormat(writer, textFormat.toCharFormat(), formatIndex); never executed: writeCharacterFormat(writer, textFormat.toCharFormat(), formatIndex); | 0 | ||||||||||||||||||
| 422 | break; never executed: break; | 0 | ||||||||||||||||||
| 423 | case QTextFormat::BlockFormat: never executed: case QTextFormat::BlockFormat: | 0 | ||||||||||||||||||
| 424 | writeBlockFormat(writer, textFormat.toBlockFormat(), formatIndex); | - | ||||||||||||||||||
| 425 | break; never executed: break; | 0 | ||||||||||||||||||
| 426 | case QTextFormat::ListFormat: never executed: case QTextFormat::ListFormat: | 0 | ||||||||||||||||||
| 427 | writeListFormat(writer, textFormat.toListFormat(), formatIndex); | - | ||||||||||||||||||
| 428 | break; never executed: break; | 0 | ||||||||||||||||||
| 429 | case QTextFormat::FrameFormat: never executed: case QTextFormat::FrameFormat: | 0 | ||||||||||||||||||
| 430 | writeFrameFormat(writer, textFormat.toFrameFormat(), formatIndex); | - | ||||||||||||||||||
| 431 | break; never executed: break; | 0 | ||||||||||||||||||
| 432 | case QTextFormat::TableFormat: never executed: case QTextFormat::TableFormat: | 0 | ||||||||||||||||||
| 433 | ;break; never executed: break; | 0 | ||||||||||||||||||
| 434 | } | - | ||||||||||||||||||
| 435 | } never executed: end of block | 0 | ||||||||||||||||||
| 436 | - | |||||||||||||||||||
| 437 | writer.writeEndElement(); // automatic-styles | - | ||||||||||||||||||
| 438 | } never executed: end of block | 0 | ||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | void QTextOdfWriter::writeBlockFormat(QXmlStreamWriter &writer, QTextBlockFormat format, int formatIndex) const | - | ||||||||||||||||||
| 441 | { | - | ||||||||||||||||||
| 442 | writer.writeStartElement(styleNS, QString::fromLatin1("style")); | - | ||||||||||||||||||
| 443 | writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("p%1").arg(formatIndex)); | - | ||||||||||||||||||
| 444 | writer.writeAttribute(styleNS, QString::fromLatin1("family"), QString::fromLatin1("paragraph")); | - | ||||||||||||||||||
| 445 | writer.writeStartElement(styleNS, QString::fromLatin1("paragraph-properties")); | - | ||||||||||||||||||
| 446 | - | |||||||||||||||||||
| 447 | if (format.hasProperty(QTextFormat::BlockAlignment)) {
| 0 | ||||||||||||||||||
| 448 | const Qt::Alignment alignment = format.alignment() & Qt::AlignHorizontal_Mask; | - | ||||||||||||||||||
| 449 | QString value; | - | ||||||||||||||||||
| 450 | if (alignment == Qt::AlignLeading)
| 0 | ||||||||||||||||||
| 451 | value = QString::fromLatin1("start"); never executed: value = QString::fromLatin1("start"); | 0 | ||||||||||||||||||
| 452 | else if (alignment == Qt::AlignTrailing)
| 0 | ||||||||||||||||||
| 453 | value = QString::fromLatin1("end"); never executed: value = QString::fromLatin1("end"); | 0 | ||||||||||||||||||
| 454 | else if (alignment == (Qt::AlignLeft | Qt::AlignAbsolute))
| 0 | ||||||||||||||||||
| 455 | value = QString::fromLatin1("left"); never executed: value = QString::fromLatin1("left"); | 0 | ||||||||||||||||||
| 456 | else if (alignment == (Qt::AlignRight | Qt::AlignAbsolute))
| 0 | ||||||||||||||||||
| 457 | value = QString::fromLatin1("right"); never executed: value = QString::fromLatin1("right"); | 0 | ||||||||||||||||||
| 458 | else if (alignment == Qt::AlignHCenter)
| 0 | ||||||||||||||||||
| 459 | value = QString::fromLatin1("center"); never executed: value = QString::fromLatin1("center"); | 0 | ||||||||||||||||||
| 460 | else if (alignment == Qt::AlignJustify)
| 0 | ||||||||||||||||||
| 461 | value = QString::fromLatin1("justify"); never executed: value = QString::fromLatin1("justify"); | 0 | ||||||||||||||||||
| 462 | else | - | ||||||||||||||||||
| 463 | qWarning() << "QTextOdfWriter: unsupported paragraph alignment; " << format.alignment(); never executed: QMessageLogger(__FILE__, 463, __PRETTY_FUNCTION__).warning() << "QTextOdfWriter: unsupported paragraph alignment; " << format.alignment(); | 0 | ||||||||||||||||||
| 464 | if (! value.isNull())
| 0 | ||||||||||||||||||
| 465 | writer.writeAttribute(foNS, QString::fromLatin1("text-align"), value); never executed: writer.writeAttribute(foNS, QString::fromLatin1("text-align"), value); | 0 | ||||||||||||||||||
| 466 | } never executed: end of block | 0 | ||||||||||||||||||
| 467 | - | |||||||||||||||||||
| 468 | if (format.hasProperty(QTextFormat::BlockTopMargin))
| 0 | ||||||||||||||||||
| 469 | writer.writeAttribute(foNS, QString::fromLatin1("margin-top"), pixelToPoint(qMax(qreal(0.), format.topMargin())) ); never executed: writer.writeAttribute(foNS, QString::fromLatin1("margin-top"), pixelToPoint(qMax(qreal(0.), format.topMargin())) ); | 0 | ||||||||||||||||||
| 470 | if (format.hasProperty(QTextFormat::BlockBottomMargin))
| 0 | ||||||||||||||||||
| 471 | writer.writeAttribute(foNS, QString::fromLatin1("margin-bottom"), pixelToPoint(qMax(qreal(0.), format.bottomMargin())) ); never executed: writer.writeAttribute(foNS, QString::fromLatin1("margin-bottom"), pixelToPoint(qMax(qreal(0.), format.bottomMargin())) ); | 0 | ||||||||||||||||||
| 472 | if (format.hasProperty(QTextFormat::BlockLeftMargin) || format.hasProperty(QTextFormat::BlockIndent))
| 0 | ||||||||||||||||||
| 473 | writer.writeAttribute(foNS, QString::fromLatin1("margin-left"), pixelToPoint(qMax(qreal(0.), never executed: writer.writeAttribute(foNS, QString::fromLatin1("margin-left"), pixelToPoint(qMax(qreal(0.), format.leftMargin() + format.indent()))); | 0 | ||||||||||||||||||
| 474 | format.leftMargin() + format.indent()))); never executed: writer.writeAttribute(foNS, QString::fromLatin1("margin-left"), pixelToPoint(qMax(qreal(0.), format.leftMargin() + format.indent()))); | 0 | ||||||||||||||||||
| 475 | if (format.hasProperty(QTextFormat::BlockRightMargin))
| 0 | ||||||||||||||||||
| 476 | writer.writeAttribute(foNS, QString::fromLatin1("margin-right"), pixelToPoint(qMax(qreal(0.), format.rightMargin())) ); never executed: writer.writeAttribute(foNS, QString::fromLatin1("margin-right"), pixelToPoint(qMax(qreal(0.), format.rightMargin())) ); | 0 | ||||||||||||||||||
| 477 | if (format.hasProperty(QTextFormat::TextIndent))
| 0 | ||||||||||||||||||
| 478 | writer.writeAttribute(foNS, QString::fromLatin1("text-indent"), pixelToPoint(format.textIndent())); never executed: writer.writeAttribute(foNS, QString::fromLatin1("text-indent"), pixelToPoint(format.textIndent())); | 0 | ||||||||||||||||||
| 479 | if (format.hasProperty(QTextFormat::PageBreakPolicy)) {
| 0 | ||||||||||||||||||
| 480 | if (format.pageBreakPolicy() & QTextFormat::PageBreak_AlwaysBefore)
| 0 | ||||||||||||||||||
| 481 | writer.writeAttribute(foNS, QString::fromLatin1("break-before"), QString::fromLatin1("page")); never executed: writer.writeAttribute(foNS, QString::fromLatin1("break-before"), QString::fromLatin1("page")); | 0 | ||||||||||||||||||
| 482 | if (format.pageBreakPolicy() & QTextFormat::PageBreak_AlwaysAfter)
| 0 | ||||||||||||||||||
| 483 | writer.writeAttribute(foNS, QString::fromLatin1("break-after"), QString::fromLatin1("page")); never executed: writer.writeAttribute(foNS, QString::fromLatin1("break-after"), QString::fromLatin1("page")); | 0 | ||||||||||||||||||
| 484 | } never executed: end of block | 0 | ||||||||||||||||||
| 485 | if (format.hasProperty(QTextFormat::BackgroundBrush)) {
| 0 | ||||||||||||||||||
| 486 | QBrush brush = format.background(); | - | ||||||||||||||||||
| 487 | writer.writeAttribute(foNS, QString::fromLatin1("background-color"), brush.color().name()); | - | ||||||||||||||||||
| 488 | } never executed: end of block | 0 | ||||||||||||||||||
| 489 | if (format.hasProperty(QTextFormat::BlockNonBreakableLines))
| 0 | ||||||||||||||||||
| 490 | writer.writeAttribute(foNS, QString::fromLatin1("keep-together"), never executed: writer.writeAttribute(foNS, QString::fromLatin1("keep-together"), format.nonBreakableLines() ? QString::fromLatin1("true") : QString::fromLatin1("false")); | 0 | ||||||||||||||||||
| 491 | format.nonBreakableLines() ? QString::fromLatin1("true") : QString::fromLatin1("false")); never executed: writer.writeAttribute(foNS, QString::fromLatin1("keep-together"), format.nonBreakableLines() ? QString::fromLatin1("true") : QString::fromLatin1("false")); | 0 | ||||||||||||||||||
| 492 | if (format.hasProperty(QTextFormat::TabPositions)) {
| 0 | ||||||||||||||||||
| 493 | QList<QTextOption::Tab> tabs = format.tabPositions(); | - | ||||||||||||||||||
| 494 | writer.writeStartElement(styleNS, QString::fromLatin1("tab-stops")); | - | ||||||||||||||||||
| 495 | QList<QTextOption::Tab>::Iterator iterator = tabs.begin(); | - | ||||||||||||||||||
| 496 | while(iterator != tabs.end()) {
| 0 | ||||||||||||||||||
| 497 | writer.writeEmptyElement(styleNS, QString::fromLatin1("tab-stop")); | - | ||||||||||||||||||
| 498 | writer.writeAttribute(styleNS, QString::fromLatin1("position"), pixelToPoint(iterator->position) ); | - | ||||||||||||||||||
| 499 | QString type; | - | ||||||||||||||||||
| 500 | switch(iterator->type) { | - | ||||||||||||||||||
| 501 | case QTextOption::DelimiterTab: type = QString::fromLatin1("char"); break; never executed: break;never executed: case QTextOption::DelimiterTab: | 0 | ||||||||||||||||||
| 502 | case QTextOption::LeftTab: type = QString::fromLatin1("left"); break; never executed: break;never executed: case QTextOption::LeftTab: | 0 | ||||||||||||||||||
| 503 | case QTextOption::RightTab: type = QString::fromLatin1("right"); break; never executed: break;never executed: case QTextOption::RightTab: | 0 | ||||||||||||||||||
| 504 | case QTextOption::CenterTab: type = QString::fromLatin1("center"); break; never executed: break;never executed: case QTextOption::CenterTab: | 0 | ||||||||||||||||||
| 505 | } | - | ||||||||||||||||||
| 506 | writer.writeAttribute(styleNS, QString::fromLatin1("type"), type); | - | ||||||||||||||||||
| 507 | if (iterator->delimiter != 0)
| 0 | ||||||||||||||||||
| 508 | writer.writeAttribute(styleNS, QString::fromLatin1("char"), iterator->delimiter); never executed: writer.writeAttribute(styleNS, QString::fromLatin1("char"), iterator->delimiter); | 0 | ||||||||||||||||||
| 509 | ++iterator; | - | ||||||||||||||||||
| 510 | } never executed: end of block | 0 | ||||||||||||||||||
| 511 | - | |||||||||||||||||||
| 512 | writer.writeEndElement(); // tab-stops | - | ||||||||||||||||||
| 513 | } never executed: end of block | 0 | ||||||||||||||||||
| 514 | - | |||||||||||||||||||
| 515 | writer.writeEndElement(); // paragraph-properties | - | ||||||||||||||||||
| 516 | writer.writeEndElement(); // style | - | ||||||||||||||||||
| 517 | } never executed: end of block | 0 | ||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | void QTextOdfWriter::writeCharacterFormat(QXmlStreamWriter &writer, QTextCharFormat format, int formatIndex) const | - | ||||||||||||||||||
| 520 | { | - | ||||||||||||||||||
| 521 | writer.writeStartElement(styleNS, QString::fromLatin1("style")); | - | ||||||||||||||||||
| 522 | writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("c%1").arg(formatIndex)); | - | ||||||||||||||||||
| 523 | writer.writeAttribute(styleNS, QString::fromLatin1("family"), QString::fromLatin1("text")); | - | ||||||||||||||||||
| 524 | writer.writeEmptyElement(styleNS, QString::fromLatin1("text-properties")); | - | ||||||||||||||||||
| 525 | if (format.fontItalic())
| 0 | ||||||||||||||||||
| 526 | writer.writeAttribute(foNS, QString::fromLatin1("font-style"), QString::fromLatin1("italic")); never executed: writer.writeAttribute(foNS, QString::fromLatin1("font-style"), QString::fromLatin1("italic")); | 0 | ||||||||||||||||||
| 527 | if (format.hasProperty(QTextFormat::FontWeight) && format.fontWeight() != QFont::Normal) {
| 0 | ||||||||||||||||||
| 528 | QString value; | - | ||||||||||||||||||
| 529 | if (format.fontWeight() == QFont::Bold)
| 0 | ||||||||||||||||||
| 530 | value = QString::fromLatin1("bold"); never executed: value = QString::fromLatin1("bold"); | 0 | ||||||||||||||||||
| 531 | else | - | ||||||||||||||||||
| 532 | value = QString::number(format.fontWeight() * 10); never executed: value = QString::number(format.fontWeight() * 10); | 0 | ||||||||||||||||||
| 533 | writer.writeAttribute(foNS, QString::fromLatin1("font-weight"), value); | - | ||||||||||||||||||
| 534 | } never executed: end of block | 0 | ||||||||||||||||||
| 535 | if (format.hasProperty(QTextFormat::FontFamily))
| 0 | ||||||||||||||||||
| 536 | writer.writeAttribute(foNS, QString::fromLatin1("font-family"), format.fontFamily()); never executed: writer.writeAttribute(foNS, QString::fromLatin1("font-family"), format.fontFamily()); | 0 | ||||||||||||||||||
| 537 | else | - | ||||||||||||||||||
| 538 | writer.writeAttribute(foNS, QString::fromLatin1("font-family"), QString::fromLatin1("Sans")); // Qt default never executed: writer.writeAttribute(foNS, QString::fromLatin1("font-family"), QString::fromLatin1("Sans")); | 0 | ||||||||||||||||||
| 539 | if (format.hasProperty(QTextFormat::FontPointSize))
| 0 | ||||||||||||||||||
| 540 | writer.writeAttribute(foNS, QString::fromLatin1("font-size"), QString::fromLatin1("%1pt").arg(format.fontPointSize())); never executed: writer.writeAttribute(foNS, QString::fromLatin1("font-size"), QString::fromLatin1("%1pt").arg(format.fontPointSize())); | 0 | ||||||||||||||||||
| 541 | if (format.hasProperty(QTextFormat::FontCapitalization)) {
| 0 | ||||||||||||||||||
| 542 | switch(format.fontCapitalization()) { | - | ||||||||||||||||||
| 543 | case QFont::MixedCase: never executed: case QFont::MixedCase: | 0 | ||||||||||||||||||
| 544 | writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("none")); break; never executed: break; | 0 | ||||||||||||||||||
| 545 | case QFont::AllUppercase: never executed: case QFont::AllUppercase: | 0 | ||||||||||||||||||
| 546 | writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("uppercase")); break; never executed: break; | 0 | ||||||||||||||||||
| 547 | case QFont::AllLowercase: never executed: case QFont::AllLowercase: | 0 | ||||||||||||||||||
| 548 | writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("lowercase")); break; never executed: break; | 0 | ||||||||||||||||||
| 549 | case QFont::Capitalize: never executed: case QFont::Capitalize: | 0 | ||||||||||||||||||
| 550 | writer.writeAttribute(foNS, QString::fromLatin1("text-transform"), QString::fromLatin1("capitalize")); break; never executed: break; | 0 | ||||||||||||||||||
| 551 | case QFont::SmallCaps: never executed: case QFont::SmallCaps: | 0 | ||||||||||||||||||
| 552 | writer.writeAttribute(foNS, QString::fromLatin1("font-variant"), QString::fromLatin1("small-caps")); break; never executed: break; | 0 | ||||||||||||||||||
| 553 | } | - | ||||||||||||||||||
| 554 | } never executed: end of block | 0 | ||||||||||||||||||
| 555 | if (format.hasProperty(QTextFormat::FontLetterSpacing))
| 0 | ||||||||||||||||||
| 556 | writer.writeAttribute(foNS, QString::fromLatin1("letter-spacing"), pixelToPoint(format.fontLetterSpacing())); never executed: writer.writeAttribute(foNS, QString::fromLatin1("letter-spacing"), pixelToPoint(format.fontLetterSpacing())); | 0 | ||||||||||||||||||
| 557 | if (format.hasProperty(QTextFormat::FontWordSpacing) && format.fontWordSpacing() != 0)
| 0 | ||||||||||||||||||
| 558 | writer.writeAttribute(foNS, QString::fromLatin1("word-spacing"), pixelToPoint(format.fontWordSpacing())); never executed: writer.writeAttribute(foNS, QString::fromLatin1("word-spacing"), pixelToPoint(format.fontWordSpacing())); | 0 | ||||||||||||||||||
| 559 | if (format.hasProperty(QTextFormat::FontUnderline))
| 0 | ||||||||||||||||||
| 560 | writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-type"), never executed: writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-type"), format.fontUnderline() ? QString::fromLatin1("single") : QString::fromLatin1("none")); | 0 | ||||||||||||||||||
| 561 | format.fontUnderline() ? QString::fromLatin1("single") : QString::fromLatin1("none")); never executed: writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-type"), format.fontUnderline() ? QString::fromLatin1("single") : QString::fromLatin1("none")); | 0 | ||||||||||||||||||
| 562 | if (format.hasProperty(QTextFormat::FontOverline)) {
| 0 | ||||||||||||||||||
| 563 | // bool fontOverline () const TODO | - | ||||||||||||||||||
| 564 | } never executed: end of block | 0 | ||||||||||||||||||
| 565 | if (format.hasProperty(QTextFormat::FontStrikeOut))
| 0 | ||||||||||||||||||
| 566 | writer.writeAttribute(styleNS,QString::fromLatin1( "text-line-through-type"), never executed: writer.writeAttribute(styleNS,QString::fromLatin1( "text-line-through-type"), format.fontStrikeOut() ? QString::fromLatin1("single") : QString::fromLatin1("none")); | 0 | ||||||||||||||||||
| 567 | format.fontStrikeOut() ? QString::fromLatin1("single") : QString::fromLatin1("none")); never executed: writer.writeAttribute(styleNS,QString::fromLatin1( "text-line-through-type"), format.fontStrikeOut() ? QString::fromLatin1("single") : QString::fromLatin1("none")); | 0 | ||||||||||||||||||
| 568 | if (format.hasProperty(QTextFormat::TextUnderlineColor))
| 0 | ||||||||||||||||||
| 569 | writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-color"), format.underlineColor().name()); never executed: writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-color"), format.underlineColor().name()); | 0 | ||||||||||||||||||
| 570 | if (format.hasProperty(QTextFormat::FontFixedPitch)) {
| 0 | ||||||||||||||||||
| 571 | // bool fontFixedPitch () const TODO | - | ||||||||||||||||||
| 572 | } never executed: end of block | 0 | ||||||||||||||||||
| 573 | if (format.hasProperty(QTextFormat::TextUnderlineStyle)) {
| 0 | ||||||||||||||||||
| 574 | QString value; | - | ||||||||||||||||||
| 575 | switch (format.underlineStyle()) { | - | ||||||||||||||||||
| 576 | case QTextCharFormat::NoUnderline: value = QString::fromLatin1("none"); break; never executed: break;never executed: case QTextCharFormat::NoUnderline: | 0 | ||||||||||||||||||
| 577 | case QTextCharFormat::SingleUnderline: value = QString::fromLatin1("solid"); break; never executed: break;never executed: case QTextCharFormat::SingleUnderline: | 0 | ||||||||||||||||||
| 578 | case QTextCharFormat::DashUnderline: value = QString::fromLatin1("dash"); break; never executed: break;never executed: case QTextCharFormat::DashUnderline: | 0 | ||||||||||||||||||
| 579 | case QTextCharFormat::DotLine: value = QString::fromLatin1("dotted"); break; never executed: break;never executed: case QTextCharFormat::DotLine: | 0 | ||||||||||||||||||
| 580 | case QTextCharFormat::DashDotLine: value = QString::fromLatin1("dash-dot"); break; never executed: break;never executed: case QTextCharFormat::DashDotLine: | 0 | ||||||||||||||||||
| 581 | case QTextCharFormat::DashDotDotLine: value = QString::fromLatin1("dot-dot-dash"); break; never executed: break;never executed: case QTextCharFormat::DashDotDotLine: | 0 | ||||||||||||||||||
| 582 | case QTextCharFormat::WaveUnderline: value = QString::fromLatin1("wave"); break; never executed: break;never executed: case QTextCharFormat::WaveUnderline: | 0 | ||||||||||||||||||
| 583 | case QTextCharFormat::SpellCheckUnderline: value = QString::fromLatin1("none"); break; never executed: break;never executed: case QTextCharFormat::SpellCheckUnderline: | 0 | ||||||||||||||||||
| 584 | } | - | ||||||||||||||||||
| 585 | writer.writeAttribute(styleNS, QString::fromLatin1("text-underline-style"), value); | - | ||||||||||||||||||
| 586 | } never executed: end of block | 0 | ||||||||||||||||||
| 587 | if (format.hasProperty(QTextFormat::TextVerticalAlignment)) {
| 0 | ||||||||||||||||||
| 588 | QString value; | - | ||||||||||||||||||
| 589 | switch (format.verticalAlignment()) { | - | ||||||||||||||||||
| 590 | case QTextCharFormat::AlignMiddle: never executed: case QTextCharFormat::AlignMiddle: | 0 | ||||||||||||||||||
| 591 | case QTextCharFormat::AlignNormal: value = QString::fromLatin1("0%"); break; never executed: break;never executed: case QTextCharFormat::AlignNormal: | 0 | ||||||||||||||||||
| 592 | case QTextCharFormat::AlignSuperScript: value = QString::fromLatin1("super"); break; never executed: break;never executed: case QTextCharFormat::AlignSuperScript: | 0 | ||||||||||||||||||
| 593 | case QTextCharFormat::AlignSubScript: value = QString::fromLatin1("sub"); break; never executed: break;never executed: case QTextCharFormat::AlignSubScript: | 0 | ||||||||||||||||||
| 594 | case QTextCharFormat::AlignTop: value = QString::fromLatin1("100%"); break; never executed: break;never executed: case QTextCharFormat::AlignTop: | 0 | ||||||||||||||||||
| 595 | case QTextCharFormat::AlignBottom : value = QString::fromLatin1("-100%"); break; never executed: break;never executed: case QTextCharFormat::AlignBottom : | 0 | ||||||||||||||||||
| 596 | case QTextCharFormat::AlignBaseline: break; never executed: break;never executed: case QTextCharFormat::AlignBaseline: | 0 | ||||||||||||||||||
| 597 | } | - | ||||||||||||||||||
| 598 | writer.writeAttribute(styleNS, QString::fromLatin1("text-position"), value); | - | ||||||||||||||||||
| 599 | } never executed: end of block | 0 | ||||||||||||||||||
| 600 | if (format.hasProperty(QTextFormat::TextOutline))
| 0 | ||||||||||||||||||
| 601 | writer.writeAttribute(styleNS, QString::fromLatin1("text-outline"), QString::fromLatin1("true")); never executed: writer.writeAttribute(styleNS, QString::fromLatin1("text-outline"), QString::fromLatin1("true")); | 0 | ||||||||||||||||||
| 602 | if (format.hasProperty(QTextFormat::TextToolTip)) {
| 0 | ||||||||||||||||||
| 603 | // QString toolTip () const TODO | - | ||||||||||||||||||
| 604 | } never executed: end of block | 0 | ||||||||||||||||||
| 605 | if (format.hasProperty(QTextFormat::IsAnchor)) {
| 0 | ||||||||||||||||||
| 606 | // bool isAnchor () const TODO | - | ||||||||||||||||||
| 607 | } never executed: end of block | 0 | ||||||||||||||||||
| 608 | if (format.hasProperty(QTextFormat::AnchorHref)) {
| 0 | ||||||||||||||||||
| 609 | // QString anchorHref () const TODO | - | ||||||||||||||||||
| 610 | } never executed: end of block | 0 | ||||||||||||||||||
| 611 | if (format.hasProperty(QTextFormat::AnchorName)) {
| 0 | ||||||||||||||||||
| 612 | // QString anchorName () const TODO | - | ||||||||||||||||||
| 613 | } never executed: end of block | 0 | ||||||||||||||||||
| 614 | if (format.hasProperty(QTextFormat::ForegroundBrush)) {
| 0 | ||||||||||||||||||
| 615 | QBrush brush = format.foreground(); | - | ||||||||||||||||||
| 616 | writer.writeAttribute(foNS, QString::fromLatin1("color"), brush.color().name()); | - | ||||||||||||||||||
| 617 | } never executed: end of block | 0 | ||||||||||||||||||
| 618 | if (format.hasProperty(QTextFormat::BackgroundBrush)) {
| 0 | ||||||||||||||||||
| 619 | QBrush brush = format.background(); | - | ||||||||||||||||||
| 620 | writer.writeAttribute(foNS, QString::fromLatin1("background-color"), brush.color().name()); | - | ||||||||||||||||||
| 621 | } never executed: end of block | 0 | ||||||||||||||||||
| 622 | - | |||||||||||||||||||
| 623 | writer.writeEndElement(); // style | - | ||||||||||||||||||
| 624 | } never executed: end of block | 0 | ||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | void QTextOdfWriter::writeListFormat(QXmlStreamWriter &writer, QTextListFormat format, int formatIndex) const | - | ||||||||||||||||||
| 627 | { | - | ||||||||||||||||||
| 628 | writer.writeStartElement(textNS, QString::fromLatin1("list-style")); | - | ||||||||||||||||||
| 629 | writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("L%1").arg(formatIndex)); | - | ||||||||||||||||||
| 630 | - | |||||||||||||||||||
| 631 | QTextListFormat::Style style = format.style(); | - | ||||||||||||||||||
| 632 | if (style == QTextListFormat::ListDecimal || style == QTextListFormat::ListLowerAlpha
| 0 | ||||||||||||||||||
| 633 | || style == QTextListFormat::ListUpperAlpha
| 0 | ||||||||||||||||||
| 634 | || style == QTextListFormat::ListLowerRoman
| 0 | ||||||||||||||||||
| 635 | || style == QTextListFormat::ListUpperRoman) {
| 0 | ||||||||||||||||||
| 636 | writer.writeStartElement(textNS, QString::fromLatin1("list-level-style-number")); | - | ||||||||||||||||||
| 637 | writer.writeAttribute(styleNS, QString::fromLatin1("num-format"), bulletChar(style)); | - | ||||||||||||||||||
| 638 | - | |||||||||||||||||||
| 639 | if (format.hasProperty(QTextFormat::ListNumberSuffix))
| 0 | ||||||||||||||||||
| 640 | writer.writeAttribute(styleNS, QString::fromLatin1("num-suffix"), format.numberSuffix()); never executed: writer.writeAttribute(styleNS, QString::fromLatin1("num-suffix"), format.numberSuffix()); | 0 | ||||||||||||||||||
| 641 | else | - | ||||||||||||||||||
| 642 | writer.writeAttribute(styleNS, QString::fromLatin1("num-suffix"), QString::fromLatin1(".")); never executed: writer.writeAttribute(styleNS, QString::fromLatin1("num-suffix"), QString::fromLatin1(".")); | 0 | ||||||||||||||||||
| 643 | - | |||||||||||||||||||
| 644 | if (format.hasProperty(QTextFormat::ListNumberPrefix))
| 0 | ||||||||||||||||||
| 645 | writer.writeAttribute(styleNS, QString::fromLatin1("num-prefix"), format.numberPrefix()); never executed: writer.writeAttribute(styleNS, QString::fromLatin1("num-prefix"), format.numberPrefix()); | 0 | ||||||||||||||||||
| 646 | - | |||||||||||||||||||
| 647 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 648 | writer.writeStartElement(textNS, QString::fromLatin1("list-level-style-bullet")); | - | ||||||||||||||||||
| 649 | writer.writeAttribute(textNS, QString::fromLatin1("bullet-char"), bulletChar(style)); | - | ||||||||||||||||||
| 650 | } never executed: end of block | 0 | ||||||||||||||||||
| 651 | - | |||||||||||||||||||
| 652 | writer.writeAttribute(textNS, QString::fromLatin1("level"), QString::number(format.indent())); | - | ||||||||||||||||||
| 653 | writer.writeEmptyElement(styleNS, QString::fromLatin1("list-level-properties")); | - | ||||||||||||||||||
| 654 | writer.writeAttribute(foNS, QString::fromLatin1("text-align"), QString::fromLatin1("start")); | - | ||||||||||||||||||
| 655 | QString spacing = QString::fromLatin1("%1mm").arg(format.indent() * 8); | - | ||||||||||||||||||
| 656 | writer.writeAttribute(textNS, QString::fromLatin1("space-before"), spacing); | - | ||||||||||||||||||
| 657 | //writer.writeAttribute(textNS, QString::fromLatin1("min-label-width"), spacing); | - | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | writer.writeEndElement(); // list-level-style-* | - | ||||||||||||||||||
| 660 | writer.writeEndElement(); // list-style | - | ||||||||||||||||||
| 661 | } never executed: end of block | 0 | ||||||||||||||||||
| 662 | - | |||||||||||||||||||
| 663 | void QTextOdfWriter::writeFrameFormat(QXmlStreamWriter &writer, QTextFrameFormat format, int formatIndex) const | - | ||||||||||||||||||
| 664 | { | - | ||||||||||||||||||
| 665 | writer.writeStartElement(styleNS, QString::fromLatin1("style")); | - | ||||||||||||||||||
| 666 | writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("s%1").arg(formatIndex)); | - | ||||||||||||||||||
| 667 | writer.writeAttribute(styleNS, QString::fromLatin1("family"), QString::fromLatin1("section")); | - | ||||||||||||||||||
| 668 | writer.writeEmptyElement(styleNS, QString::fromLatin1("section-properties")); | - | ||||||||||||||||||
| 669 | if (format.hasProperty(QTextFormat::FrameTopMargin))
| 0 | ||||||||||||||||||
| 670 | writer.writeAttribute(foNS, QString::fromLatin1("margin-top"), pixelToPoint(qMax(qreal(0.), format.topMargin())) ); never executed: writer.writeAttribute(foNS, QString::fromLatin1("margin-top"), pixelToPoint(qMax(qreal(0.), format.topMargin())) ); | 0 | ||||||||||||||||||
| 671 | if (format.hasProperty(QTextFormat::FrameBottomMargin))
| 0 | ||||||||||||||||||
| 672 | writer.writeAttribute(foNS, QString::fromLatin1("margin-bottom"), pixelToPoint(qMax(qreal(0.), format.bottomMargin())) ); never executed: writer.writeAttribute(foNS, QString::fromLatin1("margin-bottom"), pixelToPoint(qMax(qreal(0.), format.bottomMargin())) ); | 0 | ||||||||||||||||||
| 673 | if (format.hasProperty(QTextFormat::FrameLeftMargin))
| 0 | ||||||||||||||||||
| 674 | writer.writeAttribute(foNS, QString::fromLatin1("margin-left"), pixelToPoint(qMax(qreal(0.), format.leftMargin())) ); never executed: writer.writeAttribute(foNS, QString::fromLatin1("margin-left"), pixelToPoint(qMax(qreal(0.), format.leftMargin())) ); | 0 | ||||||||||||||||||
| 675 | if (format.hasProperty(QTextFormat::FrameRightMargin))
| 0 | ||||||||||||||||||
| 676 | writer.writeAttribute(foNS, QString::fromLatin1("margin-right"), pixelToPoint(qMax(qreal(0.), format.rightMargin())) ); never executed: writer.writeAttribute(foNS, QString::fromLatin1("margin-right"), pixelToPoint(qMax(qreal(0.), format.rightMargin())) ); | 0 | ||||||||||||||||||
| 677 | - | |||||||||||||||||||
| 678 | writer.writeEndElement(); // style | - | ||||||||||||||||||
| 679 | - | |||||||||||||||||||
| 680 | // TODO consider putting the following properties in a qt-namespace. | - | ||||||||||||||||||
| 681 | // Position position () const | - | ||||||||||||||||||
| 682 | // qreal border () const | - | ||||||||||||||||||
| 683 | // QBrush borderBrush () const | - | ||||||||||||||||||
| 684 | // BorderStyle borderStyle () const | - | ||||||||||||||||||
| 685 | // qreal padding () const | - | ||||||||||||||||||
| 686 | // QTextLength width () const | - | ||||||||||||||||||
| 687 | // QTextLength height () const | - | ||||||||||||||||||
| 688 | // PageBreakFlags pageBreakPolicy () const | - | ||||||||||||||||||
| 689 | } never executed: end of block | 0 | ||||||||||||||||||
| 690 | - | |||||||||||||||||||
| 691 | void QTextOdfWriter::writeTableCellFormat(QXmlStreamWriter &writer, QTextTableCellFormat format, int formatIndex) const | - | ||||||||||||||||||
| 692 | { | - | ||||||||||||||||||
| 693 | writer.writeStartElement(styleNS, QString::fromLatin1("style")); | - | ||||||||||||||||||
| 694 | writer.writeAttribute(styleNS, QString::fromLatin1("name"), QString::fromLatin1("T%1").arg(formatIndex)); | - | ||||||||||||||||||
| 695 | writer.writeAttribute(styleNS, QString::fromLatin1("family"), QString::fromLatin1("table")); | - | ||||||||||||||||||
| 696 | writer.writeEmptyElement(styleNS, QString::fromLatin1("table-properties")); | - | ||||||||||||||||||
| 697 | - | |||||||||||||||||||
| 698 | - | |||||||||||||||||||
| 699 | qreal padding = format.topPadding(); | - | ||||||||||||||||||
| 700 | if (padding > 0 && padding == format.bottomPadding()
| 0 | ||||||||||||||||||
| 701 | && padding == format.leftPadding() && padding == format.rightPadding()) {
| 0 | ||||||||||||||||||
| 702 | writer.writeAttribute(foNS, QString::fromLatin1("padding"), pixelToPoint(padding)); | - | ||||||||||||||||||
| 703 | } never executed: end of block | 0 | ||||||||||||||||||
| 704 | else { | - | ||||||||||||||||||
| 705 | if (padding > 0)
| 0 | ||||||||||||||||||
| 706 | writer.writeAttribute(foNS, QString::fromLatin1("padding-top"), pixelToPoint(padding)); never executed: writer.writeAttribute(foNS, QString::fromLatin1("padding-top"), pixelToPoint(padding)); | 0 | ||||||||||||||||||
| 707 | if (format.bottomPadding() > 0)
| 0 | ||||||||||||||||||
| 708 | writer.writeAttribute(foNS, QString::fromLatin1("padding-bottom"), pixelToPoint(format.bottomPadding())); never executed: writer.writeAttribute(foNS, QString::fromLatin1("padding-bottom"), pixelToPoint(format.bottomPadding())); | 0 | ||||||||||||||||||
| 709 | if (format.leftPadding() > 0)
| 0 | ||||||||||||||||||
| 710 | writer.writeAttribute(foNS, QString::fromLatin1("padding-left"), pixelToPoint(format.leftPadding())); never executed: writer.writeAttribute(foNS, QString::fromLatin1("padding-left"), pixelToPoint(format.leftPadding())); | 0 | ||||||||||||||||||
| 711 | if (format.rightPadding() > 0)
| 0 | ||||||||||||||||||
| 712 | writer.writeAttribute(foNS, QString::fromLatin1("padding-right"), pixelToPoint(format.rightPadding())); never executed: writer.writeAttribute(foNS, QString::fromLatin1("padding-right"), pixelToPoint(format.rightPadding())); | 0 | ||||||||||||||||||
| 713 | } never executed: end of block | 0 | ||||||||||||||||||
| 714 | - | |||||||||||||||||||
| 715 | if (format.hasProperty(QTextFormat::TextVerticalAlignment)) {
| 0 | ||||||||||||||||||
| 716 | QString pos; | - | ||||||||||||||||||
| 717 | switch (format.verticalAlignment()) { | - | ||||||||||||||||||
| 718 | case QTextCharFormat::AlignMiddle: never executed: case QTextCharFormat::AlignMiddle: | 0 | ||||||||||||||||||
| 719 | pos = QString::fromLatin1("middle"); break; never executed: break; | 0 | ||||||||||||||||||
| 720 | case QTextCharFormat::AlignTop: never executed: case QTextCharFormat::AlignTop: | 0 | ||||||||||||||||||
| 721 | pos = QString::fromLatin1("top"); break; never executed: break; | 0 | ||||||||||||||||||
| 722 | case QTextCharFormat::AlignBottom: never executed: case QTextCharFormat::AlignBottom: | 0 | ||||||||||||||||||
| 723 | pos = QString::fromLatin1("bottom"); break; never executed: break; | 0 | ||||||||||||||||||
| 724 | default: never executed: default: | 0 | ||||||||||||||||||
| 725 | pos = QString::fromLatin1("automatic"); break; never executed: break; | 0 | ||||||||||||||||||
| 726 | } | - | ||||||||||||||||||
| 727 | writer.writeAttribute(styleNS, QString::fromLatin1("vertical-align"), pos); | - | ||||||||||||||||||
| 728 | } never executed: end of block | 0 | ||||||||||||||||||
| 729 | - | |||||||||||||||||||
| 730 | // TODO | - | ||||||||||||||||||
| 731 | // ODF just search for style-table-cell-properties-attlist) | - | ||||||||||||||||||
| 732 | // QTextFormat::BackgroundImageUrl | - | ||||||||||||||||||
| 733 | // format.background | - | ||||||||||||||||||
| 734 | // QTextFormat::FrameBorder | - | ||||||||||||||||||
| 735 | - | |||||||||||||||||||
| 736 | writer.writeEndElement(); // style | - | ||||||||||||||||||
| 737 | } never executed: end of block | 0 | ||||||||||||||||||
| 738 | - | |||||||||||||||||||
| 739 | /////////////////////// | - | ||||||||||||||||||
| 740 | - | |||||||||||||||||||
| 741 | QTextOdfWriter::QTextOdfWriter(const QTextDocument &document, QIODevice *device) | - | ||||||||||||||||||
| 742 | : officeNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:office:1.0")), | - | ||||||||||||||||||
| 743 | textNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:text:1.0")), | - | ||||||||||||||||||
| 744 | styleNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:style:1.0")), | - | ||||||||||||||||||
| 745 | foNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0")), | - | ||||||||||||||||||
| 746 | tableNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:table:1.0")), | - | ||||||||||||||||||
| 747 | drawNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0")), | - | ||||||||||||||||||
| 748 | xlinkNS (QLatin1String("http://www.w3.org/1999/xlink")), | - | ||||||||||||||||||
| 749 | svgNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0")), | - | ||||||||||||||||||
| 750 | m_document(&document), | - | ||||||||||||||||||
| 751 | m_device(device), | - | ||||||||||||||||||
| 752 | m_strategy(0), | - | ||||||||||||||||||
| 753 | m_codec(0), | - | ||||||||||||||||||
| 754 | m_createArchive(true) | - | ||||||||||||||||||
| 755 | { | - | ||||||||||||||||||
| 756 | } never executed: end of block | 0 | ||||||||||||||||||
| 757 | - | |||||||||||||||||||
| 758 | bool QTextOdfWriter::writeAll() | - | ||||||||||||||||||
| 759 | { | - | ||||||||||||||||||
| 760 | if (m_createArchive)
| 0 | ||||||||||||||||||
| 761 | m_strategy = new QZipStreamStrategy(m_device); never executed: m_strategy = new QZipStreamStrategy(m_device); | 0 | ||||||||||||||||||
| 762 | else | - | ||||||||||||||||||
| 763 | m_strategy = new QXmlStreamStrategy(m_device); never executed: m_strategy = new QXmlStreamStrategy(m_device); | 0 | ||||||||||||||||||
| 764 | - | |||||||||||||||||||
| 765 | if (!m_device->isWritable() && ! m_device->open(QIODevice::WriteOnly)) {
| 0 | ||||||||||||||||||
| 766 | qWarning() << "QTextOdfWriter::writeAll: the device can not be opened for writing"; | - | ||||||||||||||||||
| 767 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 768 | } | - | ||||||||||||||||||
| 769 | QXmlStreamWriter writer(m_strategy->contentStream); | - | ||||||||||||||||||
| 770 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||
| 771 | if (m_codec)
| 0 | ||||||||||||||||||
| 772 | writer.setCodec(m_codec); never executed: writer.setCodec(m_codec); | 0 | ||||||||||||||||||
| 773 | #endif | - | ||||||||||||||||||
| 774 | // prettyfy | - | ||||||||||||||||||
| 775 | writer.setAutoFormatting(true); | - | ||||||||||||||||||
| 776 | writer.setAutoFormattingIndent(2); | - | ||||||||||||||||||
| 777 | - | |||||||||||||||||||
| 778 | writer.writeNamespace(officeNS, QString::fromLatin1("office")); | - | ||||||||||||||||||
| 779 | writer.writeNamespace(textNS, QString::fromLatin1("text")); | - | ||||||||||||||||||
| 780 | writer.writeNamespace(styleNS, QString::fromLatin1("style")); | - | ||||||||||||||||||
| 781 | writer.writeNamespace(foNS, QString::fromLatin1("fo")); | - | ||||||||||||||||||
| 782 | writer.writeNamespace(tableNS, QString::fromLatin1("table")); | - | ||||||||||||||||||
| 783 | writer.writeNamespace(drawNS, QString::fromLatin1("draw")); | - | ||||||||||||||||||
| 784 | writer.writeNamespace(xlinkNS, QString::fromLatin1("xlink")); | - | ||||||||||||||||||
| 785 | writer.writeNamespace(svgNS, QString::fromLatin1("svg")); | - | ||||||||||||||||||
| 786 | writer.writeStartDocument(); | - | ||||||||||||||||||
| 787 | writer.writeStartElement(officeNS, QString::fromLatin1("document-content")); | - | ||||||||||||||||||
| 788 | writer.writeAttribute(officeNS, QString::fromLatin1("version"), QString::fromLatin1("1.2")); | - | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | // add fragments. (for character formats) | - | ||||||||||||||||||
| 791 | QTextDocumentPrivate::FragmentIterator fragIt = m_document->docHandle()->begin(); | - | ||||||||||||||||||
| 792 | QSet<int> formats; | - | ||||||||||||||||||
| 793 | while (fragIt != m_document->docHandle()->end()) {
| 0 | ||||||||||||||||||
| 794 | const QTextFragmentData * const frag = fragIt.value(); | - | ||||||||||||||||||
| 795 | formats << frag->format; | - | ||||||||||||||||||
| 796 | ++fragIt; | - | ||||||||||||||||||
| 797 | } never executed: end of block | 0 | ||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | // add blocks (for blockFormats) | - | ||||||||||||||||||
| 800 | QTextDocumentPrivate::BlockMap &blocks = m_document->docHandle()->blockMap(); | - | ||||||||||||||||||
| 801 | QTextDocumentPrivate::BlockMap::Iterator blockIt = blocks.begin(); | - | ||||||||||||||||||
| 802 | while (blockIt != blocks.end()) {
| 0 | ||||||||||||||||||
| 803 | const QTextBlockData * const block = blockIt.value(); | - | ||||||||||||||||||
| 804 | formats << block->format; | - | ||||||||||||||||||
| 805 | ++blockIt; | - | ||||||||||||||||||
| 806 | } never executed: end of block | 0 | ||||||||||||||||||
| 807 | - | |||||||||||||||||||
| 808 | // add objects for lists, frames and tables | - | ||||||||||||||||||
| 809 | QVector<QTextFormat> allFormats = m_document->allFormats(); | - | ||||||||||||||||||
| 810 | QList<int> copy = formats.toList(); | - | ||||||||||||||||||
| 811 | for (QList<int>::Iterator iter = copy.begin(); iter != copy.end(); ++iter) {
| 0 | ||||||||||||||||||
| 812 | QTextObject *object = m_document->objectForFormat(allFormats[*iter]); | - | ||||||||||||||||||
| 813 | if (object)
| 0 | ||||||||||||||||||
| 814 | formats << object->formatIndex(); never executed: formats << object->formatIndex(); | 0 | ||||||||||||||||||
| 815 | } never executed: end of block | 0 | ||||||||||||||||||
| 816 | - | |||||||||||||||||||
| 817 | writeFormats(writer, formats); | - | ||||||||||||||||||
| 818 | - | |||||||||||||||||||
| 819 | writer.writeStartElement(officeNS, QString::fromLatin1("body")); | - | ||||||||||||||||||
| 820 | writer.writeStartElement(officeNS, QString::fromLatin1("text")); | - | ||||||||||||||||||
| 821 | QTextFrame *rootFrame = m_document->rootFrame(); | - | ||||||||||||||||||
| 822 | writeFrame(writer, rootFrame); | - | ||||||||||||||||||
| 823 | writer.writeEndElement(); // text | - | ||||||||||||||||||
| 824 | writer.writeEndElement(); // body | - | ||||||||||||||||||
| 825 | writer.writeEndElement(); // document-content | - | ||||||||||||||||||
| 826 | writer.writeEndDocument(); | - | ||||||||||||||||||
| 827 | delete m_strategy; | - | ||||||||||||||||||
| 828 | m_strategy = 0; | - | ||||||||||||||||||
| 829 | - | |||||||||||||||||||
| 830 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 831 | } | - | ||||||||||||||||||
| 832 | - | |||||||||||||||||||
| 833 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 834 | - | |||||||||||||||||||
| 835 | #endif // QT_NO_TEXTODFWRITER | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |