diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-08-18 11:20:20 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-08-18 11:58:30 +0200 |
commit | be515af4d9e86c8bc13a47413676bda80cee6a3e (patch) | |
tree | 1177aa753b42e977c902e012f8f4d49b8b0b1699 | |
parent | f1095b41c6506b153199a72b36fc720804ea9ebc (diff) |
DOCX filter: improve qFormat export handling
The old rule was: write qFormat for everything that's not a custom
style.
The new rule: write qFormat for everything that's a custom style + have
a whitelist of non-custom, but qFormat styles.
This matches better what Word does (whitelist is from the latent style
section of an empty document, created by Word).
Change-Id: Ie7a0802e886c41b8d26ca9aa154913aa2f3ff87a
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 53 |
2 files changed, 56 insertions, 3 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 2d47c8cbcc7f..593358ecf16c 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -1191,6 +1191,12 @@ DECLARE_OOXMLEXPORT_TEST(testCharacterBorder, "charborder.odt") CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadow.Location); CPPUNIT_ASSERT_EQUAL(sal_Int16(318), aShadow.ShadowWidth); } + + if (xmlDocPtr pXmlStyles = parseExport("word/styles.xml")) + { + // Make sure we write qFormat for custom style names. + assertXPath(pXmlStyles, "//w:style[@w:styleId='Heading']/w:qFormat", 1); + } } DECLARE_OOXMLEXPORT_TEST(testStyleInheritance, "style-inheritance.docx") diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index f8f2d00f0054..4ead52631169 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -5054,6 +5054,55 @@ oox::drawingml::DrawingML& DocxAttributeOutput::GetDrawingML() return m_rDrawingML; } +/// Functor to do case-insensitive ordering of OUString instances. +struct OUStringIgnoreCase +{ + bool operator() (const OUString& lhs, const OUString& rhs) const + { + return lhs.compareToIgnoreAsciiCase(rhs) < 0; + } +}; + +/// Guesses if a style created in Writer (no grab-bag) should be qFormat or not. +static bool lcl_guessQFormat(const OUString& rName, sal_uInt16 nWwId) +{ + // If the style has no dedicated STI number, then it's probably a custom style -> qFormat. + if (nWwId == ww::stiUser) + 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"); + aWhitelist.insert("Intense Quote"); + aWhitelist.insert("Subtle Emphasis,"); + aWhitelist.insert("Intense Emphasis"); + aWhitelist.insert("Subtle Reference"); + aWhitelist.insert("Intense Reference"); + aWhitelist.insert("Book Title"); + aWhitelist.insert("TOC Heading"); + } + // Not custom style? Then we have a list of standard styles which should be qFormat. + return aWhitelist.find(rName) != aWhitelist.end(); +} + void DocxAttributeOutput::StartStyle( const OUString& rName, StyleType eType, sal_uInt16 nBase, sal_uInt16 nNext, sal_uInt16 nWwId, sal_uInt16 nId, bool bAutoUpdate ) { @@ -5148,9 +5197,7 @@ void DocxAttributeOutput::StartStyle( const OUString& rName, StyleType eType, if (bUnhideWhenUsed) m_pSerializer->singleElementNS(XML_w, XML_unhideWhenUsed, FSEND); - // If the style has a dedicated STI number, then chances are high that Word - // will have qFormat enabled for it, so let's do the same. - if (bQFormat || nWwId != ww::stiUser) + if (bQFormat || lcl_guessQFormat(rName, nWwId)) m_pSerializer->singleElementNS(XML_w, XML_qFormat, FSEND); if (bLocked) m_pSerializer->singleElementNS(XML_w, XML_locked, FSEND); |