sw/source/filter/ww8/wrtw8sty.cxx                 |   10 ++++++++++
 sw/source/filter/ww8/wrtww8.hxx                   |    2 ++
 sw/source/filter/ww8/ww8atr.cxx                   |   13 ++++++++++---
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    3 +--
 writerfilter/source/dmapper/StyleSheetTable.cxx   |    7 ++++---
 writerfilter/source/dmapper/StyleSheetTable.hxx   |    2 +-
 6 files changed, 28 insertions(+), 9 deletions(-)

New commits:
commit 345f23474845da0defa4a9276228f54b5ded5736
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Tue Feb 7 14:17:11 2023 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Feb 7 17:13:48 2023 +0000

    tdf#153083 writerfilter,sw: DOCX locale-dependent TOC \t style names, 3
    
    The import crashed on fdo85740-1.docx with an unhandled exception.
    
    This is because it mapped the TOC style "Table of Figures" from "table
    of figures", but the ApplyStyleSheetsImpl() actually uses the converted
    name "Drawing" instead, so "Table of Figures" didn't exist.
    
    (regression from commit ca71482237d31703454062b8b2f544a8bacd2831)
    
    It turns out that once that is fixed, the DOCX export needs to convert
    "Drawing" back to "Table of Figures" in the TOC field.
    
    Change-Id: I4858c79dd74154b229b7568610c0b8ba7b3e2b6a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146610
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/source/filter/ww8/wrtw8sty.cxx 
b/sw/source/filter/ww8/wrtw8sty.cxx
index c520cd867772..27fcae621b17 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -458,6 +458,16 @@ OString const & MSWordStyles::GetStyleId(sal_uInt16 nSlot) 
const
     return m_aStyles[nSlot].style_id;
 }
 
+OUString MSWordStyles::GetStyleWWName(SwFormat const*const pFormat) const
+{
+    if (auto slot = m_rExport.m_pStyles->GetSlot(pFormat); slot != 0xfff)
+    {
+        assert(!m_aStyles[slot].ww_name.isEmpty());
+        return m_aStyles[slot].ww_name;
+    }
+    return OUString();
+}
+
 /// For WW8 only - extend pO so that the size of pTableStrm is even.
 static void impl_SkipOdd(std::unique_ptr<ww::bytes> const& pO, std::size_t 
nTableStrmTell)
 {
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index cf5d0bfa104b..f7bcce6d8d72 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -1638,6 +1638,8 @@ public:
 
     /// Get styleId of the nSlot-th style (nSlot is its position in m_aStyles).
     OString const & GetStyleId(sal_uInt16 nSlot) const;
+    /// the awful TOC field references names, not styleIds
+    OUString GetStyleWWName(SwFormat const* pFormat) const;
 
     const SwFormat* GetSwFormat(sal_uInt16 nSlot) const { return 
m_aStyles[nSlot].format; }
     /// Get numbering rule of the nSlot-th style
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 68fb57f4ce26..c76bb671c3f9 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -2375,7 +2375,11 @@ void AttributeOutputBase::StartTOX( const SwSection& 
rSect )
                     SwTextFormatColl const*const pColl = 
GetExport().m_rDoc.FindTextFormatCollByName(rStyle);
                     if (pColl)
                     {
-                        sStr += "\\t \"" + rStyle + sEntryEnd;
+                        OUString const 
converted(GetExport().m_pStyles->GetStyleWWName(pColl));
+                        if (!converted.isEmpty())
+                        {
+                            sStr += "\\t \"" + converted + sEntryEnd;
+                        }
                     }
                 }
                 break;
@@ -2524,11 +2528,14 @@ void AttributeOutputBase::StartTOX( const SwSection& 
rSect )
                                         SwTextFormatColl* pColl = 
