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