[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - sw/qa writerfilter/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Feb 26 12:49:37 UTC 2019


 sw/qa/extras/rtfexport/data/tdf123393.rtf        |   14 +++++++++
 sw/qa/extras/rtfexport/rtfexport3.cxx            |   13 ++++++++
 writerfilter/source/rtftok/rtfdispatchsymbol.cxx |    4 +-
 writerfilter/source/rtftok/rtfdocumentimpl.cxx   |   35 +++++++++++++++--------
 writerfilter/source/rtftok/rtfdocumentimpl.hxx   |    5 +++
 5 files changed, 58 insertions(+), 13 deletions(-)

New commits:
commit bfc0eca6cfabfe6950de3345554318150a531d44
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Feb 25 21:38:48 2019 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Feb 26 13:49:15 2019 +0100

    tdf#123393 RTF import: fix too big font size in table cell
    
    The reason was that A2 had an explicit paragraph style reference, but A1
    did not, so table buffering caused A2 style to affect A1 style as well.
    
    Combine this with style deduplication, and then A2 style considered the
    direct formatting (font size) in A1 to be redundant, so it was lost on
    import.
    
    Fix the problem by moving the copy&pasted properties buffering to a
    single function, and there buffering not only the properties, but also
    the active style index.
    
    (cherry picked from commit b7dabb80f45a65713f114c61e1d695f3f8093812)
    
    Change-Id: I99f2020b8bef237849fd622b25ac5ef0516d69e4
    Reviewed-on: https://gerrit.libreoffice.org/68373
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/qa/extras/rtfexport/data/tdf123393.rtf b/sw/qa/extras/rtfexport/data/tdf123393.rtf
new file mode 100644
index 000000000000..381b038d314c
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf123393.rtf
@@ -0,0 +1,14 @@
+{\rtf1
+{\fonttbl
+{\f0 Times New Roman;}
+}
+{\stylesheet
+{\s0\fs20 Normal;}
+{\s31\fs14 Body Text 3;}
+}
+Before\par
+\trowd\cellx2694\cellx4678
+\pard\intbl\fs14 A1\cell
+\pard\intbl\s31\fs14 B1\cell\row
+\pard\plain After\par
+}
diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx b/sw/qa/extras/rtfexport/rtfexport3.cxx
index e4a069464335..576f7b6c85b8 100644
--- a/sw/qa/extras/rtfexport/rtfexport3.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport3.cxx
@@ -219,6 +219,19 @@ DECLARE_RTFEXPORT_TEST(testTdf122455, "tdf122455.rtf")
     CPPUNIT_ASSERT_EQUAL(16.0, getProperty<double>(getRun(getParagraph(1), 1), "CharHeight"));
 }
 
+DECLARE_RTFEXPORT_TEST(testTdf123393, "tdf123393.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);
+    uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
+    // Without the accompanying fix in place, this test would have failed with
+    // 'Expected: 7; Actual  : 10', i.e. font size was too large.
+    CPPUNIT_ASSERT_EQUAL(
+        7.f, getProperty<float>(getRun(getParagraphOfText(1, xCell->getText()), 1), "CharHeight"));
+}
+
 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 f7371ee7ac22..2603ebe22952 100644
--- a/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx
@@ -184,10 +184,10 @@ RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
                 // There were no runs in the cell, so we need to send paragraph and character properties here.
                 auto pPValue = new RTFValue(m_aStates.top().aParagraphAttributes,
                                             m_aStates.top().aParagraphSprms);
-                m_aTableBufferStack.back().emplace_back(Buf_t(BUFFER_PROPS, pPValue, nullptr));
+                bufferProperties(m_aTableBufferStack.back(), pPValue, nullptr);
                 auto pCValue = new RTFValue(m_aStates.top().aCharacterAttributes,
                                             m_aStates.top().aCharacterSprms);
-                m_aTableBufferStack.back().emplace_back(Buf_t(BUFFER_PROPS, pCValue, nullptr));
+                bufferProperties(m_aTableBufferStack.back(), pCValue, nullptr);
             }
 
             RTFValue::Pointer_t pValue;
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 16b4b7cff5cd..104e0e004bf6 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -570,7 +570,7 @@ void RTFDocumentImpl::checkNeedPap()
         {
             auto pValue = new RTFValue(m_aStates.top().aParagraphAttributes,
                                        m_aStates.top().aParagraphSprms);
-            m_aStates.top().pCurrentBuffer->push_back(Buf_t(BUFFER_PROPS, pValue, nullptr));
+            bufferProperties(*m_aStates.top().pCurrentBuffer, pValue, nullptr);
         }
     }
 }
@@ -588,7 +588,7 @@ void RTFDocumentImpl::runProps()
     {
         auto pValue
             = new RTFValue(m_aStates.top().aCharacterAttributes, m_aStates.top().aCharacterSprms);
-        m_aStates.top().pCurrentBuffer->push_back(Buf_t(BUFFER_PROPS, pValue, nullptr));
+        bufferProperties(*m_aStates.top().pCurrentBuffer, pValue, nullptr);
     }
 
     // Delete the sprm, so the trackchange range will be started only once.
