qtextodfwriter.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qtextodfwriter.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12static QString pixelToPoint(qreal pixels)-
13{-
14-
15 return
never executed: return QString::number(pixels * 72 / 96) + QString::fromLatin1("pt");
QString::number(pixels * 72 / 96) + QString::fromLatin1("pt");
never executed: return QString::number(pixels * 72 / 96) + QString::fromLatin1("pt");
0
16}-
17-
18-
19class QOutputStrategy {-
20public:-
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: return QString::fromLatin1("Pictures/Picture%1").arg(counter++);
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-
34class QXmlStreamStrategy : public QOutputStrategy {-
35public:-
36 QXmlStreamStrategy(QIODevice *device)-
37 {-
38 contentStream = device;-
39 }
never executed: end of block
0
40-
41 virtual ~QXmlStreamStrategy()-
42 {-
43 if (contentStream
contentStreamDescription
TRUEnever evaluated
FALSEnever evaluated
)
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-
52class QZipStreamStrategy : public QOutputStrategy {-
53public:-
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-
95private:-
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-
110static QString bulletChar(QTextListFormat::Style style)-
111{-
112 switch(style) {-
113 case
never executed: case QTextListFormat::ListDisc:
QTextListFormat::ListDisc:
never executed: case QTextListFormat::ListDisc:
0
114 return
never executed: return QChar(0x25cf);
QChar(0x25cf);
never executed: return QChar(0x25cf);
0
115 case
never executed: case QTextListFormat::ListCircle:
QTextListFormat::ListCircle:
never executed: case QTextListFormat::ListCircle:
0
116 return
never executed: return QChar(0x25cb);
QChar(0x25cb);
never executed: return QChar(0x25cb);
0
117 case
never executed: case QTextListFormat::ListSquare:
QTextListFormat::ListSquare:
never executed: case QTextListFormat::ListSquare:
0
118 return
never executed: return QChar(0x25a1);
QChar(0x25a1);
never executed: return QChar(0x25a1);
0
119 case
never executed: case QTextListFormat::ListDecimal:
QTextListFormat::ListDecimal:
never executed: case QTextListFormat::ListDecimal:
0
120 return
never executed: return QString::fromLatin1("1");
QString::fromLatin1("1");
never executed: return QString::fromLatin1("1");
0
121 case
never executed: case QTextListFormat::ListLowerAlpha:
QTextListFormat::ListLowerAlpha:
never executed: case QTextListFormat::ListLowerAlpha:
0
122 return
never executed: return QString::fromLatin1("a");
QString::fromLatin1("a");
never executed: return QString::fromLatin1("a");
0
123 case
never executed: case QTextListFormat::ListUpperAlpha:
QTextListFormat::ListUpperAlpha:
never executed: case QTextListFormat::ListUpperAlpha:
0
124 return
never executed: return QString::fromLatin1("A");
QString::fromLatin1("A");
never executed: return QString::fromLatin1("A");
0
125 case
never executed: case QTextListFormat::ListLowerRoman:
QTextListFormat::ListLowerRoman:
never executed: case QTextListFormat::ListLowerRoman:
0
126 return
never executed: return QString::fromLatin1("i");
QString::fromLatin1("i");
never executed: return QString::fromLatin1("i");
0
127 case
never executed: case QTextListFormat::ListUpperRoman:
QTextListFormat::ListUpperRoman:
never executed: case QTextListFormat::ListUpperRoman:
0
128 return
never executed: return QString::fromLatin1("I");
QString::fromLatin1("I");
never executed: return QString::fromLatin1("I");
0
129 default
never executed: default:
:
never executed: default:
0
130 case
never executed: case QTextListFormat::ListStyleUndefined:
QTextListFormat::ListStyleUndefined:
never executed: case QTextListFormat::ListStyleUndefined:
0
131 return
never executed: return QString();
QString();
never executed: return QString();
0
132 }-
133}-
134-
135void QTextOdfWriter::writeFrame(QXmlStreamWriter &writer, const QTextFrame *frame)-
136{-
137 ((!(frame)) ? qt_assert("frame",__FILE__,188) : qt_noop());-
138 const QTextTable *table = qobject_cast<const QTextTable*> (frame);-
139-
140 if (table
tableDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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: end of block
else if (frame->document()
frame->document()Description
TRUEnever evaluated
FALSEnever evaluated
&& frame->document()->rootFrame() != frame
frame->documen...ame() != frameDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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()
! iterator.atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
153 if (iterator.currentFrame()
iterator.currentFrame()Description
TRUEnever evaluated
FALSEnever evaluated
&& child != iterator.currentFrame()
child != itera...currentFrame()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
154 writeFrame(writer, iterator.currentFrame());
never executed: writeFrame(writer, iterator.currentFrame());
0
155 else {-
156 QTextBlock block = iterator.currentBlock();-
157 if (table
tableDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
158 QTextTableCell cell = table->cellAt(block.position());-
159 if (tableRow < cell.row()
tableRow < cell.row()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
160 if (tableRow >= 0
tableRow >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
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
cell.columnSpan() > 1Description
TRUEnever evaluated
FALSEnever evaluated
)
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
cell.rowSpan() > 1Description
TRUEnever evaluated
FALSEnever evaluated
)
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()
cell.format()....leCellFormat()Description
TRUEnever evaluated
FALSEnever evaluated
) {
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
tableDescription
TRUEnever evaluated
FALSEnever evaluated
)
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
tableRow >= 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
182 writer.writeEndElement();
never executed: writer.writeEndElement();
0
183-
184 if (table
tableDescription
TRUEnever evaluated
FALSEnever evaluated
|| (frame->document()
frame->document()Description
TRUEnever evaluated
FALSEnever evaluated
&& frame->document()->rootFrame() != frame
frame->documen...ame() != frameDescription
TRUEnever evaluated
FALSEnever evaluated
))
0
185 writer.writeEndElement();
never executed: writer.writeEndElement();
0
186}
never executed: end of block
0
187-
188void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &block)-
189{-
190 if (block.textList()
block.textList()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
191 const int listLevel = block.textList()->format().indent();-
192 if (m_listStack.isEmpty()
m_listStack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| m_listStack.top() != block.textList()
m_listStack.to...ock.textList()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
193-
194 while (m_listStack.count() >= listLevel
m_listStack.co...) >= listLevelDescription
TRUEnever evaluated
FALSEnever evaluated
&& !m_listStack.isEmpty()
!m_listStack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
&& m_listStack.top() != block.textList()
m_listStack.to...ock.textList()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
195 m_listStack.pop();-
196 writer.writeEndElement();-
197 if (m_listStack.count()
m_listStack.count()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
198 writer.writeEndElement();
never executed: writer.writeEndElement();
0
199 }
never executed: end of block
0
200 while (m_listStack.count() < listLevel
m_listStack.co...() < listLevelDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
201 if (m_listStack.count()
m_listStack.count()Description
TRUEnever evaluated
FALSEnever evaluated
)
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
m_listStack.co... listLevel - 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
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()
! m_listStack.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
218 m_listStack.pop();-
219 writer.writeEndElement();-
220 if (m_listStack.count()
m_listStack.count()Description
TRUEnever evaluated
FALSEnever evaluated
)
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
block.length() == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
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()
block.textList()Description
TRUEnever evaluated
FALSEnever evaluated
)
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()
!frag.atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
; ++frag) {
0
237 bool isHyperlink = frag.fragment().charFormat().hasProperty(QTextFormat::AnchorHref);-
238 if (isHyperlink
isHyperlinkDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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
fragmentText.length() == 1Description
TRUEnever evaluated
FALSEnever evaluated
&& fragmentText[0] == 0xFFFC
fragmentText[0] == 0xFFFCDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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()
i <= fragmentText.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
259 QChar character = fragmentText[i];-
260 bool isSpace = character.unicode() == ' ';-
261-
262-
263 if (!isSpace
!isSpaceDescription
TRUEnever evaluated
FALSEnever evaluated
&& escapeNextSpace
escapeNextSpaceDescription
TRUEnever evaluated
FALSEnever evaluated
&& precedingSpaces > 1
precedingSpaces > 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
264 const bool startParag = exportedIndex == 0
exportedIndex == 0Description
TRUEnever evaluated
FALSEnever evaluated
&& i == precedingSpaces
i == precedingSpacesDescription
TRUEnever evaluated
FALSEnever evaluated
;
0
265 if (!startParag
!startParagDescription
TRUEnever evaluated
FALSEnever evaluated
)
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
startParagDescription
TRUEnever evaluated
FALSEnever evaluated
?0:1);
0
269 if (count > 1
count > 1Description
TRUEnever evaluated
FALSEnever evaluated
)
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()
i < fragmentText.count()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
276 if (character.unicode() == 0x2028
character.unicode() == 0x2028Description
TRUEnever evaluated
FALSEnever evaluated
) {
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'
character.unicode() == '\t'Description
TRUEnever evaluated
FALSEnever evaluated
) {
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: end of block
else if (isSpace
isSpaceDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
289 ++precedingSpaces;-
290 escapeNextSpace = true;-
291 }
never executed: end of block
else if (!isSpace
!isSpaceDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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
isHyperlinkDescription
TRUEnever evaluated
FALSEnever evaluated
)
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()
block.textList()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
306 writer.writeEndElement();
never executed: writer.writeEndElement();
0
307}
never executed: end of block
0
308-
309void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextFragment &fragment) const-
310{-
311 writer.writeStartElement(drawNS, QString::fromLatin1("frame"));-
312 if (m_strategy == 0
m_strategy == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
313-
314 }
never executed: end of block
0
315 else if (fragment.charFormat().isImageFormat()
fragment.charF...sImageFormat()Description
TRUEnever evaluated
FALSEnever evaluated
) {
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(":/"))
name.startsWit...1String(":/"))Description
TRUEnever evaluated
FALSEnever evaluated
)
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
data.type() == QVariant::ImageDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
327 image = qvariant_cast<QImage>(data);-
328 }
never executed: end of block
else if (data.type() == QVariant::ByteArray
data.type() ==...ant::ByteArrayDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
329 image.loadFromData(data.toByteArray());-
330 }
never executed: end of block
0
331-
332 if (image.isNull()
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
333 QString context;-
334 if (image.isNull()
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
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()
! image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
) {
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 = (
(imageFormat.h...::ImageWidth))Description
TRUEnever evaluated
FALSEnever evaluated
imageFormat.hasProperty(QTextFormat::ImageWidth))
(imageFormat.h...::ImageWidth))Description
TRUEnever evaluated
FALSEnever evaluated
? imageFormat.width() : image.width();
0
350 writer.writeAttribute(svgNS, QString::fromLatin1("width"), pixelToPoint(width));-
351 qreal height = (
(imageFormat.h...:ImageHeight))Description
TRUEnever evaluated
FALSEnever evaluated
imageFormat.hasProperty(QTextFormat::ImageHeight))
(imageFormat.h...:ImageHeight))Description
TRUEnever evaluated
FALSEnever evaluated
? imageFormat.height() : image.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-
363void 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()
formatId.hasNext()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
369 int formatIndex = formatId.next();-
370 QTextFormat textFormat = allStyles.at(formatIndex);-
371 switch (textFormat.type()) {-
372 case
never executed: case QTextFormat::CharFormat:
QTextFormat::CharFormat:
never executed: case QTextFormat::CharFormat:
0
373 if (textFormat.isTableCellFormat()
textFormat.isTableCellFormat()Description
TRUEnever evaluated
FALSEnever evaluated
)
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: case QTextFormat::BlockFormat:
QTextFormat::BlockFormat:
never executed: case QTextFormat::BlockFormat:
0
379 writeBlockFormat(writer, textFormat.toBlockFormat(), formatIndex);-
380 break;
never executed: break;
0
381 case
never executed: case QTextFormat::ListFormat:
QTextFormat::ListFormat:
never executed: case QTextFormat::ListFormat:
0
382 writeListFormat(writer, textFormat.toListFormat(), formatIndex);-
383 break;
never executed: break;
0
384 case
never executed: case QTextFormat::FrameFormat:
QTextFormat::FrameFormat:
never executed: case QTextFormat::FrameFormat:
0
385 writeFrameFormat(writer, textFormat.toFrameFormat(), formatIndex);-
386 break;
never executed: break;
0
387 case
never executed: case QTextFormat::TableFormat:
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-
395void 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)
format.hasProp...lockAlignment)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
403 const Qt::Alignment alignment = format.alignment() & Qt::AlignHorizontal_Mask;-
404 QString value;-
405 if (alignment == Qt::AlignLeading
alignment == Qt::AlignLeadingDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
406 value = QString::fromLatin1("start");
never executed: value = QString::fromLatin1("start");
0
407 else if (alignment == Qt::AlignTrailing
alignment == Qt::AlignTrailingDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
408 value = QString::fromLatin1("end");
never executed: value = QString::fromLatin1("end");
0
409 else if (alignment == (Qt::AlignLeft | Qt::AlignAbsolute)
alignment == (...AlignAbsolute)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
410 value = QString::fromLatin1("left");
never executed: value = QString::fromLatin1("left");
0
411 else if (alignment == (Qt::AlignRight | Qt::AlignAbsolute)
alignment == (...AlignAbsolute)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
412 value = QString::fromLatin1("right");
never executed: value = QString::fromLatin1("right");
0
413 else if (alignment == Qt::AlignHCenter
alignment == Qt::AlignHCenterDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
414 value = QString::fromLatin1("center");
never executed: value = QString::fromLatin1("center");
0
415 else if (alignment == Qt::AlignJustify
alignment == Qt::AlignJustifyDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
416 value = QString::fromLatin1("justify");
never executed: value = QString::fromLatin1("justify");
0
417 else-
418 QMessageLogger(__FILE__, 469, __PRETTY_FUNCTION__).warning() << "QTextOdfWriter: unsupported paragraph alignment; " << format.alignment();
never executed: QMessageLogger(__FILE__, 469, __PRETTY_FUNCTION__).warning() << "QTextOdfWriter: unsupported paragraph alignment; " << format.alignment();
0
419 if (! value.isNull()
! value.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...lockTopMargin)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...kBottomMargin)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...ockLeftMargin)Description
TRUEnever evaluated
FALSEnever evaluated
|| format.hasProperty(QTextFormat::BlockIndent)
format.hasProp...::BlockIndent)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...ckRightMargin)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...t::TextIndent)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...geBreakPolicy)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
435 if (format.pageBreakPolicy() & QTextFormat::PageBreak_AlwaysBefore
format.pageBre...k_AlwaysBeforeDescription
TRUEnever evaluated
FALSEnever evaluated
)
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
format.pageBre...ak_AlwaysAfterDescription
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...ckgroundBrush)Description
TRUEnever evaluated
FALSEnever evaluated
) {
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)
format.hasProp...reakableLines)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...:TabPositions)Description
TRUEnever evaluated
FALSEnever evaluated
) {
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()
iterator != tabs.end()Description
TRUEnever evaluated
FALSEnever evaluated
) {
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: case QTextOption::DelimiterTab:
QTextOption::DelimiterTab:
never executed: case QTextOption::DelimiterTab:
type = QString::fromLatin1("char"); break;
never executed: break;
0
457 case
never executed: case QTextOption::LeftTab:
QTextOption::LeftTab:
never executed: case QTextOption::LeftTab:
type = QString::fromLatin1("left"); break;
never executed: break;
0
458 case
never executed: case QTextOption::RightTab:
QTextOption::RightTab:
never executed: case QTextOption::RightTab:
type = QString::fromLatin1("right"); break;
never executed: break;
0
459 case
never executed: case QTextOption::CenterTab:
QTextOption::CenterTab:
never executed: case QTextOption::CenterTab:
type = QString::fromLatin1("center"); break;
never executed: break;
0
460 }-
461 writer.writeAttribute(styleNS, QString::fromLatin1("type"), type);-
462 if (iterator->delimiter != 0
iterator->delimiter != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
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-
474void 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()
format.fontItalic()Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...t::FontWeight)Description
TRUEnever evaluated
FALSEnever evaluated
&& format.fontWeight() != QFont::Normal
format.fontWei... QFont::NormalDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
483 QString value;-
484 if (format.fontWeight() == QFont::Bold
format.fontWei...== QFont::BoldDescription
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...t::FontFamily)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...FontPointSize)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...apitalization)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
497 switch(format.fontCapitalization()) {-
498 case
never executed: case QFont::MixedCase:
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: case QFont::AllUppercase:
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: case QFont::AllLowercase:
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: case QFont::Capitalize:
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: case QFont::SmallCaps:
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)
format.hasProp...LetterSpacing)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...ntWordSpacing)Description
TRUEnever evaluated
FALSEnever evaluated
&& format.fontWordSpacing() != 0
format.fontWordSpacing() != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...FontUnderline)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...:FontOverline)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
518-
519 }
never executed: end of block
0
520 if (format.hasProperty(QTextFormat::FontStrikeOut)
format.hasProp...FontStrikeOut)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...nderlineColor)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...ontFixedPitch)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
526-
527 }
never executed: end of block
0
528 if (format.hasProperty(QTextFormat::TextUnderlineStyle)
format.hasProp...nderlineStyle)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
529 QString value;-
530 switch (format.underlineStyle()) {-
531 case
never executed: case QTextCharFormat::NoUnderline:
QTextCharFormat::NoUnderline:
never executed: case QTextCharFormat::NoUnderline:
value = QString::fromLatin1("none"); break;
never executed: break;
0
532 case
never executed: case QTextCharFormat::SingleUnderline:
QTextCharFormat::SingleUnderline:
never executed: case QTextCharFormat::SingleUnderline:
value = QString::fromLatin1("solid"); break;
never executed: break;
0
533 case
never executed: case QTextCharFormat::DashUnderline:
QTextCharFormat::DashUnderline:
never executed: case QTextCharFormat::DashUnderline:
value = QString::fromLatin1("dash"); break;
never executed: break;
0
534 case
never executed: case QTextCharFormat::DotLine:
QTextCharFormat::DotLine:
never executed: case QTextCharFormat::DotLine:
value = QString::fromLatin1("dotted"); break;
never executed: break;
0
535 case
never executed: case QTextCharFormat::DashDotLine:
QTextCharFormat::DashDotLine:
never executed: case QTextCharFormat::DashDotLine:
value = QString::fromLatin1("dash-dot"); break;
never executed: break;
0
536 case
never executed: case QTextCharFormat::DashDotDotLine:
QTextCharFormat::DashDotDotLine:
never executed: case QTextCharFormat::DashDotDotLine:
value = QString::fromLatin1("dot-dot-dash"); break;
never executed: break;
0
537 case
never executed: case QTextCharFormat::WaveUnderline:
QTextCharFormat::WaveUnderline:
never executed: case QTextCharFormat::WaveUnderline:
value = QString::fromLatin1("wave"); break;
never executed: break;
0
538 case
never executed: case QTextCharFormat::SpellCheckUnderline:
QTextCharFormat::SpellCheckUnderline:
never executed: case QTextCharFormat::SpellCheckUnderline:
value = QString::fromLatin1("none"); break;
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)
format.hasProp...icalAlignment)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
543 QString value;-
544 switch (format.verticalAlignment()) {-
545 case
never executed: case QTextCharFormat::AlignMiddle:
QTextCharFormat::AlignMiddle:
never executed: case QTextCharFormat::AlignMiddle:
0
546 case
never executed: case QTextCharFormat::AlignNormal:
QTextCharFormat::AlignNormal:
never executed: case QTextCharFormat::AlignNormal:
value = QString::fromLatin1("0%"); break;
never executed: break;
0
547 case
never executed: case QTextCharFormat::AlignSuperScript:
QTextCharFormat::AlignSuperScript:
never executed: case QTextCharFormat::AlignSuperScript:
value = QString::fromLatin1("super"); break;
never executed: break;
0
548 case
never executed: case QTextCharFormat::AlignSubScript:
QTextCharFormat::AlignSubScript:
never executed: case QTextCharFormat::AlignSubScript:
value = QString::fromLatin1("sub"); break;
never executed: break;
0
549 case
never executed: case QTextCharFormat::AlignTop:
QTextCharFormat::AlignTop:
never executed: case QTextCharFormat::AlignTop:
value = QString::fromLatin1("100%"); break;
never executed: break;
0
550 case
never executed: case QTextCharFormat::AlignBottom :
QTextCharFormat::AlignBottom :
never executed: case QTextCharFormat::AlignBottom :
value = QString::fromLatin1("-100%"); break;
never executed: break;
0
551 case
never executed: case QTextCharFormat::AlignBaseline:
QTextCharFormat::AlignBaseline:
never executed: case QTextCharFormat::AlignBaseline:
break;
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)
format.hasProp...::TextOutline)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...::TextToolTip)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
558-
559 }
never executed: end of block
0
560 if (format.hasProperty(QTextFormat::IsAnchor)
format.hasProp...mat::IsAnchor)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
561-
562 }
never executed: end of block
0
563 if (format.hasProperty(QTextFormat::AnchorHref)
format.hasProp...t::AnchorHref)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
564-
565 }
never executed: end of block
0
566 if (format.hasProperty(QTextFormat::AnchorName)
format.hasProp...t::AnchorName)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
567-
568 }
never executed: end of block
0
569 if (format.hasProperty(QTextFormat::ForegroundBrush)
format.hasProp...regroundBrush)Description
TRUEnever evaluated
FALSEnever evaluated
) {
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)
format.hasProp...ckgroundBrush)Description
TRUEnever evaluated
FALSEnever evaluated
) {
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-
581void 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
style == QText...t::ListDecimalDescription
TRUEnever evaluated
FALSEnever evaluated
|| style == QTextListFormat::ListLowerAlpha
style == QText...ListLowerAlphaDescription
TRUEnever evaluated
FALSEnever evaluated
0
588 || style == QTextListFormat::ListUpperAlpha
style == QText...ListUpperAlphaDescription
TRUEnever evaluated
FALSEnever evaluated
0
589 || style == QTextListFormat::ListLowerRoman
style == QText...ListLowerRomanDescription
TRUEnever evaluated
FALSEnever evaluated
0
590 || style == QTextListFormat::ListUpperRoman
style == QText...ListUpperRomanDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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)
format.hasProp...tNumberSuffix)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...tNumberPrefix)Description
TRUEnever evaluated
FALSEnever evaluated
)
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: end of block
else {
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-
618void 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)
format.hasProp...rameTopMargin)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...eBottomMargin)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...ameLeftMargin)Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...meRightMargin)Description
TRUEnever evaluated
FALSEnever evaluated
)
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-
636void 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
padding > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& padding == format.bottomPadding()
padding == for...ottomPadding()Description
TRUEnever evaluated
FALSEnever evaluated
0
646 && padding == format.leftPadding()
padding == for....leftPadding()Description
TRUEnever evaluated
FALSEnever evaluated
&& padding == format.rightPadding()
padding == for...rightPadding()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
647 writer.writeAttribute(foNS, QString::fromLatin1("padding"), pixelToPoint(padding));-
648 }
never executed: end of block
0
649 else {-
650 if (padding > 0
padding > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
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
format.bottomPadding() > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
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
format.leftPadding() > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
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
format.rightPadding() > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
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)
format.hasProp...icalAlignment)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
661 QString pos;-
662 switch (format.verticalAlignment()) {-
663 case
never executed: case QTextCharFormat::AlignMiddle:
QTextCharFormat::AlignMiddle:
never executed: case QTextCharFormat::AlignMiddle:
0
664 pos = QString::fromLatin1("middle"); break;
never executed: break;
0
665 case
never executed: case QTextCharFormat::AlignTop:
QTextCharFormat::AlignTop:
never executed: case QTextCharFormat::AlignTop:
0
666 pos = QString::fromLatin1("top"); break;
never executed: break;
0
667 case
never executed: case QTextCharFormat::AlignBottom:
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-
686QTextOdfWriter::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-
703bool QTextOdfWriter::writeAll()-
704{-
705 if (m_createArchive
m_createArchiveDescription
TRUEnever evaluated
FALSEnever evaluated
)
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()
!m_device->isWritable()Description
TRUEnever evaluated
FALSEnever evaluated
&& ! m_device->open(QIODevice::WriteOnly)
! m_device->op...ce::WriteOnly)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
711 QMessageLogger(__FILE__, 772, __PRETTY_FUNCTION__).warning("QTextOdfWriter::writeAll: the device can not be opened for writing");-
712 return
never executed: return false;
false;
never executed: return false;
0
713 }-
714 QXmlStreamWriter writer(m_strategy->contentStream);-
715-
716 if (m_codec
m_codecDescription
TRUEnever evaluated
FALSEnever evaluated
)
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()
fragIt != m_do...andle()->end()Description
TRUEnever evaluated
FALSEnever evaluated
) {
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()
blockIt != blocks.end()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
748 const QTextBlockData * const block = blockIt.value();-
749 formats << block->format;-
750 ++blockIt;-
751 }
never executed: end of block
0
752-
753-
754 const QVector<QTextFormat> allFormats = m_document->allFormats();-
755 const QList<int> copy = formats.toList();-
756 for (auto index : copy) {-
757 QTextObject *object = m_document->objectForFormat(allFormats[index]);-
758 if (object
objectDescription
TRUEnever evaluated
FALSEnever evaluated
)
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: return true;
true;
never executed: return true;
0
776}-
777-
778-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9