vcl/source/gdi/impgraph.cxx | 11 +++++++++++ vcl/source/gdi/pdfwriter_impl.cxx | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-)
New commits: commit 5d347c3d72a1d05f998f93f1e1ffea0b55457217 Author: Patrick Luby <[email protected]> AuthorDate: Wed Oct 11 19:53:18 2023 -0400 Commit: Patrick Luby <[email protected]> CommitDate: Thu Oct 19 18:25:14 2023 +0200 tdf#157680 scale down size and adjust size and scale factor for /BBox The size of an embedded PDF files is multiplied by PDF_INSERT_MAGIC_SCALE_FACTOR for platforms like macOS so undo that by adjusting the size and scale factor. For some unknown reason, when exporting the following PDF, the estimated size of embedded PDF charts are 20x larger than expected. This only occurs on macOS so possibly there is some special conversion from MapUnit::MapPoint to MapUnit::MapTwip elsewhere in the code: https://bugs.documentfoundation.org/attachment.cgi?id=190109 Change-Id: Id0563466fea3d7a3a0419787ec9da45f0c1d2e0a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157852 Tested-by: Jenkins Reviewed-by: Patrick Luby <[email protected]> diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index f3f877d3b939..780e2c26fd15 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -788,6 +788,17 @@ Size ImpGraphic::getPrefSize() const // svg not yet buffered in maBitmapEx, return size derived from range const basegfx::B2DRange& rRange = maVectorGraphicData->getRange(); +#ifdef MACOSX + // tdf#157680 scale down estimated size of embedded PDF + // For some unknown reason, the embedded PDF sizes + // are 20x larger than expected. This only occurs on + // macOS so possibly there is some special conversion + // from MapUnit::MapPoint to MapUnit::MapTwip elsewhere + // in the code. + if (maVectorGraphicData->getType() == VectorGraphicDataType::Pdf) + aSize = Size(basegfx::fround(rRange.getWidth() / 20.0f), basegfx::fround(rRange.getHeight() / 20.0f)); + else +#endif aSize = Size(basegfx::fround(rRange.getWidth()), basegfx::fround(rRange.getHeight())); } else diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 2d5fe724a4ac..506fde66b6c7 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -71,6 +71,7 @@ #include <vcl/lineinfo.hxx> #include <vcl/metric.hxx> #include <vcl/mnemonic.hxx> +#include <vcl/pdfread.hxx> #include <vcl/settings.hxx> #include <strhelper.hxx> #include <vcl/svapp.hxx> @@ -9111,6 +9112,7 @@ void PDFWriterImpl::writeReferenceXObject(const ReferenceXObjectEmit& rEmit) // vcl::ImportPDF() uses getDefaultPdfResolutionDpi to set the desired // rendering DPI so we have to take into account that here too. static const double fResolutionDPI = vcl::pdf::getDefaultPdfResolutionDpi(); + static const double fMagicScaleFactor = PDF_INSERT_MAGIC_SCALE_FACTOR; sal_Int32 nOldDPIX = GetDPIX(); sal_Int32 nOldDPIY = GetDPIY(); @@ -9125,15 +9127,13 @@ void PDFWriterImpl::writeReferenceXObject(const ReferenceXObjectEmit& rEmit) sal_Int32 nWrappedFormObject = 0; if (!m_aContext.UseReferenceXObject) { -#ifdef MACOSX // tdf#156842 increase scale for external PDF data - // For some unknown reason, the scale is 8 times larger than for - // non-external PDF XObjects. + // Multiply PDF_INSERT_MAGIC_SCALE_FACTOR for platforms like macOS + // that scale all images by this number. // This fix also allows the CppunitTest_vcl_pdfexport to run // successfully on macOS. - fScaleX = 8.0 / aSize.Width(); - fScaleY = 8.0 / aSize.Height(); -#endif + fScaleX = fMagicScaleFactor / aSize.Width(); + fScaleY = fMagicScaleFactor / aSize.Height(); // Parse the PDF data, we need that to write the PDF dictionary of our // object. @@ -9375,9 +9375,11 @@ void PDFWriterImpl::writeReferenceXObject(const ReferenceXObjectEmit& rEmit) appendDouble(fScaleY, aLine); aLine.append(" 0 0 ]"); aLine.append(" /BBox [ 0 0 "); - aLine.append(aSize.Width()); + // tdf#157680 reduce size by magic scale factor in /BBox + aLine.append(aSize.Width() / fMagicScaleFactor); aLine.append(" "); - aLine.append(aSize.Height()); + // tdf#157680 reduce size by magic scale factor in /BBox + aLine.append(aSize.Height() / fMagicScaleFactor); aLine.append(" ]\n"); if (m_aContext.UseReferenceXObject && rEmit.m_nEmbeddedObject > 0)
