1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include "util_ghostscript.h"
#include "scpaths.h"
#include "scribuscore.h"
#include "scimgdataloader_pdf.h"
#ifdef HAVE_PODOFO
#include <podofo/podofo.h>
#endif
ScImgDataLoader_PDF::ScImgDataLoader_PDF(void) : ScImgDataLoader()
{
initSupportedFormatList();
}
void ScImgDataLoader_PDF::initSupportedFormatList(void)
{
m_supportedFormats.clear();
m_supportedFormats.append( "pdf" );
}
void ScImgDataLoader_PDF::loadEmbeddedProfile(const QString& fn, int /* page */)
{
m_embeddedProfile.resize(0);
m_profileComponents = 0;
}
bool ScImgDataLoader_PDF::loadPicture(const QString& fn, int page, int gsRes, bool /*thumbnail*/)
{
QStringList args;
if (!QFile::exists(fn))
return false;
QString tmpFile = QDir::toNativeSeparators(ScPaths::getTempFileDir() + "sc.png");
QString picFile = QDir::toNativeSeparators(fn);
float xres = gsRes;
float yres = gsRes;
initialize();
m_imageInfoRecord.actualPageNumber = page;
m_imageInfoRecord.type = ImageTypePDF;
m_imageInfoRecord.exifDataValid = false;
m_imageInfoRecord.numberOfPages = 99; // FIXME
#ifdef HAVE_PODOFO
try
{
PoDoFo::PdfError::EnableDebug( false );
#if (PODOFO_VERSION == 0 && PODOFO_MINOR > 6)
PoDoFo::PdfError::EnableLogging( false );
#endif
#if (PODOFO_VERSION == 0 && PODOFO_MINOR == 5 && PODOFO_REVISION == 99) || PODOFO_MINOR > 5
PoDoFo::PdfMemDocument doc( fn.toLocal8Bit().data() );
#else
PoDoFo::PdfDocument doc( fn.toLocal8Bit().data() );
#endif
m_imageInfoRecord.numberOfPages = doc.GetPageCount();
if (page > m_imageInfoRecord.numberOfPages)
{
qDebug() << "Incorrect page number specified!";
m_imageInfoRecord.actualPageNumber = page = 0;
}
}
catch(PoDoFo::PdfError& e)
{
qDebug() << "PoDoFo error while reading page count!";
e.PrintErrorMsg();
}
#endif
args.append("-r"+QString::number(gsRes));
args.append("-sOutputFile="+tmpFile);
args.append("-dFirstPage=" + QString::number(qMax(1, page)));
args.append("-dLastPage=" + QString::number(qMax(1, page)));
args.append(picFile);
// qDebug() << "scimgdataloader_pdf:" << args;
int retg = callGS(args);
if (retg == 0)
{
m_image.load(tmpFile);
QFile::remove(tmpFile);
if (!ScCore->havePNGAlpha())
{
for( int yi=0; yi < m_image.height(); ++yi )
{
QRgb *s = (QRgb*)(m_image.scanLine( yi ));
for(int xi=0; xi < m_image.width(); ++xi )
{
if((*s) == 0xffffffff)
(*s) &= 0x00ffffff;
s++;
}
}
}
m_imageInfoRecord.BBoxX = 0;
m_imageInfoRecord.BBoxH = m_image.height();
m_imageInfoRecord.xres = qRound(gsRes);
m_imageInfoRecord.yres = qRound(gsRes);
m_imageInfoRecord.colorspace = ColorSpaceRGB;
m_image.setDotsPerMeterX ((int) (xres / 0.0254));
m_image.setDotsPerMeterY ((int) (yres / 0.0254));
return true;
}
return false;
}
bool ScImgDataLoader_PDF::preloadAlphaChannel(const QString& fn, int page, int gsRes, bool& hasAlpha)
{
float xres, yres;
// short resolutionunit = 0;
initialize();
m_imageInfoRecord.actualPageNumber = page;
hasAlpha = false;
QFileInfo fi = QFileInfo(fn);
if (!fi.exists())
return false;
QString tmp, BBox;
QString tmpFile = QDir::toNativeSeparators(ScPaths::getTempFileDir() + "sc.png");
QString picFile = QDir::toNativeSeparators(fn);
QStringList args;
xres = gsRes;
yres = gsRes;
args.append("-r"+QString::number(gsRes));
// args.append("-sOutputFile=\""+tmpFile + "\"");
args.append("-sOutputFile="+tmpFile);
args.append("-dFirstPage=" + QString::number(qMax(1, page)));
args.append("-dLastPage=" + QString::number(qMax(1, page)));
// args.append("\""+picFile+"\"");
args.append(picFile);
// qDebug() << "scimgdataloader_pdf(alpha):" << args;
int retg = callGS(args);
if (retg == 0)
{
m_image.load(tmpFile);
QFile::remove(tmpFile);
if (!ScCore->havePNGAlpha())
{
QRgb *s;
for( int yi=0; yi < m_image.height(); ++yi )
{
s = (QRgb*)(m_image.scanLine( yi ));
for(int xi=0; xi < m_image.width(); ++xi )
{
if((*s) == 0xffffffff)
(*s) &= 0x00ffffff;
s++;
}
}
}
hasAlpha = true;
return true;
}
return false;
}
|