[Libreoffice-commits] core.git: sw/qa sw/source writerfilter/source

Mike Kaganski mike.kaganski at collabora.com
Mon Dec 11 11:00:36 UTC 2017


 sw/qa/extras/rtfexport/data/tdf114333.rtf        |    5 +++++
 sw/qa/extras/rtfexport/data/tdf97035.rtf         |    2 +-
 sw/qa/extras/rtfexport/rtfexport2.cxx            |    4 ++--
 sw/qa/extras/rtfexport/rtfexport3.cxx            |   12 ++++++++++++
 sw/qa/extras/rtfimport/rtfimport.cxx             |    2 +-
 sw/source/filter/ww8/rtfattributeoutput.cxx      |   21 +--------------------
 writerfilter/source/rtftok/rtfdispatchsymbol.cxx |    5 +++--
 writerfilter/source/rtftok/rtfdispatchvalue.cxx  |    8 ++++++++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx   |    8 ++++++++
 writerfilter/source/rtftok/rtfdocumentimpl.hxx   |    4 ++++
 10 files changed, 45 insertions(+), 26 deletions(-)

New commits:
commit 0f9a596aa853b4f2beeff25c131246a7b31492a4
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Fri Dec 8 17:52:56 2017 +0300

    tdf#114333: consider trleft for 1st cell width on import; don't...
    
    ... recalculate cell widths by factor pagewidth/tablewidth on export
    This makes the import and export symmetrical.
    
    Unit test included.
    
    Some existing unit tests were updated:
    - testTdf97035: the previous width of B1 cell (3571 twips) was not
    stable enough on round-trip. Old code saved table with wrong width,
    and incidentally that made it to output correct width of the cell.
    New code outputs table width correctly, and drops unneeded cell width
    adjustment on export, so the rounding error on initial import makes
    output cell width wrong.
    We have a cumbersome arithmetics to import cell widths from RTF:
    1. In DomainMapperTableManager::sprm (case NS_ooxml::LN_CT_TblGridBase_gridCol)
    we do convertTwipToMM100 on initial sizes in twips;
    2. Then, in DomainMapperTableManager::endOfRowAction, we do
    rtl::math::round((fGridWidth * 10000) / nFullWidthRelative) on the
    mm100 sizes (the 10000 is UNO_TABLE_COLUMN_SUM from unotbl.cxx, which
    allows to measure cell widths in 100ths of percent of table's width
    instead of absolute sizes)
    3. Last, in SwTable::NewSetTabCols, we do
    lcl_MulDiv64<long>(nNewPos, rParm.nNewWish, nNewWidth)
    where rParm.nNewWish is table's width in twips (again), and nNewWidth
    is 10000. So, the three permutations give us twips back, but rounding
    errors may make result differ from initial value (as in case of cell
    width 1927 twips and table width 15527 twips, which results in 1926).
    
    The unstable width that resulted in roundtrip error was changed by 1.
    The changed unit test file is checked to still correctly test tdf#97035
    
    - testFdo55525: previously, the testdoc was imported with wrong width
    (too narrow); that caused rounding error on cell width calculation.
    Current tested value is more correct.
    
    Change-Id: I69112521c35b316ed6df11d5e4ff7336534164bd
    Reviewed-on: https://gerrit.libreoffice.org/46094
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/qa/extras/rtfexport/data/tdf114333.rtf b/sw/qa/extras/rtfexport/data/tdf114333.rtf
new file mode 100644
index 000000000000..3c2097575aed
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf114333.rtf
@@ -0,0 +1,5 @@
+{\rtf1
+\trowd\trleft4820\cellx9638
+aaa\cell
+\row
+\par }
\ No newline at end of file
diff --git a/sw/qa/extras/rtfexport/data/tdf97035.rtf b/sw/qa/extras/rtfexport/data/tdf97035.rtf
index a8f1d8a43e81..da0112436112 100644
--- a/sw/qa/extras/rtfexport/data/tdf97035.rtf
+++ b/sw/qa/extras/rtfexport/data/tdf97035.rtf
@@ -125,7 +125,7 @@
 }
 }\f3 \li0 \strike0 \ul0 \b0 \ql \fs16 \ri0 \cf1 \i0 \intbl \cell \row }}{
 {\trowd \itap0 \trleft0 
-\clpadt60 \clpadft3 \clpadr60 \clpadfr3 \clbrdrl \trql \clvertalc \cellx3571 
+\clpadt60 \clpadft3 \clpadr60 \clpadfr3 \clbrdrl \trql \clvertalc \cellx3572 
 \clpadt60 \clpadft3 \clpadr60 \clpadfr3 \trql \clvertalc \cellx15418 
 \intbl 
 {\li0 \f3 \b0 \ql \ri0 \fs20 \cf1 \i0 
diff --git a/sw/qa/extras/rtfexport/rtfexport2.cxx b/sw/qa/extras/rtfexport/rtfexport2.cxx
index 99a8ed9abd4a..60032e92a145 100644
--- a/sw/qa/extras/rtfexport/rtfexport2.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport2.cxx
@@ -1838,9 +1838,9 @@ DECLARE_RTFEXPORT_TEST(testTdf97035, "tdf97035.rtf")
                                                     uno::UNO_QUERY);
     uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
 
-    // First cell width of the second row should be 2299
+    // First cell width of the second row should be 2300
     uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(sal_Int16(2299), getProperty<uno::Sequence<text::TableColumnSeparator>>(
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(2300), getProperty<uno::Sequence<text::TableColumnSeparator>>(
                                               xTableRows->getByIndex(1), "TableColumnSeparators")[0]
                                               .Position);
 }
diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx b/sw/qa/extras/rtfexport/rtfexport3.cxx
index 0c63f23972e0..c8941ed26633 100644
--- a/sw/qa/extras/rtfexport/rtfexport3.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport3.cxx
@@ -68,6 +68,18 @@ DECLARE_RTFEXPORT_TEST(testTdf104035, "tdf104035.rtf")
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(convertTwipToMm100(450)), aTabStops[0].Position);
 }
 
