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

Miklos Vajna vmiklos at collabora.co.uk
Wed Feb 28 09:20:27 UTC 2018


 sw/qa/extras/rtfimport/data/tdf115715.rtf      |   38 +++++++++++++++++++++++++
 sw/qa/extras/rtfimport/rtfimport.cxx           |   17 +++++++----
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   30 ++++++++++++++++---
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |    4 ++
 4 files changed, 79 insertions(+), 10 deletions(-)

New commits:
commit 7963353a816f22a66330923f90f500820784313a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Feb 26 21:17:59 2018 +0100

    tdf#115715 RTF import: ignore zero para indents in styles without parents
    
    The only reason the DOCX equivalent of the bugdoc was imported correctly
    is that these default zero margins are simply missing from the DOCX
    markup, suggesting Word ignores them. We now do the same, this way
    the stripped down document's 3 paragraphs all have different margins as
    expected.
    
    (Also rework the testTdf112211_2 testcase to test the original problem
    better: I verified that the layout is unchanged before/after this
    patch.)
    
    (cherry picked from commit 59363e639b67a8acbd6da240635de47921b2c955)
    
    Change-Id: I88d56c27c19e070e983c3392f99bca96597cd56e
    Reviewed-on: https://gerrit.libreoffice.org/50435
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/qa/extras/rtfimport/data/tdf115715.rtf b/sw/qa/extras/rtfimport/data/tdf115715.rtf
new file mode 100644
index 000000000000..4f8311d8de11
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/tdf115715.rtf
@@ -0,0 +1,38 @@
+{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff1\deff0\stshfdbch0\stshfloch1\stshfhich1\stshfbi1\deflang1033\deflangfe2052\themelang1033\themelangfe2052\themelangcs1025
+\noqfpromote
+{\stylesheet
+{\ql \rin0\lin0 \ltrch\fcs0 \f1\fs24\cf1\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 \sqformat \spriority0 Normal;}
+{\s55\ql \rin0\lin0 \afs26 \ltrch\fcs0 \f1\fs26\lang1033\langfe2052\cgrid\langnp1033\langfenp2052 \sbasedon0 \snext55 \slink22 Style 55;}
+{\s56\ql \fi-720\rin0\lin0 \afs26 \ltrch\fcs0 \f1\fs26\lang1033\langfe2052\cgrid\langnp1033\langfenp2052 \sbasedon0 \snext56 \slink24 Style 56;}
+}
+{\*\listtable
+{\list\listtemplateid-454920584
+{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace0\levelindent0
+{\leveltext\'02\'00.;}
+{\levelnumbers\'01;}
+\af0\afs26\ltrch\fcs0
+\fs26\hres0\chhres0}
+{\listlevel\levelnfc4\levelnfcn4\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace0\levelindent0
+{\leveltext\'02\'01.;}
+{\levelnumbers\'01;}
+\af0\afs26 \ltrch\fcs0 \fs26\hres0\chhres0}
+{\listname;}
+\listid1}
+}
+{\*\listoverridetable
+{\listoverride\listid1\listoverridecount0\ls1}
+}
+\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440
+\pard\plain before
+\par
+\pard\plain\s56\fi-720\li1580
+\ls1\rin0\lin1580 \afs26 \ltrch\fcs0 \f1\fs26\lang1033\langfe2052\cgrid\langnp1033\langfenp2052
+{\ltrch\fcs0
+\lang1033\langfe1033\langfenp1033 1}
+\par
+\pard\plain\s55\ql \li1580
+\ls1\ilvl1\rin0\lin1580 \afs26 \ltrch\fcs0 \f1\fs26\lang1033\langfe2052\cgrid\langnp1033\langfenp2052
+{\ltrch\fcs0
+\lang1033\langfe1033\langfenp1033 a}
+\par
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 2ae659ae8351..233cf1d5dc3b 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -179,6 +179,14 @@ DECLARE_RTFIMPORT_TEST(testFdo46662, "fdo46662.rtf")
     }
 }
 
+DECLARE_RTFIMPORT_TEST(testTdf115715, "tdf115715.rtf")
+{
+    // This was 0, second paragraph was shifted to the right, it had the same
+    // horizontal position as the 3rd paragraph.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1270),
+                         getProperty<sal_Int32>(getParagraph(2), "ParaFirstLineIndent"));
+}
+
 DECLARE_RTFIMPORT_TEST(testTdf115155, "tdf115155.rtf")
 {
     auto xLevels
@@ -348,11 +356,10 @@ DECLARE_RTFIMPORT_TEST(testFdo52066, "fdo52066.rtf")
 
 DECLARE_RTFIMPORT_TEST(testTdf112211_2, "tdf112211-2.rtf")
 {
-    uno::Reference<beans::XPropertyState> xPropertyState(getParagraph(2), uno::UNO_QUERY);
-    beans::PropertyState ePropertyState = xPropertyState->getPropertyState("ParaLeftMargin");
-    // This was beans::PropertyState_DIRECT_VALUE -> direct formatting
-    // prevented inheritance from numbering definition.
-    CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DEFAULT_VALUE, ePropertyState);
+    // Spacing between the bullet and the actual text was too large.
+    // This is now around 269, large old value was 629.
+    int nWidth = parseDump("/root/page/body/txt[2]/Text[@nType='POR_TABLEFT']", "nWidth").toInt32();
+    CPPUNIT_ASSERT_LESS(300, nWidth);
 }
 
 DECLARE_RTFIMPORT_TEST(testFdo49892, "fdo49892.rtf")
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index bfb40c83b8be..9c4c714baeb3 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -114,7 +114,7 @@ void putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer
     putNestedAttribute(rSprms, nParent, nId, pValue, eOverwrite, false);
 }
 
-static RTFValue::Pointer_t lcl_getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId)
+RTFValue::Pointer_t getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId)
 {
     RTFValue::Pointer_t pParent = rSprms.find(nParent);
     if (!pParent)
@@ -377,11 +377,11 @@ void RTFDocumentImpl::checkFirstRun()
 
         // set the requested default font, if there are none
         RTFValue::Pointer_t pFont
-            = lcl_getNestedAttribute(m_aDefaultState.aCharacterSprms,
-                                     NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii);
+            = getNestedAttribute(m_aDefaultState.aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts,
+                                 NS_ooxml::LN_CT_Fonts_ascii);
         RTFValue::Pointer_t pCurrentFont
-            = lcl_getNestedAttribute(m_aStates.top().aCharacterSprms,
-                                     NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii);
+            = getNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts,
+                                 NS_ooxml::LN_CT_Fonts_ascii);
         if (pFont && !pCurrentFont)
             putNestedAttribute(m_aStates.top().aCharacterSprms, NS_ooxml::LN_EG_RPrBase_rFonts,
                                NS_ooxml::LN_CT_Fonts_ascii, pFont);
