filters

epsimport.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, The Karbon Developers
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qcstring.h>
00021 #include <qstring.h>
00022 #include <qfile.h>
00023 
00024 #include <kgenericfactory.h>
00025 #include <KoFilter.h>
00026 #include <KoFilterChain.h>
00027 #include <krun.h>
00028 #include <kprocess.h>
00029 
00030 #include <kdebug.h>
00031 
00032 #include "epsimport.h"
00033 #include "pscommentlexer.h"
00034 
00035 class EpsImportFactory : KGenericFactory<EpsImport, KoFilter>
00036 {
00037 public:
00038     EpsImportFactory( void )
00039         : KGenericFactory<EpsImport, KoFilter>( "karbonepsimport" )
00040     {}
00041 
00042 protected:
00043     virtual void setupTranslations( void )
00044     {
00045         KGlobal::locale()->insertCatalogue( "kofficefilters" );
00046     }
00047 };
00048 
00049 K_EXPORT_COMPONENT_FACTORY( libkarbonepsimport, EpsImportFactory() )
00050 
00051 EpsImport::EpsImport( KoFilter*, const char*, const QStringList& )
00052     : KoFilter()
00053 {
00054 }
00055 
00056 EpsImport::~EpsImport()
00057 {
00058 }
00059 
00060 KoFilter::ConversionStatus
00061 EpsImport::convert( const QCString& from, const QCString& to )
00062 {
00063     if(
00064         to != "application/illustrator" ||
00065         (
00066             from != "image/x-eps" &&
00067             from != "application/postscript" ) )
00068     {
00069         return KoFilter::NotImplemented;
00070     }
00071 
00072     // Copy input filename:
00073     QString input = m_chain->inputFile();
00074 
00075 
00076     // EPS original bounding box
00077     int llx = -1, lly = -1, urx = -1, ury = -1;
00078     BoundingBoxExtractor extractor;
00079 
00080     QFile file (input);
00081 
00082     if ( file.open(IO_ReadOnly) )
00083     {
00084         extractor.parse (file);
00085         llx = extractor.llx();
00086         lly = extractor.lly();
00087         urx = extractor.urx();
00088         ury = extractor.ury();
00089             file.close();
00090     }
00091     else
00092         qDebug ("file could not be opened");
00093 
00094     // sed filter
00095     QString sedFilter = QString ("sed -e \"s/%%BoundingBox: 0 0 612 792/%%BoundingBox: %1 %2 %3 %4/g\"").
00096             arg(llx).arg(lly).arg(urx).arg(ury);
00097 
00098     // Build ghostscript call to convert ps/eps -> ai:
00099     QString command(
00100         "gs -q -P- -dBATCH -dNOPAUSE -dSAFER -dPARANOIDSAFER -dNODISPLAY ps2ai.ps ");
00101     command += KProcess::quote(input);
00102     command += " | ";
00103     command += sedFilter;
00104     command += " > ";
00105     command += KProcess::quote(m_chain->outputFile());
00106 
00107     qDebug ("command to execute is (%s)", QFile::encodeName(command).data());
00108 
00109     // Execute it:
00110     if( !system( QFile::encodeName(command)) )
00111         return KoFilter::OK;
00112     else
00113         return KoFilter::StupidError;
00114 }
00115 
00116 #include "epsimport.moc"
00117 
KDE Home | KDE Accessibility Home | Description of Access Keys