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

Miklos Vajna vmiklos at collabora.co.uk
Tue Oct 31 13:19:52 UTC 2017


 sw/qa/extras/rtfexport/data/tdf113408.rtf      |   24 ++++++++++++++++++++++++
 sw/qa/extras/rtfexport/rtfexport.cxx           |    6 ++++++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   16 +++++++++-------
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |    2 +-
 4 files changed, 40 insertions(+), 8 deletions(-)

New commits:
commit 1970a686273c5d4fc1eeb4430283e37085d9f647
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Oct 31 09:48:33 2017 +0100

    tdf#113408 RTF import style dedup: separate paragraph and character handling
    
    The problem was that the paragraph in question had no left margin, while
    it should have one. The reason for this is that the style deduplication
    logic took both the current paragraph and character style, but the
    direct formatting only contained character formatting, so it tried to
    emit the default values for all paragraph formatting.
    
    This started to show up after commit
    657c6cc3acec0528209a8584b838cd6de581c437 (tdf#104228 RTF import: fix
    override of style left/right para margin, 2016-12-13), but the root
    cause is much older, it was there since commit
    321d7ec2071472b3765a00806715e7ad9f8a306f (fdo#82078 RTF import: fix bold
    text spilling over to non-bold text, 2014-09-06).
    
    Change-Id: If03240a85cc9de89afe9111c2d29de2672e407bf
    Reviewed-on: https://gerrit.libreoffice.org/44097
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sw/qa/extras/rtfexport/data/tdf113408.rtf b/sw/qa/extras/rtfexport/data/tdf113408.rtf
new file mode 100644
index 000000000000..60d9bc98d70f
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf113408.rtf
@@ -0,0 +1,24 @@
+{\rtf1\adeflang1037\ansi\ansicpg1252\uc1\adeff1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs1025
+{\fonttbl
+{\f0\fbidi \froman\fcharset238\fprq2 Times New Roman;}
+}
+{\stylesheet
+{Normal;}
+{\s66\li720\ri0 List Paragraph;}
+}
+{\*\listtable
+{\list\listtemplateid1275618250\listhybrid
+{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0
+\levelstartat1\levelspace0\levelindent0
+{\leveltext\leveltemplateid67698703\'02\'00.;}
+{\levelnumbers\'01;}
+\rtlch\fcs1 \af0 \fbias0 \fi-360\li720 }
+{\listname ;}
+\listid1880166401}
+}
+{\*\listoverridetable
+{\listoverride\listid1880166401\listoverridecount0\ls9}
+}
+\paperw12240\paperh15840\margl1440\margr1440\margt1800\margb1440\gutter0\viewkind1
+\pard \s66\li720\ri0\itap0 \par
+}
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx
index 5923007b8d3a..1d75996fcdda 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -743,6 +743,12 @@ DECLARE_RTFEXPORT_TEST(testPictureWrapPolygon, "picture-wrap-polygon.rtf")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(-67)), getProperty<sal_Int32>(getShape(1), "VertOrientPosition"));
 }
 
