diff options
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/ww8/attributeoutputbase.hxx | 3 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 13 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8sty.cxx | 44 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.hxx | 8 |
6 files changed, 61 insertions, 15 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 962f09b86258..64e4c0660284 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -1372,9 +1372,6 @@ void Test::testCharacterBorder() void Test::testStyleInheritance() { - // This document has several issues to fix, more checks will be here to - // test its various aspects - // Check that now styleId's are more like what MSO produces xmlDocPtr pXmlStyles = parseExport("word/styles.xml"); // the 1st style always must be Normal @@ -1440,6 +1437,9 @@ void Test::testStyleInheritance() if (aLatentStyleException[i].Name == "name") aName = aLatentStyleException[i].Value.get<OUString>(); CPPUNIT_ASSERT_EQUAL(OUString("Normal"), aName); // This checks the "name" attribute of the first exception. + + // This numbering style wasn't roundtripped. + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='NoList']/w:name", "val", "No List"); } void Test::testSmartart() diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx b/sw/source/filter/ww8/attributeoutputbase.hxx index fc04861d6782..a528d28cb034 100644 --- a/sw/source/filter/ww8/attributeoutputbase.hxx +++ b/sw/source/filter/ww8/attributeoutputbase.hxx @@ -136,7 +136,8 @@ namespace msword { enum StyleType { STYLE_TYPE_PARA, - STYLE_TYPE_CHAR + STYLE_TYPE_CHAR, + STYLE_TYPE_LIST }; class AttributeOutputBase diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 4a1cdcf2873c..53f15b293e78 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -3599,8 +3599,15 @@ oox::drawingml::DrawingML& DocxAttributeOutput::GetDrawingML() void DocxAttributeOutput::StartStyle( const OUString& rName, StyleType eType, sal_uInt16 nBase, sal_uInt16 nNext, sal_uInt16 /*nWwId*/, sal_uInt16 nId, bool bAutoUpdate ) { + const char* pType = 0; + switch (eType) + { + case STYLE_TYPE_PARA: pType = "paragraph"; break; + case STYLE_TYPE_CHAR: pType = "character"; break; + case STYLE_TYPE_LIST: pType = "numbering"; break; + } m_pSerializer->startElementNS( XML_w, XML_style, - FSNS( XML_w, XML_type ), (eType == STYLE_TYPE_PARA ? "paragraph": "character"), + FSNS( XML_w, XML_type ), pType, FSNS( XML_w, XML_styleId ), m_rExport.pStyles->GetStyleId(nId).getStr(), FSEND ); @@ -3608,14 +3615,14 @@ void DocxAttributeOutput::StartStyle( const OUString& rName, StyleType eType, FSNS( XML_w, XML_val ), OUStringToOString( OUString( rName ), RTL_TEXTENCODING_UTF8 ).getStr(), FSEND ); - if ( nBase != 0x0FFF ) + if ( nBase != 0x0FFF && eType != STYLE_TYPE_LIST) { m_pSerializer->singleElementNS( XML_w, XML_basedOn, FSNS( XML_w, XML_val ), m_rExport.pStyles->GetStyleId(nBase).getStr(), FSEND ); } - if ( nNext != nId ) + if ( nNext != nId && eType != STYLE_TYPE_LIST) { m_pSerializer->singleElementNS( XML_w, XML_next, FSNS( XML_w, XML_val ), m_rExport.pStyles->GetStyleId(nNext).getStr(), diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index bf45dacd37ac..14f8174b4f28 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -457,7 +457,7 @@ void DocxExport::PrepareNewPageDesc( const SfxItemSet* pSet, void DocxExport::InitStyles() { - pStyles = new MSWordStyles( *this ); + pStyles = new MSWordStyles( *this, /*bListStyles =*/ true ); // setup word/styles.xml and the relations + content type m_pFilter->addRelation( m_pDocumentFS->getOutputStream(), diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index 52ac3025442f..850a6ea509b4 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -139,8 +139,9 @@ sal_uInt16 MSWordExportBase::GetId( const SwTxtFmtColl& rColl ) const //typedef pFmtT -MSWordStyles::MSWordStyles( MSWordExportBase& rExport ) - : m_rExport( rExport ) +MSWordStyles::MSWordStyles( MSWordExportBase& rExport, bool bListStyles ) + : m_rExport( rExport ), + m_bListStyles(bListStyles) { // if exist any Foot-/End-Notes then get from the EndNoteInfo struct // the CharFormats. They will create it! @@ -152,7 +153,8 @@ MSWordStyles::MSWordStyles( MSWordExportBase& rExport ) m_rExport.pDoc->GetFtnInfo().GetCharFmt( *m_rExport.pDoc ); } sal_uInt16 nAlloc = WW8_RESERVED_SLOTS + m_rExport.pDoc->GetCharFmts()->size() - 1 + - m_rExport.pDoc->GetTxtFmtColls()->size() - 1; + m_rExport.pDoc->GetTxtFmtColls()->size() - 1 + + (bListStyles ? m_rExport.pDoc->GetNumRuleTbl().size() - 1 : 0); // somewhat generous ( free for up to 15 ) pFmtA = new SwFmt*[ nAlloc ]; @@ -205,6 +207,11 @@ sal_uInt16 MSWordStyles::BuildGetSlot( const SwFmt& rFmt ) return nRet; } +sal_uInt16 MSWordStyles::BuildGetSlot(const SwNumRule&) +{ + return nUsedSlots++; +} + sal_uInt16 MSWordStyles::GetWWId( const SwFmt& rFmt ) const { sal_uInt16 nRet = ww::stiUser; // User-Style als default @@ -293,6 +300,19 @@ void MSWordStyles::BuildStylesTable() SwTxtFmtColl* pFmt = rArr2[n]; pFmtA[ BuildGetSlot( *pFmt ) ] = pFmt; } + + if (!m_bListStyles) + return; + + const SwNumRuleTbl& rNumRuleTbl = m_rExport.pDoc->GetNumRuleTbl(); + for (size_t i = 0; i < rNumRuleTbl.size(); ++i) + { + const SwNumRule* pNumRule = rNumRuleTbl[i]; + if (pNumRule->IsAutoRule() || pNumRule->GetName().startsWith("WWNum")) + continue; + sal_uInt16 nSlot = BuildGetSlot(*pNumRule); + m_aNumRules[nSlot] = pNumRule; + } } void MSWordStyles::BuildStyleIds() @@ -304,7 +324,7 @@ void MSWordStyles::BuildStyleIds() for (sal_uInt16 n = 1; n < nUsedSlots; ++n) { - const OUString aName(pFmtA[n]? pFmtA[n]->GetName(): OUString()); + const OUString aName(pFmtA[n]? pFmtA[n]->GetName(): (m_aNumRules.find(n) != m_aNumRules.end() ? m_aNumRules[n]->GetName() : OUString())); OStringBuffer aStyleIdBuf(aName.getLength()); for (int i = 0; i < aName.getLength(); ++i) @@ -572,6 +592,15 @@ void WW8AttributeOutput::DefaultStyle( sal_uInt16 nStyle ) } } +void MSWordStyles::OutputStyle(const SwNumRule* pNumRule, sal_uInt16 nPos) +{ + m_rExport.AttrOutput().StartStyle( pNumRule->GetName(), STYLE_TYPE_LIST, + /*nBase =*/ 0, /*nWwNext =*/ 0, /*nWWId =*/ 0, nPos, + /*bAutoUpdateFmt =*/ false ); + + m_rExport.AttrOutput().EndStyle(); +} + // OutputStyle applies for TxtFmtColls and CharFmts void MSWordStyles::OutputStyle( SwFmt* pFmt, sal_uInt16 nPos ) { @@ -677,7 +706,12 @@ void MSWordStyles::OutputStylesTable() sal_uInt16 n; for ( n = 0; n < nUsedSlots; n++ ) - OutputStyle( pFmtA[n], n ); + { + if (m_aNumRules.find(n) != m_aNumRules.end()) + OutputStyle(m_aNumRules[n], n); + else + OutputStyle( pFmtA[n], n ); + } m_rExport.AttrOutput().EndStyles( nUsedSlots ); diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index 95e498347e15..55af86680adc 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -1506,8 +1506,10 @@ public: class MSWordStyles { MSWordExportBase& m_rExport; - SwFmt** pFmtA; + SwFmt** pFmtA; ///< Slot <-> Character and paragraph style array (0 for list styles). sal_uInt16 nUsedSlots; + bool m_bListStyles; ///< If list styles are requested to be exported as well. + std::map<sal_uInt16, const SwNumRule*> m_aNumRules; ///< Slot <-> List style map. /// We need to build style id's for DOCX export; ideally we should roundtrip that, but this is good enough. std::vector<OString> m_aStyleIds; @@ -1520,6 +1522,7 @@ class MSWordStyles /// Get slot number during building the style table. sal_uInt16 BuildGetSlot( const SwFmt& rFmt ); + sal_uInt16 BuildGetSlot( const SwNumRule& rNumRule ); /// Return information about one style. void GetStyleData( SwFmt* pFmt, bool& bFmtColl, sal_uInt16& nBase, sal_uInt16& nNext ); @@ -1533,13 +1536,14 @@ class MSWordStyles /// Outputs one style - called (in a loop) from OutputStylesTable(). void OutputStyle( SwFmt* pFmt, sal_uInt16 nPos ); + void OutputStyle( const SwNumRule* pNumRule, sal_uInt16 nPos ); // No copying MSWordStyles( const MSWordStyles& ); MSWordStyles& operator=( const MSWordStyles& ); public: - MSWordStyles( MSWordExportBase& rExport ); + MSWordStyles( MSWordExportBase& rExport, bool bListStyles = false ); ~MSWordStyles(); /// Output the styles table. |