diff options
author | Justin Luth <justin_luth@sil.org> | 2018-07-16 20:55:33 +0300 |
---|---|---|
committer | Justin Luth <justin_luth@sil.org> | 2018-07-21 21:37:18 +0200 |
commit | 6b7f12f6108f136d60bd77e3787ef6a2632038cd (patch) | |
tree | ba776afea901977cc585c317c787f5d5eea0c023 | |
parent | 71821a74d65765afa9f2273d98b5b0cc3ac2782f (diff) |
writerfilter: default style is the last one
Documentation states, and the examples confirm that
"If this attribute (w:default) is specified by multiple styles, then
the last instance of a style with this property shall be used."
Change-Id: I17f06ab8944a39341a00c479117e978a01d6af7a
Reviewed-on: https://gerrit.libreoffice.org/57510
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/defaultStyle.docx | bin | 0 -> 5126 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 6 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 5 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 20 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/StyleSheetTable.cxx | 17 |
6 files changed, 38 insertions, 12 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/defaultStyle.docx b/sw/qa/extras/ooxmlexport/data/defaultStyle.docx Binary files differnew file mode 100644 index 000000000000..8e3faa70da8c --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/defaultStyle.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index 3246fe5eec4d..b4d6dad88132 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -150,6 +150,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf116410, "tdf116410.docx") CPPUNIT_ASSERT_EQUAL(1, getPages()); } +DECLARE_OOXMLEXPORT_TEST(testDefaultStyle, "defaultStyle.docx") +{ + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Default Style", OUString("Title"), getProperty<OUString>(getParagraph(1), "ParaStyleName") ); + CPPUNIT_ASSERT_EQUAL(2, getPages()); +} + DECLARE_OOXMLEXPORT_TEST(testParagraphSplitOnSectionBorder, "parasplit-on-section-border.odt") { xmlDocPtr pXmlDoc = parseExport("word/document.xml"); diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index b5f3d504fb77..5e6f2b0c0a1a 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -2936,8 +2936,9 @@ void DomainMapper::lcl_startParagraphGroup() { if (!m_pImpl->IsInShape()) { - m_pImpl->GetTopContext()->Insert( PROP_PARA_STYLE_NAME, uno::makeAny( OUString("Standard") ) ); //ConvertedStyleName - m_pImpl->SetCurrentParaStyleName("Standard"); + const OUString& sDefaultParaStyle = m_pImpl->GetDefaultParaStyleName(); + m_pImpl->GetTopContext()->Insert( PROP_PARA_STYLE_NAME, uno::makeAny( sDefaultParaStyle ) ); + m_pImpl->SetCurrentParaStyleName( sDefaultParaStyle ); } if (m_pImpl->isBreakDeferred(PAGE_BREAK)) m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_PAGE_BEFORE)); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 2939902f03ca..8c3c59243aa0 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -209,6 +209,7 @@ DomainMapper_Impl::DomainMapper_Impl( m_pLastSectionContext( ), m_pLastCharacterContext(), m_sCurrentParaStyleName(), + m_sDefaultParaStyleName(), m_bInStyleSheetImport( false ), m_bInAnyTableImport( false ), m_bInHeaderFooterImport( false ), @@ -664,6 +665,25 @@ const OUString DomainMapper_Impl::GetCurrentParaStyleName() return sName; } +const OUString DomainMapper_Impl::GetDefaultParaStyleName() +{ + // After import the default style won't change and is frequently requested: cache the LO style name. + // TODO assert !InStyleSheetImport? This function really only makes sense once import is finished anyway. + if ( m_sDefaultParaStyleName.isEmpty() ) + { + const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindDefaultParaStyle(); + if ( pEntry && !pEntry->sConvertedStyleName.isEmpty() ) + { + if ( !m_bInStyleSheetImport ) + m_sDefaultParaStyleName = pEntry->sConvertedStyleName; + return pEntry->sConvertedStyleName; + } + else + return OUString( "Standard"); + } + return m_sDefaultParaStyleName; +} + /*------------------------------------------------------------------------- returns the value from the current paragraph style - if available -----------------------------------------------------------------------*/ diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index 555c2dd35bb9..013f8aaa5799 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -475,6 +475,7 @@ private: ::std::vector<DeletableTabStop> m_aCurrentTabStops; OUString m_sCurrentParaStyleName; //highly inaccurate. Overwritten by "overlapping" paragraphs like comments, flys. + OUString m_sDefaultParaStyleName; //caches the ConvertedStyleName of the default paragraph style bool m_bInStyleSheetImport; //in import of fonts, styles, lists or lfos bool m_bInAnyTableImport; //in import of fonts, styles, lists or lfos bool m_bInHeaderFooterImport; @@ -694,6 +695,7 @@ public: void SetCurrentParaStyleName(const OUString& sStringValue) {m_sCurrentParaStyleName = sStringValue;} const OUString GetCurrentParaStyleName(); + const OUString GetDefaultParaStyleName(); css::uno::Any GetPropertyFromStyleSheet(PropertyIds eId); void SetStyleSheetImport( bool bSet ) { m_bInStyleSheetImport = bSet;} diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx index 4780ceefb829..2c7307a68d5c 100644 --- a/writerfilter/source/dmapper/StyleSheetTable.cxx +++ b/writerfilter/source/dmapper/StyleSheetTable.cxx @@ -258,6 +258,7 @@ struct StyleSheetTable_Impl StringPairMap_t m_aStyleNameMap; /// Style names which should not be used without a " (user)" suffix. std::set<OUString> m_aReservedStyleNames; + OUString m_sDefaultParaStyleName; //WW8 name ListCharStylePropertyVector_t m_aListCharStylePropertyVector; bool m_bHasImportedDefaultParaProps; bool m_bIsNewDoc; @@ -282,6 +283,7 @@ StyleSheetTable_Impl::StyleSheetTable_Impl(DomainMapper& rDMapper, m_pCurrentEntry(), m_pDefaultParaProps(new PropertyMap), m_pDefaultCharProps(new PropertyMap), + m_sDefaultParaStyleName("Normal"), m_bHasImportedDefaultParaProps(false), m_bIsNewDoc(bIsNewDoc) { @@ -456,6 +458,10 @@ void StyleSheetTable::lcl_attribute(Id Name, Value & val) if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN) { + // "If this attribute is specified by multiple styles, then the last instance shall be used." + if ( m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_PARA && !m_pImpl->m_pCurrentEntry->sStyleIdentifierD.isEmpty() ) + m_pImpl->m_sDefaultParaStyleName = m_pImpl->m_pCurrentEntry->sStyleIdentifierD; + beans::PropertyValue aValue; aValue.Name = "default"; aValue.Value <<= m_pImpl->m_pCurrentEntry->bIsDefaultStyle; @@ -1272,16 +1278,7 @@ const StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByConvertedStyleName(con const StyleSheetEntryPtr StyleSheetTable::FindDefaultParaStyle() { - StyleSheetEntryPtr pRet; - for (StyleSheetEntryPtr & pEntry : m_pImpl->m_aStyleSheetEntries) - { - if (pEntry->bIsDefaultStyle && pEntry->nStyleTypeCode == STYLE_TYPE_PARA) - { - pRet = pEntry; - break; - } - } - return pRet; + return FindStyleSheetByISTD( m_pImpl->m_sDefaultParaStyleName ); } const StyleSheetEntryPtr StyleSheetTable::GetCurrentEntry() |