[scribus-dev] patch to pdf CropBox
Ime Prezime
a401849 at gmail.com
Sat Jul 17 15:18:01 CEST 2010
by default ghostscript use MediaBox to produce an image preview. if a
PDF contains CropBox we get wrong position during image importing in
scribus image container. so we must tell to ghostscript (and podofo )
to use CropBox instead of MediaBox here is the patch...
ilija
-------------- next part --------------
******************************
in file: scimgdataloader_pdf.h
class ScImgDataLoader_PDF
{
++line 17 protected:
#ifndef HAVE_PODOFO
bool isCropBoxPresent(QString fn)
#endif
******************************
in file scimgdataloader_pdf.cpp
ScImgDataLoader_PDF::loadPicture(...
++line 67 PoDoFo::PdfPage* actualPage = doc.GetPage( page );
...
line 75: args.append("-sOutputFile="+tmpFile);
++#ifdef HAVE_PODOFO
++ if( page->GetObject()->GetDictionary().GetKey("CropBox") )
++#else
++ if( isCropBoxPresent(fn) )
++#endif
++ args.Append(" -dUseCropBox -dFirstPage="+QString::number(qMax(1, page)));
++ else
line 76: args.Append(" -dFirstPage="+QString::number(qMax(1, page)));
line 77:args.append("-dLastPage=" + QString::number(qMax(1, page)));
#ifndef HAVE_PODOFO
bool ScImgDataLoader_PDF::isCropBoxPresent(QString fn)
{
bool result = false;
QString tmp;
QFile f(fn);
if (f.open(QIODevice::ReadOnly))
{
QDataStream ts(&f);
while (!ts.atEnd())
{
tmp = readLinefromDataStream(ts);
if (tmp.contains("/CropBox"))
{
result=true;
break;
}
}
}
return result;
}
#endif
**************
in file pdflib_core.h
class PDFLibCore
{
private:
bool hasCropBox;
#ifdef HAVE_PODOFO
PoDoFo::PdfRect cropBox;
#endif
**************
in file pdflib_core.cpp
bool PDFLibCore::PDF_EmbeddedPDF(...
{
++line 6281: hasCropBox = false;
line 6313: PoDoFo::PdfRect pagesize; // = page->GetPageSize();
++ if( page->GetObject()->GetDictionary().GetKey("CropBox") )
++ {
++ pagesize = page->GetCropBox();
++ cropBox = pagesize;
++ hasCropBox = true;
++ }
++ else
++ pagesize = page->GetPageSize();
line 5893: int rotation = page->GetRotation();
line 5894: QWMatrix pageM;
pageM.scale(1.0/pagesize.GetWidth(), 1.0/pagesize.GetHeight());
pageM.rotate(-rotation);
++ if(hasCropBox)
++ {
++ PutDoc("\n/BBox [ 0 0");
++ }
++ else
++ {
PutDoc("\n/BBox [" + FToStr(pagesize.GetLeft() ));
PutDoc(" " + FToStr(pagesize.GetBottom() ));
++ }
PutDoc(" " + FToStr(pagesize.GetLeft() + pagesize.GetWidth() ));
PutDoc(" " + FToStr(pagesize.GetBottom() + pagesize.GetHeight() ));
PutDoc("]");
...
bool PDFLibCore::PDF_Image(...
{
line 6263:
if (!fromAN && output)
{
#ifdef HAVE_PODOFO
if(hasCropBox)
*output = QString(embedPre + FToStr(ImInfo.Width*ImInfo.sxa)+" 0 0 "+FToStr(ImInfo.Height*ImInfo.sya)+" "+FToStr(x*sx - cropBox.GetLeft() )+" "+FToStr(y*sy - cropBox.GetBottom()*ImInfo->sya - cropBox.GetHeight()*ImInfo->sya)+" cm\n/"+ResNam+"I"+QString::number(ImInfo.ResNum)+" Do\n");
else
#endif
*output = QString(embedPre + FToStr(ImInfo.Width*ImInfo.sxa)+" 0 0 "+FToStr(ImInfo.Height*ImInfo.sya)+" "+FToStr(x*sx)+" "+FToStr((-ImInfo.Height*ImInfo.sya+y*sy))+" cm\n/"+ResNam+"I"+QString::number(ImInfo.ResNum)+" Do\n");
}
else if (output)
*output = QString("");
return true;
}
More information about the scribus-dev
mailing list