@@ -1943,6 +1943,26 @@ RTFError RTFDocumentImpl::pushState()
 
 writerfilter::Reference<Properties>::Pointer_t RTFDocumentImpl::createStyleProperties()
 {
+    int nBasedOn = 0;
+    RTFValue::Pointer_t pBasedOn = m_aStates.top().aTableSprms.find(NS_ooxml::LN_CT_Style_basedOn);
+    if (pBasedOn)
+        nBasedOn = pBasedOn->getInt();
+    if (nBasedOn == 0)
+    {
+        // No parent style, then mimic what Word does: ignore attributes which
+        // would set a margin as formatting, but with a default value.
+        for (const auto& nId :
+             { NS_ooxml::LN_CT_Ind_firstLine, NS_ooxml::LN_CT_Ind_left, NS_ooxml::LN_CT_Ind_right,
+               NS_ooxml::LN_CT_Ind_start, NS_ooxml::LN_CT_Ind_end })
+        {
+            RTFValue::Pointer_t pValue = getNestedAttribute(m_aStates.top().aParagraphSprms,
+                                                            NS_ooxml::LN_CT_PPrBase_ind, nId);
+            if (pValue && pValue->getInt() == 0)
+                eraseNestedAttribute(m_aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PPrBase_ind,
+                                     nId);
+        }
+    }
+
     RTFValue::Pointer_t pParaProps = std::make_shared<RTFValue>(
         m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms);
     RTFValue::Pointer_t pCharProps = std::make_shared<RTFValue>(
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 5fbfb9a46975..d17fbf7844b7 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -371,6 +371,10 @@ Id getParagraphBorder(sal_uInt32 nIndex);
 void putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer_t& pValue,
                         RTFOverwrite eOverwrite = RTFOverwrite::YES, bool bAttribute = true);
 bool eraseNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId);
+
+/// Looks up the nParent then the nested nId key in rSprms.
+RTFValue::Pointer_t getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId);
+
 /// Checks if rName is contained at least once in rProperties as a key.
 bool findPropertyName(const std::vector<css::beans::PropertyValue>& rProperties,
                       const OUString& rName);


More information about the Libreoffice-commits mailing list