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

Tibor Nagy (via logerrit) logerrit at kemper.freedesktop.org
Fri Aug 7 10:19:29 UTC 2020


 cui/source/tabpages/swpossizetabpage.cxx                    |    4 
 sw/qa/core/objectpositioning/objectpositioning.cxx          |   68 ++++++++++++
 sw/source/core/objectpositioning/anchoredobjectposition.cxx |    8 +
 3 files changed, 78 insertions(+), 2 deletions(-)

New commits:
commit d54264e34c1ccc0eaf4178ab165a843028500223
Author:     Tibor Nagy <nagy.tibor2 at nisz.hu>
AuthorDate: Wed Aug 5 14:29:49 2020 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Fri Aug 7 12:18:45 2020 +0200

    tdf#133071 DOCX import: fix vertical alignment to bottom page margin
    
    The relative vertical alignment (top, center and bottom) of
    bottom page margin wasn't handled.
    
    Co-authored-by: Attila Szűcs (NISZ)
    
    Change-Id: Ib41a8790f88ef004390787e3673a209dadd86457
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100170
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/cui/source/tabpages/swpossizetabpage.cxx b/cui/source/tabpages/swpossizetabpage.cxx
index 54bb58f2c999..e78826bc5105 100644
--- a/cui/source/tabpages/swpossizetabpage.cxx
+++ b/cui/source/tabpages/swpossizetabpage.cxx
@@ -259,14 +259,14 @@ FrmMap const aHParaHtmlAbsMap[] =
 
 
 constexpr auto VERT_PARA_REL = LB::VertFrame|LB::VertPrintArea|
-                                      LB::RelPageFrame|LB::RelPagePrintArea;
+                                      LB::RelPageFrame|LB::RelPagePrintArea|LB::RelPagePrintAreaBottom;
 
 FrmMap const aVParaMap[] =
 {
     {SvxSwFramePosString::TOP,           SvxSwFramePosString::TOP,            VertOrientation::TOP,       VERT_PARA_REL},
     {SvxSwFramePosString::BOTTOM,        SvxSwFramePosString::BOTTOM,         VertOrientation::BOTTOM,    VERT_PARA_REL},
     {SvxSwFramePosString::CENTER_VERT,   SvxSwFramePosString::CENTER_VERT,    VertOrientation::CENTER,    VERT_PARA_REL},
-    {SvxSwFramePosString::FROMTOP,       SvxSwFramePosString::FROMTOP,        VertOrientation::NONE,      VERT_PARA_REL|LB::RelPagePrintAreaBottom}
+    {SvxSwFramePosString::FROMTOP,       SvxSwFramePosString::FROMTOP,        VertOrientation::NONE,      VERT_PARA_REL}
 };
 
 FrmMap const aVParaHtmlMap[] =
