diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /filters/kformula | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'filters/kformula')
22 files changed, 1415 insertions, 0 deletions
diff --git a/filters/kformula/Makefile.am b/filters/kformula/Makefile.am new file mode 100644 index 00000000..9e0d2829 --- /dev/null +++ b/filters/kformula/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = png latex mathml svg diff --git a/filters/kformula/latex/Makefile.am b/filters/kformula/latex/Makefile.am new file mode 100644 index 00000000..5e022eec --- /dev/null +++ b/filters/kformula/latex/Makefile.am @@ -0,0 +1,25 @@ +####### General stuff + +INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(KFORMULA_INCLUDES) $(all_includes) +libkfolatexexport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +libkfolatexexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) + +####### Files + +kde_module_LTLIBRARIES = libkfolatexexport.la + +libkfolatexexport_la_SOURCES = latexexport.cc + +noinst_HEADERS = latexexport.h + +######## Debug +#check_PROGRAMS = texlauncher +#texlauncher_SOURCES = texlauncher.cc +#texlauncher_LDADD = liblatexexport.la +#texlauncher_LDFLAGS = $(KDE_RPATH) $(all_libraries) + + +METASOURCES = AUTO + +service_DATA = kformula_latex_export.desktop +servicedir = $(kde_servicesdir) diff --git a/filters/kformula/latex/kformula_latex_export.desktop b/filters/kformula/latex/kformula_latex_export.desktop new file mode 100644 index 00000000..d14b62a2 --- /dev/null +++ b/filters/kformula/latex/kformula_latex_export.desktop @@ -0,0 +1,69 @@ +[Desktop Entry] +X-KDE-Export=text/x-tex +ExportDescription=LATEX +Icon= +X-KDE-Import=application/x-kformula +X-KDE-Weight=1 +ImportDescription=KFormula +Name=KFormula LaTeX Export Filter +Name[af]=Kformula Latex Voer uit Filter +Name[ar]=مِرْشَح تصدير LaTeX لدى KFormula +Name[bg]=Филтър за експортиране от KFormula в LaTeX +Name[br]=Sil ezporzh LaTeX evit KFormula +Name[ca]=Filtre d'exportació LaTeX per a KFormula +Name[cs]=Exportní filtr formátu LaTeX pro KFormula +Name[cy]=Hidlen Allforio LaTeX KFormula +Name[da]=KFormula LaTex-eksportfilter +Name[de]=KFormula LaTeX-Exportfilter +Name[el]=Φίλτρο εξαγωγής LaTeX του KFormula +Name[eo]=LaTeX-eksportfiltrilo por KFormula +Name[es]=Filtro de exportación LaTeX de KFormula +Name[et]=KFormula LaTeX'i ekspordifilter +Name[eu]=KFormula-ren LaTeX esportaziorako iragazkia +Name[fa]=پالایۀ صادرات KFormula LaTeX +Name[fi]=KFormula LaTeX -vientisuodin +Name[fr]=Filtre d'exportation LaTeX de KFormula +Name[fy]=LaTeX-Eksportfilter foar KFormula +Name[ga]=Scagaire Easpórtála LaTeX KFormula +Name[gl]=Filtro de Exportación de LaTeX para KFormula +Name[he]=מסנן ייצוא מ־KFormula ל־LaTeX +Name[hr]=KFormula LaTeX filtar izvoza +Name[hu]=KFormula LaTeX exportszűrő +Name[is]=KFormula LaTeX útflutningssía +Name[it]=Filtro di esportazione LaTeX per KFormula +Name[ja]=KFormula LaTeX エクスポートフィルタ +Name[km]=តម្រងនាំចេញ LaTeX សម្រាប់ KFormula +Name[lo]= ຕົວຕອງການສົ່ງອອກລາເທັກຊ໌ຂອງສູດຄະນິດສາດ์ K +Name[lt]=KFormula LATEX eksporto filtras +Name[lv]=KFormula LaTeX eksporta filtrs +Name[ms]=Penapis Eksport KFormula LaTeX +Name[mt]=Filtru għall-esportazzjoni ta' LaTeX minn ġo KFormula +Name[nb]=LaTeX-eksportfilter for KFormula +Name[nds]=LaTeX-Exportfilter för KFormula +Name[ne]=केडीई सूत्र लाटेक्स निर्यात फिल्टर +Name[nl]=LaTeX-exportfilter voor KFormula +Name[nn]=LaTeX-eksportfilter for KFormula +Name[pl]=Filtr eksportu do formatu LaTeX z KFormula +Name[pt]=Filtro de Exportação de LaTeX para o KFormula +Name[pt_BR]=Filtro de exportação KFormula para o LaTeX +Name[ro]=Filtru exportare KFormula pentru Latex +Name[ru]=Фильтр экспорта формул KFormula в LaTeX +Name[se]=KFormula LaTex-olggosfievrridansilli +Name[sk]=LaTeX filter pre export z KFormula +Name[sl]=Izvozni filter LaTeX za KFormulo +Name[sr]=KFormula-ин филтер за извоз у LaTeX +Name[sr@Latn]=KFormula-in filter za izvoz u LaTeX +Name[sv]=Kformula Latex-exportfilter +Name[ta]=Kformula latex ஏற்றுமதி வடிகட்டி +Name[tg]=KFormula LaTeX Филтри Содирот +Name[th]=ตัวกรองการส่งออกลาเท็กซ์ของสูตรคณิตศาสตร์ K +Name[tr]=KFormula LaTeX Aktarma Filtresi +Name[uk]=Фільтр експорту LaTeX для KFormula +Name[uz]=KFormula LaTeX eksport filteri +Name[uz@cyrillic]=KFormula LaTeX экспорт филтери +Name[xh]=Isihluzi Sokurhweba ngaphandle se KFormula LaTeX +Name[zh_CN]=KFormula LaTeX 导出过滤器 +Name[zh_TW]=KFormula LaTeX 匯出過濾程式 +ServiceTypes=KOfficeFilter +Type=Service +X-KDE-Library=libkfolatexexport diff --git a/filters/kformula/latex/latexexport.cc b/filters/kformula/latex/latexexport.cc new file mode 100644 index 00000000..20cecdcf --- /dev/null +++ b/filters/kformula/latex/latexexport.cc @@ -0,0 +1,96 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Ulrich Kuettler <[email protected]> + + 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 <qstring.h> +#include <qtextstream.h> +#include <qfile.h> + +#include <kapplication.h> +#include <kdebug.h> +#include <kgenericfactory.h> +#include <kmessagebox.h> + +#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" ) ) + + +LATEXExport::LATEXExport( KoFilter */*parent*/, const char */*name*/, const QStringList& ) + : KoFilter() +{ +} + + +KoFilter::ConversionStatus LATEXExport::convert( const QCString& from, const QCString& to ) +{ + if ( to != "text/x-tex" || from != "application/x-kformula" ) + return KoFilter::NotImplemented; + + KoStoreDevice* in = m_chain->storageFile( "root", KoStore::Read ); + if(!in) { + QApplication::restoreOverrideCursor(); + KMessageBox::error( 0, i18n( "Failed to read data." ), i18n( "LaTeX Export Error" ) ); + return KoFilter::StorageCreationError; + } + + QDomDocument dom( "KFORMULA" ); + if ( !dom.setContent( in, false ) ) { + QApplication::restoreOverrideCursor(); + KMessageBox::error( 0, i18n( "Malformed XML data." ), i18n( "LaTeX Export Error" ) ); + return KoFilter::WrongFormat; + } + + QFile f( m_chain->outputFile() ); + if( !f.open( IO_Truncate | IO_ReadWrite ) ) { + QApplication::restoreOverrideCursor(); + 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; + } + + QTextStream stream(&f); + //stream.setEncoding(QTextStream::UnicodeUTF8); + 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" diff --git a/filters/kformula/latex/latexexport.h b/filters/kformula/latex/latexexport.h new file mode 100644 index 00000000..af24003d --- /dev/null +++ b/filters/kformula/latex/latexexport.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Ulrich Kuettler <[email protected]> + + 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 LATEXEXPORT_H +#define LATEXEXPORT_H + +class QCString; +class QStringList; + +#include <KoFilter.h> + +class LATEXExport : public KoFilter +{ + Q_OBJECT +public: + LATEXExport( KoFilter *parent, const char *name, const QStringList& ); + virtual ~LATEXExport() {} + + virtual KoFilter::ConversionStatus convert( const QCString& from, const QCString& to ); +}; + +#endif // LATEXEXPORT_H diff --git a/filters/kformula/mathml/Makefile.am b/filters/kformula/mathml/Makefile.am new file mode 100644 index 00000000..cdd07955 --- /dev/null +++ b/filters/kformula/mathml/Makefile.am @@ -0,0 +1,23 @@ +####### General stuff + +INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(KFORMULA_INCLUDES) $(all_includes) +libkfomathmlexport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +libkfomathmlexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) +libkfomathmlimport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +libkfomathmlimport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) + +####### Files + +kde_module_LTLIBRARIES = libkfomathmlexport.la libkfomathmlimport.la + +libkfomathmlexport_la_SOURCES = mathmlexport.cc + +libkfomathmlimport_la_SOURCES = mathmlimport.cc + +noinst_HEADERS = mathmlexport.h mathmlimport.h + + +METASOURCES = AUTO + +service_DATA = kformula_mathml_export.desktop kformula_mathml_import.desktop +servicedir = $(kde_servicesdir) diff --git a/filters/kformula/mathml/kformula_mathml_export.desktop b/filters/kformula/mathml/kformula_mathml_export.desktop new file mode 100644 index 00000000..1fdc1bf3 --- /dev/null +++ b/filters/kformula/mathml/kformula_mathml_export.desktop @@ -0,0 +1,64 @@ +[Desktop Entry] +X-KDE-Export=application/mathml+xml +ExportDescription=MathML +Icon= +X-KDE-Import=application/x-kformula +X-KDE-Weight=1 +ImportDescription=KFormula +Name=KFormula MathML Export Filter +Name[ar]=مِرْشَح تصدير MathML لدى KFormula +Name[bg]=Филтър за експортиране от KFormula в MathML +Name[br]=Sil ezporzh MathML evit KFormula +Name[ca]=Filtre d'exportació MathML per a KFormula +Name[cs]=Exportní filtr formátu MathML pro KFormula +Name[cy]=Hidlen Allforio MathML KFormula +Name[da]=KFormula MathML-eksportfilter +Name[de]=KFormula MathML-Exportfilter +Name[el]=Φίλτρο εξαγωγής MathML του KFormula +Name[eo]=MathML-eksportfiltrilo por KFormula +Name[es]=Filtro de exportación a MathML de KFormula +Name[et]=KFormula MathML'i ekspordifilter +Name[eu]=KFormula-ren MathML esportaziorako iragazkia +Name[fa]=پالایۀ صادرات KFormula MathML +Name[fi]=KFormula MathML -vientisuodin +Name[fr]=Filtre d'exportation MathML de KFormula +Name[fy]=MathML-Eksportfilter foar KFormula +Name[ga]=Scagaire Easpórtála MathML KFormula +Name[gl]=Filtro de Exportación de MathML para KFormula +Name[he]=מסנן ייצוא מ־KFormula ל־MathML +Name[hi]=के-फ़ॉर्मूला मैथएमएल निर्यात फ़िल्टर +Name[hr]=KFormula MathML filtar izvoza +Name[hu]=KFormula MathML exportszűrő +Name[is]=KFormula MathML útflutningssía +Name[it]=Filtro di esportazione MathML per KFormula +Name[ja]=KFormula MathML エクスポートフィルタ +Name[km]=តម្រងនាំចេញ MathML សម្រាប់ KFormula +Name[lt]=KFormula MathML eksportavimo filtras +Name[lv]=KFormula MathML eksporta filtrs +Name[ms]=Penapis Eksport KFormula MathML +Name[nb]=MathML-eksportfilter for KFormula +Name[nds]=MathML-Exportfilter för KFormula +Name[ne]=केडीई सूत्र हिसाबएमएल निर्यात फिल्टर +Name[nl]=MathML-exportfilter voor KFormula +Name[nn]=MathML-eksportfilter for KFormula +Name[pl]=Filtr eksportu do formatu MathML z KFormula +Name[pt]=Filtro de Exportação de MathML para o KFormula +Name[pt_BR]=Filtro de Exportação KFormula para o MathML +Name[ru]=Фильтр экспорта формул KFormula в MathML +Name[se]=KFormula MathML-olggosfievrridansilli +Name[sk]=MathML filter pre export z KFormula +Name[sl]=Izvozni filter MathML za KFormulo +Name[sr]=KFormula-ин филтер за извоз у MathML +Name[sr@Latn]=KFormula-in filter za izvoz u MathML +Name[sv]=Kformula MathML-exportfilter +Name[ta]=Kformula mathml ஏற்றுமதி வடிகட்டி +Name[tg]=KFormula MathML Филтри Содирот +Name[tr]=KFormula MathML Aktarma Filtresi +Name[uk]=Фільтр експорту MathML для KFormula +Name[uz]=KFormula MathML eksport filteri +Name[uz@cyrillic]=KFormula MathML экспорт филтери +Name[zh_CN]=KFormula MathML 导出过滤器 +Name[zh_TW]=KFormula MathML 匯出過濾程式 +ServiceTypes=KOfficeFilter +Type=Service +X-KDE-Library=libkfomathmlexport diff --git a/filters/kformula/mathml/kformula_mathml_import.desktop b/filters/kformula/mathml/kformula_mathml_import.desktop new file mode 100644 index 00000000..a6828cb4 --- /dev/null +++ b/filters/kformula/mathml/kformula_mathml_import.desktop @@ -0,0 +1,64 @@ +[Desktop Entry] +X-KDE-Export=application/x-kformula +ExportDescription=KFormula +Icon= +X-KDE-Import=application/mathml+xml +X-KDE-Weight=1 +ImportDescription=MathM +Name=KFormula MathML Import Filter +Name[ar]=مِرْشَح استيراد MathML لدى KFormula +Name[bg]=Филтър за импортиране от MathML в KFormula +Name[br]=Sil enporzh MathML evit KFormula +Name[ca]=Filtre d'importació MathML per a KFormula +Name[cs]=Importní filtr formátu MathML pro KFormula +Name[cy]=Hidlen Fewnforio MathML KFormula +Name[da]=KFormula MathML-importfilter +Name[de]=KFormula MathML-Importfilter +Name[el]=Φίλτρο εισαγωγής MathML του KFormula +Name[eo]=MathML-importfiltrilo por KFormula +Name[es]=Filtro de importación a MathML de KFormula +Name[et]=KFormula MathML'i impordifilter +Name[eu]=KFormula-ren MathML inportaziorako iragazkia +Name[fa]=پالایۀ واردات KFormula MathML +Name[fi]=KFormula MathML -tuontisuodin +Name[fr]=Filtre d'importation MathML de KFormula +Name[fy]=MathML Ymportfilter foar KFormula +Name[ga]=Scagaire Iompórtála MathML KFormula +Name[gl]=Filtro de Importación de MathML para KFormula +Name[he]=מסנן ייבוא מ־MathML ל־KFormula +Name[hi]=के-फ़ॉर्मूला मैथएमएल आयात फ़िल्टर +Name[hr]=KFormula MathML filtar uvoza +Name[hu]=KFormula MathML importszűrő +Name[is]=KFormula MathML innflutningssía +Name[it]=Filtro di importazione MathML per KFormula +Name[ja]=KFormula MathML インポートフィルタ +Name[km]=តម្រងនាំចូល MathML សម្រាប់ KFormula +Name[lt]=KFormula MathML importavimo filtras +Name[lv]=KFormula MathML importa filtrs +Name[ms]=Penapis Import KFormula MathML +Name[nb]=MathML-importfilter for KFormula +Name[nds]=MathML-Importfilter för KFormula +Name[ne]=केडीई सूत्र हिसाबएमएल आयात फिल्टर +Name[nl]=MathML-importfilter voor KFormula +Name[nn]=MathML-importfilter for KFormula +Name[pl]=Filtr importu formatu MathML do KFormula +Name[pt]=Filtro de Importação de MathML para o KFormula +Name[pt_BR]=Filtro de Importação MathML para o KFormula +Name[ru]=Фильтр импорта формул MathML в KFormula +Name[se]=KFormula MathML-sisafievrridansilli +Name[sk]=MathML filter pre import do KFormula +Name[sl]=Uvozni filter MathML za KWord +Name[sr]=KFormula-ин филтер за увоз из MathML-а +Name[sr@Latn]=KFormula-in filter za uvoz iz MathML-a +Name[sv]=Kformula MathML-importfilter +Name[ta]=Kformula mathml இறக்குமதி வடிகட்டி +Name[tg]=KFormula MathML Филтри Воридот +Name[tr]=KFormula MathML Alma Filtresi +Name[uk]=Фільтр імпорту MathML для KFormula +Name[uz]=KFormula MathML import filteri +Name[uz@cyrillic]=KFormula MathML импорт филтери +Name[zh_CN]=KFormula MathML 导入过滤器 +Name[zh_TW]=KFormula MathML 匯入過濾程式 +ServiceTypes=KOfficeFilter +Type=Service +X-KDE-Library=libkfomathmlimport diff --git a/filters/kformula/mathml/mathmlexport.cc b/filters/kformula/mathml/mathmlexport.cc new file mode 100644 index 00000000..cbf8489e --- /dev/null +++ b/filters/kformula/mathml/mathmlexport.cc @@ -0,0 +1,94 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Ulrich Kuettler <[email protected]> + + 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 <qstring.h> +#include <qtextstream.h> +#include <qfile.h> + +#include <kapplication.h> +#include <kdebug.h> +#include <kgenericfactory.h> +#include <kmessagebox.h> + +#include <KoFilterChain.h> +#include <KoStoreDevice.h> + +#include <kformuladocument.h> +#include <kformulacontainer.h> +#include <kformulamimesource.h> + +#include "mathmlexport.h" + + +typedef KGenericFactory<MathMLExport, KoFilter> MathMLExportFactory; +K_EXPORT_COMPONENT_FACTORY( libkfomathmlexport, MathMLExportFactory( "kofficefilters" ) ) + + +MathMLExport::MathMLExport( KoFilter */*parent*/, const char */*name*/, const QStringList& ) + : KoFilter() +{ +} + + +KoFilter::ConversionStatus MathMLExport::convert( const QCString& from, const QCString& to ) +{ + if ( to != "application/mathml+xml" || from != "application/x-kformula" ) + return KoFilter::NotImplemented; + + KoStoreDevice* in = m_chain->storageFile( "root", KoStore::Read ); + if(!in) { + QApplication::restoreOverrideCursor(); + KMessageBox::error( 0, i18n( "Failed to read data." ), i18n( "MathML Export Error" ) ); + return KoFilter::StorageCreationError; + } + + QDomDocument dom; + if ( !dom.setContent( in, false ) ) { + QApplication::restoreOverrideCursor(); + KMessageBox::error( 0, i18n( "Malformed XML data." ), i18n( "MathML Export Error" ) ); + return KoFilter::WrongFormat; + } + + QFile f( m_chain->outputFile() ); + if( !f.open( IO_Truncate | IO_ReadWrite ) ) { + QApplication::restoreOverrideCursor(); + KMessageBox::error( 0, i18n( "Failed to write file." ), i18n( "MathML 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() << "Failed." << endl; + } + + QTextStream stream(&f); + stream.setEncoding( QTextStream::UnicodeUTF8 ); + formula->saveMathML( stream ); + f.close(); + + delete formula; + delete wrapper; + + return KoFilter::OK; +} + +#include "mathmlexport.moc" diff --git a/filters/kformula/mathml/mathmlexport.h b/filters/kformula/mathml/mathmlexport.h new file mode 100644 index 00000000..0e15b7a0 --- /dev/null +++ b/filters/kformula/mathml/mathmlexport.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Ulrich Kuettler <[email protected]> + + 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 MATHMLEXPORT_H +#define MATHMLEXPORT_H + +class QCString; +class QStringList; + +#include <KoFilter.h> + +class MathMLExport : public KoFilter +{ + Q_OBJECT +public: + MathMLExport( KoFilter *parent, const char *name, const QStringList& ); + virtual ~MathMLExport() {} + + virtual KoFilter::ConversionStatus convert( const QCString& from, const QCString& to ); +}; + +#endif // MATHMLEXPORT_H diff --git a/filters/kformula/mathml/mathmlimport.cc b/filters/kformula/mathml/mathmlimport.cc new file mode 100644 index 00000000..9ede69ce --- /dev/null +++ b/filters/kformula/mathml/mathmlimport.cc @@ -0,0 +1,111 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Ulrich Kuettler <[email protected]> + + 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 <kapplication.h> +#include <kdebug.h> +#include <kgenericfactory.h> +#include <kglobal.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <KoFilterChain.h> + +#include <qtextcodec.h> + +#include <kformuladocument.h> +#include <kformulacontainer.h> +#include <kformulamimesource.h> + +#include "mathmlimport.h" +#include "mathmlimport.moc" + + +typedef KGenericFactory<MathMLImport, KoFilter> MathMLImportFactory; +K_EXPORT_COMPONENT_FACTORY( libkfomathmlimport, MathMLImportFactory( "kofficefilters" ) ) + + +MathMLImport::MathMLImport(KoFilter *, const char *, const QStringList&) + : KoFilter() +{ +} + +KoFilter::ConversionStatus MathMLImport::convert( const QCString& from, const QCString& to ) +{ + kdDebug( KFormula::DEBUGID ) << "From: " << from << endl; + kdDebug( KFormula::DEBUGID ) << "To: " << to << endl; + + if(from != "application/mathml+xml" || to != "application/x-kformula") + return KoFilter::NotImplemented; + + KoStore* out = KoStore::createStore(QString(m_chain->outputFile()), KoStore::Write); + if(!out || !out->open("root")) { + KMessageBox::error( 0, i18n( "Unable to open output file." ), i18n( "MathML Import Error" ) ); + delete out; + 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(); + + //formula->loadMathML( m_chain->inputFile() ); + const QString filename( m_chain->inputFile() ); + QFile f( filename ); + if ( !f.open( IO_ReadOnly ) ) { + KMessageBox::error( 0, i18n( "Failed to open input file: %1" ).arg( filename ), i18n( "MathML Import Error" ) ); + delete wrapper; + return KoFilter::FileNotFound; + } + + QDomDocument mathML; + // Error variables for QDomDocument::setContent + QString errorMsg; + int errorLine, errorColumn; + if ( !mathML.setContent( &f, true, &errorMsg, &errorLine, &errorColumn ) ) { + delete wrapper; + QApplication::restoreOverrideCursor(); + kdError(KFormula::DEBUGID) << "Parsing error in " << filename << "! Aborting!" << endl + << " In line: " << errorLine << ", column: " << errorColumn << endl + << " Error message: " << errorMsg << endl; + KMessageBox::error( 0, i18n( "Parsing error in MathML file %4 at line %1, column %2\nError message: %3" ) + .arg( errorLine ).arg( errorColumn ).arg( i18n ( "QXml", errorMsg.utf8() ).arg( filename ) ), i18n( "MathML Import Error" ) ); + return KoFilter::WrongFormat; + } + f.close(); + if ( !formula->loadMathML( mathML ) ) { + delete wrapper; + return KoFilter::StupidError; + } + + // taken from KoDocument::saveToStore + KoStoreDevice dev( out ); + const QCString s = doc->saveXML().toCString(); // utf8 already + const int nwritten = dev.writeBlock( s.data(), s.size()-1 ); + if ( nwritten != (int)s.size()-1 ) { + kdWarning() << "wrote " << nwritten << " - expected " << s.size()-1 << endl; + KMessageBox::error( 0, i18n( "Failed to write formula." ), i18n( "MathML Import Error" ) ); + } + + out->close(); + delete out; + + delete wrapper; + return KoFilter::OK; +} + diff --git a/filters/kformula/mathml/mathmlimport.h b/filters/kformula/mathml/mathmlimport.h new file mode 100644 index 00000000..79f6c052 --- /dev/null +++ b/filters/kformula/mathml/mathmlimport.h @@ -0,0 +1,42 @@ +/* This file is part of the KDE project + Copyright (C) 2003 Ulrich Kuettler <[email protected]> + + 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 MATHMLIMPORT_H +#define MATHMLIMPORT_H + +#include <qstring.h> +#include <qtextstream.h> +#include <qfile.h> +#include <qobject.h> + +#include <KoFilter.h> +#include <KoStore.h> + +class MathMLImport : public KoFilter +{ + Q_OBJECT +public: + MathMLImport(KoFilter *parent, const char *name, const QStringList&); + virtual ~MathMLImport() {} + + virtual KoFilter::ConversionStatus convert( const QCString& from, const QCString& to ); +}; + +#endif /* MATHMLIMPORT_H */ + diff --git a/filters/kformula/png/Makefile.am b/filters/kformula/png/Makefile.am new file mode 100644 index 00000000..8b405c39 --- /dev/null +++ b/filters/kformula/png/Makefile.am @@ -0,0 +1,25 @@ +####### General stuff + +INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(KFORMULA_INCLUDES) $(all_includes) +libkfopngexport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +libkfopngexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) + +####### Files + +kde_module_LTLIBRARIES = libkfopngexport.la + +libkfopngexport_la_SOURCES = pngexport.cc pngexportdia.cc + +noinst_HEADERS = pngexport.h pngexportdia.h + +######## Debug +#check_PROGRAMS = texlauncher +#texlauncher_SOURCES = texlauncher.cc +#texlauncher_LDADD = liblatexexport.la +#texlauncher_LDFLAGS = $(KDE_RPATH) $(all_libraries) + + +METASOURCES = AUTO + +service_DATA = kformula_png_export.desktop +servicedir = $(kde_servicesdir) diff --git a/filters/kformula/png/kformula_png_export.desktop b/filters/kformula/png/kformula_png_export.desktop new file mode 100644 index 00000000..0ea0856f --- /dev/null +++ b/filters/kformula/png/kformula_png_export.desktop @@ -0,0 +1,70 @@ +[Desktop Entry] +X-KDE-Export=image/png +ExportDescription=PNG +Icon= +X-KDE-Import=application/x-kformula +X-KDE-Weight=1 +ImportDescription=KFormula +Name=KFormula PNG Export Filter +Name[af]=Kformula Png Voer uit Filter +Name[ar]=مِرْشَح تصدير PNG لدى KFormula +Name[bg]=Филтър за експортиране от KFormula в PNG +Name[br]=Sil ezporzh PNG evit KFormula +Name[ca]=Filtre d'exportació PNG per a KFormula +Name[cs]=Exportní filtr formátu PNG pro KFormula +Name[cy]=Hidlen Allforio PNG KFormula +Name[da]=KFormula PNG-eksportfilter +Name[de]=KFormula PNG-Exportfilter +Name[el]=Φίλτρο εξαγωγής PNG του KFormula +Name[eo]=PNG-eksportfiltrilo por KFormula +Name[es]=Filtro de exportación PNG de KFormula +Name[et]=KFormula PNG ekspordifilter +Name[eu]=KFormula-ren PNG esportaziorako iragazkia +Name[fa]=پالایۀ صادرات KFormula PNG +Name[fi]=KFormula PNG -vientisuodin +Name[fr]=Filtre d'exportation PNG de KFormula +Name[fy]=PNG Eksportfilter foar KFormula +Name[ga]=Scagaire Easpórtála PNG KFormula +Name[gl]=Filtro de Exportación de PNG para KFormula +Name[he]=מסנן ייצוא מ־KFormula ל־PNG +Name[hi]=के-फ़ॉर्मूला पीएनजी निर्यात फ़िल्टर +Name[hr]=KFormula PNG filtar izvoza +Name[hu]=KFormula PNG exportszűrő +Name[is]=KFormula PNG útflutningssía +Name[it]=Filtro di esportazione PNG per KFormula +Name[ja]=KFormula PNG エクスポートフィルタ +Name[km]=តម្រងនាំចេញ PNG សម្រាប់ KFormula +Name[lo]=ຕົວຕອງການສົ່ງອອກ PNG ຂອງສູດຄະນິດສາດ K +Name[lt]=KFormula PNG eksporto filtras +Name[lv]=KFormula PNG eksporta filtrs +Name[ms]=Penapis Eksport KFormula PNG +Name[mt]=Filtru għall-esportazzjoni ta' PNG minn KFormula +Name[nb]=PNG-eksportfilter for KFormula +Name[nds]=PNG-Exportfilter för KFormula +Name[ne]=केडीई सूत्र पीएनजी निर्यात फिल्टर +Name[nl]=PNG-exportfilter voor KFormula +Name[nn]=PNG-eksportfilter for KFormula +Name[pl]=Filtr eksportu do formatu PNG z KFormula +Name[pt]=Filtro de Exportação de PNG para o KFormula +Name[pt_BR]=Filtro de exportação KFormula PNG +Name[ro]=Filtru exportare KFormula pentru PNG +Name[ru]=Фильтр экспорта формул KFormula в PNG +Name[se]=KFormula PNG-olggosfievrridansilli +Name[sk]=PNG filter pre export z KFormula +Name[sl]=Izvozni filter PNG za KFormulo +Name[sr]=KFormula-ин филтер за извоз у PNG +Name[sr@Latn]=KFormula-in filter za izvoz u PNG +Name[sv]=Kformula PNG-exportfilter +Name[ta]=Kformula png ஏற்றுமதி வடிகட்டி +Name[tg]=KFormula PNG Филтри Содирот +Name[th]=ตัวกรองการส่งออก PNG ของสูตรคณิตศาสตร์ K +Name[tr]=KFormula PNG Aktarma Filtresi +Name[uk]=Фільтр експорту PNG для KFormula +Name[uz]=KFormula PNG eksport filteri +Name[uz@cyrillic]=KFormula PNG экспорт филтери +Name[xh]=Isihluzi Sokurhweba ngaphandle se KFormula PNG +Name[zh_CN]=KFormula PNG 导出过滤器 +Name[zh_TW]=KFormula PNG 匯出過濾程式 +ServiceTypes=KOfficeFilter +Type=Service +X-KDE-Library=libkfopngexport diff --git a/filters/kformula/png/pngexport.cc b/filters/kformula/png/pngexport.cc new file mode 100644 index 00000000..f51bc1f1 --- /dev/null +++ b/filters/kformula/png/pngexport.cc @@ -0,0 +1,74 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Ulrich Kuettler <[email protected]> + + 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 <qstring.h> +#include <qtextstream.h> +#include <qfile.h> +#include <qobject.h> + +#include <kapplication.h> +#include <kdebug.h> +#include <kgenericfactory.h> +#include <kmessagebox.h> + +#include <KoFilterChain.h> +#include <KoStore.h> +#include <KoStoreDevice.h> + + +#include "pngexport.h" +#include "pngexportdia.h" + + +typedef KGenericFactory<PNGExport, KoFilter> PNGExportFactory; +K_EXPORT_COMPONENT_FACTORY( libkfopngexport, PNGExportFactory( "kofficefilters" ) ) + + +PNGExport::PNGExport( KoFilter */*parent*/, const char */*name*/, const QStringList& ) + : KoFilter() +{ +} + + +KoFilter::ConversionStatus PNGExport::convert( const QCString& from, const QCString& to ) +{ + if ( to != "image/png" || from != "application/x-kformula" ) + return KoFilter::NotImplemented; + + KoStoreDevice* in = m_chain->storageFile( "root", KoStore::Read ); + if(!in) { + kapp->restoreOverrideCursor(); + KMessageBox::error( 0, i18n( "Failed to read data." ), i18n( "PNG Export Error" ) ); + return KoFilter::FileNotFound; + } + + QDomDocument dom( "KFORMULA" ); + if ( !dom.setContent( in, false ) ) { + kapp->restoreOverrideCursor(); + KMessageBox::error( 0, i18n( "Malformed XML data." ), i18n( "PNG Export Error" ) ); + return KoFilter::WrongFormat; + } + + PNGExportDia* dialog = new PNGExportDia( dom, m_chain->outputFile() ); + dialog->exec(); + delete dialog; + return KoFilter::OK; +} + +#include "pngexport.moc" diff --git a/filters/kformula/png/pngexport.h b/filters/kformula/png/pngexport.h new file mode 100644 index 00000000..b9425439 --- /dev/null +++ b/filters/kformula/png/pngexport.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Ulrich Kuettler <[email protected]> + + 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 PNGEXPORT_H +#define PNGEXPORT_H + +class QCString; +class QStringList; + +#include <KoFilter.h> + +class PNGExport : public KoFilter +{ + Q_OBJECT +public: + PNGExport( KoFilter *parent, const char *name, const QStringList& ); + virtual ~PNGExport() {} + + virtual KoFilter::ConversionStatus convert( const QCString& from, const QCString& to ); +}; + +#endif // PNGEXPORT_H diff --git a/filters/kformula/png/pngexportdia.cc b/filters/kformula/png/pngexportdia.cc new file mode 100644 index 00000000..8de33b75 --- /dev/null +++ b/filters/kformula/png/pngexportdia.cc @@ -0,0 +1,242 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Ulrich Kuettler <[email protected]> + + 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 <qcheckbox.h> +#include <qimage.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qpaintdevice.h> +#include <qrect.h> +#include <qvbuttongroup.h> +#include <qwidget.h> + +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kmessagebox.h> + +#include <kformulacontainer.h> +#include <kformuladocument.h> +#include <kformulamimesource.h> + +#include "pngexportdia.h" +#include <knuminput.h> + +PNGExportDia::PNGExportDia( const QDomDocument &dom, const QString &outFile, QWidget *parent, const char *name ) + : KDialogBase( parent, name, true, i18n("PNG Export Filter Parameters" ), Ok|Cancel ), + _fileOut( outFile ) +{ + kapp->restoreOverrideCursor(); + wrapper = new KFormula::DocumentWrapper( kapp->config(), 0 ); + KFormula::Document* doc = new KFormula::Document; + wrapper->document( doc ); + formula = doc->createFormula(); + if ( !doc->loadXML( dom ) ) { + kdError() << "Failed." << endl; + } + + setupGUI(); + + QRect rect = formula->boundingRect(); + realWidth = rect.width(); + realHeight = rect.height(); + widthEdit->setValue( realWidth ); + heightEdit->setValue( realHeight ); + percWidthEdit->setValue( 100 ); + percHeightEdit->setValue( 100 ); + + connectAll(); + connect( proportional, SIGNAL( clicked() ), + this, SLOT( proportionalClicked() ) ); +} + +PNGExportDia::~PNGExportDia() +{ + delete wrapper; +} + +void PNGExportDia::connectAll() +{ + connect( widthEdit, SIGNAL( valueChanged(int) ), + this, SLOT( widthChanged( int ) ) ); + connect( heightEdit, SIGNAL( valueChanged(int) ), + this, SLOT( heightChanged( int ) ) ); + connect( percWidthEdit, SIGNAL( valueChanged(double) ), + this, SLOT( percentWidthChanged( double ) ) ); + connect( percHeightEdit, SIGNAL( valueChanged(double) ), + this, SLOT( percentHeightChanged(double ) ) ); +} + +void PNGExportDia::disconnectAll() +{ + disconnect( widthEdit, SIGNAL( valueChanged(int) ), + this, SLOT( widthChanged( int ) ) ); + disconnect( heightEdit, SIGNAL( valueChanged(int) ), + this, SLOT( heightChanged( int ) ) ); + disconnect( percWidthEdit, SIGNAL( valueChanged(double) ), + this, SLOT( percentWidthChanged( double ) ) ); + disconnect( percHeightEdit, SIGNAL( valueChanged(double) ), + this, SLOT( percentHeightChanged(double ) ) ); +} + +void PNGExportDia::widthChanged( int width ) +{ + disconnectAll(); + width = QMIN( width, realWidth*10 ); + width = QMAX( width, realWidth/10 ); + double percent = 100.*static_cast<double>( width )/static_cast<double>( realWidth ); + percWidthEdit->setValue( percent ); + if ( proportional->isChecked() ) { + percHeightEdit->setValue( percent ); + int height = static_cast<int>( realHeight*percent/100. ); + heightEdit->setValue( height ); + } + connectAll(); +} + +void PNGExportDia::heightChanged( int height ) +{ + disconnectAll(); + height = QMIN( height, realHeight*10 ); + height = QMAX( height, realHeight/10 ); + double percent = 100.*static_cast<double>( height )/static_cast<double>( realHeight ); + percHeightEdit->setValue( percent ); + if ( proportional->isChecked() ) { + percWidthEdit->setValue( percent ); + int width = static_cast<int>( realWidth*percent/100. ); + widthEdit->setValue( width ); + } + connectAll(); +} + +void PNGExportDia::percentWidthChanged( double percent ) +{ + disconnectAll(); + percent = QMIN( percent, 1000 ); + percent = QMAX( percent, 10 ); + int width = static_cast<int>( realWidth*percent/100. ); + widthEdit->setValue( width ); + if ( proportional->isChecked() ) { + int height = static_cast<int>( realHeight*percent/100. ); + heightEdit->setValue( height ); + percHeightEdit->setValue( percent ); + } + connectAll(); +} + +void PNGExportDia::percentHeightChanged( double percent ) +{ + disconnectAll(); + percent = QMIN( percent, 1000 ); + percent = QMAX( percent, 10 ); + if ( proportional->isChecked() ) { + int width = static_cast<int>( realWidth*percent/100. ); + widthEdit->setValue( width ); + percWidthEdit->setValue( percent ); + } + int height = static_cast<int>( realHeight*percent/100. ); + heightEdit->setValue( height ); + connectAll(); +} + +void PNGExportDia::proportionalClicked() +{ + if ( proportional->isChecked() ) { + disconnectAll(); + int width = widthEdit->value( ); + width = QMIN( width, realWidth*10 ); + width = QMAX( width, realWidth/10 ); + double percent = 100.*static_cast<double>( width )/static_cast<double>( realWidth ); + percHeightEdit->setValue( percent ); + int height = static_cast<int>( realHeight*percent/100. ); + heightEdit->setValue( height ); + connectAll(); + } +} + +void PNGExportDia::setupGUI() +{ + QWidget *page = new QWidget( this ); + setMainWidget(page); + + QBoxLayout* mainLayout = new QVBoxLayout( page, KDialog::marginHint(), KDialog::spacingHint() ); + + proportional = new QCheckBox( page, "proportional" ); + proportional->setText( i18n( "Keep ratio" ) ); + proportional->setChecked( true ); + mainLayout->addWidget( proportional ); + + QLabel* height = new QLabel( page, "Height" ); + height->setText( i18n( "Height" ) ); + widthEdit = new KIntNumInput( page, "widthEdit" ); + QLabel* width = new QLabel( page, "Width" ); + width->setText( i18n( "Width" ) ); + heightEdit = new KIntNumInput( page, "heightEdit" ); + + QGridLayout* layout1 = new QGridLayout; + layout1->addWidget( height, 1, 0 ); + layout1->addWidget( widthEdit, 0, 1 ); + layout1->addWidget( width, 0, 0 ); + layout1->addWidget( heightEdit, 1, 1 ); + + mainLayout->addLayout( layout1 ); + + QLabel* percentHeight = new QLabel( page, "PercentHeight" ); + percentHeight->setText( i18n( "Height (%)" ) ); + QLabel* percentWidth = new QLabel( page, "PercentWidth" ); + percentWidth->setText( i18n( "Width (%)" ) ); + percWidthEdit = new KDoubleNumInput( page, "percWidthEdit" ); + percHeightEdit = new KDoubleNumInput( page, "percHeightEdit" ); + + QGridLayout* layout2 = new QGridLayout; + layout2->addWidget( percWidthEdit, 0, 1 ); + layout2->addWidget( percHeightEdit, 1, 1 ); + layout2->addWidget( percentHeight, 1, 0 ); + layout2->addWidget( percentWidth, 0, 0 ); + + mainLayout->addLayout( layout2 ); + + /* Display the main layout */ + mainLayout->addStretch( 5 ); + mainLayout->activate(); +} + + +void PNGExportDia::slotOk() +{ + hide(); + //doc->setZoomAndResolution( 100, 600, 600 ); + //doc->setZoomAndResolution( 1000, QPaintDevice::x11AppDpiX(), QPaintDevice::x11AppDpiY() ); + //doc->newZoomAndResolution( false, false ); + int width = widthEdit->value(); + int height = heightEdit->value(); +// kdDebug( KFormula::DEBUGID ) << k_funcinfo +// << "(" << width << " " << height << ")" +// << endl; +// width = realWidth; +// height = realHeight; + QImage image = formula->drawImage( width, height ); + if ( !image.save( _fileOut, "PNG" ) ) { + KMessageBox::error( 0, i18n( "Failed to write file." ), i18n( "PNG Export Error" ) ); + } + reject(); +} + +#include "pngexportdia.moc" diff --git a/filters/kformula/png/pngexportdia.h b/filters/kformula/png/pngexportdia.h new file mode 100644 index 00000000..3957ef88 --- /dev/null +++ b/filters/kformula/png/pngexportdia.h @@ -0,0 +1,81 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Ulrich Kuettler <[email protected]> + + 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 PNGEXPORTDIA_H +#define PNGEXPORTDIA_H + +class QCheckBox; +class QString; +class KIntNumInput; +class KDoubleNumInput; + +namespace KFormula { + class Container; + class DocumentWrapper; +} + +#include <qdom.h> + +#include <kdialogbase.h> + + +class PNGExportDia : public KDialogBase +{ + Q_OBJECT + +public: + PNGExportDia( const QDomDocument &dom, const QString &outFile, QWidget *parent=0L, const char *name=0L ); + ~PNGExportDia(); + +public slots: + void slotOk(); + +protected slots: + + void widthChanged( int ); + void heightChanged( int ); + void percentWidthChanged( double ); + void percentHeightChanged( double ); + + void proportionalClicked(); + +private: + + void connectAll(); + void disconnectAll(); + + void setupGUI(); + + int realWidth; + int realHeight; + + QString _fileOut; + QByteArray _arrayOut; + + KFormula::Container* formula; + KFormula::DocumentWrapper* wrapper; + + QCheckBox* proportional; + KIntNumInput* widthEdit; + KIntNumInput* heightEdit; + KDoubleNumInput* percWidthEdit; + KDoubleNumInput* percHeightEdit; +}; + +#endif // PNGEXPORTDIA_H diff --git a/filters/kformula/svg/Makefile.am b/filters/kformula/svg/Makefile.am new file mode 100644 index 00000000..a369e7f0 --- /dev/null +++ b/filters/kformula/svg/Makefile.am @@ -0,0 +1,25 @@ +####### General stuff + +INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(KFORMULA_INCLUDES) $(all_includes) +libkfosvgexport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +libkfosvgexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) + +####### Files + +kde_module_LTLIBRARIES = libkfosvgexport.la + +libkfosvgexport_la_SOURCES = svgexport.cc + +noinst_HEADERS = svgexport.h + +######## Debug +#check_PROGRAMS = texlauncher +#texlauncher_SOURCES = texlauncher.cc +#texlauncher_LDADD = liblatexexport.la +#texlauncher_LDFLAGS = $(KDE_RPATH) $(all_libraries) + + +METASOURCES = AUTO + +service_DATA = kformula_svg_export.desktop +servicedir = $(kde_servicesdir) diff --git a/filters/kformula/svg/kformula_svg_export.desktop b/filters/kformula/svg/kformula_svg_export.desktop new file mode 100644 index 00000000..5b7a8d12 --- /dev/null +++ b/filters/kformula/svg/kformula_svg_export.desktop @@ -0,0 +1,56 @@ +[Desktop Entry] +X-KDE-Export=image/svg+xml +ExportDescription=SVG +Icon= +X-KDE-Import=application/x-kformula +X-KDE-Weight=1 +ImportDescription=KFormula +Name=KFormula SVG Export Filter +Name[ar]=مرشح تصدير SVG لدى KFormula +Name[bg]=Филтър за експортиране от KFormula в SVG +Name[br]=Sil ezporzh SVG evit KFormula +Name[ca]=Filtre d'exportació SVG per a KFormula +Name[cy]=Hidlen Allforio SVG KFormula +Name[da]=KFormula SVG-eksportfilter +Name[de]=KFormula SVG-Exportfilter +Name[el]=Φίλτρο εξαγωγής SVG του KFormula +Name[eo]=SVG-eksportfiltrilo por KFormula +Name[es]=Filtro de exportación a SVG de KFormula +Name[et]=KFormula SVG ekspordifilter +Name[fa]=پالایۀ صادرات KFormula SVG +Name[fi]=KFormula SVG -vientisuodin +Name[fr]=Filtre d'exportation SVG de KFormula +Name[fy]=SVG-Eksportfilter foar KFormula +Name[ga]=Scagaire Easpórtála SVG KFormula +Name[gl]=Filtro de Exportación de SVG para KFormula +Name[he]=KFormula SVG מסנן יצוא +Name[hr]=KFormula SVG filtar izvoza +Name[hu]=KFormula SVG exportszűrő +Name[is]=KFormula SVG útflutningssía +Name[it]=Filtro di esportazione SVG per KFormula +Name[ja]=KFormula SVG エクスポートフィルタ +Name[km]=តម្រងនាំចេញ SVG សម្រាប់ KFormula +Name[lt]=KFormula SVG eksportavimo filtras +Name[lv]=KFormula SVG eksporta filtrs +Name[nb]=SVG-eksportfilter for KFormula +Name[nds]=SVG-Exportfilter för KFormula +Name[ne]=केडीई सूत्र एसभीजी निर्यात फिल्टर +Name[nl]=SVG-exportfilter voor KFormula +Name[pl]=Filtr eksportu do formatu SVG z KFormula +Name[pt]=Filtro de Exportação de SVG para o KFormula +Name[pt_BR]=Filtro de Exportação de SVG para o KFormula +Name[ru]=Фильтр экспорта формул KFormula в SVG +Name[se]=KFormula SVG-olggosfievrridansilli +Name[sk]=Exportný filter KFormula SVG +Name[sl]=Izvozni filter SVG za KFormulo +Name[sr]=KFormula-ин филтер за извоз у SVG +Name[sr@Latn]=KFormula-in filter za izvoz u SVG +Name[sv]=Kformula SVG-exportfilter +Name[uk]=Фільтр експорту SVG для KFormula +Name[uz]=KFormula SVG eksport filteri +Name[uz@cyrillic]=KFormula SVG экспорт филтери +Name[zh_CN]=KFormula SVG 导出过滤器 +Name[zh_TW]=KFormula SVG 匯出過濾程式 +ServiceTypes=KOfficeFilter +Type=Service +X-KDE-Library=libkfosvgexport diff --git a/filters/kformula/svg/svgexport.cc b/filters/kformula/svg/svgexport.cc new file mode 100644 index 00000000..46177a9a --- /dev/null +++ b/filters/kformula/svg/svgexport.cc @@ -0,0 +1,102 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Inge Wallin <[email protected]> + Copyright (C) 2005 Fredrik Edemar <[email protected]> + + 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 <qpicture.h> +#include <qpainter.h> + +#include <kapplication.h> +#include <kmessagebox.h> + +#include <KoFilterChain.h> +#include <KoStore.h> +//#include <KoStoreDevice.h> +#include <kgenericfactory.h> + +#include <kformulacontainer.h> +#include "kformuladocument.h" + +#include "svgexport.h" + + +typedef KGenericFactory<SvgExport, KoFilter> SvgExportFactory; +K_EXPORT_COMPONENT_FACTORY( libkfosvgexport, SvgExportFactory( "svgexport" ) ) + +SvgExport::SvgExport(KoFilter *, const char *, const QStringList&) + : KoFilter() +{ +} + +SvgExport::~SvgExport() +{ +} + + +KoFilter::ConversionStatus +SvgExport::convert(const QCString& from, const QCString& to) +{ + // Check for proper conversion. + if ( from != "application/x-kformula" || to != "image/svg+xml" ) + return KoFilter::NotImplemented; + + // Read the contents of the KFormula file + KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read ); + if ( !storeIn ) { + KMessageBox::error( 0, i18n("Failed to read data." ), + i18n( "SVG Export Error" ) ); + return KoFilter::FileNotFound; + } + + // Get the XML tree. + QDomDocument domIn; + domIn.setContent( storeIn ); + QDomElement docNode = domIn.documentElement(); + + // Read the document from the XML tree. + KFormula::DocumentWrapper* wrapper = new KFormula::DocumentWrapper( kapp->config(), 0 ); + KFormula::Document* kformulaDoc = new KFormula::Document; + wrapper->document( kformulaDoc ); + KFormula::Container* formula = kformulaDoc->createFormula(); + + if ( !kformulaDoc->loadXML( domIn ) ) { + KMessageBox::error( 0, i18n( "Malformed XML data." ), + i18n( "SVG Export Error" ) ); + return KoFilter::WrongFormat; + } + + // Draw the actual bitmap. + QPicture picture; + QPainter painter(&picture); + QRect rect(QPoint(0, 0), QPoint(500, 400)); + formula->draw( painter, rect, false ); + painter.end(); + + // Save the image. + if ( !picture.save( m_chain->outputFile(), "SVG" ) ) { + KMessageBox::error( 0, i18n( "Failed to write file." ), + i18n( "SVG Export Error" ) ); + } + + delete formula; + delete wrapper; + return KoFilter::OK; +} + + +#include <svgexport.moc> diff --git a/filters/kformula/svg/svgexport.h b/filters/kformula/svg/svgexport.h new file mode 100644 index 00000000..085654a0 --- /dev/null +++ b/filters/kformula/svg/svgexport.h @@ -0,0 +1,37 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Inge Wallin <[email protected]> + Copyright (C) 2005 Fredrik Edemar <[email protected]> + + 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 __SVGEXPORT_H__ +#define __SVGEXPORT_H__ + +#include <KoFilter.h> + +class SvgExport : public KoFilter +{ + Q_OBJECT + +public: + SvgExport(KoFilter *parent, const char *name, const QStringList&); + virtual ~SvgExport(); + + virtual KoFilter::ConversionStatus convert(const QCString& from, const QCString& to); +}; + +#endif // __SVGEXPORT_H__ |