filters
epsimport.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00073 QString input = m_chain->inputFile();
00074
00075
00076
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
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
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
00110 if( !system( QFile::encodeName(command)) )
00111 return KoFilter::OK;
00112 else
00113 return KoFilter::StupidError;
00114 }
00115
00116 #include "epsimport.moc"
00117
|