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