You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.1 KiB
97 lines
3.1 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2002 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
|
||
|
|
||
|
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.
|
||
|
*/
|
||
|
|
||
13 years ago
|
#include <tqstring.h>
|
||
13 years ago
|
#include <tqtextstream.h>
|
||
13 years ago
|
#include <tqfile.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <kgenericfactory.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
|
||
|
#include <KoFilterChain.h>
|
||
|
#include <KoStoreDevice.h>
|
||
|
|
||
|
#include <kformuladocument.h>
|
||
|
#include <kformulacontainer.h>
|
||
|
#include <kformulamimesource.h>
|
||
|
|
||
|
#include "latexexport.h"
|
||
|
|
||
|
|
||
|
typedef KGenericFactory<LATEXExport, KoFilter> LATEXExportFactory;
|
||
|
K_EXPORT_COMPONENT_FACTORY( libkfolatexexport, LATEXExportFactory( "kofficefilters" ) )
|
||
|
|
||
|
|
||
13 years ago
|
LATEXExport::LATEXExport( KoFilter */*parent*/, const char */*name*/, const TQStringList& )
|
||
15 years ago
|
: KoFilter()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
13 years ago
|
KoFilter::ConversionStatus LATEXExport::convert( const TQCString& from, const TQCString& to )
|
||
15 years ago
|
{
|
||
|
if ( to != "text/x-tex" || from != "application/x-kformula" )
|
||
|
return KoFilter::NotImplemented;
|
||
|
|
||
|
KoStoreDevice* in = m_chain->storageFile( "root", KoStore::Read );
|
||
|
if(!in) {
|
||
13 years ago
|
TQApplication::restoreOverrideCursor();
|
||
15 years ago
|
KMessageBox::error( 0, i18n( "Failed to read data." ), i18n( "LaTeX Export Error" ) );
|
||
|
return KoFilter::StorageCreationError;
|
||
|
}
|
||
|
|
||
13 years ago
|
TQDomDocument dom( "KFORMULA" );
|
||
15 years ago
|
if ( !dom.setContent( in, false ) ) {
|
||
13 years ago
|
TQApplication::restoreOverrideCursor();
|
||
15 years ago
|
KMessageBox::error( 0, i18n( "Malformed XML data." ), i18n( "LaTeX Export Error" ) );
|
||
|
return KoFilter::WrongFormat;
|
||
|
}
|
||
|
|
||
13 years ago
|
TQFile f( m_chain->outputFile() );
|
||
15 years ago
|
if( !f.open( IO_Truncate | IO_ReadWrite ) ) {
|
||
13 years ago
|
TQApplication::restoreOverrideCursor();
|
||
15 years ago
|
KMessageBox::error( 0, i18n( "Failed to write file." ), i18n( "LaTeX Export Error" ) );
|
||
|
return KoFilter::FileNotFound;
|
||
|
}
|
||
|
|
||
|
KFormula::DocumentWrapper* wrapper = new KFormula::DocumentWrapper( kapp->config(), 0 );
|
||
|
KFormula::Document* doc = new KFormula::Document;
|
||
|
wrapper->document( doc );
|
||
|
KFormula::Container* formula = doc->createFormula();
|
||
|
if ( !doc->loadXML( dom ) ) {
|
||
|
kdError(30522) << "Failed." << endl;
|
||
|
}
|
||
|
|
||
13 years ago
|
TQTextStream stream(&f);
|
||
|
//stream.setEncoding(TQTextStream::UnicodeUTF8);
|
||
15 years ago
|
stream << "\\documentclass{article}\n\\usepackage{amsmath}\n\\begin{document}\n\\[\n"
|
||
|
<< formula->texString()
|
||
|
<< "\n\\]\n\\end{document}";
|
||
|
f.close();
|
||
|
|
||
|
delete formula;
|
||
|
delete wrapper;
|
||
|
|
||
|
return KoFilter::OK;
|
||
|
}
|
||
|
|
||
|
#include "latexexport.moc"
|