vcl/source/gdi/impgraph.cxx | 11 +++++++++++ vcl/source/gdi/pdfwriter_impl.cxx | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-)
New commits: commit 5ea44cd9fd467f1ed26f69e194d0a59d9e0e71c2 Author: Patrick Luby <plub...@neooffice.org> AuthorDate: Wed Oct 11 19:53:18 2023 -0400 Commit: Patrick Luby <plub...@neooffice.org> CommitDate: Thu Oct 19 21:44: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/+/158155 Tested-by: Jenkins Reviewed-by: Patrick Luby <plub...@neooffice.org> diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 35a2145aa8e4..c4a5a1ca11b5 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 8176f3f86378..15eeb5c4a619 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> @@ -9058,6 +9059,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(); @@ -9072,15 +9074,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. @@ -9322,9 +9322,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)