sw/qa/extras/rtfexport/data/tdf117505.odt   |binary
 sw/qa/extras/rtfexport/rtfexport3.cxx       |   11 +++++++++++
 sw/source/filter/ww8/rtfattributeoutput.cxx |    9 ++++++++-
 sw/source/filter/ww8/rtfexport.cxx          |    3 +++
 sw/source/filter/ww8/rtfexport.hxx          |    4 ++++
 5 files changed, 26 insertions(+), 1 deletion(-)

New commits:
commit 5956828c88501ef1366e60010b05053a8e1e642e
Author: Miklos Vajna <vmik...@collabora.co.uk>
Date:   Tue May 22 22:05:24 2018 +0200

    tdf#117505 RTF export: fix incorrect header distance for first/follow pages
    
    In case the first and the follow page format has different header
    distances, the DOC and DOCX import work with the distance from the first
    page format when they take the last item from the MSWordSections
    container at the end of the export.
    
    RTF writes section info before the document content, and in case there
    are separate first and follow page formats, then we work with the follow
    format since commit 20a53cb9e9c7b797c091fe6ac6a34dfb28c61304
    (INTEGRATION: CWS limerickfilterteam08 (1.16.32); FILE MERGED,
    2003-09-01) as a fix for i#13107.
    
    There is no perfect solution here, the sw doc model can store different
    header distances for first and follow pages, while Word works with a
    single distance. But RTF/DOCX/DOC import puts the relevant header
    distance to the first page format and DOCX/DOC export reads the distance
    from there, so be consistent and do the same in the RTF export as well.
    
    This means the DOCX import -> RTF export -> RTF import sequence from the
    bugreport will result in a correct header distance.
    
    Change-Id: I3f1fe3080360702c41d680b8785cc3602e74685e
    Reviewed-on: https://gerrit.libreoffice.org/54680
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk>

diff --git a/sw/qa/extras/rtfexport/data/tdf117505.odt 
b/sw/qa/extras/rtfexport/data/tdf117505.odt
new file mode 100644
index 000000000000..91bde8f92393
Binary files /dev/null and b/sw/qa/extras/rtfexport/data/tdf117505.odt differ
diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx 
b/sw/qa/extras/rtfexport/rtfexport3.cxx
index 142c7f6c8381..d27eec82fea9 100644
--- a/sw/qa/extras/rtfexport/rtfexport3.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport3.cxx
@@ -145,6 +145,17 @@ DECLARE_RTFEXPORT_TEST(testTdf117268, "tdf117268.rtf")
     CPPUNIT_ASSERT_EQUAL(xCell, xAnchorCell);
 }
 
+DECLARE_RTFEXPORT_TEST(testTdf117505, "tdf117505.odt")
+{
+    uno::Reference<container::XNameAccess> 
xPageStyles(getStyles("PageStyles"));
+    uno::Reference<beans::XPropertySet> 
xFirstPage(xPageStyles->getByName("First Page"),
+                                                   uno::UNO_QUERY);
+    // This was 499, small header height resulted in visible whitespace from
+    // remaining top margin -> header content moved down.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1499),
+                         getProperty<sal_Int32>(xFirstPage, "HeaderHeight"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx 
b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 56c0d2f9d293..42199d4770b6 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -3017,7 +3017,14 @@ void RtfAttributeOutput::FormatULSpace(const 
SvxULSpaceItem& rULSpace)
             if (!m_rExport.GetCurItemSet())
                 return;
 
-            sw::util::HdFtDistanceGlue aDistances(*m_rExport.GetCurItemSet());
+            // If we export a follow page format, then our doc model has
+            // separate header/footer distances for the first page and the
+            // follow pages, but Word can have only a single distance. In case
+            // the two values differ, work with the value from the first page
+            // format to be in sync with the import.
+            sw::util::HdFtDistanceGlue 
aDistances(m_rExport.GetFirstPageItemSet()
+                                                      ? 
*m_rExport.GetFirstPageItemSet()
+                                                      : 
*m_rExport.GetCurItemSet());
 
             if (aDistances.dyaTop)
             {
diff --git a/sw/source/filter/ww8/rtfexport.cxx 
b/sw/source/filter/ww8/rtfexport.cxx
index 0b206edcf693..7c5e096ea5b3 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -1348,7 +1348,10 @@ void RtfExport::OutPageDescription(const SwPageDesc& 
rPgDsc, bool bCheckForFirst
 
     const SwFormat* pFormat = &m_pCurrentPageDesc->GetMaster(); //GetLeft();
     m_bOutPageDescs = true;
+    if (m_pCurrentPageDesc != &rPgDsc)
+        m_pFirstPageItemSet = &rPgDsc.GetMaster().GetAttrSet();
     OutputFormat(*pFormat, true, false);
+    m_pFirstPageItemSet = nullptr;
     m_bOutPageDescs = false;
 
     // normal header / footer (without a style)
diff --git a/sw/source/filter/ww8/rtfexport.hxx 
b/sw/source/filter/ww8/rtfexport.hxx
index 03f06d5e22b1..fd2c7a285e7b 100644
--- a/sw/source/filter/ww8/rtfexport.hxx
+++ b/sw/source/filter/ww8/rtfexport.hxx
@@ -189,6 +189,8 @@ public:
     void InsStyle(sal_uInt16 nId, const OString& rStyle);
     OString* GetStyle(sal_uInt16 nId);
 
+    const SfxItemSet* GetFirstPageItemSet() { return m_pFirstPageItemSet; }
+
 private:
     void WriteFonts();
     void WriteStyles();
@@ -214,6 +216,8 @@ private:
     std::map<OUString, sal_uInt16> m_aRedlineTable;
     /// If set, then Strm() returns this tream, instead of m_pWriter's stream.
     std::unique_ptr<SvMemoryStream> m_pStream;
+    /// Item set of the first page during export of a follow page format.
+    const SfxItemSet* m_pFirstPageItemSet = nullptr;
 };
 
 #endif // INCLUDED_SW_SOURCE_FILTER_WW8_RTFEXPORT_HXX
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to