diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-06-08 09:08:27 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-06-08 12:07:48 +0200 |
commit | 51942eafdb4439559b6d59f3becd4afab45277f0 (patch) | |
tree | fbf70bbd31358db2af6c68abec8518244c626e18 /sw/qa | |
parent | e216988657e20a1e52986f742ab60464697bcb41 (diff) |
DOC import: allow negative page border distances
In case the margin (distance between body frame and page frame) is
smaller than the border spacing (distance between border and page
frame), then we can map that to a negative border distance during the
import of DOCX files since commit
1f127a2b9e1c1daab0972f98fc8708ecb7afa299 (sw layout: allow negative page
border distances, 2022-06-07), but DOC import had the same problem.
The above commit intentionally kept the default behavior of
BorderDistanceFromWord() unchanged to avoid side effects in other
clients of that function (not DOCX import), but means that DOC import
was still broken.
Given that it turns out there are only 2 callers of
BorderDistanceFromWord(), fix the problem by allowing negative border
distances unconditionally: this simplifies code & SetBorderDistance() in
the DOC import will now get the correct border distance out of the box.
DOC export works out of the box without any additional work.
Change-Id: I6bf15b3c73823c9265218b7b3a7b869e131818db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135484
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/filter/ww8/data/negative-page-border.doc | bin | 0 -> 22528 bytes | |||
-rw-r--r-- | sw/qa/filter/ww8/ww8.cxx | 55 |
2 files changed, 55 insertions, 0 deletions
diff --git a/sw/qa/filter/ww8/data/negative-page-border.doc b/sw/qa/filter/ww8/data/negative-page-border.doc Binary files differnew file mode 100644 index 000000000000..6ea5e9030fa3 --- /dev/null +++ b/sw/qa/filter/ww8/data/negative-page-border.doc diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx new file mode 100644 index 000000000000..eb735b16a746 --- /dev/null +++ b/sw/qa/filter/ww8/ww8.cxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +namespace +{ +constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/filter/ww8/data/"; + +/** + * Covers sw/source/filter/ww8/ fixes. + * + * Note that these tests are meant to be simple: either load a file and assert some result or build + * a document model with code, export and assert that result. + * + * Keep using the various sw_<format>import/export suites for multiple filter calls inside a single + * test. + */ +class Test : public SwModelTestBase +{ +}; + +CPPUNIT_TEST_FIXTURE(Test, testSwAttrSet) +{ + // Given a document with a border distance that is larger than the margin, when loading that + // document: + createSwDoc(DATA_DIRECTORY, "negative-page-border.doc"); + + // Then make sure we map that to a negative border distance (move border from the edge of body + // frame towards the center of the page, not towards the edge of the page): + uno::Reference<container::XNameAccess> xStyleFamily = getStyles("PageStyles"); + uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY); + auto nTopMargin = xStyle->getPropertyValue("TopMargin").get<sal_Int32>(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 501 + // - Actual : 342 + // i.e. the border properties influenced the margin, which was 284 twips in the sprmSDyaTop + // SPRM. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(501), nTopMargin); + auto aTopBorder = xStyle->getPropertyValue("TopBorder").get<table::BorderLine2>(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(159), aTopBorder.LineWidth); + auto nTopBorderDistance = xStyle->getPropertyValue("TopBorderDistance").get<sal_Int32>(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-646), nTopBorderDistance); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |