summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-07-06 09:09:41 +0200
committerAndras Timar <andras.timar@collabora.com>2015-08-06 12:53:13 +0200
commit893cc01aff0fe0c95e9d46e9c9f5a0e66420dc2a (patch)
tree98fbefb03d1b64f671eead97ee385cadb79cda3b /writerfilter
parent247a7722642db10a07d6eaac22afda89f1303cbe (diff)
tdf#92481 RTF import: handle \widowctrl
(cherry picked from commit ffc7b671e213d366e59d39ddbbef66544ebf01e5) Change-Id: I1af1d6bc150c16a2c6b0fe788a41c8c18caee6c6 Reviewed-on: https://gerrit.libreoffice.org/16785 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/SettingsTable.cxx25
-rw-r--r--writerfilter/source/ooxml/model.xml4
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx3
3 files changed, 30 insertions, 2 deletions
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 8a68e6d10090..b9f65f0cda9a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -3515,6 +3515,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) << "'");