sd/qa/unit/SdrPdfImportTest.cxx | 2 +- svx/source/svdraw/svdpdf.cxx | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-)
New commits: commit 6bcbed0f57dfe36082f7242946aaae25ba30319e Author: Caolán McNamara <[email protected]> AuthorDate: Wed Aug 6 09:42:30 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Thu Oct 2 15:44:47 2025 +0200 match pdf text size and vertical positioning Change-Id: Icaf9630ee287b817685cc74de0fcf85522937c11 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190984 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191772 Tested-by: Caolán McNamara <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> diff --git a/sd/qa/unit/SdrPdfImportTest.cxx b/sd/qa/unit/SdrPdfImportTest.cxx index da4298d5fe7c..14c88f88d7fa 100644 --- a/sd/qa/unit/SdrPdfImportTest.cxx +++ b/sd/qa/unit/SdrPdfImportTest.cxx @@ -129,7 +129,7 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testImportSimpleText) CPPUNIT_ASSERT(pImportedObject); // Check the object position - CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(2011, 2102), Size(2106 + 1, 298 + 1)), + CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(2011, 2018), Size(2107, 470)), pImportedObject->GetLogicRect()); // Object should be a text object containing one paragraph with diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index a6fcb118951f..bb41623618ab 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -104,6 +104,12 @@ ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools: mpVD->SetLineColor(); mpVD->SetFillColor(); maOldLineColor.SetRed(mpVD->GetLineColor().GetRed() + 1); + + // Get TextBounds relative to baseline + vcl::Font aFnt = mpVD->GetFont(); + aFnt.SetAlignment(ALIGN_BASELINE); + mpVD->SetFont(aFnt); + mpLineAttr = std::make_unique<SfxItemSet>( SfxItemSet::makeFixedSfxItemSet<XATTR_LINE_FIRST, XATTR_LINE_LAST>(rModel.GetItemPool())); mpFillAttr = std::make_unique<SfxItemSet>( @@ -783,20 +789,20 @@ void ImpSdrPdfImport::InsertTextObject(const Point& rPos, const Size& rSize, con FontMetric aFontMetric(mpVD->GetFontMetric()); vcl::Font aFont(mpVD->GetFont()); - TextAlign eAlignment(aFont.GetAlignment()); + assert(aFont.GetAlignment() == ALIGN_BASELINE); + + tools::Rectangle aOurRect; + (void)mpVD->GetTextBoundRect(aOurRect, rStr); - // sal_Int32 nTextWidth = static_cast<sal_Int32>(mpVD->GetTextWidth(rStr) * mfScaleX); - sal_Int32 nTextHeight = static_cast<sal_Int32>(mpVD->GetTextHeight() * mfScaleY); + auto nDiff = aFontMetric.GetDescent() - aOurRect.Bottom(); + Point aPos(rPos.X(), rPos.Y() + nDiff); - Point aPosition(basegfx::fround<tools::Long>(rPos.X() * mfScaleX + maOfs.X()), - basegfx::fround<tools::Long>(rPos.Y() * mfScaleY + maOfs.Y())); - Size aSize(basegfx::fround<tools::Long>(rSize.Width() * mfScaleX), - basegfx::fround<tools::Long>(rSize.Height() * mfScaleY)); + Size aBoundsSize(rSize.Width(), -aFontMetric.GetLineHeight()); - if (eAlignment == ALIGN_BASELINE) - aPosition.AdjustY(basegfx::fround<tools::Long>(aFontMetric.GetAscent() * -mfScaleY)); - else if (eAlignment == ALIGN_BOTTOM) - aPosition.AdjustY(-nTextHeight); + Point aPosition(basegfx::fround<tools::Long>(aPos.X() * mfScaleX + maOfs.X()), + basegfx::fround<tools::Long>(aPos.Y() * mfScaleY + maOfs.Y())); + Size aSize(basegfx::fround<tools::Long>(aBoundsSize.Width() * mfScaleX), + basegfx::fround<tools::Long>(aBoundsSize.Height() * mfScaleY)); tools::Rectangle aTextRect(aPosition, aSize); rtl::Reference<SdrRectObj> pText = new SdrRectObj(*mpModel, aTextRect, SdrObjKind::Text); commit a44927269b1a043d2c74b68f118483932c9371a7 Author: Caolán McNamara <[email protected]> AuthorDate: Mon Aug 18 13:29:44 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Thu Oct 2 15:44:32 2025 +0200 use same map mode that line breaking will use Change-Id: I29fd267e21f246d2de9bc3f75675b1465a0a6dfa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190983 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191771 Tested-by: Caolán McNamara <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index a509c9fad5cb..a6fcb118951f 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -99,6 +99,7 @@ ImpSdrPdfImport::ImpSdrPdfImport(SdrModel& rModel, SdrLayerID nLay, const tools: { // Same as SdModule mpVD->SetReferenceDevice(VirtualDevice::RefDevMode::Dpi600); + mpVD->SetMapMode(MapMode(MapUnit::Map100thMM)); mpVD->EnableOutput(false); mpVD->SetLineColor(); mpVD->SetFillColor();