+DECLARE_RTFEXPORT_TEST(testTdf114333, "tdf114333.rtf")
+{
+    uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
+                                                    uno::UNO_QUERY);
+    uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
+    // Check the distance from left
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(8502), getProperty<sal_Int32>(xTable, "LeftMargin"));
+    // This was 17000 = 8502 + 8498 on import, 15240 on export and following import
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(8498), getProperty<sal_Int32>(xTable, "Width"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 2b1127a135d5..8f6d767f96a6 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -444,7 +444,7 @@ DECLARE_RTFIMPORT_TEST(testFdo55525, "fdo55525.rtf")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(-1877), getProperty<sal_Int32>(xTable, "LeftMargin"));
     // Cell width of A1 was 3332 (e.g. not set, 30% percent of total width)
     uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(sal_Int16(896), getProperty<uno::Sequence<text::TableColumnSeparator>>(
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(897), getProperty<uno::Sequence<text::TableColumnSeparator>>(
                                              xTableRows->getByIndex(0), "TableColumnSeparators")[0]
                                              .Position);
 }
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index ae9bc3f7efb3..59c64b82d9fc 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -724,23 +724,7 @@ void RtfAttributeOutput::TableDefinition(
     const SwWriteTableRows& aRows = m_pTableWrt->GetRows();
     SwWriteTableRow* pRow = aRows[pTableTextNodeInfoInner->getRow()];
     SwTwips nSz = 0;
-    Point aPt;
-    SwRect aRect(pFormat->FindLayoutRect(false, &aPt));
-    SwTwips nPageSize = aRect.Width();
 
-    // Handle the page size when not rendered
-    if (0 == nPageSize)
-    {
-        const SwNode* pNode = pTableTextNodeInfoInner->getNode();
-        const SwFrameFormat* pFrameFormat
-            = GetExport().m_pParentFrame
-                  ? &GetExport().m_pParentFrame->GetFrameFormat()
-                  : GetExport().m_pDoc->GetPageDesc(0).GetPageFormatOfNode(*pNode, false);
-
-        const SvxLRSpaceItem& rLR = pFrameFormat->GetLRSpace();
-        nPageSize = pFrameFormat->GetFrameSize().GetWidth() - rLR.GetLeft() - rLR.GetRight();
-    }
-    SwTwips nTableSz = pFormat->GetFrameSize().GetWidth();
     // Not using m_nTableDepth, which is not yet incremented here.
     sal_uInt32 nCurrentDepth = pTableTextNodeInfoInner->getDepth();
     m_aCells[nCurrentDepth] = pRow->GetCells().size();
@@ -756,10 +740,7 @@ void RtfAttributeOutput::TableDefinition(
         // value of nSz is needed.
         nSz += pCellFormat->GetFrameSize().GetWidth();
         m_aRowDefs.append(OOO_STRING_SVTOOLS_RTF_CELLX);
-        SwTwips nCalc = nSz;
-        nCalc *= nPageSize;
-        nCalc /= nTableSz;
-        m_aRowDefs.append((sal_Int32)(pFormat->GetLRSpace().GetLeft() + nCalc));
+        m_aRowDefs.append((sal_Int32)(pFormat->GetLRSpace().GetLeft() + nSz));
     }
 }
 
