1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
/*
* Copyright (c) 2010 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KOTEXTWRITER_P_H
#define KOTEXTWRITER_P_H
#include <QMap>
#include <QHash>
#include <QStack>
#include <QPair>
#include <QString>
#include <KoTextWriter.h>
#include <KoXmlReaderForward.h>
class KoInlineObject;
class KoTextInlineRdf;
class KoList;
class KoShapeSavingContext;
class KoXmlWriter;
class KoTableColumnStyle;
class KoTextSharedSavingData;
class KoTableRowStyle;
class KoDocumentRdfBase;
class QTextDocument;
class QTextTable;
class QTextTableCellFormat;
class QTextList;
class QTextStream;
/**
* XXX: Apidox!
*/
class TagInformation
{
public:
TagInformation():tagName(0), attributeList()
{
}
void setTagName(const char *tagName)
{
this->tagName = tagName;
}
void addAttribute(const QString& attributeName, const QString& attributeValue)
{
attributeList.push_back(QPair<QString,QString>(attributeName, attributeValue));
}
void addAttribute(const QString& attributeName, int value)
{
addAttribute(attributeName, QString::number(value));
}
void clear()
{
tagName = nullptr;
attributeList.clear();
}
const char *name() const
{
return tagName;
}
const QVector<QPair<QString, QString> >& attributes() const
{
return attributeList;
}
private:
const char *tagName;
QVector<QPair<QString, QString> > attributeList;
};
/**
* XXX: Apidox!
*/
class Q_DECL_HIDDEN KoTextWriter::Private
{
public:
explicit Private(KoShapeSavingContext &context);
~Private() {}
void writeBlocks(QTextDocument *document, int from, int to,
QHash<QTextList *, QString> &listStyles,
QTextTable *currentTable = 0,
QTextList *currentList = 0);
QHash<QTextList *, QString> saveListStyles(QTextBlock block, int to);
private:
enum ElementType {
Span,
ParagraphOrHeader,
ListItem,
List,
NumberedParagraph,
Table,
TableRow,
TableColumn,
TableCell
};
void openTagRegion(KoTextWriter::Private::ElementType elementType, TagInformation &tagInformation);
void closeTagRegion();
QString saveParagraphStyle(const QTextBlock &block);
QString saveParagraphStyle(const QTextBlockFormat &blockFormat, const QTextCharFormat &charFormat);
QString saveCharacterStyle(const QTextCharFormat &charFormat, const QTextCharFormat &blockCharFormat);
QString saveTableStyle(const QTextTable &table);
QString saveTableColumnStyle(const KoTableColumnStyle &columnStyle, int columnNumber, const QString &tableStyleName);
QString saveTableRowStyle(const KoTableRowStyle &rowStyle, int rowNumber, const QString &tableStyleName);
QString saveTableCellStyle(const QTextTableCellFormat &cellFormat, int columnNumber, const QString &tableStyleName);
void saveParagraph(const QTextBlock &block, int from, int to);
void saveTable(QTextTable *table, QHash<QTextList *, QString> &listStyles, int from, int to);
QTextBlock& saveList(QTextBlock &block, QHash<QTextList *, QString> &listStyles, int level, QTextTable *currentTable);
void saveTableOfContents(QTextDocument *document, QHash<QTextList *, QString> &listStyles, QTextBlock toc);
void saveBibliography(QTextDocument *document, QHash<QTextList *, QString> &listStyles, QTextBlock bib);
void saveInlineRdf(KoTextInlineRdf *rdf, TagInformation *tagInfos);
void addNameSpaceDefinitions(QString &generatedXmlString);
// Common methods
void writeAttributes(QTextStream &outputXmlStream, KoXmlElement &element);
void writeNode(QTextStream &outputXmlStream, KoXmlNode &node, bool writeOnlyChildren = false);
QString createXmlId();
public:
KoDocumentRdfBase *rdfData;
KoTextSharedSavingData *sharedData;
KoStyleManager *styleManager;
QTextDocument *document;
int globalFrom; // to and from positions, relevant for finding matching bookmarks etc
int globalTo;
private:
KoXmlWriter *writer;
QStack<const char *> openedTagStack;
KoShapeSavingContext &context;
// Things like bookmarks need to be properly turn down during a cut and paste operation
// when their end markeris not included in the selection. However, when recursing into
// e.g. the QTextDocument of a table, we need have a clean slate. Hence, a stack of stacks.
QStack< QStack<KoInlineObject*> *> pairedInlineObjectsStackStack;
QStack<KoInlineObject*> *currentPairedInlineObjectsStack;
QMap<KoList *, QString> listXmlIds;
QMap<KoList *, QString> numberedParagraphListIds;
};
#endif // KOTEXTWRITER_P_H
|