diff --git a/sw/qa/core/objectpositioning/objectpositioning.cxx b/sw/qa/core/objectpositioning/objectpositioning.cxx
index edd4d2bdcab7..58ea30b3ce53 100644
--- a/sw/qa/core/objectpositioning/objectpositioning.cxx
+++ b/sw/qa/core/objectpositioning/objectpositioning.cxx
@@ -73,6 +73,74 @@ CPPUNIT_TEST_FIXTURE(SwCoreObjectpositioningTest, testVertPosFromBottom)
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(564), nBodyBottom - nAnchoredBottom);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreObjectpositioningTest, testVertAlignBottomMargin)
+{
+    // Create a document, insert three shapes and align it the bottom,center,top of page print area bottom.
+    // The size of shapes are 284 ~ 0.5cm
+    // The height of page print area bottom is 1134 ~ 2cm
+    mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+    uno::Reference<css::lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+
+    //Create first shape and align bottom of page print area bottom.
+    uno::Reference<drawing::XShape> xShapeBottom(
+        xFactory->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
+    xShapeBottom->setSize(awt::Size(500, 500));
+    uno::Reference<beans::XPropertySet> xShapePropsBottom(xShapeBottom, uno::UNO_QUERY);
+    xShapePropsBottom->setPropertyValue("AnchorType",
+                                        uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+    xShapePropsBottom->setPropertyValue("VertOrient", uno::makeAny(text::VertOrientation::BOTTOM));
+    xShapePropsBottom->setPropertyValue("VertOrientRelation",
+                                        uno::makeAny(text::RelOrientation::PAGE_PRINT_AREA_BOTTOM));
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplierBottom(mxComponent, uno::UNO_QUERY);
+    xDrawPageSupplierBottom->getDrawPage()->add(xShapeBottom);
+
+    //Create second shape and align center of page print area bottom.
+    uno::Reference<drawing::XShape> xShapeCenter(
+        xFactory->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
+    xShapeCenter->setSize(awt::Size(500, 500));
+    uno::Reference<beans::XPropertySet> xShapePropsCenter(xShapeCenter, uno::UNO_QUERY);
+    xShapePropsCenter->setPropertyValue("AnchorType",
+                                        uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+    xShapePropsCenter->setPropertyValue("VertOrient", uno::makeAny(text::VertOrientation::CENTER));
+    xShapePropsCenter->setPropertyValue("VertOrientRelation",
+                                        uno::makeAny(text::RelOrientation::PAGE_PRINT_AREA_BOTTOM));
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplierCenter(mxComponent, uno::UNO_QUERY);
+    xDrawPageSupplierCenter->getDrawPage()->add(xShapeCenter);
+
+    //Create third shape and align top of page print area bottom.
+    uno::Reference<drawing::XShape> xShapeTop(
+        xFactory->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY);
+    xShapeTop->setSize(awt::Size(500, 500));
+    uno::Reference<beans::XPropertySet> xShapePropsTop(xShapeTop, uno::UNO_QUERY);
+    xShapePropsTop->setPropertyValue("AnchorType",
+                                     uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+    xShapePropsTop->setPropertyValue("VertOrient", uno::makeAny(text::VertOrientation::TOP));
+    xShapePropsTop->setPropertyValue("VertOrientRelation",
+                                     uno::makeAny(text::RelOrientation::PAGE_PRINT_AREA_BOTTOM));
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplierTop(mxComponent, uno::UNO_QUERY);
+    xDrawPageSupplierTop->getDrawPage()->add(xShapeTop);
+
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    sal_Int32 nBodyBottom = getXPath(pXmlDoc, "//body/infos/bounds", "bottom").toInt32(); //14989
+    sal_Int32 nPageBottom = getXPath(pXmlDoc, "//page/infos/bounds", "bottom").toInt32(); //16123
+    sal_Int32 nFirstShapeBottom
+        = getXPath(pXmlDoc, "//SwAnchoredDrawObject[1]/bounds", "bottom").toInt32(); //16124
+    sal_Int32 nSecondShapeBottom
+        = getXPath(pXmlDoc, "//SwAnchoredDrawObject[2]/bounds", "bottom").toInt32(); //15699
+    sal_Int32 nSecondShapeTop
+        = getXPath(pXmlDoc, "//SwAnchoredDrawObject[2]/bounds", "top").toInt32(); //15414
+    sal_Int32 nThirdShapeTop
+        = getXPath(pXmlDoc, "//SwAnchoredDrawObject[3]/bounds", "top").toInt32(); //14989
+
+    // Verify that the distance between the bottom of page and bottom of first shape is around 0cm. (align=bottom)
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), nFirstShapeBottom - nPageBottom);
+    // Verify that the distance between the bottom of page and bottom of second shape is around 0.75cm and
+    // verify that the distance between the bottom of body and top of second shape is around 0.75cm.(align=center)
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(424), nPageBottom - nSecondShapeBottom);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(425), nSecondShapeTop - nBodyBottom);
+    // Verify that the distance between the bottom of body and top of third shape is around 0cm. (align=top)
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nThirdShapeTop - nBodyBottom);
+}
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/objectpositioning/anchoredobjectposition.cxx b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
index 99bbd7f49d5d..a547ddd01633 100644
--- a/sw/source/core/objectpositioning/anchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
@@ -285,6 +285,14 @@ void SwAnchoredObjectPosition::GetVertAlignmentValues(
             }
         }
         break;
+        case text::RelOrientation::PAGE_PRINT_AREA_BOTTOM:
+        {
+            nHeight = aRectFnSet.GetBottomMargin(_rPageAlignLayFrame);
+            nOffset = aRectFnSet.YDiff(
+                      aRectFnSet.GetPrtBottom(_rPageAlignLayFrame),
+                      nVertOrientTop);
+        }
+        break;
         // #i22341# - vertical alignment at top of line
         case text::RelOrientation::TEXT_LINE:
         {


More information about the Libreoffice-commits mailing list