GetExport().m_rDoc.FindTextFormatCollByName(sStyle);
                                         if (pColl)
                                         {
-                                            if 
(!pColl->IsAssignedToListLevelOfOutlineStyle() || 
pColl->GetAssignedOutlineStyleLevel() < nTOXLvl)
+                                            OUString const 
converted(GetExport().m_pStyles->GetStyleWWName(pColl));
+                                            if (!converted.isEmpty() &&
+                                                
(!pColl->IsAssignedToListLevelOfOutlineStyle()
+                                                 || 
pColl->GetAssignedOutlineStyleLevel() < nTOXLvl))
                                             {
                                                 if( !sTOption.isEmpty() )
                                                     sTOption += tsep;
-                                                sTOption += sStyle + sLvl;
+                                                sTOption += converted + sLvl;
                                             }
                                         }
                                     }
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 485a9399a7c7..32870f0a236a 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -6155,8 +6155,7 @@ OUString DomainMapper_Impl::ConvertTOCStyleName(OUString 
const& rTOCStyleName)
     {   // practical case: Word wrote i18n name to TOC field, but it doesn't
         // exist in styles.xml; tdf#153083 clone it for best roundtrip
         SAL_INFO("writerfilter.dmapper", "cloning TOC paragraph style 
(presumed built-in) " << rTOCStyleName << " from " << pStyle->sStyleName);
-        GetStyleSheetTable()->CloneTOCStyle(GetFontTable(), pStyle, 
rTOCStyleName);
-        return rTOCStyleName;
+        return GetStyleSheetTable()->CloneTOCStyle(GetFontTable(), pStyle, 
rTOCStyleName);
     }
     else
     {
diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx 
b/writerfilter/source/dmapper/StyleSheetTable.cxx
index 52c14f2bf04d..1b7874e1c5fc 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -1062,7 +1062,7 @@ void StyleSheetTable::ApplyClonedTOCStyles()
     m_pImpl->ApplyClonedTOCStylesToXText(xBody);
 }
 
-void StyleSheetTable::CloneTOCStyle(FontTablePtr const& rFontTable, 
StyleSheetEntryPtr const pStyle, OUString const& rNewName)
+OUString StyleSheetTable::CloneTOCStyle(FontTablePtr const& rFontTable, 
StyleSheetEntryPtr const pStyle, OUString const& rNewName)
 {
     StyleSheetEntryPtr const pClone(new StyleSheetEntry(*pStyle));
     pClone->sStyleIdentifierD = rNewName;
@@ -1071,9 +1071,10 @@ void StyleSheetTable::CloneTOCStyle(FontTablePtr const& 
rFontTable, StyleSheetEn
     m_pImpl->m_aStyleSheetEntries.push_back(pClone);
     // add it so it will be found if referenced from another TOC
     m_pImpl->m_aStyleSheetEntriesMap.emplace(rNewName, pClone);
-    m_pImpl->m_ClonedTOCStylesMap.emplace(pStyle->sStyleName, rNewName);
+    m_pImpl->m_ClonedTOCStylesMap.emplace(pStyle->sStyleName, 
pClone->sConvertedStyleName);
     std::vector<StyleSheetEntryPtr> const styles{ pClone };
-    return ApplyStyleSheetsImpl(rFontTable, styles);
+    ApplyStyleSheetsImpl(rFontTable, styles);
+    return pClone->sConvertedStyleName;
 }
 
 void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable )
diff --git a/writerfilter/source/dmapper/StyleSheetTable.hxx 
b/writerfilter/source/dmapper/StyleSheetTable.hxx
index e2f79d863e8f..0ee33b8d8056 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.hxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.hxx
@@ -99,7 +99,7 @@ public:
     StyleSheetEntryPtr FindDefaultParaStyle();
 
     OUString ConvertStyleName( const OUString& rWWName, bool bExtendedSearch = 
false );
-    void CloneTOCStyle(FontTablePtr const& rFontTable, StyleSheetEntryPtr 
const pStyle, OUString const& rName);
+    OUString CloneTOCStyle(FontTablePtr const& rFontTable, StyleSheetEntryPtr 
const pStyle, OUString const& rName);
     void ApplyClonedTOCStyles();
 
     OUString getOrCreateCharStyle( PropertyValueVector_t& rCharProperties, 
bool bAlwaysCreate );

Reply via email to