sd/qa/unit/SdrPdfImportTest.cxx | 16 +++++++++++-- sd/qa/unit/export-tests.cxx | 12 ++++++++-- svx/source/svdraw/svdpdf.cxx | 47 ++++++++++++++++++++-------------------- vcl/source/gdi/mtfxmldump.cxx | 14 +++++++++++ 4 files changed, 62 insertions(+), 27 deletions(-)
New commits: commit cc115d39787a786ab2cad5f87c168723753689da Author: Caolán McNamara <[email protected]> AuthorDate: Mon Sep 15 17:05:17 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Fri Oct 3 15:02:15 2025 +0200 horizontally position the text rect to get the ink in the same place ditch auto expand of the text shape. Change-Id: I3a7cd2d6bbedc4db6640a6f1bbe6ad1ae43a4631 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190987 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191775 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins diff --git a/sd/qa/unit/SdrPdfImportTest.cxx b/sd/qa/unit/SdrPdfImportTest.cxx index 14c88f88d7fa..f495b3d0f546 100644 --- a/sd/qa/unit/SdrPdfImportTest.cxx +++ b/sd/qa/unit/SdrPdfImportTest.cxx @@ -129,8 +129,20 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testImportSimpleText) CPPUNIT_ASSERT(pImportedObject); // Check the object position - CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(2011, 2018), Size(2107, 470)), - pImportedObject->GetLogicRect()); +#if !defined _WIN32 + CPPUNIT_ASSERT_EQUAL(Point(2004, 2018), pImportedObject->GetLogicRect().GetPos()); +#else + // need to check why windows appears to be different + CPPUNIT_ASSERT_EQUAL(Point(1998, 2018), pImportedObject->GetLogicRect().GetPos()); +#endif + + // Check the object size +#if !defined _WIN32 + CPPUNIT_ASSERT_EQUAL(Size(2165, 470), pImportedObject->GetLogicRect().GetSize()); +#else + // need to check why windows appears to be different + CPPUNIT_ASSERT_EQUAL(Size(3944, 470), pImportedObject->GetLogicRect().GetSize()); +#endif // Object should be a text object containing one paragraph with // content "This is PDF!" diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx index 4aacdf0fd87a..443ee00b4431 100644 --- a/sd/qa/unit/export-tests.cxx +++ b/sd/qa/unit/export-tests.cxx @@ -1059,9 +1059,17 @@ CPPUNIT_TEST_FIXTURE(SdExportTest, testExplodedPdfTextPos) saveAndReload(u"OpenDocument Drawing Flat XML"_ustr); xmlDocUniquePtr pXml = parseLayout(); + sal_Int32 x = getXPath(pXml, "//textarray[1]", "x").toInt32(); + // was 2028 originally +#if !defined _WIN32 + CPPUNIT_ASSERT_DOUBLES_EQUAL(2003, x, 0); +#else + // need to check why windows appears to be different + CPPUNIT_ASSERT_DOUBLES_EQUAL(1985, x, 0); +#endif sal_Int32 y = getXPath(pXml, "//textarray[1]", "y").toInt32(); - // was 3092 before - CPPUNIT_ASSERT_DOUBLES_EQUAL(3055, y, 0); + // was 3092 originally + CPPUNIT_ASSERT_DOUBLES_EQUAL(3063, y, 0); } CPPUNIT_TEST_FIXTURE(SdExportTest, testEmbeddedText) diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index b5cc9ce8ce5d..3d9de5d5c151 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -784,28 +784,39 @@ void ImpSdrPdfImport::ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> con InsertTextObject(aRect.TopLeft(), aRect.GetSize(), sText); } -void ImpSdrPdfImport::InsertTextObject(const Point& rPos, const Size& rSize, const OUString& rStr) +void ImpSdrPdfImport::InsertTextObject(const Point& rPos, const Size& /*rSize*/, + const OUString& rStr) { - // calc text box size, add 5% to make it fit safely - FontMetric aFontMetric(mpVD->GetFontMetric()); vcl::Font aFont(mpVD->GetFont()); assert(aFont.GetAlignment() == ALIGN_BASELINE); + /* Get our text bounds of this text, which is nominally relative to a 0 + left margin, so we know where the inked rect begins relative to the + start of the text area, and we can adjust the pdf rectangle by that so + the SdrRectObj text will get rendered at the same x position. + + Similarly find the relative vertical distance from the inked bounds + to the baseline and adjust the pdf rect so the SdrRectObj will render + the text at the same y position. + */ tools::Rectangle aOurRect; (void)mpVD->GetTextBoundRect(aOurRect, rStr); - auto nDiff = aFontMetric.GetDescent() - aOurRect.Bottom(); - Point aPos(rPos.X(), rPos.Y() + nDiff); + auto nXDiff = aOurRect.Left(); + auto nYDiff = aFontMetric.GetDescent() - aOurRect.Bottom(); - Size aBoundsSize(rSize.Width(), -aFontMetric.GetLineHeight()); + Point aPos(rPos.X() - nXDiff, rPos.Y() + nYDiff); + // As per ImpEditEngine::CalcParaWidth the width of the text box has to be 1 unit wider than the text + auto nTextWidth = mpVD->GetTextWidth(rStr) + 1; + Size aSize(nTextWidth, -aFontMetric.GetLineHeight()); - 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)); + Point aSdrPos(basegfx::fround<tools::Long>(aPos.X() * mfScaleX + maOfs.X()), + basegfx::fround<tools::Long>(aPos.Y() * mfScaleY + maOfs.Y())); + Size aSdrSize(basegfx::fround<tools::Long>(aSize.Width() * mfScaleX), + basegfx::fround<tools::Long>(aSize.Height() * mfScaleY)); - tools::Rectangle aTextRect(aPosition, aSize); + tools::Rectangle aTextRect(aSdrPos, aSdrSize); rtl::Reference<SdrRectObj> pText = new SdrRectObj(*mpModel, aTextRect, SdrObjKind::Text); pText->SetMergedItem(makeSdrTextUpperDistItem(0)); @@ -813,17 +824,7 @@ void ImpSdrPdfImport::InsertTextObject(const Point& rPos, const Size& rSize, con pText->SetMergedItem(makeSdrTextRightDistItem(0)); pText->SetMergedItem(makeSdrTextLeftDistItem(0)); - if (aFont.GetAverageFontWidth()) - { - pText->ClearMergedItem(SDRATTR_TEXT_AUTOGROWWIDTH); - pText->SetMergedItem(makeSdrTextAutoGrowHeightItem(false)); - // don't let the margins eat the space needed for the text - pText->SetMergedItem(SdrTextFitToSizeTypeItem(drawing::TextFitToSizeType_ALLLINES)); - } - else - { - pText->SetMergedItem(makeSdrTextAutoGrowWidthItem(true)); - } + pText->SetMergedItem(makeSdrTextAutoGrowHeightItem(false)); pText->SetLayer(mnLayer); pText->NbcSetText(rStr); @@ -840,7 +841,7 @@ void ImpSdrPdfImport::InsertTextObject(const Point& rPos, const Size& rSize, con } Degree100 nAngle = to<Degree100>(aFont.GetOrientation()); if (nAngle) - pText->SdrAttrObj::NbcRotate(aPosition, nAngle); + pText->SdrAttrObj::NbcRotate(aSdrPos, nAngle); InsertObj(pText.get(), false); } commit c2b575b1004e79837bf0309dd53fcf519325f282 Author: Caolán McNamara <[email protected]> AuthorDate: Mon Sep 15 20:27:16 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Fri Oct 3 15:02:07 2025 +0200 add italic to mtf xml dump Change-Id: I9c8ce33664b255624c4065e64a9d89bc6b366210 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190993 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> (cherry picked from commit 497f8c831246653287bb2204c6532f8ce4820025) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191815 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx index b20b01cc330f..039db43254d6 100644 --- a/vcl/source/gdi/mtfxmldump.cxx +++ b/vcl/source/gdi/mtfxmldump.cxx @@ -226,6 +226,19 @@ OUString convertFontWeightToString(FontWeight eFontWeight) return OUString(); } +OUString convertFontItalicToString(FontItalic eFontItalic) +{ + switch (eFontItalic) + { + case ITALIC_DONTKNOW: return u"unknown"_ustr; + case ITALIC_OBLIQUE: return u"oblique"_ustr; + case ITALIC_NORMAL: return u"normal"_ustr; + case ITALIC_NONE: return u"none"_ustr; + case FontItalic_FORCE_EQUAL_SIZE: return u"equalsize"_ustr; + } + return OUString(); +} + OUString convertFontStrikeoutToString(FontStrikeout eFontStrikeout) { switch (eFontStrikeout) @@ -1332,6 +1345,7 @@ void MetafileXmlDump::writeXml(const GDIMetaFile& rMetaFile, tools::XmlWriter& r rWriter.attribute("height", aFont.GetFontSize().Height()); rWriter.attribute("orientation", aFont.GetOrientation().get()); rWriter.attribute("weight", convertFontWeightToString(aFont.GetWeightMaybeAskConfig())); + rWriter.attribute("italic", convertFontItalicToString(aFont.GetItalicMaybeAskConfig())); rWriter.attribute("vertical", aFont.IsVertical() ? "true" : "false"); rWriter.attribute("emphasis", aFont.GetEmphasisMark() != FontEmphasisMark::NONE ? "true" : "false"); rWriter.attribute("shadow", aFont.IsShadow() ? "true" : "false");
