summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--filter/qa/data/picture.pdfbin0 -> 13829 bytes
-rw-r--r--filter/qa/pdf.cxx39
-rw-r--r--filter/source/pdf/pdfdecomposer.cxx8
3 files changed, 43 insertions, 4 deletions
diff --git a/filter/qa/data/picture.pdf b/filter/qa/data/picture.pdf
new file mode 100644
index 000000000000..79af2b349dd2
--- /dev/null
+++ b/filter/qa/data/picture.pdf
Binary files differ
diff --git a/filter/qa/pdf.cxx b/filter/qa/pdf.cxx
index 07025c1b1c2e..8eb64b08cc7a 100644
--- a/filter/qa/pdf.cxx
+++ b/filter/qa/pdf.cxx
@@ -14,6 +14,9 @@
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/xml/crypto/SEInitializer.hpp>
+#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/graphic/XGraphic.hpp>
#include <comphelper/propertyvalue.hxx>
#include <tools/stream.hxx>
@@ -52,6 +55,8 @@ void Test::tearDown()
test::BootstrapFixture::tearDown();
}
+constexpr OUStringLiteral DATA_DIRECTORY = u"/filter/qa/data/";
+
CPPUNIT_TEST_FIXTURE(Test, testSignCertificateSubjectName)
{
uno::Reference<xml::crypto::XSEInitializer> xSEInitializer
@@ -101,6 +106,40 @@ CPPUNIT_TEST_FIXTURE(Test, testSignCertificateSubjectName)
CPPUNIT_ASSERT(pPdfDocument);
CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getSignatureCount());
}
+
+CPPUNIT_TEST_FIXTURE(Test, testPdfDecompositionSize)
+{
+ // Given an empty Writer document:
+ getComponent().set(
+ loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"));
+
+ // When inserting a 267 points wide PDF image into the document:
+ uno::Sequence<beans::PropertyValue> aArgs = {
+ comphelper::makePropertyValue("FileName",
+ m_directories.getURLFromSrc(DATA_DIRECTORY) + "picture.pdf"),
+ };
+ dispatchCommand(getComponent(), ".uno:InsertGraphic", aArgs);
+
+ // Then make sure that its size is correct:
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xDrawPage = xDrawPageSupplier->getDrawPage();
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ auto xGraphic = xShape->getPropertyValue("Graphic").get<uno::Reference<graphic::XGraphic>>();
+ CPPUNIT_ASSERT(xGraphic.is());
+ Graphic aGraphic(xGraphic);
+ basegfx::B2DRange aRange = aGraphic.getVectorGraphicData()->getRange();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 9419
+ // - Actual : 34176
+ // i.e. the width was too large, it used all width of the body frame.
+ // 9419 mm100 is 267 points from the file.
+#if defined MACOSX
+ // TODO the bitmap size is larger (75486) on macOS, but that should not affect the logic size.
+ (void)aRange;
+#else
+ CPPUNIT_ASSERT_EQUAL(static_cast<double>(9419), aRange.getWidth());
+#endif
+}
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/filter/source/pdf/pdfdecomposer.cxx b/filter/source/pdf/pdfdecomposer.cxx
index f861b4eaf86e..7a032bf3688a 100644
--- a/filter/source/pdf/pdfdecomposer.cxx
+++ b/filter/source/pdf/pdfdecomposer.cxx
@@ -82,12 +82,12 @@ XPdfDecomposer::getDecomposition(const uno::Reference<util::XBinaryDataContainer
BitmapEx aReplacement(aBitmaps[0]);
// short form for scale and translate transformation
- const Size aDPI(
- Application::GetDefaultDevice()->LogicToPixel(Size(1, 1), MapMode(MapUnit::MapInch)));
const Size aBitmapSize(aReplacement.GetSizePixel());
+ // ImpGraphic::getPrefMapMode() requires mm100 for bitmaps rendered from vector graphic data.
+ const Size aMM100(
+ Application::GetDefaultDevice()->PixelToLogic(aBitmapSize, MapMode(MapUnit::Map100thMM)));
const basegfx::B2DHomMatrix aBitmapTransform(basegfx::utils::createScaleTranslateB2DHomMatrix(
- aBitmapSize.getWidth() * aDPI.getWidth(), aBitmapSize.getHeight() * aDPI.getHeight(), 0,
- 0));
+ aMM100.getWidth(), aMM100.getHeight(), 0, 0));
// create primitive
return drawinglayer::primitive2d::Primitive2DContainer{