sw/qa/extras/ooxmlexport/data/tdf95495.docx     |binary
 sw/qa/extras/ooxmlexport/ooxmlexport3.cxx       |   10 +++++
 writerfilter/source/dmapper/StyleSheetTable.cxx |   44 ++++++++++++++++++------
 3 files changed, 44 insertions(+), 10 deletions(-)

New commits:
commit 125dd0be473d15681049814c3982f1ae2c66660f
Author:     Szabolcs Toth <szabolcs...@gmail.com>
AuthorDate: Fri Jan 24 10:40:01 2020 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Thu Feb 13 09:37:51 2020 +0100

    tdf#95495 DOCX import: fix inherited list level of custom styles
    
    in DOCX export of MSO 2003, 2007 and 2010, where ilvl and outlinelvl
    settings are missing, based on the settings of the parent styles.
    
    Change-Id: I01d239db505d46a89d7f3b9118ef0b55697bc7fc
    CO-Author: Balázs Nádasdy (NISZ)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87328
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf95495.docx 
b/sw/qa/extras/ooxmlexport/data/tdf95495.docx
new file mode 100644
index 000000000000..21f534b11223
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf95495.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
index 9001db35e92c..4293f1deb695 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
@@ -1061,6 +1061,16 @@ DECLARE_OOXMLEXPORT_TEST(testFontTypes, 
"tdf120344_FontTypes.docx")
     assertXPath(qXmlDocument, 
"/w:numbering/w:abstractNum[1]/w:lvl[1]/w:rPr/w:rFonts [@w:ascii='Arial 
Black']", 1);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testNumberingLevels, "tdf95495.docx")
+{
+    xmlDocPtr pXmlDocument = parseExport("word/document.xml");
+    if (!pXmlDocument)
+        return;
+
+    // tdf#95495: set list level of the custom style based on the setting of 
the parent style
+    assertXPath(pXmlDocument, "/w:document/w:body/w:p[2]/w:pPr/w:numPr/w:ilvl 
[@w:val = '1']", 1);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx 
b/writerfilter/source/dmapper/StyleSheetTable.cxx
index 33c22e357110..b3348099cfaf 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -886,6 +886,12 @@ uno::Sequence< OUString > PropValVector::getNames()
     return comphelper::containerToSequence(aRet);
 }
 
+static bool lcl_IsOutLineStyle(const OUString& sPrefix, const OUString& 
sStyleName)
+{
+    OUString sSuffix;
+    return sStyleName.getLength() == (sPrefix.getLength() + 2) && 
sStyleName.startsWith(sPrefix + " ", &sSuffix) && sSuffix.toInt32() > 0;
+}
+
 void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable )
 {
     try
@@ -1043,13 +1049,39 @@ void StyleSheetTable::ApplyStyleSheets( const 
FontTablePtr& rFontTable )
                         }
 
                         // Set the outline levels
-                        const StyleSheetPropertyMap* pStyleSheetProperties = 
dynamic_cast<const StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : 
nullptr);
+                        StyleSheetPropertyMap* pStyleSheetProperties = 
dynamic_cast<StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : 
nullptr);
+
                         if ( pStyleSheetProperties )
                         {
                             beans::PropertyValue aLvlVal( getPropertyName( 
PROP_OUTLINE_LEVEL ), 0,
                                     uno::makeAny( sal_Int16( 
pStyleSheetProperties->GetOutlineLevel( ) + 1 ) ),
                                     beans::PropertyState_DIRECT_VALUE );
                             aPropValues.push_back(aLvlVal);
+
+                            // tdf#95495 missing list level settings in custom 
styles in old DOCX: apply settings of the parent style
+                            if (pStyleSheetProperties->GetListLevel() == -1 && 
pStyleSheetProperties->GetOutlineLevel() == -1)
+                            {
+                                const beans::PropertyValues aPropGrabBag = 
pEntry->GetInteropGrabBagSeq();
+                                for (const auto& rVal : aPropGrabBag)
+                                {
+                                    if (rVal.Name == "customStyle" && 
rVal.Value == true)
+                                    {
+                                        OUString sBaseId = 
pEntry->sBaseStyleIdentifier;
+                                        for (const auto& aSheetProps : 
m_pImpl->m_aStyleSheetEntries)
+                                        {
+                                            if (aSheetProps->sStyleIdentifierD 
== sBaseId)
+                                            {
+                                                StyleSheetPropertyMap* 
aStyleSheetProps
+                                                    = 
dynamic_cast<StyleSheetPropertyMap*>(aSheetProps->pProperties.get());
+                                                
pStyleSheetProperties->SetListLevel(aStyleSheetProps->GetListLevel());
+                                                
pStyleSheetProperties->SetOutlineLevel(aStyleSheetProps->GetOutlineLevel());
+                                                
pStyleSheetProperties->SetNumId(aStyleSheetProps->GetNumId());
+                                                break;
+                                            }
+                                        }
+                                    }
+                                }
+                            }
                         }
 
                         uno::Reference< beans::XPropertyState >xState( xStyle, 
uno::UNO_QUERY_THROW );
@@ -1063,15 +1095,7 @@ void StyleSheetTable::ApplyStyleSheets( const 
FontTablePtr& rFontTable )
                         }
                         else if ( sConvertedStyleName == "Text body" )
                             xState->setPropertyToDefault(getPropertyName( 
PROP_PARA_BOTTOM_MARGIN ));
-                        else if( sConvertedStyleName == "Heading 1" ||
-                                sConvertedStyleName == "Heading 2" ||
-                                sConvertedStyleName == "Heading 3" ||
-                                sConvertedStyleName == "Heading 4" ||
-                                sConvertedStyleName == "Heading 5" ||
-                                sConvertedStyleName == "Heading 6" ||
-                                sConvertedStyleName == "Heading 7" ||
-                                sConvertedStyleName == "Heading 8" ||
-                                sConvertedStyleName == "Heading 9" )
+                        else if( lcl_IsOutLineStyle("Heading", 
sConvertedStyleName) )
                         {
                             xState->setPropertyToDefault(getPropertyName( 
PROP_CHAR_WEIGHT ));
                             xState->setPropertyToDefault(getPropertyName( 
PROP_CHAR_WEIGHT_ASIAN ));
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to