sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginHasHeader.docx
 |binary
 
sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginNoHeader.docx
  |binary
 sw/qa/extras/ooxmlexport/ooxmlexport14.cxx                                     
             |   36 ++++++++++
 sw/source/core/inc/pagefrm.hxx                                                 
             |    1 
 sw/source/core/layout/anchoreddrawobject.cxx                                   
             |    9 ++
 sw/source/core/layout/pagechg.cxx                                              
             |   12 +++
 writerfilter/source/dmapper/GraphicImport.cxx                                  
             |    7 +
 7 files changed, 65 insertions(+)

New commits:
commit a85c2504c002dff069c129ab244cb2ba5820943d
Author:     Regényi Balázs <regenyi.balazs+ger...@gmail.com>
AuthorDate: Mon Jun 22 10:28:15 2020 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Thu Jul 2 12:32:33 2020 +0200

    tdf#123324 DOCX import: fix shape height relative to top page margin
    
    using UNO API RelativeHeightRelation and the associated
    lo-ext attribute for OpenDocument export.
    
    See commit 43d7f4e3640c5e370fd1204739c2b0c7eb5f40e4
    (offapi: document the 4 new properties which are no longer read-only).
    
    Co-authored-by: Szabolcs Tóth
    
    Change-Id: Ibaba4b3762de5a70506dacd85a818b8972b18144
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96869
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git 
a/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginHasHeader.docx
 
b/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginHasHeader.docx
new file mode 100644
index 000000000000..b978eec993c7
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginHasHeader.docx
 differ
diff --git 
a/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginNoHeader.docx
 
b/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginNoHeader.docx
new file mode 100644
index 000000000000..70c2793cbf96
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf123324_testRelativeAnchorHeightFromTopMarginNoHeader.docx
 differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
index 167c05111a51..3ca1a456182f 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx
@@ -1163,6 +1163,42 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf108505, 
"tdf108505.docx")
         getProperty<OUString>(xText, "CharFontName"));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorHeightFromTopMarginHasHeader,
+                         
"tdf123324_testRelativeAnchorHeightFromTopMarginHasHeader.docx")
+{
+    // TODO: fix export too
+    if (mbExported)
+        return;
+    // tdf#123324 The height was set relative to page print area top,
+    // but this was handled relative to page height.
+    // Note: page print area top = margin + header height.
+    // In this case the header exists.
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    const sal_Int32 nAnchoredHeight
+        = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", 
"height").toInt32();
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2551), nAnchoredHeight);
+}
+
+DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorHeightFromTopMarginNoHeader,
+                         
"tdf123324_testRelativeAnchorHeightFromTopMarginNoHeader.docx")
+{
+    // TODO: fix export too
+    if (mbExported)
+        return;
+    // tdf#123324 The height was set relative from top margin, but this was 
handled relative from page height.
+    // Note: the MSO Word margin = LO margin + LO header height.
+    // In this case the header does not exist, so MSO Word margin and LO 
Writer margin are the same.
+
+    // tdf#123324 The height was set relative to page print area top,
+    // but this was handled relative to page height.
+    // Note: page print area top = margin + header height.
+    // In this case the header does not exist, so OpenDocument and OOXML 
margins are the same.
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    const sal_Int32 nAnchoredHeight
+        = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", 
"height").toInt32();
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2551), nAnchoredHeight);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/pagefrm.hxx b/sw/source/core/inc/pagefrm.hxx
index 3c7f29f52ad0..a9f642c1f03e 100644
--- a/sw/source/core/inc/pagefrm.hxx
+++ b/sw/source/core/inc/pagefrm.hxx
@@ -330,6 +330,7 @@ public:
     /// If false is returned, then the caller should handle negative 
difference as (at least) zero difference instead.
     bool CheckPageHeightValidForHideWhitespace(SwTwips nDiff);
 
+    const SwHeaderFrame* GetHeaderFrame() const;
     const SwFooterFrame* GetFooterFrame() const;
 };
 
diff --git a/sw/source/core/layout/anchoreddrawobject.cxx 
b/sw/source/core/layout/anchoreddrawobject.cxx
index 1af32ed2fa80..1ea69271f202 100644
--- a/sw/source/core/layout/anchoreddrawobject.cxx
+++ b/sw/source/core/layout/anchoreddrawobject.cxx
@@ -688,6 +688,15 @@ SwRect SwAnchoredDrawObject::GetObjBoundRect() const
             if (GetDrawObj()->GetRelativeHeightRelation() == 
text::RelOrientation::FRAME)
                 // Exclude margins.
                 nHeight = 
GetPageFrame()->getFramePrintArea().SVRect().GetHeight();
+            else if (GetDrawObj()->GetRelativeHeightRelation() == 
text::RelOrientation::PAGE_PRINT_AREA)
+            {
+                // count required height: print area top = top margin + header
+                SwRect aHeaderRect;
+                const SwHeaderFrame* pHeaderFrame = 
GetPageFrame()->GetHeaderFrame();
+                if (pHeaderFrame)
+                    aHeaderRect = pHeaderFrame->GetPaintArea();
+                nHeight = GetPageFrame()->GetTopMargin() + 
aHeaderRect.Height();
+            }
             else if (GetDrawObj()->GetRelativeHeightRelation() == 
text::RelOrientation::PAGE_PRINT_AREA_BOTTOM)
             {
                 // count required height: print area bottom = bottom margin + 
footer
diff --git a/sw/source/core/layout/pagechg.cxx 
b/sw/source/core/layout/pagechg.cxx
index a3188eb2a5ca..ebcf239ef580 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -2512,6 +2512,18 @@ bool 
SwPageFrame::CheckPageHeightValidForHideWhitespace(SwTwips nDiff)
     return true;
 }
 
+const SwHeaderFrame* SwPageFrame::GetHeaderFrame() const
+{
+    const SwFrame* pLowerFrame = Lower();
+    while (pLowerFrame)
+    {
+        if (pLowerFrame->IsHeaderFrame())
+            return dynamic_cast<const SwHeaderFrame*>(pLowerFrame);
+        pLowerFrame = pLowerFrame->GetNext();
+    }
+    return nullptr;
+}
+
 const SwFooterFrame* SwPageFrame::GetFooterFrame() const
 {
     const SwFrame* pLowerFrame = Lower();
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx 
b/writerfilter/source/dmapper/GraphicImport.cxx
index 8286503ca114..6c8523ab9bff 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -996,6 +996,13 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
                         
xPropertySet->setPropertyValue("RelativeHeightRelation", 
uno::makeAny(text::RelOrientation::PAGE_FRAME));
                     }
                     break;
+                case NS_ooxml::LN_ST_SizeRelFromV_topMargin:
+                    if (m_xShape.is())
+                    {
+                        uno::Reference<beans::XPropertySet> 
xPropertySet(m_xShape, uno::UNO_QUERY);
+                        
xPropertySet->setPropertyValue("RelativeHeightRelation", 
uno::makeAny(text::RelOrientation::PAGE_PRINT_AREA));
+                    }
+                    break;
                 case NS_ooxml::LN_ST_SizeRelFromV_bottomMargin:
                     if (m_xShape.is())
                     {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to