[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - sw/qa writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Jul 6 15:10:28 PDT 2015


 sw/qa/extras/rtfimport/data/tdf92481.rtf       |    6 ++++++
 sw/qa/extras/rtfimport/rtfimport.cxx           |    6 ++++++
 writerfilter/source/dmapper/SettingsTable.cxx  |   25 +++++++++++++++++++++++--
 writerfilter/source/ooxml/model.xml            |    4 ++++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |    3 +++
 5 files changed, 42 insertions(+), 2 deletions(-)

New commits:
commit ff3a1d983acc04715e16373c1ca8cc64dafdccd0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Jul 6 09:09:41 2015 +0200

    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 at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/sw/qa/extras/rtfimport/data/tdf92481.rtf b/sw/qa/extras/rtfimport/data/tdf92481.rtf
new file mode 100644
index 0000000..09a6c5e
--- /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 8a22358..99637e8 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 ef4ed92..dbb2da1 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 df0ae0e..9a8c4d0 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 8a68e6d..b9f65f0 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) << "'");


More information about the Libreoffice-commits mailing list