+DECLARE_RTFEXPORT_TEST(testTdf113408, "tdf113408.rtf")
+{
+    // This was 0, left margin was not inherited from style properly.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin"));
+}
+
 DECLARE_RTFEXPORT_TEST(testAbi10039, "abi10039.odt")
 {
     // Make sure we don't just crash on export, and additionally the shape should not be inline (as it's at-page anchored originally).
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 386d3085d903..6f7ee8062fee 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -439,7 +439,7 @@ static void lcl_copyFlatten(RTFReferenceProperties& rProps, RTFSprms& rStyleAttr
         rStyleAttributes.set(rAttribute.first, rAttribute.second);
 }
 
-writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RTFSprms& rAttributes, RTFSprms& rSprms)
+writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RTFSprms& rAttributes, RTFSprms& rSprms, Id nStyleType)
 {
     int nStyle = 0;
     if (!m_aStates.empty())
@@ -461,13 +461,15 @@ writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::getProperties(RT
         RTFSprms aStyleSprms;
         RTFSprms aStyleAttributes;
         // Ensure the paragraph style is a flat list.
-        lcl_copyFlatten(rProps, aStyleAttributes, aStyleSprms);
+        if (!nStyleType || nStyleType == NS_ooxml::LN_Value_ST_StyleType_paragraph)
+            lcl_copyFlatten(rProps, aStyleAttributes, aStyleSprms);
 
         if (itChar != m_aStyleTableEntries.end())
         {
             // Found active character style, then update aStyleSprms/Attributes.
             RTFReferenceProperties& rCharProps = *static_cast<RTFReferenceProperties*>(itChar->second.get());
-            lcl_copyFlatten(rCharProps, aStyleAttributes, aStyleSprms);
+            if (!nStyleType || nStyleType == NS_ooxml::LN_Value_ST_StyleType_character)
+                lcl_copyFlatten(rCharProps, aStyleAttributes, aStyleSprms);
         }
 
         // Get rid of direct formatting what is already in the style.
@@ -491,7 +493,7 @@ void RTFDocumentImpl::checkNeedPap()
         if (!m_aStates.top().pCurrentBuffer)
         {
             writerfilter::Reference<Properties>::Pointer_t const pParagraphProperties(
-                getProperties(m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms)
+                getProperties(m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms, NS_ooxml::LN_Value_ST_StyleType_paragraph)
             );
 
             // Writer will ignore a page break before a text frame, so guard it with empty paragraphs
@@ -526,7 +528,7 @@ void RTFDocumentImpl::runProps()
 {
     if (!m_aStates.top().pCurrentBuffer)
     {
-        writerfilter::Reference<Properties>::Pointer_t const pProperties = getProperties(m_aStates.top().aCharacterAttributes, m_aStates.top().aCharacterSprms);
+        Reference<Properties>::Pointer_t const pProperties = getProperties(m_aStates.top().aCharacterAttributes, m_aStates.top().aCharacterSprms, NS_ooxml::LN_Value_ST_StyleType_character);
         Mapper().props(pProperties);
     }
     else
@@ -1421,7 +1423,7 @@ void RTFDocumentImpl::prepareProperties(
     writerfilter::Reference<Properties>::Pointer_t& o_rpTableRowProperties,
     int const nCells, int const nCurrentCellX)
 {
-    o_rpParagraphProperties = getProperties(rState.aParagraphAttributes, rState.aParagraphSprms);
+    o_rpParagraphProperties = getProperties(rState.aParagraphAttributes, rState.aParagraphSprms, NS_ooxml::LN_Value_ST_StyleType_paragraph);
 
     if (rState.aFrame.hasProperties())
     {
@@ -1505,7 +1507,7 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer,
         {
             // Construct properties via getProperties() and not directly, to take care of deduplication.
             writerfilter::Reference<Properties>::Pointer_t const pProp(
-                getProperties(std::get<1>(aTuple)->getAttributes(), std::get<1>(aTuple)->getSprms())
+                getProperties(std::get<1>(aTuple)->getAttributes(), std::get<1>(aTuple)->getSprms(), 0)
             );
             Mapper().props(pProp);
         }
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 4e47c54fdc61..bb1c86de1b78 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -476,7 +476,7 @@ private:
     void runBreak();
     void parBreak();
     void tableBreak();
-    writerfilter::Reference<Properties>::Pointer_t getProperties(RTFSprms& rAttributes, RTFSprms& rSprms);
+    writerfilter::Reference<Properties>::Pointer_t getProperties(RTFSprms& rAttributes, RTFSprms& rSprms, Id nStyleType);
     void checkNeedPap();
     void sectBreak(bool bFinal = false);
     void prepareProperties(


More information about the Libreoffice-commits mailing list