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