summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/filter/ipdf/pdfread.cxx21
-rw-r--r--vcl/source/gdi/vectorgraphicdata.cxx12
2 files changed, 29 insertions, 4 deletions
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index d89283e902ac..39c2933be8d5 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -24,6 +24,7 @@
#include <unotools/datetime.hxx>
#include <vcl/filter/PDFiumLibrary.hxx>
+#include <sal/log.hxx>
using namespace com::sun::star;
@@ -147,9 +148,10 @@ VectorGraphicDataArray createVectorGraphicDataArray(SvStream& rStream)
namespace vcl
{
size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBitmaps,
- const size_t nFirstPage, int nPages, const double fResolutionDPI)
+ const size_t nFirstPage, int nPages, const basegfx::B2DTuple* pSizeHint)
{
#if HAVE_FEATURE_PDFIUM
+ const double fResolutionDPI = 96;
auto pPdfium = vcl::pdf::PDFiumLibrary::get();
// Load the buffer using pdfium.
@@ -168,9 +170,19 @@ size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBi
if (!pPdfPage)
break;
+ // Calculate the bitmap size in points.
+ size_t nPageWidthPoints = FPDF_GetPageWidth(pPdfPage);
+ size_t nPageHeightPoints = FPDF_GetPageHeight(pPdfPage);
+ if (pSizeHint && pSizeHint->getX() && pSizeHint->getY())
+ {
+ // Have a size hint, prefer that over the logic size from the PDF.
+ nPageWidthPoints = convertMm100ToTwip(pSizeHint->getX()) / 20;
+ nPageHeightPoints = convertMm100ToTwip(pSizeHint->getY()) / 20;
+ }
+
// Returned unit is points, convert that to pixel.
- const size_t nPageWidth = pointToPixel(FPDF_GetPageWidth(pPdfPage), fResolutionDPI);
- const size_t nPageHeight = pointToPixel(FPDF_GetPageHeight(pPdfPage), fResolutionDPI);
+ const size_t nPageWidth = pointToPixel(nPageWidthPoints, fResolutionDPI);
+ const size_t nPageHeight = pointToPixel(nPageHeightPoints, fResolutionDPI);
FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1);
if (!pPdfBitmap)
break;
@@ -217,7 +229,10 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
{
VectorGraphicDataArray aPdfDataArray = createVectorGraphicDataArray(rStream);
if (!aPdfDataArray.hasElements())
+ {
+ SAL_WARN("vcl.filter", "ImportPDF: empty PDF data array");
return false;
+ }
auto aVectorGraphicDataPtr = std::make_shared<VectorGraphicData>(aPdfDataArray, OUString(),
VectorGraphicDataType::Pdf);
diff --git a/vcl/source/gdi/vectorgraphicdata.cxx b/vcl/source/gdi/vectorgraphicdata.cxx
index bfaa544bc7d4..d0d1e3ca6412 100644
--- a/vcl/source/gdi/vectorgraphicdata.cxx
+++ b/vcl/source/gdi/vectorgraphicdata.cxx
@@ -150,7 +150,9 @@ void VectorGraphicData::ensurePdfReplacement()
sal_Int32 nUsePageIndex = 0;
if (mnPageIndex >= 0)
nUsePageIndex = mnPageIndex;
- vcl::RenderPDFBitmaps(maVectorGraphicDataArray.getConstArray(), maVectorGraphicDataArray.getLength(), aBitmaps, nUsePageIndex, 1/*, fResolutionDPI*/);
+ vcl::RenderPDFBitmaps(maVectorGraphicDataArray.getConstArray(),
+ maVectorGraphicDataArray.getLength(), aBitmaps, nUsePageIndex, 1,
+ &maSizeHint);
if (!aBitmaps.empty())
maReplacement = aBitmaps[0];
}
@@ -212,7 +214,15 @@ void VectorGraphicData::ensureSequenceAndRange()
}
if (myInputStream.is())
+ {
+ // Pass the size hint of the graphic to the EMF parser.
+ geometry::RealPoint2D aSizeHint;
+ aSizeHint.X = maSizeHint.getX();
+ aSizeHint.Y = maSizeHint.getY();
+ xEmfParser->setSizeHint(aSizeHint);
+
maSequence = comphelper::sequenceToContainer<std::deque<css::uno::Reference< css::graphic::XPrimitive2D >>>(xEmfParser->getDecomposition(myInputStream, maPath, aSequence));
+ }
break;
}