sw/qa/extras/rtfimport/data/tdf44986.rtf         |   35 +++++++++++++++++++++++
 sw/qa/extras/rtfimport/rtfimport.cxx             |   10 ++++++
 writerfilter/source/rtftok/rtfdispatchsymbol.cxx |   10 ++++++
 writerfilter/source/rtftok/rtfdispatchvalue.cxx  |    3 +
 writerfilter/source/rtftok/rtfdocumentimpl.cxx   |    8 ++++-
 writerfilter/source/rtftok/rtfdocumentimpl.hxx   |    3 +
 6 files changed, 68 insertions(+), 1 deletion(-)

New commits:
commit 0f2d5db38bac64b665c6e4a127bbbd63a7ed9af5
Author: Miklos Vajna <vmik...@collabora.co.uk>
Date:   Tue Sep 6 08:16:37 2016 +0200

    tdf#44986 RTF import: handle \trwWidthA by faking cells
    
    The DOCX import handles this at a tokenizer level, so let's do the same
    in the RTF case as well.
    
    Change-Id: Id7ff43fa9e9bcd05b13d187623d39fb072758057
    Reviewed-on: https://gerrit.libreoffice.org/28679
    Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk>
    Tested-by: Jenkins <c...@libreoffice.org>

diff --git a/sw/qa/extras/rtfimport/data/tdf44986.rtf 
b/sw/qa/extras/rtfimport/data/tdf44986.rtf
new file mode 100644
index 0000000..d255e10
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/tdf44986.rtf
@@ -0,0 +1,35 @@
+{\rtf1
+\pard\plain \ltrpar\ql 
\li0\ri0\widctlpar\wrapdefault\nooverflow\faroman\rin0\lin0\itap0\pararsid8937578
 \rtlch\fcs1
+\af0\afs20\alang1025 \ltrch\fcs0 
\fs20\lang1031\langfe1031\cgrid\langnp1031\langfenp1031
+{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid7962097 before}
+{\rtlch\fcs1 \ab\af0 \ltrch\fcs0 \b\insrsid11416584
+\par \ltrrow}
+\trowd 
\irow0\irowband0\ltrrow\ts11\trgaph70\trleft-144\trkeep\trbrdrt\brdrs\brdrw15 
\trbrdrl\brdrs\brdrw15 \trbrdrb\brdrs\brdrw15 \trbrdrr\brdrs\brdrw15
+\trftsWidth1\trftsWidthB3\trftsWidthA3\trwWidthA6237\trpaddl70\trpaddr70\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblind-74\tblindtype3
 \clvertalt\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrnone 
\clbrdrr\brdrs\brdrw15
+\cltxlrtb\clftsWidth3\clwWidth3405\clshdrawnil \cellx3261\pard\plain 
\ltrpar\ql \li0\ri0\widctlpar\intbl\wrapdefault\nooverflow\faroman\rin0\lin0 
\rtlch\fcs1 \af0\afs20\alang1025 \ltrch\fcs0 
\fs20\lang1031\langfe1031\cgrid\langnp1031\langfenp1031
+{
+\rtlch\fcs1 \af4\afs16 \ltrch\fcs0 
\fs16\loch\af4\hich\af4\dbch\af31505\insrsid15290907\charrsid14246932 
\hich\af4\dbch\af31505\loch\f4 A1}
+{\rtlch\fcs1 \af4 \ltrch\fcs0 
\loch\af4\hich\af4\dbch\af31505\insrsid11416584\charrsid14246932 \cell
+}
+\pard\plain \ltrpar\ql 
\li0\ri0\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0
 \rtlch\fcs1 \af0\afs20\alang1025 \ltrch\fcs0 
\fs20\lang1031\langfe1031\cgrid\langnp1031\langfenp1031
+{\rtlch\fcs1 \af0 \ltrch\fcs0
+\insrsid11416584\charrsid14246932 \trowd 
\irow0\irowband0\ltrrow\ts11\trgaph70\trleft-144\trkeep\trbrdrt\brdrs\brdrw15 
\trbrdrl\brdrs\brdrw15 \trbrdrb\brdrs\brdrw15 \trbrdrr\brdrs\brdrw15
+\trftsWidth1\trftsWidthB3\trftsWidthA3\trwWidthA6237\trpaddl70\trpaddr70\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblind-74\tblindtype3
 \clvertalt\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrnone 
\clbrdrr\brdrs\brdrw15
+\cltxlrtb\clftsWidth3\clwWidth3405\clshdrawnil \cellx3261\row \ltrrow}
+\trowd \irow1\irowband1\lastrow 
\ltrrow\ts11\trgaph70\trleft-144\trbrdrt\brdrs\brdrw15 \trbrdrl\brdrs\brdrw15 
\trbrdrb\brdrs\brdrw15 \trbrdrr\brdrs\brdrw15
+\trftsWidth1\trftsWidthB3\trpaddl70\trpaddr70\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblind-74\tblindtype3
 \clvertalt\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrnone 
\clbrdrr\brdrs\brdrw15 \cltxlrtb\clftsWidth3\clwWidth9642\clshdrawnil
+\cellx9498\pard\plain \ltrpar\ql 
\li0\ri0\widctlpar\intbl\wrapdefault\nooverflow\faroman\rin0\lin0 \rtlch\fcs1 
\af0\afs20\alang1025 \ltrch\fcs0 
\fs20\lang1031\langfe1031\cgrid\langnp1031\langfenp1031
+{\rtlch\fcs1 \af1\afs16 \ltrch\fcs0
+\fs16\loch\af1\hich\af1\dbch\af31505\insrsid15290907\charrsid14246932 
\hich\af1\dbch\af31505\loch\f1 A2}
+{\rtlch\fcs1 \af1\afs16 \ltrch\fcs0 
\fs16\loch\af1\hich\af1\dbch\af31505\insrsid11416584\charrsid14246932 \cell }
+\pard\plain \ltrpar
+\ql 
\li0\ri0\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0
 \rtlch\fcs1 \af0\afs20\alang1025 \ltrch\fcs0 
\fs20\lang1031\langfe1031\cgrid\langnp1031\langfenp1031
+{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid11416584\charrsid14246932
+\trowd \irow1\irowband1\lastrow 
\ltrrow\ts11\trgaph70\trleft-144\trbrdrt\brdrs\brdrw15 \trbrdrl\brdrs\brdrw15 
\trbrdrb\brdrs\brdrw15 \trbrdrr\brdrs\brdrw15
+\trftsWidth1\trftsWidthB3\trpaddl70\trpaddr70\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblind-74\tblindtype3
 \clvertalt\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrnone 
\clbrdrr\brdrs\brdrw15 \cltxlrtb\clftsWidth3\clwWidth9642\clshdrawnil
+\cellx9498\row }
+\pard \ltrpar\ql 
\li0\ri0\widctlpar\wrapdefault\nooverflow\faroman\rin0\lin0\itap0\pararsid8937578
+{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid7962097 after}
+{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid14246932
+\par }
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx 
b/sw/qa/extras/rtfimport/rtfimport.cxx
index f607168..9f6f137 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -2684,6 +2684,16 @@ DECLARE_RTFIMPORT_TEST(testTdf100507, "tdf100507.rtf")
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6618), 
getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin"));
 }
 