diff --git a/writerfilter/source/rtftok/rtfdispatchsymbol.cxx b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
index 8e76355ce945..e5ae836bb206 100644
--- a/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
@@ -199,7 +199,8 @@ RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
                 new TableRowBuffer(m_aTableBufferStack.back(), m_aNestedTableCellsSprms,
                                    m_aNestedTableCellsAttributes, m_nNestedCells));
             prepareProperties(m_aStates.top(), pBuffer->pParaProperties, pBuffer->pFrameProperties,
-                              pBuffer->pRowProperties, m_nNestedCells, m_nNestedCurrentCellX);
+                              pBuffer->pRowProperties, m_nNestedCells,
+                              m_nNestedCurrentCellX - m_nNestedTRLeft);
 
             if (m_aTableBufferStack.size() == 1 || !m_aStates.top().pCurrentBuffer)
             {
@@ -309,7 +310,7 @@ RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
             writerfilter::Reference<Properties>::Pointer_t frameProperties;
             writerfilter::Reference<Properties>::Pointer_t rowProperties;
             prepareProperties(m_aStates.top(), paraProperties, frameProperties, rowProperties,
-                              m_nTopLevelCells, m_nTopLevelCurrentCellX);
+                              m_nTopLevelCells, m_nTopLevelCurrentCellX - m_nTopLevelTRLeft);
             sendProperties(paraProperties, frameProperties, rowProperties);
 
             m_bNeedPap = true;
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index daaf9a44b969..a704bbdf2ffa 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -917,6 +917,14 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
                                std::make_shared<RTFValue>(NS_ooxml::LN_Value_ST_TblWidth_dxa));
             putNestedAttribute(m_aStates.top().aTableRowSprms, NS_ooxml::LN_CT_TblPrBase_tblInd,
                                NS_ooxml::LN_CT_TblWidth_w, std::make_shared<RTFValue>(nParam));
+            auto const aDestination = m_aStates.top().eDestination;
+            int& rCurrentTRLeft((Destination::NESTEDTABLEPROPERTIES == aDestination)
+                                    ? m_nNestedTRLeft
+                                    : m_nTopLevelTRLeft);
+            int& rCurrentCellX((Destination::NESTEDTABLEPROPERTIES == aDestination)
+                                   ? m_nNestedCurrentCellX
+                                   : m_nTopLevelCurrentCellX);
+            rCurrentTRLeft = rCurrentCellX = nParam;
         }
         break;
         case RTF_COLS:
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 9f53f85f0a07..3cd40f81d9c6 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -261,6 +261,8 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
     , m_nNestedCells(0)
     , m_nTopLevelCells(0)
     , m_nInheritingCells(0)
+    , m_nNestedTRLeft(0)
+    , m_nTopLevelTRLeft(0)
     , m_nNestedCurrentCellX(0)
     , m_nTopLevelCurrentCellX(0)
     , m_nBackupTopLevelCurrentCellX(0)
@@ -1670,9 +1672,15 @@ void RTFDocumentImpl::resetTableRowProperties()
                                        std::make_shared<RTFValue>(-1), RTFOverwrite::NO_APPEND);
     m_aStates.top().aTableRowAttributes = m_aDefaultState.aTableRowAttributes;
     if (Destination::NESTEDTABLEPROPERTIES == m_aStates.top().eDestination)
+    {
+        m_nNestedTRLeft = 0;
         m_nNestedCurrentCellX = 0;
+    }
     else
+    {
+        m_nTopLevelTRLeft = 0;
         m_nTopLevelCurrentCellX = 0;
+    }
 }
 
 RTFError RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam)
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 5988e03d6c63..e8d757c41959 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -552,6 +552,10 @@ private:
     std::deque<RTFSprms> m_aTableInheritingCellsSprms;
     std::deque<RTFSprms> m_aTableInheritingCellsAttributes;
 
+    // Left row margin (for nested and top-level rows)
+    int m_nNestedTRLeft;
+    int m_nTopLevelTRLeft;
+
     /// Current cellx value (nested table)
     int m_nNestedCurrentCellX;
     /// Current cellx value (top-level table)


More information about the Libreoffice-commits mailing list