summaryrefslogtreecommitdiff
path: root/writerfilter/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-06-07 08:03:34 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-06-07 08:45:46 +0200
commit1f127a2b9e1c1daab0972f98fc8708ecb7afa299 (patch)
treeb81fbf9af5bb65d09dc9538f1daa467f90d5e167 /writerfilter/qa
parentf4b6cee77e1725837f9a6044fec0b561c7049c3b (diff)
sw layout: allow negative page border distances
Writer follows the CSS box model when it comes to page borders: there can be a positive distance between the edge of the page and the border, and again a positive distance between the border and the body frame. This ensures that the page border never intersect with the body frame, which is usually what users expect. Word, however, can work with 2 distances for border and text, both measured from the edge of the page, leading to a page border, which is inside the body text. This is described at great detail at <https://wiki.openoffice.org/wiki/Writer/MSInteroperability/PageBorder#Importing_case_3:>. Fix the problem by allowing negative border distances: this doesn't influence the position or the size of the body frame, but it gives us a way to position the border more towards the center of the page, leading the matching layout between Writer and Word. The doc model (to allow negative border distances), UNO API and DOCX filter is updated in this commit. The ODT filter works without explicit effort. Other filters are not yet updated in this commit. Change-Id: I723e1bdb8dc6391129f1686f88826cc089f6fd67 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135462 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'writerfilter/qa')
-rw-r--r--writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx60
-rw-r--r--writerfilter/qa/cppunittests/dmapper/data/negative-page-border-no-margin.docxbin0 -> 12206 bytes
-rw-r--r--writerfilter/qa/cppunittests/dmapper/data/negative-page-border.docxbin0 -> 12124 bytes
3 files changed, 60 insertions, 0 deletions
diff --git a/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx b/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx
index ae32ce1e4dc7..cc651d224736 100644
--- a/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx
@@ -16,6 +16,7 @@
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
+#include <com/sun/star/table/BorderLine2.hpp>
using namespace ::com::sun::star;
@@ -108,6 +109,65 @@ CPPUNIT_TEST_FIXTURE(Test, testTableNegativeVerticalPos)
// i.e. this was imported as a plain table, resulting in a 0 top margin (y pos too large).
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xDrawPage->getCount());
}
+
+CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorder)
+{
+ // Given a document with a top margin and a border which has more spacing than the margin:
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "negative-page-border.docx";
+
+ // When loading that document:
+ getComponent() = loadFromDesktop(aURL);
+
+ // Then make sure that the border distance is negative, so it can appear at the correct
+ // position:
+ uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(getComponent(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamilies
+ = xStyleFamiliesSupplier->getStyleFamilies();
+ uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"),
+ uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY);
+ auto nTopMargin = xStyle->getPropertyValue("TopMargin").get<sal_Int32>();
+ 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>();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: -646
+ // - Actual : 0
+ // i.e. the border negative distance was lost.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-646), nTopBorderDistance);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorderNoMargin)
+{
+ // Given a document with no top margin and a border which has spacing:
+ OUString aURL
+ = m_directories.getURLFromSrc(DATA_DIRECTORY) + "negative-page-border-no-margin.docx";
+
+ // When loading that document:
+ getComponent() = loadFromDesktop(aURL);
+
+ // Then make sure that the border distance is negative, so it can appear at the correct
+ // position:
+ uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(getComponent(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamilies
+ = xStyleFamiliesSupplier->getStyleFamilies();
+ uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"),
+ uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY);
+ auto nTopMargin = xStyle->getPropertyValue("TopMargin").get<sal_Int32>();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), 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>();
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: -1147
+ // - Actual : 0
+ // i.e. the border negative distance was lost.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1147), nTopBorderDistance);
+}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/qa/cppunittests/dmapper/data/negative-page-border-no-margin.docx b/writerfilter/qa/cppunittests/dmapper/data/negative-page-border-no-margin.docx
new file mode 100644
index 000000000000..8bd464a9ea6c
--- /dev/null
+++ b/writerfilter/qa/cppunittests/dmapper/data/negative-page-border-no-margin.docx
Binary files differ
diff --git a/writerfilter/qa/cppunittests/dmapper/data/negative-page-border.docx b/writerfilter/qa/cppunittests/dmapper/data/negative-page-border.docx
new file mode 100644
index 000000000000..878ba1e7899b
--- /dev/null
+++ b/writerfilter/qa/cppunittests/dmapper/data/negative-page-border.docx
Binary files differ