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::makeFixedSfxItemSet(rModel.GetItemPool())); mpFillAttr = std::make_unique( @@ -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); - // sal_Int32 nTextWidth = static_cast(mpVD->GetTextWidth(rStr) * mfScaleX); - sal_Int32 nTextHeight = static_cast(mpVD->GetTextHeight() * mfScaleY); + tools::Rectangle aOurRect; + (void)mpVD->GetTextBoundRect(aOurRect, rStr); - Point aPosition(basegfx::fround(rPos.X() * mfScaleX + maOfs.X()), - basegfx::fround(rPos.Y() * mfScaleY + maOfs.Y())); - Size aSize(basegfx::fround(rSize.Width() * mfScaleX), - basegfx::fround(rSize.Height() * mfScaleY)); + auto nDiff = aFontMetric.GetDescent() - aOurRect.Bottom(); + Point aPos(rPos.X(), rPos.Y() + nDiff); - if (eAlignment == ALIGN_BASELINE) - aPosition.AdjustY(basegfx::fround(aFontMetric.GetAscent() * -mfScaleY)); - else if (eAlignment == ALIGN_BOTTOM) - aPosition.AdjustY(-nTextHeight); + Size aBoundsSize(rSize.Width(), -aFontMetric.GetLineHeight()); + + Point aPosition(basegfx::fround(aPos.X() * mfScaleX + maOfs.X()), + basegfx::fround(aPos.Y() * mfScaleY + maOfs.Y())); + Size aSize(basegfx::fround(aBoundsSize.Width() * mfScaleX), + basegfx::fround(aBoundsSize.Height() * mfScaleY)); tools::Rectangle aTextRect(aPosition, aSize); rtl::Reference pText = new SdrRectObj(*mpModel, aTextRect, SdrObjKind::Text);