diff options
author | Mark Hung <marklh9@gmail.com> | 2016-02-04 00:53:01 +0800 |
---|---|---|
committer | Mark Hung <marklh9@gmail.com> | 2016-02-13 15:22:52 +0000 |
commit | 78284714b73a8307174c596295894e8f3951e09a (patch) | |
tree | 8225a5d52e9bb655425921c20ef80e532decea37 | |
parent | 3c8b880c5edc1dcbf0f481c558c6093513df6b45 (diff) |
tdf#76817: fix missing heading styles assigned to outline levels in ooxml
1. Export pStyle because writerfilter regard a list as an outline
only if associated pStyle is set to "Heading N".
2. Export English style name to ensure style names created by LO
with non-English UI is always recognized.
Change-Id: I88c590e4bae6cf30e78ebc1011023461eac4e883
Reviewed-on: https://gerrit.libreoffice.org/22086
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mark Hung <marklh9@gmail.com>
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 1 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 44 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 3 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8sty.cxx | 10 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.hxx | 2 |
5 files changed, 41 insertions, 19 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 6e9840630786..7e693894ce9b 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -637,6 +637,7 @@ DECLARE_OOXMLEXPORT_TEST(testOOxmlOutlineNumberTypes, "outline-number-types.odt" { if (xmlDocPtr pXmlDoc = parseExport("word/numbering.xml")) { + assertXPath(pXmlDoc, "/w:numbering/w:abstractNum[1]/w:lvl[1]/w:pStyle", "val", "Heading1"); assertXPath(pXmlDoc, "/w:numbering/w:abstractNum[1]/w:lvl[1]/w:numFmt", "val", "none"); assertXPath(pXmlDoc, "/w:numbering/w:abstractNum[1]/w:lvl[2]/w:numFmt", "val", "decimalEnclosedCircle"); assertXPath(pXmlDoc, "/w:numbering/w:abstractNum[1]/w:lvl[3]/w:numFmt", "val", "decimal"); // CHARS_GREEK_UPPER_LETTER fallback to decimal diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 011e67952f3b..4cf04b9f3c66 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -5179,24 +5179,17 @@ static bool lcl_guessQFormat(const OUString& rName, sal_uInt16 nWwId) if (nWwId == ww::stiUser) return true; + // Allow exported built-in styles UI language neutral + if ( nWwId == ww::stiNormal || + ( nWwId>= ww::stiLev1 && nWwId <= ww::stiLev9 ) || + nWwId == ww::stiCaption || nWwId == ww::stiTitle || + nWwId == ww::stiSubtitle || nWwId == ww::stiStrong || + nWwId == ww::stiEmphasis ) + return true; + static std::set<OUString, OUStringIgnoreCase> aWhitelist; if (aWhitelist.empty()) { - aWhitelist.insert("Normal"); - aWhitelist.insert("Heading 1"); - aWhitelist.insert("Heading 2"); - aWhitelist.insert("Heading 3"); - aWhitelist.insert("Heading 4"); - aWhitelist.insert("Heading 5"); - aWhitelist.insert("Heading 6"); - aWhitelist.insert("Heading 7"); - aWhitelist.insert("Heading 8"); - aWhitelist.insert("Heading 9"); - aWhitelist.insert("Caption"); - aWhitelist.insert("Title"); - aWhitelist.insert("Subtitle"); - aWhitelist.insert("Strong"); - aWhitelist.insert("Emphasis"); aWhitelist.insert("No Spacing"); aWhitelist.insert("List Paragraph"); aWhitelist.insert("Quote"); @@ -5255,10 +5248,16 @@ void DocxAttributeOutput::StartStyle( const OUString& rName, StyleType eType, SAL_WARN("sw.ww8", "Unhandled style property: " << rGrabBag[i].Name); } + // MSO exports English names and writerfilter only recognize them. + const sal_Char *pEnglishName = nullptr; const char* pType = nullptr; switch (eType) { - case STYLE_TYPE_PARA: pType = "paragraph"; break; + case STYLE_TYPE_PARA: + pType = "paragraph"; + if ( nWwId < ww::stiMax) + pEnglishName = ww::GetEnglishNameFromSti( static_cast<ww::sti>(nWwId ) ); + break; case STYLE_TYPE_CHAR: pType = "character"; break; case STYLE_TYPE_LIST: pType = "numbering"; break; } @@ -5270,9 +5269,8 @@ void DocxAttributeOutput::StartStyle( const OUString& rName, StyleType eType, pStyleAttributeList->add(FSNS(XML_w, XML_customStyle), "1"); XFastAttributeListRef xStyleAttributeList(pStyleAttributeList); m_pSerializer->startElementNS( XML_w, XML_style, xStyleAttributeList); - m_pSerializer->singleElementNS( XML_w, XML_name, - FSNS( XML_w, XML_val ), OUStringToOString( OUString( rName ), RTL_TEXTENCODING_UTF8 ).getStr(), + FSNS( XML_w, XML_val ), pEnglishName ? pEnglishName : OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr(), FSEND ); if ( nBase != 0x0FFF && eType != STYLE_TYPE_LIST) @@ -5992,6 +5990,8 @@ void DocxAttributeOutput::NumberingDefinition( sal_uInt16 nId, const SwNumRule & void DocxAttributeOutput::StartAbstractNumbering( sal_uInt16 nId ) { + const SwNumRule* pRule = (*m_rExport.m_pUsedNumTable)[nId - 1]; + m_bExportingOutline = pRule && pRule->IsOutlineRule(); m_pSerializer->startElementNS( XML_w, XML_abstractNum, FSNS( XML_w, XML_abstractNumId ), OString::number( nId ).getStr(), FSEND ); @@ -6030,6 +6030,14 @@ void DocxAttributeOutput::NumberingLevel( sal_uInt8 nLevel, FSEND ); } + if (m_bExportingOutline) + { + sal_uInt16 nId = m_rExport.m_pStyles->GetHeadingParagraphStyleId( nLevel ); + if ( nId != SAL_MAX_UINT16 ) + m_pSerializer->singleElementNS( XML_w, XML_pStyle , + FSNS( XML_w, XML_val ), m_rExport.m_pStyles->GetStyleId(nId).getStr(), + FSEND ); + } // format OString aFormat( impl_LevelNFC( nNumberingType ,pOutSet) ); diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index d046ffb33cf9..4089d295eb44 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -821,6 +821,9 @@ private: sal_Int32 m_nHyperLinkCount; sal_Int16 m_nFieldsInHyperlink; + // If the exported numbering rule defines the outlines + bool m_bExportingOutline; + struct PostponedGraphic { PostponedGraphic( const SwGrfNode* n, Size s, const SwFlyFrameFormat* pOLEFrameFormat, SwOLENode* pOLENode, const SdrObject* sObj ) diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index 325d051501e8..e094f1ebf258 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -154,6 +154,7 @@ MSWordStyles::MSWordStyles( MSWordExportBase& rExport, bool bListStyles ) // somewhat generous ( free for up to 15 ) m_pFormatA = new SwFormat*[ nAlloc ]; memset( m_pFormatA, 0, nAlloc * sizeof( SwFormat* ) ); + memset( m_aHeadingParagraphStyles, -1 , MAXLEVEL * sizeof( sal_uInt16)); BuildStylesTable(); BuildStyleIds(); @@ -289,7 +290,14 @@ void MSWordStyles::BuildStylesTable() for( size_t n = 1; n < rArr2.size(); n++ ) { SwTextFormatColl* pFormat = rArr2[n]; - m_pFormatA[ BuildGetSlot( *pFormat ) ] = pFormat; + sal_uInt16 nId ; + m_pFormatA[ nId = BuildGetSlot( *pFormat ) ] = pFormat; + if ( pFormat->IsAssignedToListLevelOfOutlineStyle() ) + { + int nLvl = pFormat->GetAssignedOutlineStyleLevel() ; + if (nLvl >= 0 && nLvl < MAXLEVEL) + m_aHeadingParagraphStyles[nLvl] = nId ; + } } if (!m_bListStyles) diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index 5a3f7ab12626..10e639b82f17 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -1515,6 +1515,7 @@ public: class MSWordStyles { MSWordExportBase& m_rExport; + sal_uInt16 m_aHeadingParagraphStyles[MAXLEVEL]; SwFormat** m_pFormatA; ///< Slot <-> Character and paragraph style array (0 for list styles). sal_uInt16 m_nUsedSlots; bool m_bListStyles; ///< If list styles are requested to be exported as well. @@ -1566,6 +1567,7 @@ public: const SwFormat* GetSwFormat(sal_uInt16 nId) const { return m_pFormatA[nId]; } /// Get numbering rule of the nId-th style const SwNumRule* GetSwNumRule(sal_uInt16 nId) const; + sal_uInt16 GetHeadingParagraphStyleId(sal_uInt16 nLevel) const { return m_aHeadingParagraphStyles[ nLevel ]; } }; #define MSWORD_MAX_STYLES_LIMIT 4091 |