Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scimgdataloader_pdf.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include <qfile.h>
00008 #include <qfileinfo.h>
00009 #include "gsutil.h"
00010 #include "scpaths.h"
00011 #include "scribuscore.h"
00012 #include "scimgdataloader_pdf.h"
00013 
00014 ScImgDataLoader_PDF::ScImgDataLoader_PDF(void) : ScImgDataLoader()
00015 {
00016        initSupportedFormatList();
00017 }
00018 
00019 void ScImgDataLoader_PDF::initSupportedFormatList(void)
00020 {
00021        m_supportedFormats.clear();
00022        m_supportedFormats.append( "pdf" );
00023 }
00024 
00025 void ScImgDataLoader_PDF::loadEmbeddedProfile(const QString& fn)
00026 {
00027        m_embeddedProfile.resize(0);
00028        m_profileComponents = 0;
00029 }
00030 
00031 bool ScImgDataLoader_PDF::loadPicture(const QString& fn, int gsRes, bool /*thumbnail*/)
00032 {
00033        QStringList args;
00034        if (!QFile::exists(fn))
00035               return false;
00036        QString tmpFile = QDir::convertSeparators(ScPaths::getTempFileDir() + "sc.png");
00037        QString picFile = QDir::convertSeparators(fn);
00038        float xres = gsRes;
00039        float yres = gsRes;
00040 
00041        initialize();
00042        m_imageInfoRecord.type = 4;
00043        m_imageInfoRecord.exifDataValid = false;
00044        args.append("-r"+QString::number(gsRes));
00045        args.append("-sOutputFile="+tmpFile);
00046        args.append("-dFirstPage=1");
00047        args.append("-dLastPage=1");
00048        args.append(picFile);
00049        int retg = callGS(args);
00050        if (retg == 0)
00051        {
00052               m_image.load(tmpFile);
00053               unlink(tmpFile);
00054               m_image.setAlphaBuffer(true);
00055               if (ScCore->havePNGAlpha() != 0)
00056               {
00057                      for( int yi=0; yi < m_image.height(); ++yi )
00058                      {
00059                             QRgb *s = (QRgb*)(m_image.scanLine( yi ));
00060                             for(int xi=0; xi < m_image.width(); ++xi )
00061                             {
00062                                    if((*s) == 0xffffffff)
00063                                           (*s) &= 0x00ffffff;
00064                                    s++;
00065                             }
00066                      }
00067               }
00068               m_imageInfoRecord.BBoxX = 0;
00069               m_imageInfoRecord.BBoxH = m_image.height();
00070               m_imageInfoRecord.xres = qRound(gsRes);
00071               m_imageInfoRecord.yres = qRound(gsRes);
00072               m_imageInfoRecord.colorspace = 0;
00073               m_image.setDotsPerMeterX ((int) (xres / 0.0254));
00074               m_image.setDotsPerMeterY ((int) (yres / 0.0254));
00075               return true;
00076        }
00077        return false;
00078 }
00079 
00080 void ScImgDataLoader_PDF::preloadAlphaChannel(const QString& fn, int gsRes)
00081 {
00082        float xres, yres;
00083 //     short resolutionunit = 0;
00084        initialize();
00085        QFileInfo fi = QFileInfo(fn);
00086        if (!fi.exists())
00087               return;
00088        QString tmp, BBox;
00089        QString ext = fi.extension(false).lower();
00090        QString tmpFile = QDir::convertSeparators(ScPaths::getTempFileDir() + "sc.png");
00091        QString picFile = QDir::convertSeparators(fn);
00092        QStringList args;
00093        xres = gsRes;
00094        yres = gsRes;
00095        args.append("-r"+QString::number(gsRes));
00096 //     args.append("-sOutputFile=\""+tmpFile + "\"");
00097        args.append("-sOutputFile="+tmpFile);
00098        args.append("-dFirstPage=1");
00099        args.append("-dLastPage=1");
00100 //     args.append("\""+picFile+"\"");
00101        args.append(picFile);
00102        int retg = callGS(args);
00103        if (retg == 0)
00104        {
00105               m_image.load(tmpFile);
00106               unlink(tmpFile);
00107               m_image.setAlphaBuffer(true);
00108               if (ScCore->havePNGAlpha() != 0)
00109               {
00110                      QRgb *s;
00111                      for( int yi=0; yi < m_image.height(); ++yi )
00112                      {
00113                             s = (QRgb*)(m_image.scanLine( yi ));
00114                             for(int xi=0; xi < m_image.width(); ++xi )
00115                             {
00116                                    if((*s) == 0xffffffff)
00117                                           (*s) &= 0x00ffffff;
00118                                    s++;
00119                             }
00120                      }
00121               }
00122        }
00123 }