44 #ifndef QT_NO_TEXTODFWRITER 48 #include <QImageWriter> 49 #include <QTextListFormat> 109 manifestWriter(&manifest)
121 manifestWriter.setAutoFormatting(
true);
122 manifestWriter.setAutoFormattingIndent(1);
125 manifestWriter.writeStartDocument();
134 manifestWriter.writeEndDocument();
144 zip.addFile(fileName, bytes);
167 return QChar(0x25cf);
169 return QChar(0x25cb);
171 return QChar(0x25a1);
205 while (! iterator.
atEnd()) {
212 if (tableRow < cell.
row()) {
215 tableRow = cell.
row();
227 writeBlock(writer, block);
245 if (m_listStack.isEmpty() || m_listStack.top() != block.
textList()) {
247 while (m_listStack.count() >= listLevel && !m_listStack.isEmpty() && m_listStack.top() != block.
textList() ) {
250 if (m_listStack.count())
253 while (m_listStack.count() < listLevel) {
254 if (m_listStack.count())
257 if (m_listStack.count() == listLevel - 1) {
270 while (! m_listStack.isEmpty()) {
273 if (m_listStack.count())
278 if (block.
length() == 1) {
293 QString fragmentText = frag.fragment().text();
294 if (fragmentText.
length() == 1 && fragmentText[0] == 0xFFFC) {
295 writeInlineCharacter(writer, frag.fragment());
301 .arg(frag.fragment().charFormatIndex()));
302 bool escapeNextSpace =
true;
303 int precedingSpaces = 0;
304 int exportedIndex = 0;
305 for (
int i=0; i <= fragmentText.
count(); ++i) {
306 bool isSpace =
false;
307 QChar character = fragmentText[i];
308 isSpace = character.
unicode() ==
' ';
311 if (!isSpace && escapeNextSpace && precedingSpaces > 1) {
312 const bool startParag = exportedIndex == 0 && i == precedingSpaces;
314 writer.
writeCharacters(fragmentText.
mid(exportedIndex, i - precedingSpaces + 1 - exportedIndex));
316 const int count = precedingSpaces - (startParag?0:1);
323 if (i < fragmentText.
count()) {
324 if (character.
unicode() == 0x2028) {
330 }
else if (character.
unicode() ==
'\t') {
336 }
else if (isSpace) {
338 escapeNextSpace =
true;
339 }
else if (!isSpace) {
357 if (m_strategy == 0) {
383 name = imageFormat.
name();
392 imageWriter.
write(image);
393 QString filename = m_strategy->createUniqueImageName();
415 QSetIterator<int> formatId(formats);
416 while(formatId.hasNext()) {
417 int formatIndex = formatId.next();
419 switch (textFormat.
type()) {
424 writeCharacterFormat(writer, textFormat.
toCharFormat(), formatIndex);
427 writeBlockFormat(writer, textFormat.
toBlockFormat(), formatIndex);
430 writeListFormat(writer, textFormat.
toListFormat(), formatIndex);
433 writeFrameFormat(writer, textFormat.
toFrameFormat(), formatIndex);
466 qWarning() <<
"QTextOdfWriter: unsupported paragraph alignment; " << format.
alignment();
499 while(iterator != tabs.
end()) {
503 switch(iterator->type) {
510 if (iterator->delimiter != 0)
745 : officeNS (
QLatin1String(
"urn:oasis:names:tc:opendocument:xmlns:office:1.0")),
746 textNS (
QLatin1String(
"urn:oasis:names:tc:opendocument:xmlns:text:1.0")),
747 styleNS (
QLatin1String(
"urn:oasis:names:tc:opendocument:xmlns:style:1.0")),
748 foNS (
QLatin1String(
"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0")),
749 tableNS (
QLatin1String(
"urn:oasis:names:tc:opendocument:xmlns:table:1.0")),
750 drawNS (
QLatin1String(
"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0")),
752 svgNS (
QLatin1String(
"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0")),
753 m_document(&document),
757 m_createArchive(true)
769 qWarning() <<
"QTextOdfWriter::writeAll: the device can not be opened for writing";
773 #ifndef QT_NO_TEXTCODEC 805 while (blockIt != blocks.
end()) {
817 formats <<
object->formatIndex();
838 #endif // QT_NO_TEXTODFWRITER static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QVariant class acts like a union for the most common Qt data types.
T qobject_cast(QObject *object)
int columns() const
Returns the number of columns in the table.
void writeCharacterFormat(QXmlStreamWriter &writer, QTextCharFormat format, int formatIndex) const
The QXmlStreamWriter class provides an XML writer with a simple streaming API.
qreal rightPadding() const
Gets the right padding of the table cell.
int formatIndex() const
Returns the index of the object's format in the document's internal list of formats.
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
The QTextListFormat class provides formatting information for lists in a QTextDocument.
int blockFormatIndex() const
Returns an index into the document's internal list of block formats for the text block's format...
QIODevice * contentStream
#define QT_END_NAMESPACE
This macro expands to.
const QColor & color() const
Returns the brush color.
FragmentIterator end() const
QTextList * textList() const
If the block represents a list item, returns the list that the item belongs to; otherwise returns 0...
const QByteArray & data() const
Returns the data contained in the buffer.
bool isWritable() const
Returns true if data can be written to the device; otherwise returns false.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
bool fontStrikeOut() const
Returns true if the text format's font is struck out (has a horizontal line drawn through it); otherw...
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QTextFrame class represents a frame in a QTextDocument.
QColor underlineColor() const
Returns the color used to underline the characters with this format.
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
QTextTableCellFormat toTableCellFormat() const
Returns this format as a table cell format.
The QByteArray class provides an array of bytes.
bool atEnd() const
Returns true if the current item is the last item in the text block.
PageBreakFlags pageBreakPolicy() const
Returns the currently set page break policy for the paragraph.
QTextFrame * currentFrame() const
Returns the current frame pointed to by the iterator, or 0 if the iterator currently points to a bloc...
int length() const
Returns the number of characters in this string.
QString & prepend(QChar c)
static QString pixelToPoint(qreal pixels)
Convert pixels to postscript point units.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
const QTextDocument * m_document
QTextDocument * document() const
Returns the document this object belongs to.
iterator begin() const
Returns a text block iterator pointing to the beginning of the text block.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
void writeEndDocument()
Closes all remaining open start elements and writes a newline.
void writeFrameFormat(QXmlStreamWriter &writer, QTextFrameFormat format, int formatIndex) const
static Q_GUI_EXPORT ExternalImageLoaderFunction externalLoader
qreal leftMargin() const
Returns the width of the frame's left margin in pixels.
The QBuffer class provides a QIODevice interface for a QByteArray.
void writeTableCellFormat(QXmlStreamWriter &writer, QTextTableCellFormat format, int formatIndex) const
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
qreal height() const
Returns the height of the rectangle occupied by the image.
static QString bulletChar(QTextListFormat::Style style)
qreal topMargin() const
Returns the paragraph's top margin.
int indent() const
Returns the paragraph's indent.
qreal rightMargin() const
Returns the paragraph's right margin.
Qt::Alignment alignment() const
Returns the paragraph's alignment.
QTextObject * objectForFormat(const QTextFormat &) const
Returns the text object associated with the format f.
The QChar class provides a 16-bit Unicode character.
bool load(QIODevice *device, const char *format)
This function reads a QImage from the given device.
FragmentMap::ConstIterator FragmentIterator
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
virtual void addFile(const QString &fileName, const QString &mimeType, const QByteArray &bytes)=0
int rowSpan() const
Returns the number of rows this cell spans.
QTextFrame * rootFrame() const
Returns the document's root frame.
int position() const
Returns the index of the block's first character within the document.
QTextFrameFormat toFrameFormat() const
Returns this format as a frame format.
void addFile(const QString &fileName, const QString &mimeType)
QZipStreamStrategy(QIODevice *device)
void writeBlock(QXmlStreamWriter &writer, const QTextBlock &block)
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false...
int type() const
Returns the type of this format.
QTextTableCell cellAt(int row, int col) const
Returns the table cell at the given row and column in the table.
void setCodec(QTextCodec *codec)
Sets the codec for this stream to codec.
QTextCharFormat charFormat() const
Returns the text fragment's character format.
The QTextImageFormat class provides formatting information for images in a QTextDocument.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Style style() const
Returns the list format's style.
UnderlineStyle underlineStyle() const
Returns the style of underlining the text.
void writeAttribute(const QString &qualifiedName, const QString &value)
Writes an attribute with qualifiedName and value.
qreal topMargin() const
Returns the width of the frame's top margin in pixels.
virtual void addFile(const QString &fileName, const QString &mimeType, const QByteArray &bytes)
QTextCharFormat format() const
Returns the cell's character format.
qreal bottomMargin() const
Returns the width of the frame's bottom margin in pixels.
virtual void addFile(const QString &, const QString &, const QByteArray &)
QString numberSuffix() const
Returns the list format's number suffix.
QList< T > toList() const
Style
This enum describes the symbols used to decorate list items:
The QTextFormat class provides formatting information for a QTextDocument.
The QImageWriter class provides a format independent interface for writing images to files or other d...
QTextDocumentPrivate * docHandle() const
So that not all classes have to be friends of each other.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
void writeNamespace(const QString &namespaceUri, const QString &prefix=QString())
Writes a namespace declaration for namespaceUri with prefix.
QList< QTextOption::Tab > tabPositions() const
Returns a list of tab positions defined for the text block.
void writeBlockFormat(QXmlStreamWriter &writer, QTextBlockFormat format, int formatIndex) const
int fontWeight() const
Returns the text format's font weight.
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
The QTextBlock class provides a container for text fragments in a QTextDocument.
static const char * data(const QByteArray &arr)
QTextBlockFormat toBlockFormat() const
Returns this format as a block format.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
QTextListFormat toListFormat() const
Returns this format as a list format.
int row() const
Returns the number of the row in the table that contains this cell.
virtual ~QOutputStrategy()
int length() const
Returns the length of the block in characters.
QBrush background() const
Returns the brush used to paint the document's background.
The QTextTable class represents a table in a QTextDocument.
const BlockMap & blockMap() const
void writeListFormat(QXmlStreamWriter &writer, QTextListFormat format, int formatIndex) const
The QTextFragment class holds a piece of text in a QTextDocument with a single QTextCharFormat.
void writeCharacters(const QString &text)
Writes text.
qreal textIndent() const
Returns the paragraph's text indent.
The QTextBlock::iterator class provides an iterator for reading the contents of a QTextBlock...
const T & at(int i) const
Returns the item at index position i in the vector.
The iterator class provides an iterator for reading the contents of a QTextFrame. ...
The QBrush class defines the fill pattern of shapes drawn by QPainter.
bool isNull() const
Returns true if this string is null; otherwise returns false.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
QVector< QTextFormat > allFormats() const
Returns a vector of text formats for all the formats used in the document.
virtual ~QXmlStreamStrategy()
VerticalAlignment verticalAlignment() const
Returns the vertical alignment used for characters with this format.
int width() const
Returns the width of the image.
QTextImageFormat toImageFormat() const
Returns this format as an image format.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
bool nonBreakableLines() const
Returns true if the lines in the paragraph are non-breakable; otherwise returns false.
QString numberPrefix() const
Returns the list format's number prefix.
void writeFormats(QXmlStreamWriter &writer, QSet< int > formatIds) const
void writeStartDocument()
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setAutoFormattingIndent(int spacesOrTabs)
void writeEndElement()
Closes the previous start element.
void writeFrame(QXmlStreamWriter &writer, const QTextFrame *frame)
FragmentIterator begin() const
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
qreal bottomMargin() const
Returns the paragraph's bottom margin.
qreal fontWordSpacing() const
Returns the current word spacing value.
qreal rightMargin() const
Returns the width of the frame's right margin in pixels.
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
The QTextTableCell class represents the properties of a cell in a QTextTable.
The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument...
QBrush foreground() const
Returns the brush used to render foreground details, such as text, frame outlines, and table borders.
QXmlStreamStrategy(QIODevice *device)
void writeEmptyElement(const QString &qualifiedName)
Writes an empty element with qualified name qualifiedName.
int height() const
Returns the height of the image.
T qvariant_cast(const QVariant &)
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
The QTextTableCellFormat class provides formatting information for table cells in a QTextDocument...
QOutputStrategy * m_strategy
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
int tableCellFormatIndex() const
Returns the index of the tableCell's format in the document's internal list of formats.
QTextCharFormat toCharFormat() const
Returns this format as a character format.
void setAutoFormatting(bool)
bool atEnd() const
Returns true if the current item is the last item in the text frame.
void writeInlineCharacter(QXmlStreamWriter &writer, const QTextFragment &fragment) const
qreal fontPointSize() const
Returns the font size used to display text in this format.
qreal topPadding() const
Gets the top padding of the table cell.
bool isImageFormat() const
Returns true if this text format is an image format; otherwise returns false.
int columnSpan() const
Returns the number of columns this cell spans.
bool isTableCellFormat() const
Returns true if this text format is a TableCellFormat; otherwise returns false.
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
the QZipWriter class provides a way to create a new zip archive.
qreal fontLetterSpacing() const
Returns the current letter spacing percentage.
The QTextObject class is a base class for different kinds of objects that can group parts of a QTextD...
The QIODevice class is the base interface class of all I/O devices in Qt.
qreal leftPadding() const
Gets the left padding of the table cell.
bool fontItalic() const
Returns true if the text format's font is italic; otherwise returns false.
bool write(const QImage &image)
Writes the image image to the assigned device or file name.
QString fontFamily() const
Returns the text format's font family.
qreal bottomPadding() const
Gets the bottom padding of the table cell.
QTextBlock currentBlock() const
Returns the current block the iterator points to.
static QString fileName(const QString &fileUrl)
int indent() const
Returns the list format's indentation.
qreal leftMargin() const
Returns the paragraph's left margin.
QString name() const
Returns the name of the color in the format "#RRGGBB"; i.e.
QFont::Capitalization fontCapitalization() const
Returns the current capitalization type of the font.
QTextOdfWriter(const QTextDocument &document, QIODevice *device)
QString name() const
Returns the name of the image.
bool fontUnderline() const
Returns true if the text format's font is underlined; otherwise returns false.
void writeStartElement(const QString &qualifiedName)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool loadFromData(const uchar *buf, int len, const char *format=0)
Loads an image from the first len bytes of the given binary data.
iterator begin() const
Returns an iterator pointing to the first document element inside the frame.
qreal width() const
Returns the width of the rectangle occupied by the image.
QXmlStreamWriter manifestWriter
QString createUniqueImageName()
QTextListFormat format() const
Returns the list's format.