sw/qa/extras/layout/data/tdf159085.fodt |   61 ++++++++++++++++++++++++++++++++
 sw/qa/extras/layout/layout3.cxx         |   24 ++++++++++++
 sw/source/core/text/portxt.cxx          |    9 ++++
 3 files changed, 93 insertions(+), 1 deletion(-)

New commits:
commit d511367c102ef2ada0f73dbe81744d39865d58ba
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Tue Jan 9 13:35:23 2024 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue Jan 9 20:03:00 2024 +0100

    tdf#195085 sw smart justify: fix bad shrinking at soft hyphen
    
    Soft hyphen in the word could result too much shrinking,
    calculating with an extra (non-existing) space.
    
    Change-Id: If8b7af40ff50d12c0f2428a6f2475e261fbd0f42
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161827
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/layout/data/tdf159085.fodt 
b/sw/qa/extras/layout/data/tdf159085.fodt
new file mode 100644
index 000000000000..efd0e98e9213
--- /dev/null
+++ b/sw/qa/extras/layout/data/tdf159085.fodt
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:c
 alcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext: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:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:
 meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:settings>
+  <config:config-item-set config:name="ooo:configuration-settings">
+   <config:config-item config:name="JustifyLinesWithShrinking" 
config:type="boolean">true</config:config-item>
+   <config:config-item config:name="PrinterIndependentLayout" 
config:type="string">high-resolution</config:config-item>
+  </config:config-item-set>
+ </office:settings>
+ <office:font-face-decls>
+  <style:font-face style:name="Arial" svg:font-family="Arial" 
style:font-family-generic="swiss"/>
+  <style:font-face style:name="Arial1" svg:font-family="Arial" 
style:font-family-generic="system" style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:styles>
+  <style:default-style style:family="paragraph">
+   <style:paragraph-properties fo:hyphenation-ladder-count="no-limit" 
style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" 
style:line-break="strict" style:tab-stop-distance="36pt" 
style:writing-mode="page"/>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Calibri" fo:font-size="10pt" 
fo:language="en" fo:country="US" style:letter-kerning="false" 
style:font-name-asian="MS Mincho" style:font-size-asian="10pt" 
style:language-asian="en" style:country-asian="US" 
style:font-name-complex="Calibri1" style:font-size-complex="10pt" 
style:language-complex="ar" style:country-complex="SA" fo:hyphenate="false" 
fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2" 
loext:hyphenation-no-caps="false" loext:hyphenation-no-last-word="false" 
loext:hyphenation-word-char-count="5" loext:hyphenation-zone="no-limit"/>
+  </style:default-style>
+  <style:default-style style:family="table">
+   <style:table-properties table:border-model="collapsing"/>
+  </style:default-style>
+  <style:default-style style:family="table-row">
+   <style:table-row-properties fo:keep-together="auto"/>
+  </style:default-style>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text">
+   <style:paragraph-properties fo:margin-top="0pt" fo:margin-bottom="0pt" 
style:contextual-spacing="false" fo:text-align="start" 
style:justify-single-word="false" fo:orphans="2" fo:widows="2" 
style:writing-mode="lr-tb"/>
+   <style:text-properties style:font-name="Arial" fo:font-family="Arial" 
style:font-family-generic="swiss" fo:font-size="12pt" fo:language="en" 
fo:country="GB" style:font-name-asian="Times New Roman1" 
style:font-family-asian="&apos;Times New Roman&apos;" 
style:font-family-generic-asian="system" style:font-pitch-asian="variable" 
style:font-size-asian="12pt" style:font-name-complex="Arial1" 
style:font-family-complex="Arial" style:font-family-generic-complex="system" 
style:font-pitch-complex="variable" style:font-size-complex="12pt"/>
+  </style:style>
+ </office:styles>
+ <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:text-properties officeooo:paragraph-rsid="0018cb95"/>
+  </style:style>
+  <style:style style:name="T1" style:family="text">
+   <style:text-properties fo:font-size="10pt" fo:language="es" fo:country="ES" 
style:font-size-asian="10pt" style:font-size-complex="10pt"/>
+  </style:style>
+  <style:style style:name="T2" style:family="text">
+   <style:text-properties fo:font-size="10pt" fo:language="es" fo:country="ES" 
officeooo:rsid="001a9d3d" style:font-size-asian="10pt" 
style:font-size-complex="10pt"/>
+  </style:style>
+  <style:style style:name="T3" style:family="text">
+   <style:text-properties fo:font-size="10pt" style:font-size-asian="10pt" 
style:font-size-complex="10pt"/>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="419.56pt" 
fo:page-height="595.3pt" style:num-format="1" 
style:print-orientation="portrait" fo:margin-top="21.6pt" 
fo:margin-bottom="14.4pt" fo:margin-left="36pt" fo:margin-right="36pt" 
style:writing-mode="lr-tb" style:layout-grid-color="#c0c0c0" 
style:layout-grid-lines="31" style:layout-grid-base-height="18pt" 
style:layout-grid-ruby-height="0pt" style:layout-grid-mode="none" 
style:layout-grid-ruby-below="false" style:layout-grid-print="false" 
style:layout-grid-display="false" style:layout-grid-base-width="10.46pt" 
style:layout-grid-snap-to="true" style:footnote-max-height="0pt" 
loext:margin-gutter="0pt">
+    <style:footnote-sep style:width="0.51pt" 
style:distance-before-sep="2.86pt" style:distance-after-sep="2.86pt" 
style:line-style="solid" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style/>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1" 
draw:style-name="dp1"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:p text:style-name="P1" loext:marker-style-name="T3"><text:span 
text:style-name="T1">venenatis, quis commodo dolor posuere. Curabitur dignissim 
sapien quis cur­sus egestas.</text:span></text:p>
+   <text:p text:style-name="P1" loext:marker-style-name="T3"><text:span 
text:style-name="T1">venenatis, quis commodo dolor posuere. Curabitur dignissim 
sapien quis cur</text:span><text:span 
text:style-name="T2">­</text:span><text:span text:style-name="T1">sus 
egestas.</text:span></text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index da882cba559d..e4bfc5195b4b 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -246,6 +246,30 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158333)
                 "venenatis, quis commodo dolor posuere. Curabitur dignissim 
