[Libreoffice-commits] core.git: sw/qa writerfilter/source

Justin Luth justin_luth at sil.org
Tue Apr 24 06:58:30 UTC 2018


 sw/qa/extras/ooxmlexport/data/tdf106062_nonHangingFootnote.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport9.cxx                      |    9 +++
 writerfilter/source/dmapper/DomainMapper.cxx                   |   24 ++++++++--
 writerfilter/source/dmapper/DomainMapper_Impl.cxx              |   16 ------
 writerfilter/source/dmapper/DomainMapper_Impl.hxx              |    1 
 5 files changed, 33 insertions(+), 17 deletions(-)

New commits:
commit 946fee3ef1e319ad63a599b72dbd55ef52cbc640
Author: Justin Luth <justin_luth at sil.org>
Date:   Fri Mar 30 21:22:44 2018 +0300

    tdf#106062 ooxmlimport: skip fake tab only on hanging indent
    
    Export has changed, so that it only exports a tab when the
    footnote paragraph has a hanging indent. Adjusting the import
    code to match that change.
    
    Please test with MSO before flagging this patch as a regression.
    Certainly there will be some documents previously saved by LO
    which will now, in LO, show an extra tab character after the footnote.
    Any previously saved document without a hanging indent will display
    this extra tab. However, MSO has always seen that extra tab, so
    these patches are enhancing compatibility.
    
    This patch corrects several incorrect assumptions:
    -The paragraph style is not necessarily "Footnote".
    -The paragraph may have directly defined a hanging margin.
    -An aesthetic tab is needed on a hanging indent, not a defined margin.
    
    Change-Id: Ieaa76448ce202d92efdb8d1fc04ba2674ed120ba
    Reviewed-on: https://gerrit.libreoffice.org/52172
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Justin Luth <justin_luth at sil.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf106062_nonHangingFootnote.odt b/sw/qa/extras/ooxmlexport/data/tdf106062_nonHangingFootnote.odt
new file mode 100644
index 000000000000..af5e225ea08c
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf106062_nonHangingFootnote.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index 24397c8688a6..9a10e7d0f2cb 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -917,6 +917,15 @@ DECLARE_OOXMLEXPORT_TEST(testTdf105095, "tdf105095.docx")
     CPPUNIT_ASSERT_EQUAL( OUString("\tfootnote"), xTextRange->getString() );
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf106062_nonHangingFootnote, "tdf106062_nonHangingFootnote.odt")
+{
+    uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xFootnotes(xFootnotesSupplier->getFootnotes(), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xTextRange(xFootnotes->getByIndex(0), uno::UNO_QUERY);
+    // This failed, tab between the footnote number and the footnote content was lost on import.
+    CPPUNIT_ASSERT_MESSAGE( "Footnote starts with a tab", xTextRange->getString().startsWith("\t") );
+}
+
 DECLARE_OOXMLEXPORT_TEST( testActiveXCheckbox, "activex_checkbox.docx" )
 {
     uno::Reference<drawing::XControlShape> xControlShape( getShape(1), uno::UNO_QUERY );
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index c600e007320a..41e35e0bad04 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -3287,10 +3287,28 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
         m_pImpl->m_bHasFtnSep = true;
         return;
     }
-    else if (len == 1 && sText[0] == '\t' && m_pImpl->m_bIgnoreNextTab)
+    else if (len == 1 && sText[0] == '\t' )
     {
-        m_pImpl->m_bIgnoreNextTab = false;
-        return;
+        if ( m_pImpl->m_bCheckFirstFootnoteTab && m_pImpl->IsInFootOrEndnote() )
+        {
+            // Allow MSO to emulate LO footnote text starting at left margin - only meaningful with hanging indent
+            m_pImpl->m_bCheckFirstFootnoteTab = false;
+            sal_Int32 nFirstLineIndent = 0;
+            m_pImpl->GetPropertyFromStyleSheet(PROP_PARA_FIRST_LINE_INDENT) >>= nFirstLineIndent;
+            PropertyMapPtr pParaContext = m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH);
+            boost::optional<PropertyMap::Property> oHangingIndent = pParaContext->getProperty(PROP_PARA_FIRST_LINE_INDENT);
+            if ( oHangingIndent )
+                oHangingIndent->second >>= nFirstLineIndent;
+
+            if ( nFirstLineIndent < 0 )
+                m_pImpl->m_bIgnoreNextTab = true;
+        }
+
+        if ( m_pImpl->m_bIgnoreNextTab )
+        {
+            m_pImpl->m_bIgnoreNextTab = false;
+            return;
+        }
     }
 
     if (!m_pImpl->hasTableManager())
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 0cbabe033df9..99c520c30aa5 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -243,6 +243,7 @@ DomainMapper_Impl::DomainMapper_Impl(
         m_bHasFtn(false),
         m_bHasFtnSep(false),
         m_bIgnoreNextPara(false),
+        m_bCheckFirstFootnoteTab(false),
         m_bIgnoreNextTab(false),
         m_bFrameBtLr(false),
         m_bIsSplitPara(false),
@@ -1806,6 +1807,7 @@ void DomainMapper_Impl::PopPageHeaderFooter()
 void DomainMapper_Impl::PushFootOrEndnote( bool bIsFootnote )
 {
     m_bInFootOrEndnote = true;
+    m_bCheckFirstFootnoteTab = true;
     try
     {
         // Redlines outside the footnote should not affect footnote content
@@ -1828,20 +1830,6 @@ void DomainMapper_Impl::PushFootOrEndnote( bool bIsFootnote )
         // Redlines for the footnote anchor
         CheckRedline( xFootnote->getAnchor( ) );
 
-        // LO inserts a tab when exporting to MS formats in order to emulate its automatic space
-        // between the footnote number and text using the paragraph margin.
-        // So ignore that tab when there is a margin set.
-        uno::Reference<style::XStyleFamiliesSupplier> xStylesSupplier( GetTextDocument(), uno::UNO_QUERY);
-        uno::Reference<container::XNameAccess> xStyleFamilies = xStylesSupplier->getStyleFamilies();
-        uno::Reference<container::XNameContainer> xStyles;
-        xStyleFamilies->getByName("ParagraphStyles") >>= xStyles;
-        uno::Reference<beans::XPropertySet> xStyle(xStyles->getByName("Footnote"), uno::UNO_QUERY);
-        if (xStyle.is())
-        {
-            sal_Int32 nMargin = 0;
-            xStyle->getPropertyValue("ParaLeftMargin") >>= nMargin;
-            m_bIgnoreNextTab = nMargin > 0;
-        }
     }
     catch( const uno::Exception& e )
     {
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 911d2e8ee100..d671c210853b 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -927,6 +927,7 @@ public:
     /// If the next newline should be ignored, used by the special footnote separator paragraph.
     bool m_bIgnoreNextPara;
     /// If the next tab should be ignored, used for footnotes.
+    bool m_bCheckFirstFootnoteTab;
     bool m_bIgnoreNextTab;
     bool m_bFrameBtLr; ///< Bottom to top, left to right text frame direction is requested for the current text frame.
     /// Pending floating tables: they may be converted to text frames at the section end.


More information about the Libreoffice-commits mailing list