+DECLARE_RTFIMPORT_TEST(testTdf44986, "tdf44986.rtf")
+{
+    // Check that the table at the second paragraph.
+    uno::Reference<text::XTextTable> xTable(getParagraphOrTable(2), 
uno::UNO_QUERY);
+    uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), 
uno::UNO_QUERY);
+    // Check the first row of the table, it should have two cells (one 
separator).
+    // This was 0: the first row had no separators, so it had only one cell, 
which was too wide.
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty< 
uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), 
"TableColumnSeparators").getLength());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdispatchsymbol.cxx 
b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
index 218810b..2a4154b 100644
--- a/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
@@ -229,6 +229,16 @@ RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword 
nKeyword)
     break;
     case RTF_ROW:
     {
+        if (m_aStates.top().nTableRowWidthAfter > 0)
+        {
+            // Add fake cellx / cell, RTF equivalent of
+            // OOXMLFastContextHandlerTextTableRow::handleGridAfter().
+            auto pXValue = 
std::make_shared<RTFValue>(m_aStates.top().nTableRowWidthAfter);
+            
m_aStates.top().aTableRowSprms.set(NS_ooxml::LN_CT_TblGridBase_gridCol, 
pXValue, RTFOverwrite::NO_APPEND);
+            dispatchSymbol(RTF_CELL);
+            m_aStates.top().nTableRowWidthAfter = 0;
+        }
+
         bool bRestored = false;
         // Ending a row, but no cells defined?
         // See if there was an invalid table row reset, so we can restore cell 
infos to help invalid documents.
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx 
b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index 30621f9..0a77075 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -1403,6 +1403,9 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword 
nKeyword, int nParam)
     case RTF_DIBITMAP:
         m_aStates.top().aPicture.eStyle = RTFBmpStyle::DIBITMAP;
         break;
+    case RTF_TRWWIDTHA:
+        m_aStates.top().nTableRowWidthAfter = nParam;
+        break;
     default:
     {
         SAL_INFO("writerfilter", "TODO handle value '" << 
keywordToString(nKeyword) << "'");
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx 
b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index b011373..0dd4fc9 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -3057,6 +3057,11 @@ RTFError RTFDocumentImpl::popState()
             replayBuffer(m_aSuperBuffer, nullptr, nullptr);
     }
 
+    if (!m_aStates.empty() && m_aStates.top().nTableRowWidthAfter > 0 && 
aState.nTableRowWidthAfter == 0)
+        // An RTF_ROW in the inner group already parsed nTableRowWidthAfter,
+        // don't do it again in the outer state later.
+        m_aStates.top().nTableRowWidthAfter = 0;
+
     return RTFError::OK;
 }
 
@@ -3225,7 +3230,8 @@ RTFParserState::RTFParserState(RTFDocumentImpl* 
pDocumentImpl)
       bInShapeGroup(false),
       bInShape(false),
       bCreatedShapeGroup(false),
-      bStartedTrackchange(false)
+      bStartedTrackchange(false),
+      nTableRowWidthAfter(0)
 {
 }
 
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx 
b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 50fc298..f2294aa 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -314,6 +314,9 @@ public:
     OUString aPropName;
     /// User-defined property: value type.
     css::uno::Type aPropType;
+
+    /// Width of invisible cell at the end of the row.
+    int nTableRowWidthAfter;
 };
 
 /// An RTF stack is similar to std::stack, except that it has an operator[].
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to