sapien quis ");
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159085)
+{
+    createSwDoc("tdf159085.fodt");
+    // Ensure that all text portions are calculated before testing.
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    SwViewShell* pViewShell
+        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    CPPUNIT_ASSERT(pViewShell);
+    pViewShell->Reformat();
+
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+    // This was "... cursus" instead of breaking the word at soft hyphen
+    assertXPath(
+        pXmlDoc, "/root/page/body/txt[1]/SwParaPortion/SwLineLayout[1]"_ostr, 
"portion"_ostr,
+        u"venenatis, quis commodo dolor posuere. Curabitur dignissim sapien 
quis cur­"_ustr);
+
+    // This was "... cursus" instead of breaking the word at soft hyphen
+    assertXPath(
+        pXmlDoc, "/root/page/body/txt[2]/SwParaPortion/SwLineLayout[1]"_ostr, 
"portion"_ostr,
+        u"venenatis, quis commodo dolor posuere. Curabitur dignissim sapien 
quis cur­"_ustr);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158419)
 {
     createSwDoc("tdf130088.docx");
diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx
index 228e2e02e4d6..38e2e2af61a8 100644
--- a/sw/source/core/text/portxt.cxx
+++ b/sw/source/core/text/portxt.cxx
@@ -325,7 +325,14 @@ bool SwTextPortion::Format_( SwTextFormatInfo &rInf )
 
         // call with an extra space: shrinking can result a new word in the 
line
         // and a new space before that, which is also a shrank space
-        bFull = !aGuess.Guess( *this, rInf, Height(), nSpacesInLine + 1 );
+        // (except if the line was already broken at a soft hyphen, i.e. 
inside a word)
+        if ( aGuess.BreakPos() < TextFrameIndex(rInf.GetText().getLength()) &&
+             rInf.GetText()[sal_Int32(aGuess.BreakPos())] != CHAR_SOFTHYPHEN )
+        {
+            ++nSpacesInLine;
+        }
+
+        bFull = !aGuess.Guess( *this, rInf, Height(), nSpacesInLine );
     }
 
     // these are the possible cases:

Reply via email to