@@ -1143,7 +1143,7 @@ void RTFDocumentImpl::resolvePict(bool const bInline, uno::Reference<drawing::XS
     else
     {
         auto pValue = new RTFValue(aAttributes, aSprms);
-        m_aStates.top().pCurrentBuffer->push_back(Buf_t(BUFFER_PROPS, pValue, nullptr));
+        bufferProperties(*m_aStates.top().pCurrentBuffer, pValue, nullptr);
     }
 }
 
@@ -1672,6 +1672,11 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer, RTFSprms* const pSprms,
         }
         else if (std::get<0>(aTuple) == BUFFER_PICTURE)
             m_aStates.top().aPicture = std::get<1>(aTuple)->getPicture();
+        else if (std::get<0>(aTuple) == BUFFER_SETSTYLE)
+        {
+            if (!m_aStates.empty())
+                m_aStates.top().nCurrentStyleIndex = std::get<1>(aTuple)->getInt();
+        }
         else
             assert(false);
     }
@@ -2121,7 +2126,7 @@ RTFError RTFDocumentImpl::popState()
             else
             {
                 auto pFFValue = new RTFValue(aFFAttributes, aFFSprms);
-                m_aStates.top().pCurrentBuffer->push_back(Buf_t(BUFFER_PROPS, pFFValue, nullptr));
+                bufferProperties(*m_aStates.top().pCurrentBuffer, pFFValue, nullptr);
             }
             m_aFormfieldAttributes.clear();
             m_aFormfieldSprms.clear();
@@ -2313,8 +2318,8 @@ RTFError RTFDocumentImpl::popState()
             if (!m_aStates.top().pCurrentBuffer)
                 Mapper().props(new RTFReferenceProperties(lcl_getBookmarkProperties(nPos, aStr)));
             else
-                m_aStates.top().pCurrentBuffer->push_back(Buf_t(
-                    BUFFER_PROPS, new RTFValue(lcl_getBookmarkProperties(nPos, aStr)), nullptr));
+                bufferProperties(*m_aStates.top().pCurrentBuffer,
+                                 new RTFValue(lcl_getBookmarkProperties(nPos, aStr)), nullptr);
         }
         break;
         case Destination::BOOKMARKEND:
@@ -2326,9 +2331,9 @@ RTFError RTFDocumentImpl::popState()
                 Mapper().props(new RTFReferenceProperties(
                     lcl_getBookmarkProperties(m_aBookmarks[aStr], aStr)));
             else
-                m_aStates.top().pCurrentBuffer->push_back(Buf_t(
-                    BUFFER_PROPS, new RTFValue(lcl_getBookmarkProperties(m_aBookmarks[aStr], aStr)),
-                    nullptr));
+                bufferProperties(*m_aStates.top().pCurrentBuffer,
+                                 new RTFValue(lcl_getBookmarkProperties(m_aBookmarks[aStr], aStr)),
+                                 nullptr);
         }
         break;
         case Destination::INDEXENTRY:
@@ -3030,8 +3035,8 @@ RTFError RTFDocumentImpl::popState()
         if (!m_aStates.top().pCurrentBuffer)
             Mapper().props(new RTFReferenceProperties(RTFSprms(), aTCSprms));
         else
-            m_aStates.top().pCurrentBuffer->push_back(
-                Buf_t(BUFFER_PROPS, new RTFValue(RTFSprms(), aTCSprms), nullptr));
+            bufferProperties(*m_aStates.top().pCurrentBuffer, new RTFValue(RTFSprms(), aTCSprms),
+                             nullptr);
     }
 
     // This is the end of the doc, see if we need to close the last section.
@@ -3459,6 +3464,14 @@ RTFParserState::RTFParserState(RTFDocumentImpl* pDocumentImpl)
 
 void RTFDocumentImpl::resetFrame() { m_aStates.top().aFrame = RTFFrame(&m_aStates.top()); }
 
+void RTFDocumentImpl::bufferProperties(RTFBuffer_t& rBuffer, const RTFValue::Pointer_t& pValue,
+                                       const tools::SvRef<TableRowBuffer>& pTableProperties)
+{
+    rBuffer.emplace_back(
+        Buf_t(BUFFER_SETSTYLE, new RTFValue(m_aStates.top().nCurrentStyleIndex), nullptr));
+    rBuffer.emplace_back(Buf_t(BUFFER_PROPS, pValue, pTableProperties));
+}
+
 RTFPicture::RTFPicture() = default;
 
 RTFShape::RTFShape() = default;
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 6fe21351c5c8..d51512889d74 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -76,6 +76,8 @@ enum class RTFBorderState
 /// Different kind of buffers for table cell contents.
 enum RTFBufferTypes
 {
+    BUFFER_SETSTYLE,
+    /// Stores properties, should be created only in bufferProperties().
     BUFFER_PROPS,
     BUFFER_NESTROW,
     BUFFER_CELLEND,
@@ -499,6 +501,9 @@ public:
     bool isStyleSheetImport();
     /// Resets m_aStates.top().aFrame.
     void resetFrame();
+    /// Buffers properties to be sent later.
+    void bufferProperties(RTFBuffer_t& rBuffer, const RTFValue::Pointer_t& pValue,
+                          const tools::SvRef<TableRowBuffer>& pTableProperties);
 
 private:
     SvStream& Strm();


More information about the Libreoffice-commits mailing list