[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: [patch] KoOdfExporter and MSWordOdfImport port & fixes
From: "=?utf-8?q?Jaros=C5=82aw_Staniek?=" <staniek () kde ! org>
Date: 2009-05-29 13:50:43
Message-ID: 200905291550.43847.jstaniek () kogmbh ! net
[Download RAW message or body]
Dear all,
For review:
1. KoOdfExporter.patch
The goal: the code in convert is common, so KoOdfExporter is introduced to
avoid copy/pastes.
*created KoOdfExporter
**based on MSWordOdfImport::convert()
**added KoOdfWriters helper struct to make the API a bit cleaner
2. MSWordOdfImport.patch
*MSWordOdfImport:
**MSWordOdfImport is also ported to KoOdfExporter API
**fixed warnings in MSWordOdfImport's Document::Document()
**removed uses of QConstString
**moved filename conversion to Document ctor
**Document::processStyles(): fixed bug in 'i' variable used twice
--
regards / pozdrawiam, Jaroslaw Staniek
Kexi & KOffice (http://www.kexi-project.org, http://www.koffice.org)
KDE Libraries for MS Windows (http://windows.kde.org)
http://www.linkedin.com/in/jstaniek
["KoOdfExporter.patch" (text/x-patch)]
Index: libs/main/KoOdfExporter.h
===================================================================
--- libs/main/KoOdfExporter.h (revision 0)
+++ libs/main/KoOdfExporter.h (revision 0)
@@ -0,0 +1,101 @@
+/* This file is part of the KDE project
+ Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
+ Copyright (C) 2009 Jarosław Staniek <staniek@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 KOODFEXPORTER_H
+#define KOODFEXPORTER_H
+
+#include "KoFilter.h"
+
+class KoXmlWriter;
+class KoChain;
+class KoStore;
+class KoGenStyles;
+
+/**
+ * @brief Convenience structure encapsulating XML writers used when writing ODF \
document. + */
+struct KOMAIN_EXPORT KoOdfWriters
+{
+ /**
+ * Creates structure encapsulating XML writers. All members are set initially to \
0. + */
+ KoOdfWriters();
+ KoXmlWriter *content;
+ KoXmlWriter *body;
+ KoXmlWriter *meta;
+ KoXmlWriter *manifest;
+};
+
+/**
+ * @brief The base class for filters exporting to ODF.
+ *
+ * Derive your filter class from this base class and implement
+ * the pure virtual methods. Don't forget to specify the Q_OBJECT
+ * macro in your class even if you don't use signals or slots.
+ * This is needed as filters are created on the fly.
+ * The m_chain member allows access to the @ref KoFilterChain
+ * which invokes the filter to query for input/output.
+ *
+ * @note Take care: The m_chain pointer is invalid while the constructor
+ * runs due to the implementation -- @em don't use it in the constructor.
+ * After the constructor, when running the @ref convert() method it's
+ * guaranteed to be valid, so no need to check against 0.
+ *
+ * @author Jarosław Staniek <staniek@kde.org>
+ */
+class KOMAIN_EXPORT KoOdfExporter : public KoFilter
+{
+ Q_OBJECT
+public:
+ virtual ~KoOdfExporter();
+
+ virtual KoFilter::ConversionStatus convert( const QByteArray& from, const \
QByteArray& to ); +
+protected:
+ /**
+ * This is the constructor your filter has to call, obviously.
+ */
+ KoOdfExporter(QObject* parent = 0);
+
+ /**
+ * @return true if @a mime is accepted source mime type.
+ * Implement it for your filter.
+ */
+ virtual bool acceptsSourceMimeType(const QByteArray& mime) const = 0;
+
+ /**
+ * @return true if @a mime is accepted destination mime type.
+ * Implement it for your filter.
+ */
+ virtual bool acceptsDestinationMimeType(const QByteArray& mime) const = 0;
+
+ /**
+ * This method is called in convert() after creating @a outputStore, @a writers \
and @a mainStyles. + * Implement it for your filter with code that fills the ODF \
structures with converted data. + */
+ virtual KoFilter::ConversionStatus createDocument(KoStore *outputStore,
+ KoOdfWriters *writers, \
KoGenStyles *mainStyles) = 0; +
+private:
+ class Private;
+ Private* d;
+};
+
+#endif /* KOODFEXPORTER_H */
Index: libs/main/KoOdfExporter.cpp
===================================================================
--- libs/main/KoOdfExporter.cpp (revision 0)
+++ libs/main/KoOdfExporter.cpp (revision 0)
@@ -0,0 +1,171 @@
+/* This file is part of the KDE project
+ Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
+ Copyright (C) 2009 Jarosław Staniek <staniek@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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.
+*/
+
+#include "KoOdfExporter.h"
+
+#include <QBuffer>
+#include <QByteArray>
+
+#include <KDebug>
+
+#include <KoOdfWriteStore.h>
+#include <KoStoreDevice.h>
+#include <KoFilterChain.h>
+#include <KoGenStyles.h>
+#include <KoXmlWriter.h>
+
+#include <memory>
+
+KoOdfWriters::KoOdfWriters()
+ : content(0), body(0), meta(0), manifest(0)
+{
+}
+
+//------------------------------------------
+
+class KoOdfExporter::Private
+{
+public:
+ Private() {}
+};
+
+//------------------------------------------
+
+KoOdfExporter::KoOdfExporter( QObject* parent )
+ : KoFilter( parent )
+ , d( new Private )
+{
+}
+
+KoOdfExporter::~KoOdfExporter()
+{
+ delete d;
+}
+
+KoFilter::ConversionStatus KoOdfExporter::convert( const QByteArray& from, const \
QByteArray& to ) +{
+ // check for proper conversion
+ if (!acceptsSourceMimeType(from)) {
+ kWarning() << "Invalid source mimetype" << from;
+ return KoFilter::NotImplemented;
+ }
+ if (!acceptsDestinationMimeType(to)) {
+ kWarning() << "Invalid destination mimetype" << to;
+ return KoFilter::NotImplemented;
+ }
+
+ //create output files
+ std::auto_ptr<KoStore> outputStore(
+ KoStore::createStore( m_chain->outputFile(), KoStore::Write, to, \
KoStore::Zip ) ); + if ( !outputStore.get() ) {
+ kWarning() << "Unable to open output file!";
+ return KoFilter::FileNotFound;
+ }
+ outputStore->disallowNameExpansion();
+ kDebug() << "created outputStore.";
+ KoOdfWriteStore oasisStore( outputStore.get() );
+
+ kDebug() << "created oasisStore.";
+
+ // KoGenStyles for writing styles while we're parsing
+ KoGenStyles mainStyles;
+
+ KoOdfWriters writers;
+
+ // create a writer for meta.xml
+ QBuffer buf;
+ buf.open(QIODevice::WriteOnly);
+ KoXmlWriter metaWriter(&buf);
+ writers.meta = &metaWriter;
+
+ // create a writer for manifest.xml
+ QBuffer manifestBuf;
+ manifestBuf.open(QIODevice::WriteOnly);
+ KoXmlWriter manifestWriter(&manifestBuf);
+ writers.manifest = &manifestWriter;
+
+ //open contentWriter & bodyWriter *temp* writers
+ //so we can write picture files while we parse
+ QBuffer contentBuf;
+ KoXmlWriter contentWriter(&contentBuf);
+ writers.content = &contentWriter;
+ QBuffer bodyBuf;
+ KoXmlWriter bodyWriter(&bodyBuf);
+ writers.body = &bodyWriter;
+
+ // open main tags
+ bodyWriter.startElement("office:body");
+ bodyWriter.startElement("office:text");
+
+ const KoFilter::ConversionStatus result
+ = createDocument(outputStore.get(), &writers, &mainStyles);
+ if ( result != KoFilter::OK )
+ return result;
+
+ //save the office:automatic-styles & and fonts in content.xml
+ mainStyles.saveOdfFontFaceDecls(&contentWriter);
+ mainStyles.saveOdfAutomaticStyles(&contentWriter, false);
+
+ //close tags in body
+ bodyWriter.endElement();//office:text
+ bodyWriter.endElement();//office:body
+
+ //now create real content/body writers & dump the information there
+ KoXmlWriter* realContentWriter = oasisStore.contentWriter();
+ realContentWriter->addCompleteElement(&contentBuf);
+ KoXmlWriter* realBodyWriter = oasisStore.bodyWriter();
+ realBodyWriter->addCompleteElement(&bodyBuf);
+
+ //now close content & body writers
+ if ( !oasisStore.closeContentWriter() ) {
+ kWarning() << "Error closing content.";
+ return KoFilter::CreationError;
+ }
+
+ kDebug(30010) << "closed content & body writers.";
+
+ //create the manifest file
+ KoXmlWriter* realManifestWriter = oasisStore.manifestWriter( to );
+ //create the styles.xml file
+ mainStyles.saveOdfStylesDotXml( outputStore.get(), realManifestWriter );
+ realManifestWriter->addManifestEntry( "content.xml", "text/xml" );
+ realManifestWriter->addCompleteElement(&manifestBuf);
+
+ kDebug(30010) << "created manifest and styles.xml";
+
+ //create meta.xml
+ if (!outputStore->open("meta.xml")) {
+ return KoFilter::CreationError;
+ }
+ KoStoreDevice metaDev(outputStore.get());
+ KoXmlWriter* meta = KoOdfWriteStore::createOasisXmlWriter(&metaDev, \
"office:document-meta"); + meta->startElement("office:meta");
+ meta->addCompleteElement(&buf);
+ meta->endElement(); //office:meta
+ meta->endElement(); //office:document-meta
+ meta->endDocument();
+ if (!outputStore->close()) {
+ return KoFilter::CreationError;
+ }
+ realManifestWriter->addManifestEntry("meta.xml", "text/xml");
+ oasisStore.closeManifestWriter();
+
+ return KoFilter::OK;
+}
Index: libs/main/CMakeLists.txt
===================================================================
--- libs/main/CMakeLists.txt (revision 974471)
+++ libs/main/CMakeLists.txt (working copy)
@@ -72,6 +72,7 @@
KoDockWidgetTitleBar.cpp
KoPrintJob.cpp
KoExistingDocumentPane.cpp
+ KoOdfExporter.cpp
)
["MSWordOdfImport.patch" (text/x-patch)]
Index: filters/kword/msword-odf/mswordodfimport.cpp
===================================================================
--- filters/kword/msword-odf/mswordodfimport.cpp (revision 974473)
+++ filters/kword/msword-odf/mswordodfimport.cpp (working copy)
@@ -22,23 +22,12 @@
#include "mswordodfimport.h"
-#include <qdom.h>
-#include <qfontinfo.h>
-#include <QFile>
-#include <QString>
-#include <QBuffer>
-//Added by qt3to4:
-#include <QByteArray>
+#include <KDebug>
+#include <KGenericFactory>
-#include <kdebug.h>
-#include <kgenericfactory.h>
-
#include <KoFilterChain.h>
-#include <KoOdfWriteStore.h>
-#include <KoStoreDevice.h>
-//#include <KoXmlWriter.h>
-#include <document.h>
+#include "document.h"
typedef KGenericFactory<MSWordOdfImport> MSWordOdfImportFactory;
K_EXPORT_COMPONENT_FACTORY( libmswordodf_import, MSWordOdfImportFactory( \
"kofficefilters" ) ) @@ -46,13 +35,10 @@
class MSWordOdfImport::Private
{
public:
- QString inputFile;
- QString outputFile;
-
- Document* document;
};
-MSWordOdfImport::MSWordOdfImport( QObject *parent, const QStringList& ) : \
KoFilter(parent) +MSWordOdfImport::MSWordOdfImport( QObject *parent, const \
QStringList & ) + : KoOdfExporter(parent)
{
d = new Private;
}
@@ -62,160 +48,39 @@
delete d;
}
-KoFilter::ConversionStatus MSWordOdfImport::convert( const QByteArray& from, const \
QByteArray& to ) +bool MSWordOdfImport::acceptsSourceMimeType(const QByteArray& mime) \
const {
- // check for proper conversion
- if ( to != "application/vnd.oasis.opendocument.text" || from != \
"application/msword" )
- return KoFilter::NotImplemented;
+ return mime == "application/msword";
+}
- kDebug(30513) <<"######################## MSWordOdfImport::convert \
########################"; +bool MSWordOdfImport::acceptsDestinationMimeType(const \
QByteArray& mime) const +{
+ return mime == "application/vnd.oasis.opendocument.text";
+}
- d->inputFile = m_chain->inputFile();
- d->outputFile = m_chain->outputFile();
-
- //create output files
- KoStore* storeout;
- storeout = KoStore::createStore( d->outputFile, KoStore::Write,
- "application/vnd.oasis.opendocument.text", KoStore::Zip );
- if ( !storeout ) {
- kWarning() << "Unable to open output file!";
- return KoFilter::FileNotFound;
- }
- storeout->disallowNameExpansion();
- kDebug(30513) <<"created storeout.";
- KoOdfWriteStore oasisStore( storeout );
-
- kDebug(30513) <<"created oasisStore.";
-
- //create KoGenStyles for writing styles while we're parsing
- KoGenStyles* mainStyles = new KoGenStyles();
-
- //create a writer for meta.xml
- QBuffer buf;
- buf.open(QIODevice::WriteOnly);
- KoXmlWriter metaWriter(&buf);
-
- //create a writer for manifest.xml
- QBuffer manifestBuf;
- manifestBuf.open(QIODevice::WriteOnly);
- KoXmlWriter manifestWriter(&manifestBuf);
-
- //open contentWriter & bodyWriter *temp* writers
- //so we can write picture files while we parse
- QBuffer contentBuf;
- QBuffer bodyBuf;
- KoXmlWriter* contentWriter = new KoXmlWriter(&contentBuf);
- KoXmlWriter* bodyWriter = new KoXmlWriter(&bodyBuf);
- if ( !bodyWriter || !contentWriter )
- {
- delete d->document;
- delete storeout;
- return KoFilter::CreationError; //not sure if this is the right error to return
- }
-
- kDebug(30513) <<"created temp contentWriter and bodyWriter.";
-
- //open tags in bodyWriter
- bodyWriter->startElement("office:body");
- bodyWriter->startElement("office:text");
-
+KoFilter::ConversionStatus MSWordOdfImport::createDocument(KoStore *outputStore,
+ KoOdfWriters *writers, \
KoGenStyles *mainStyles) +{
//create our document object, writing to the temporary buffers
- d->document = new Document(QFile::encodeName( d->inputFile ).data(), m_chain, \
bodyWriter, mainStyles,
- &metaWriter, storeout, &manifestWriter);
+ Document doc(m_chain->inputFile(), m_chain, writers, mainStyles, outputStore);
//check that we can parse the document?
- if ( !d->document->hasParser() )
- {
- delete d->document;
- delete storeout;
+ if ( !doc.hasParser() ) {
return KoFilter::WrongFormat;
}
//actual parsing & action
- if ( !d->document->parse() ) //parse file into the queues?
- {
- delete d->document;
- delete storeout;
- return KoFilter::CreationError;
+ if ( !doc.parse() ) { //parse file into the queues?
+ return KoFilter::CreationError;
}
- d->document->processSubDocQueue(); //process the queues we've created?
- d->document->finishDocument(); //process footnotes, pictures, ...
- if ( !d->document->bodyFound() )
- {
- delete d->document;
- delete storeout;
- return KoFilter::WrongFormat;
+ doc.processSubDocQueue(); //process the queues we've created?
+ doc.finishDocument(); //process footnotes, pictures, ...
+ if ( !doc.bodyFound() ) {
+ return KoFilter::WrongFormat;
}
- kDebug(30513) <<"finished parsing.";
-
- //save the office:automatic-styles & and fonts in content.xml
- mainStyles->saveOdfFontFaceDecls(contentWriter);
- mainStyles->saveOdfAutomaticStyles(contentWriter, false);
-
- //close tags in bodyWriter
- bodyWriter->endElement();//office:text
- bodyWriter->endElement();//office:body
-
- //now create real content/body writers & dump the information there
- KoXmlWriter* realContentWriter = oasisStore.contentWriter();
- realContentWriter->addCompleteElement(&contentBuf);
- KoXmlWriter* realBodyWriter = oasisStore.bodyWriter();
- realBodyWriter->addCompleteElement(&bodyBuf);
-
- //now close content & body writers
- if ( !oasisStore.closeContentWriter() )
- {
- kWarning() << "Error closing content.";
- delete d->document;
- delete storeout;
- return KoFilter::CreationError;
- }
-
- kDebug(30513) <<"closed content & body writers.";
-
- //create the manifest file
- KoXmlWriter* realManifestWriter = oasisStore.manifestWriter( \
"application/vnd.oasis.opendocument.text" );
- //create the styles.xml file
- mainStyles->saveOdfStylesDotXml( storeout, realManifestWriter );
- realManifestWriter->addManifestEntry( "content.xml", "text/xml" );
- realManifestWriter->addCompleteElement(&manifestBuf);
-
- kDebug(30513) <<"created manifest and styles.xml";
-
- //create meta.xml
- if(!storeout->open("meta.xml")) {
- delete d->document;
- delete storeout;
- delete mainStyles;
- return KoFilter::CreationError;
- }
- KoStoreDevice metaDev(storeout);
- KoXmlWriter* meta = KoOdfWriteStore::createOasisXmlWriter(&metaDev, \
"office:document-meta");
- meta->startElement("office:meta");
- meta->addCompleteElement(&buf);
- meta->endElement(); //office:meta
- meta->endElement(); //office:document-meta
- meta->endDocument();
- if(!storeout->close()) {
- delete d->document;
- delete storeout;
- delete mainStyles;
- return KoFilter::CreationError;
- }
- realManifestWriter->addManifestEntry("meta.xml", "text/xml");
- oasisStore.closeManifestWriter();
-
- //done, so cleanup now
- delete d->document;
- delete storeout;
- delete mainStyles;
- d->inputFile.clear();
- d->outputFile.clear();
- d->document = 0;
-
- kDebug(30513) <<"######################## MSWordOdfImport::convert done \
####################"; + kDebug(30513) << "finished parsing.";
return KoFilter::OK;
}
-#include <mswordodfimport.moc>
+#include "mswordodfimport.moc"
Index: filters/kword/msword-odf/mswordodfimport.h
===================================================================
--- filters/kword/msword-odf/mswordodfimport.h (revision 974473)
+++ filters/kword/msword-odf/mswordodfimport.h (working copy)
@@ -23,20 +23,23 @@
#ifndef MSWORDODFIMPORT_H
#define MSWORDODFIMPORT_H
-#include <KoFilter.h>
-#include <KoXmlWriter.h>
-//Added by qt3to4:
-#include <QByteArray>
+#include <KoOdfExporter.h>
-class MSWordOdfImport : public KoFilter
+class MSWordOdfImport : public KoOdfExporter
{
Q_OBJECT
public:
MSWordOdfImport( QObject* parent, const QStringList& );
virtual ~MSWordOdfImport();
- virtual KoFilter::ConversionStatus convert( const QByteArray& from, const \
QByteArray& to ); +protected:
+ virtual bool acceptsSourceMimeType(const QByteArray& mime) const;
+ virtual bool acceptsDestinationMimeType(const QByteArray& mime) const;
+
+ virtual KoFilter::ConversionStatus createDocument(KoStore *outputStore,
+ KoOdfWriters *writers, \
KoGenStyles *mainStyles); +
private:
class Private;
Private* d;
Index: filters/kword/msword-odf/document.cpp
===================================================================
--- filters/kword/msword-odf/document.cpp (revision 974473)
+++ filters/kword/msword-odf/document.cpp (working copy)
@@ -2,6 +2,7 @@
Copyright (C) 2002 Werner Trobin <trobin@kde.org>
Copyright (C) 2002 David Faure <faure@kde.org>
Copyright (C) 2008 Benjamin Cail <cricketc@gmail.com>
+ Copyright (C) 2009 Jarosław Staniek <staniek@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
@@ -28,6 +29,7 @@
#include <KoUnit.h>
#include <KoPageLayout.h>
+#include <KoOdfExporter.h>
#include <kdebug.h>
#include <wv2/styles.h>
@@ -44,26 +46,31 @@
#include <Q3ValueList>
#include <QBuffer>
-Document::Document( const std::string& fileName, KoFilterChain* chain, KoXmlWriter* \
bodyWriter,
- KoGenStyles* mainStyles, KoXmlWriter* metaWriter, KoStore* store, \
KoXmlWriter* manifestWriter)
- : m_replacementHandler( new KWordReplacementHandler ),
- m_pictureHandler( new KWordPictureHandler(this, bodyWriter, manifestWriter, \
store, mainStyles)),
- m_textHandler( 0 ), m_headerCount(0), m_hasHeader(false), m_hasFooter(false),
- m_chain( chain ), m_currentListDepth( -1 ), m_evenOpen( false ), m_oddOpen( \
false ), m_pageLayoutStyle(0),
- m_parser( wvWare::ParserFactory::createParser( fileName ) )/*, \
m_headerFooters( 0 ), m_bodyFound( false ),
- m_footNoteNumber( 0 ), m_endNoteNumber( 0 )*/
+
+Document::Document( const QString& fileName, KoFilterChain* chain, KoOdfWriters \
*writers, + KoGenStyles* mainStyles, KoStore* store )
+ : m_chain( chain ),
+ m_parser( wvWare::ParserFactory::createParser( \
QFile::encodeName(fileName).data() ) ), + m_replacementHandler( new \
KWordReplacementHandler ), + m_pictureHandler( new KWordPictureHandler(this, \
writers->body, writers->manifest, store, mainStyles)), + m_textHandler( 0 ),
+ m_bodyFound( false ), m_evenOpen( false ), m_oddOpen( false ),
+ m_currentListDepth( -1 ),
+ m_pageLayoutStyle(0),
+ m_odfWriters( writers ),
+ m_hasHeader(false), m_headerCount(0), m_hasFooter(false)
+ /*, m_headerFooters( 0 ), m_footNoteNumber( 0 ), m_endNoteNumber( 0 )*/
{
kDebug(30513);
if ( m_parser ) // 0 in case of major error (e.g. unsupported format)
{
- m_bodyWriter = bodyWriter; //pointer for writing to the body
+
m_mainStyles = mainStyles; //KoGenStyles object for collecting styles
- m_metaWriter = metaWriter; //pointer for writing to meta.xml
m_buffer = 0; //set pointers to 0
m_bufferEven = 0;
m_writer = 0;
- m_textHandler = new KWordTextHandler(m_parser, bodyWriter, mainStyles);
- m_tableHandler= new KWordTableHandler(bodyWriter, mainStyles),
+ m_textHandler = new KWordTextHandler(m_parser, m_odfWriters->body, mainStyles);
+ m_tableHandler= new KWordTableHandler(m_odfWriters->body, mainStyles),
connect( m_textHandler, SIGNAL( subDocFound( const wvWare::FunctorBase*, int ) ),
this, SLOT( slotSubDocFound( const wvWare::FunctorBase*, int ) ) );
connect( m_textHandler, SIGNAL( footnoteFound( const wvWare::FunctorBase*, \
int ) ), @@ -122,6 +129,7 @@
}
const wvWare::Word97::DOP& dop = m_parser->dop();
+ Q_UNUSED(dop)
//"tabStopValue", (double)dop.dxaTab / 20.0
//dop.nFtn = initial footnote number for document, starts at 1
//Conversion::numberFormatCode(dop.nfcFtnRef2)
@@ -184,24 +192,24 @@
kDebug(30513) ;
wvWare::AssociatedStrings strings( m_parser->associatedStrings() );
if(!strings.author().isNull()) {
- m_metaWriter->startElement("meta:initial-creator");
- m_metaWriter->addTextSpan(Conversion::string(strings.author()).string());
- m_metaWriter->endElement();
+ m_odfWriters->meta->startElement("meta:initial-creator");
+ m_odfWriters->meta->addTextSpan(Conversion::string(strings.author()));
+ m_odfWriters->meta->endElement();
}
if(!strings.title().isNull()) {
- m_metaWriter->startElement("dc:title");
- m_metaWriter->addTextSpan(Conversion::string(strings.title()).string());
- m_metaWriter->endElement();
+ m_odfWriters->meta->startElement("dc:title");
+ m_odfWriters->meta->addTextSpan(Conversion::string(strings.title()));
+ m_odfWriters->meta->endElement();
}
if(!strings.subject().isNull()) {
- m_metaWriter->startElement("dc:subject");
- m_metaWriter->addTextSpan(Conversion::string(strings.subject()).string());
- m_metaWriter->endElement();
+ m_odfWriters->meta->startElement("dc:subject");
+ m_odfWriters->meta->addTextSpan(Conversion::string(strings.subject()));
+ m_odfWriters->meta->endElement();
}
if(!strings.lastRevBy().isNull()) {
- m_metaWriter->startElement("dc:creator");
- m_metaWriter->addTextSpan(Conversion::string(strings.lastRevBy()).string());
- m_metaWriter->endElement();
+ m_odfWriters->meta->startElement("dc:creator");
+ m_odfWriters->meta->addTextSpan(Conversion::string(strings.lastRevBy()));
+ m_odfWriters->meta->endElement();
}
}
@@ -219,26 +227,26 @@
//grab style
const wvWare::Style* style = styles.styleByIndex( i );
Q_ASSERT( style );
- QConstString displayName = Conversion::string(style->name());
- QString name = Conversion::string(style->name());
- //need to replace all non-alphanumeric characters with hex representation
- for(int i = 0; i < name.size(); i++) {
- if(!name[i].isLetterOrNumber()) {
- name.remove(i, 1);
- i--;
- }
- }
- kDebug(30513) << "Style" << i << ":" << displayName.string();
- kDebug(30513) << "style->type() = " << style->type();
- kDebug(30513) << "style->sti() = " << style->sti();
+ const QString displayName( Conversion::string(style->name()) );
+ QString name( Conversion::string(style->name()) );
+ //need to replace all non-alphanumeric characters with hex representation
+ for(int j = 0; j < name.size(); j++) {
+ if(!name[j].isLetterOrNumber()) {
+ name.remove(j, 1);
+ j--;
+ }
+ }
+ kDebug(30513) << "Style" << i << ":" << displayName;
+ kDebug(30513) << "style->type() = " << style->type();
+ kDebug(30513) << "style->sti() = " << style->sti();
- //process paragraph styles
+ //process paragraph styles
if ( style && style->type() == wvWare::Style::sgcPara )
{
const wvWare::Style* followingStyle = styles.styleByID( \
style->followingStyle() ); if ( followingStyle && followingStyle != style )
{
- QConstString followingName = Conversion::string( \
followingStyle->name() ); + const QString followingName( \
Conversion::string( followingStyle->name() ) ); }
//create this style & add formatting info to it
@@ -303,8 +311,8 @@
//close any open list tags in the body writer
for (int i = 0; i <= m_currentListDepth; i++)
{
- m_bodyWriter->endElement(); //close the text:list-item
- m_bodyWriter->endElement(); //text:list
+ m_odfWriters->body->endElement(); //close the text:list-item
+ m_odfWriters->body->endElement(); //text:list
}
m_currentListDepth = -1;
}
Index: filters/kword/msword-odf/texthandler.cpp
===================================================================
--- filters/kword/msword-odf/texthandler.cpp (revision 974473)
+++ filters/kword/msword-odf/texthandler.cpp (working copy)
@@ -443,8 +443,8 @@
//this handles a basic section of text
void KWordTextHandler::runOfText( const wvWare::UString& text, \
wvWare::SharedPtr<const wvWare::Word97::CHP> chp ) {
- QConstString newText(Conversion::string(text));
- kDebug(30513) << newText.string();
+ QString newText(Conversion::string(text));
+ kDebug(30513) << newText;
// text after fieldStart and before fieldSeparator is useless
if( m_insideField && !m_fieldAfterSeparator ) {
@@ -456,13 +456,13 @@
if(m_insideField && m_fieldAfterSeparator && (m_fieldType > 0))
{
kDebug(30513) << "adding this text to field value.";
- m_fieldValue.append(newText.string());
+ m_fieldValue.append(newText);
return;
}
//write the text with its formatting inside a <text:span> tag
KoGenStyle textStyle(KoGenStyle::StyleTextAuto, "text");
- writeFormattedText(&textStyle, chp, m_currentStyle ? &m_currentStyle->chp() : 0, \
newText.string(), true, QString("T")); + writeFormattedText(&textStyle, chp, \
m_currentStyle ? &m_currentStyle->chp() : 0, newText, true, QString("T"));
} //end runOfText()
@@ -655,8 +655,8 @@
return QString();
const wvWare::Word97::FFN& ffn ( m_parser->font( fc ) );
- QConstString fontName( Conversion::string( ffn.xszFfn ) );
- QString font = fontName.string();
+ QString fontName( Conversion::string( ffn.xszFfn ) );
+ QString font = fontName;
return font;
/*
#ifdef FONT_DEBUG
@@ -888,7 +888,7 @@
}
else
{
- kWarning(30513) << "Not supported: counter text without the depth in it:" << \
Conversion::string(text).string(); + kWarning(30513) << "Not supported: counter \
text without the depth in it:" << Conversion::string(text); }
if ( listInfo->startAtOverridden() ) //||
Index: filters/kword/msword-odf/document.h
===================================================================
--- filters/kword/msword-odf/document.h (revision 974473)
+++ filters/kword/msword-odf/document.h (working copy)
@@ -2,6 +2,7 @@
Copyright (C) 2002 Werner Trobin <trobin@kde.org>
Copyright (C) 2002 David Faure <faure@kde.org>
Copyright (C) 2008 Benjamin Cail <cricketc@gmail.com>
+ Copyright (C) 2009 Jarosław Staniek <staniek@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
@@ -50,6 +51,7 @@
}
}
class KoFilterChain;
+class KoOdfWriters;
class KWordReplacementHandler;
class KWordTableHandler;
class KWordPictureHandler;
@@ -59,8 +61,8 @@
{
Q_OBJECT
public:
- Document(const std::string& fileName, KoFilterChain* chain, KoXmlWriter* \
bodyWriter,
- KoGenStyles* mainStyles, KoXmlWriter* metaWriter, KoStore* store, \
KoXmlWriter* manifestWriter); + Document(const QString& fileName, KoFilterChain* \
chain, KoOdfWriters *writers, + KoGenStyles* mainStyles, KoStore* store);
virtual ~Document();
bool hasParser() const { return m_parser != 0L; }
@@ -128,33 +130,32 @@
enum NewFrameBehavior { Reconnect=0, NoFollowup=1, Copy=2 };
void generateFrameBorder( QDomElement& frameElementOut, const \
wvWare::Word97::BRC& brcTop, const wvWare::Word97::BRC& brcBottom, const \
wvWare::Word97::BRC& brcLeft, const wvWare::Word97::BRC& brcRight, const \
wvWare::Word97::SHD& shd );
+ KoFilterChain* m_chain;
+ wvWare::SharedPtr<wvWare::Parser> m_parser;
KWordReplacementHandler* m_replacementHandler;
KWordTableHandler* m_tableHandler;
KWordPictureHandler* m_pictureHandler;
KWordTextHandler* m_textHandler;
- KoFilterChain* m_chain;
- wvWare::SharedPtr<wvWare::Parser> m_parser;
std::queue<SubDocument> m_subdocQueue;
std::queue<KWord::Table> m_tableQueue;
QStringList m_pictureList; // for <PICTURES>
- unsigned char m_headerFooters; // a mask of HeaderData::Type bits
+ //unsigned char m_headerFooters; // a mask of HeaderData::Type bits
bool m_bodyFound;
bool m_evenOpen; //we're processing an even header or footer
bool m_oddOpen; //we're processing an odd header or footer
- int m_footNoteNumber; // number of footnote _framesets_ written out
- int m_endNoteNumber; // number of endnote _framesets_ written out
+ //int m_footNoteNumber; // number of footnote _framesets_ written out
+ //int m_endNoteNumber; // number of endnote _framesets_ written out
int m_currentListDepth; //track list depth in case we need to close a list here \
(-1 if no list)
- KoXmlWriter* m_bodyWriter; //for writing to the body of content.xml
KoGenStyles* m_mainStyles; //for collecting styles
- KoXmlWriter* m_metaWriter; //for writing to meta.xml
KoGenStyle* m_masterStyle; //for header/footer stuff, at least
KoGenStyle* m_pageLayoutStyle; //page layout style
+ KoOdfWriters *m_odfWriters; //for writing elements of the ODF package
KoXmlWriter* m_writer; //for header/footer tags
bool m_hasHeader;
+ int m_headerCount; //just so we have a unique name for the element we're putting \
in m_masterStyle bool m_hasFooter;
QBuffer* m_buffer; //for header/footer tags
QBuffer* m_bufferEven; //for even header/footer tags
- int m_headerCount; //just so we have a unique name for the element we're putting \
in m_masterStyle
QString m_masterStyleName; //need to know what the master style name is so we \
can write it };
Index: filters/kword/msword-odf/conversion.h
===================================================================
--- filters/kword/msword-odf/conversion.h (revision 974473)
+++ filters/kword/msword-odf/conversion.h (working copy)
@@ -41,11 +41,10 @@
namespace Conversion
{
- // UString -> QConstString conversion. Use .string() to get the QString.
- // Always store the QConstString into a variable first, to avoid a deep copy.
- inline QConstString string( const wvWare::UString& str ) {
- // Let's hope there's no copying of the QConstString happening...
- return QConstString( reinterpret_cast<const QChar*>( str.data() ), \
str.length() ); + // UString -> QString conversion.
+ // Always store the QString into a variable first, to avoid a deep copy.
+ inline QString string( const wvWare::UString& str ) {
+ return QString::fromRawData( reinterpret_cast<const QChar*>( str.data() ), \
str.length() ); }
// Prepare text for inclusion in XML
_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic