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 59363e639b67a8acbd6da240635de47921b2c955
Author: Miklos Vajna <vmik...@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.)
    
    Change-Id: I88d56c27c19e070e983c3392f99bca96597cd56e
    Reviewed-on: https://gerrit.libreoffice.org/50391
    Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk>
    Tested-by: Jenkins <c...@libreoffice.org>

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 fd05a6ce69d7..860fe0712044 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -175,6 +175,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
@@ -344,11 +352,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 44b671de27bc..a499234f1d80 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -103,7 +103,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)
@@ -368,11 +368,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);
@@ -1937,6 +1937,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 71e7657036f8..ae05d7a0647d 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -393,6 +393,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);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to