sw/qa/extras/layout/data/tdf159050-wrap-adjust.fodt | 25 ++++++++++++++++++ sw/qa/extras/layout/layout3.cxx | 27 ++++++++++++++++++++ sw/source/core/text/porfly.cxx | 12 ++++++++ 3 files changed, 63 insertions(+), 1 deletion(-)
New commits: commit 3ab08b58cbac8be8bbd5d5a409b54e488b0e2c73 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Thu Jan 11 13:16:45 2024 +0600 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Thu Jan 11 13:15:31 2024 +0100 tdf#159050: let fly portion swallow hole portion width Change-Id: I65492418ca5f5f5b04e5f9bab9ac3e6bf2108aff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161910 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161919 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/extras/layout/data/tdf159050-wrap-adjust.fodt b/sw/qa/extras/layout/data/tdf159050-wrap-adjust.fodt new file mode 100644 index 000000000000..49d9e57071fb --- /dev/null +++ b/sw/qa/extras/layout/data/tdf159050-wrap-adjust.fodt @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:automatic-styles> + <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard"> + <style:paragraph-properties fo:text-align="justify" style:justify-single-word="false"/> + </style:style> + <style:style style:name="gr1" style:family="graphic"> + <style:graphic-properties draw:fill="solid" draw:fill-color="#ffff00" draw:opacity="50%" draw:textarea-horizontal-align="justify" draw:textarea-vertical-align="middle" draw:auto-grow-height="false" fo:min-height="0.7in" fo:min-width="0.7in" style:run-through="foreground" style:wrap="dynamic" style:number-wrapped-paragraphs="no-limit" style:wrap-contour="true" style:wrap-contour-mode="full" style:vertical-pos="from-top" style:vertical-rel="paragraph" style:horizontal-pos="from-left" style:horizontal-rel="paragraph"/> + </style:style> + <style:page-layout style:name="pm1"> + <style:page-layout-properties fo:page-width="8.5in" fo:page-height="11in" style:num-format="1" style:print-orientation="portrait" fo:margin-top="1in" fo:margin-bottom="1in" fo:margin-left="0.8in" fo:margin-right="0.8in" style:writing-mode="lr-tb"/> + </style:page-layout> + </office:automatic-styles> + <office:master-styles> + <style:master-page style:name="Standard" style:page-layout-name="pm1"/> + </office:master-styles> + <office:body> + <office:text> + <text:p text:style-name="P1"><draw:custom-shape text:anchor-type="paragraph" draw:z-index="0" draw:name="Shape 1" draw:style-name="gr1" svg:width="0.7in" svg:height="0.7in" svg:x="6.28in" svg:y="0in"> + <draw:enhanced-geometry svg:viewBox="0 0 21600 21600" draw:type="rectangle" draw:enhanced-path="M 0 0 L 21600 0 21600 21600 0 21600 0 0 Z N"/> + </draw:custom-shape>Pretium semper. Proin luctus orci ac neque venenatis, quis commodo dolor posuere. Curabitur dignissim</text:p> + </office:text> + </office:body> +</office:document> \ No newline at end of file diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx index e17eaa108a30..9a1d9b2fb7c5 100644 --- a/sw/qa/extras/layout/layout3.cxx +++ b/sw/qa/extras/layout/layout3.cxx @@ -2205,6 +2205,33 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf57187_Tdf158900) u"PortionType::Break"_ustr); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159050) +{ + // Given a document with a justified paragraph and a box with optimal wrapping + createSwDoc("tdf159050-wrap-adjust.fodt"); + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + // Make sure there is only one page, one anchored object, one paragraph, and two lines + assertXPath(pXmlDoc, "/root/page"_ostr, 1); + assertXPath(pXmlDoc, "/root/page/body/txt/anchored/SwAnchoredDrawObject"_ostr, 1); + assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion"_ostr, 1); + assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout"_ostr, 2); + + // Without the fix, this would fail: there was an unexpected second fly portion. + assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*"_ostr, 4); + assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[1]"_ostr, "type"_ostr, + u"PortionType::Text"_ustr); + assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[1]"_ostr, + "length"_ostr, u"91"_ustr); + assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[2]"_ostr, "type"_ostr, + u"PortionType::Hole"_ustr); + assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[2]"_ostr, + "length"_ostr, u"1"_ustr); + assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[3]"_ostr, "type"_ostr, + u"PortionType::Fly"_ustr); + assertXPath(pXmlDoc, "/root/page/body/txt/SwParaPortion/SwLineLayout[1]/*[4]"_ostr, "type"_ostr, + u"PortionType::Margin"_ustr); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/porfly.cxx b/sw/source/core/text/porfly.cxx index 7bee98d9821a..14d1bf6eaa8a 100644 --- a/sw/source/core/text/porfly.cxx +++ b/sw/source/core/text/porfly.cxx @@ -58,6 +58,16 @@ bool SwFlyPortion::Format( SwTextFormatInfo &rInf ) rInf.GetLastTab()->FormatEOL( rInf ); rInf.GetLast()->FormatEOL( rInf ); + + SetBlankWidth(0); + if (auto blankWidth = rInf.GetLast()->ExtraBlankWidth()) + { + // Swallow previous blank width + SetBlankWidth(blankWidth); + rInf.GetLast()->ExtraBlankWidth(0); + rInf.X(rInf.X() - blankWidth); // Step back + } + PrtWidth( o3tl::narrowing<sal_uInt16>(GetFix() - rInf.X() + PrtWidth()) ); if( !Width() ) { @@ -78,7 +88,7 @@ bool SwFlyPortion::Format( SwTextFormatInfo &rInf ) && ' ' != rInf.GetChar(rInf.GetIdx() - TextFrameIndex(1)) && ( !rInf.GetLast() || !rInf.GetLast()->IsBreakPortion() ) ) { - SetBlankWidth( rInf.GetTextSize(OUString(' ')).Width() ); + SetBlankWidth(GetBlankWidth() + rInf.GetTextSize(OUString(' ')).Width()); SetLen(TextFrameIndex(1)); }