diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-07-06 09:09:41 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-07-06 09:16:02 +0200 |
commit | ffc7b671e213d366e59d39ddbbef66544ebf01e5 (patch) | |
tree | 4bd44fc97f71be6b327b8dac3b5ee487b72d3d81 | |
parent | 04c0b70c9bbd7c8d6e30a95c5693d283c992fd98 (diff) |
tdf#92481 RTF import: handle \widowctrl
Change-Id: I1af1d6bc150c16a2c6b0fe788a41c8c18caee6c6
-rw-r--r-- | sw/qa/extras/rtfimport/data/tdf92481.rtf | 6 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 6 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SettingsTable.cxx | 25 | ||||
-rw-r--r-- | writerfilter/source/ooxml/model.xml | 4 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 3 |
5 files changed, 42 insertions, 2 deletions
diff --git a/sw/qa/extras/rtfimport/data/tdf92481.rtf b/sw/qa/extras/rtfimport/data/tdf92481.rtf new file mode 100644 index 000000000000..09a6c5e5934f --- /dev/null +++ b/sw/qa/extras/rtfimport/data/tdf92481.rtf @@ -0,0 +1,6 @@ +{\rtf1 +\widowctrl +\pard\plain +Hello. +\par +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 24116ef86ac0..7ec1931d53b9 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -2313,6 +2313,12 @@ DECLARE_RTFIMPORT_TEST(testTdf92061, "tdf92061.rtf") CPPUNIT_ASSERT_EQUAL(OUString("body-after"), getRun(getParagraph(1), 3)->getString()); } +DECLARE_RTFIMPORT_TEST(testTdf92481, "tdf92481.rtf") +{ + // This was 0, RTF_WIDOWCTRL was not imported. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int8>(2), getProperty<sal_Int8>(getParagraph(1), "ParaWidows")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SettingsTable.cxx b/writerfilter/source/dmapper/SettingsTable.cxx index ef4ed92d0bfa..dbb2da19b5c0 100644 --- a/writerfilter/source/dmapper/SettingsTable.cxx +++ b/writerfilter/source/dmapper/SettingsTable.cxx @@ -79,6 +79,7 @@ struct SettingsTable_Impl bool m_bDoNotUseHTMLParagraphAutoSpacing; bool m_bNoColumnBalance; bool m_bAutoHyphenation; + bool m_bWidowControl; bool m_bSplitPgBreakAndParaMark; bool m_bMirrorMargin; uno::Sequence<beans::PropertyValue> m_pThemeFontLangProps; @@ -111,6 +112,7 @@ struct SettingsTable_Impl , m_bDoNotUseHTMLParagraphAutoSpacing(false) , m_bNoColumnBalance(false) , m_bAutoHyphenation(false) + , m_bWidowControl(false) , m_bSplitPgBreakAndParaMark(false) , m_bMirrorMargin(false) , m_pThemeFontLangProps(3) @@ -288,6 +290,9 @@ void SettingsTable::lcl_sprm(Sprm& rSprm) case NS_ooxml::LN_CT_Settings_autoHyphenation: m_pImpl->m_bAutoHyphenation = nIntValue; break; + case NS_ooxml::LN_CT_Settings_widowControl: + m_pImpl->m_bWidowControl = nIntValue; + break; default: { #ifdef DEBUG_WRITERFILTER @@ -373,6 +378,11 @@ uno::Sequence<beans::PropertyValue> SettingsTable::GetCompatSettings() const return comphelper::containerToSequence(m_pImpl->m_aCompatSettings); } +static bool lcl_isDefault(const uno::Reference<beans::XPropertyState>& xPropertyState, const OUString& rPropertyName) +{ + return xPropertyState->getPropertyState(rPropertyName) == beans::PropertyState_DEFAULT_VALUE; +} + void SettingsTable::ApplyProperties(uno::Reference<text::XTextDocument> const& xDoc) { uno::Reference< beans::XPropertySet> xDocProps( xDoc, uno::UNO_QUERY ); @@ -382,18 +392,29 @@ void SettingsTable::ApplyProperties(uno::Reference<text::XTextDocument> const& x xDocProps->setPropertyValue("RecordChanges", uno::makeAny( m_pImpl->m_bRecordChanges ) ); // Auto hyphenation: turns on hyphenation by default, <w:suppressAutoHyphens/> may still disable it at a paragraph level. - if (m_pImpl->m_bAutoHyphenation) + // Situation is similar for RTF_WIDOWCTRL, which turns on widow / orphan control by default. + if (m_pImpl->m_bAutoHyphenation || m_pImpl->m_bWidowControl) { uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xDoc, uno::UNO_QUERY); + if (!xStyleFamiliesSupplier.is()) + return; + uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies(); uno::Reference<container::XNameContainer> xParagraphStyles = xStyleFamilies->getByName("ParagraphStyles").get< uno::Reference<container::XNameContainer> >(); uno::Reference<style::XStyle> xDefault = xParagraphStyles->getByName("Standard").get< uno::Reference<style::XStyle> >(); uno::Reference<beans::XPropertyState> xPropertyState(xDefault, uno::UNO_QUERY); - if (xPropertyState->getPropertyState("ParaIsHyphenation") == beans::PropertyState_DEFAULT_VALUE) + if (m_pImpl->m_bAutoHyphenation && lcl_isDefault(xPropertyState, "ParaIsHyphenation")) { uno::Reference<beans::XPropertySet> xPropertySet(xDefault, uno::UNO_QUERY); xPropertySet->setPropertyValue("ParaIsHyphenation", uno::makeAny(true)); } + if (m_pImpl->m_bWidowControl && lcl_isDefault(xPropertyState, "ParaWidows") && lcl_isDefault(xPropertyState, "ParaOrphans")) + { + uno::Reference<beans::XPropertySet> xPropertySet(xDefault, uno::UNO_QUERY); + uno::Any aAny = uno::makeAny(static_cast<sal_Int8>(2)); + xPropertySet->setPropertyValue("ParaWidows", aAny); + xPropertySet->setPropertyValue("ParaOrphans", aAny); + } } } diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml index df0ae0e5b5e0..9a8c4d07af77 100644 --- a/writerfilter/source/ooxml/model.xml +++ b/writerfilter/source/ooxml/model.xml @@ -60,6 +60,10 @@ <token tokenid="ooxml:footerl"/> <token tokenid="ooxml:footerr"/> <token tokenid="ooxml:footerf"/> + + <!-- Present in RTF, but not in OOXML. --> + <token tokenid="ooxml:CT_Settings_widowControl"/> + <namespace name="dml-stylesheet"> <start name="theme"/> <start name="themeOverride"/> diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 7fe58a77f6dd..43c73c279b01 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -3514,6 +3514,9 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) case RTF_SAUTOUPD: m_aStates.top().aTableSprms.set(NS_ooxml::LN_CT_Style_autoRedefine, std::make_shared<RTFValue>(1)); break; + case RTF_WIDOWCTRL: + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_widowControl, std::make_shared<RTFValue>(1)); + break; default: { SAL_INFO("writerfilter", "TODO handle flag '" << lcl_RtfToString(nKeyword) << "'"); |