sw/qa/extras/uiwriter/uiwriter7.cxx |   19 ++++++++++++++-----
 sw/source/core/text/itrform2.cxx    |   13 ++++++++-----
 2 files changed, 22 insertions(+), 10 deletions(-)

New commits:
commit b345858e92351ceb997cf8e77024d7fe573a99c6
Author:     Mark Hung <mark...@gmail.com>
AuthorDate: Sat Jun 11 19:52:28 2022 +0800
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jun 16 21:15:29 2022 +0200

    tdf#149089 snap to grid if IsSnapToChars() is false
    
    for non-CJK scripts. Non Asian text was centered within as many cells
    as required according to ODF1.2 20.301. But it also required that
    text should be snapped to grid if style:layout-grid-snap-to is
    true ( i.e. IsSnapToChars() is false ) per ODF1.2 20.305. That means
    ODF1.2 20.301 ruled.
    
    This patch changes the width of inserted SwKernGridPortion so that
    non-CJK text aligns to the edge of text grid to make ODF1.2 20.301
    rule, an provide more consistent layout result as expected.
    
    Change-Id: Id6b4d2b965e20670eb9ddf657d36b8a49073f32a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135654
    Tested-by: Jenkins
    Reviewed-by: Mark Hung <mark...@gmail.com>
    (cherry picked from commit 47eff9bf12abf963907b4d3dcb90b73e0ccc646d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135984
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/extras/uiwriter/uiwriter7.cxx 
b/sw/qa/extras/uiwriter/uiwriter7.cxx
index 8b5a23d1a695..0ac6b0183068 100644
--- a/sw/qa/extras/uiwriter/uiwriter7.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter7.cxx
@@ -2779,11 +2779,20 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf149089)
 {
     createSwDoc(DATA_DIRECTORY, "tdf149089.odt");
     xmlDocUniquePtr pXmlDoc = parseLayoutDump();
-    sal_Int32 nTextPortionWidth = getXPath(pXmlDoc, "(//SwLinePortion)[1]", 
"width").toInt32();
-    sal_Int32 nKernPortionWidth = getXPath(pXmlDoc, "(//SwLinePortion)[2]", 
"width").toInt32();
-    // nKernPortionWidth was about 1/3 of nTextPortionWidth
-    double nRatio = double(nKernPortionWidth) / nTextPortionWidth;
-    CPPUNIT_ASSERT_LESS(0.05, nRatio);
+    sal_Int32 nPorLen1 = getXPath(pXmlDoc, "(//SwLinePortion)[1]", 
"length").toInt32();
+    sal_Int32 nPorLen2 = getXPath(pXmlDoc, "(//SwLinePortion)[2]", 
"length").toInt32();
+    sal_Int32 nPorLen3 = getXPath(pXmlDoc, "(//SwLinePortion)[3]", 
"length").toInt32();
+    // Two SwTextPortion and one SwKernPortion
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3), nPorLen1); // SwTextPortion 
"&#x4E00;&#x4E00; "
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(12), nPorLen2); // SwTextPortion "BUG 
11111111"
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nPorLen3); // SwKernPortion
+
+    sal_Int32 nPorWidth1 = getXPath(pXmlDoc, "(//SwLinePortion)[1]", 
"width").toInt32();
+    sal_Int32 nPorWidth2 = getXPath(pXmlDoc, "(//SwLinePortion)[2]", 
"width").toInt32();
+    sal_Int32 nPorWidth3 = getXPath(pXmlDoc, "(//SwLinePortion)[3]", 
"width").toInt32();
+    sal_Int32 nGridWidth1 = nPorWidth1 / 3;
+    sal_Int32 nGridWidth2 = (nPorWidth2 + nPorWidth3) / 7;
+    CPPUNIT_ASSERT_EQUAL(nGridWidth1, nGridWidth2);
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index e7bcde5983b8..563ddd5c4c02 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -686,15 +686,18 @@ void SwTextFormatter::BuildPortions( SwTextFormatInfo 
&rInf )
                                  0;
                 const SwTwips nTmpWidth = i * nGridWidth;
                 const SwTwips nKernWidth = std::min(nTmpWidth - nSumWidth, 
nRestWidth);
-                const SwTwips nKernWidth_1 = nKernWidth / 2;
+                const SwTwips nKernWidth_1 = pGrid->IsSnapToChars() ?
+                    nKernWidth / 2 : 0;
 
                 OSL_ENSURE( nKernWidth <= nRestWidth,
                         "Not enough space left for adjusting non-asian text in 
grid mode" );
+                if (nKernWidth_1)
+                {
+                    pGridKernPortion->Width( pGridKernPortion->Width() + 
nKernWidth_1 );
+                    rInf.X( rInf.X() + nKernWidth_1 );
+                }
 
-                pGridKernPortion->Width( pGridKernPortion->Width() + 
nKernWidth_1 );
-                rInf.X( rInf.X() + nKernWidth_1 );
-
-                if ( ! bFull )
+                if ( ! bFull && nKernWidth - nKernWidth_1 > 0 )
                     new SwKernPortion( *pPor, static_cast<short>(nKernWidth - 
nKernWidth_1),
                                        false, true );
 

Reply via email to