diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-06-08 17:05:42 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-06-08 17:46:58 +0200 |
commit | d4123356c61db269651e950a0a2cc93e6d801c90 (patch) | |
tree | 2c0ec62f7fa9ad9a6a2de1ea6402fa4b45dd6df8 /writerfilter | |
parent | c44fc5056913423258d740e74f4980017e2431ff (diff) |
RTF filter: allow measuring page borders from the edge of the page
This is similar to commit 51942eafdb4439559b6d59f3becd4afab45277f0 (DOC
import: allow negative page border distances, 2022-06-08), except here
we map \pgbrdropt's 5th bit to the "from page edge" bool, and then the
rest of the import works already after the DOCX fixes.
Similarly, the export has to map the "from page edge" bool to \pgbrdropt
and has to call into editeng::BorderDistancesToWord(), but the rest of
the process works after the DOCX fixes.
Change-Id: Ic88f1ab17ac169025c38790ffa895748df0a76c0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135502
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'writerfilter')
3 files changed, 50 insertions, 0 deletions
diff --git a/writerfilter/qa/cppunittests/rtftok/data/negative-page-border.rtf b/writerfilter/qa/cppunittests/rtftok/data/negative-page-border.rtf new file mode 100644 index 000000000000..e5bec712a60e --- /dev/null +++ b/writerfilter/qa/cppunittests/rtftok/data/negative-page-border.rtf @@ -0,0 +1,7 @@ +{\rtf1 +\paperw11906\paperh16838\margl1134\margr1134\margt284\margb1134 +\sectd\pgbrdropt32\pgbrdrt\brdrs\brdrw90\brsp560 \pgbrdrl\brdrs\brdrw90\brsp560 \pgbrdrb\brdrs\brdrw90\brsp560 \pgbrdrr\brdrs\brdrw90\brsp560 +\pard\plain +In this example, the page top margin (0.5cm) is the same as the border top margin (0.5 cm). +\par +} diff --git a/writerfilter/qa/cppunittests/rtftok/rtfdispatchvalue.cxx b/writerfilter/qa/cppunittests/rtftok/rtfdispatchvalue.cxx index 662e65d75166..4479a0c3cbd3 100644 --- a/writerfilter/qa/cppunittests/rtftok/rtfdispatchvalue.cxx +++ b/writerfilter/qa/cppunittests/rtftok/rtfdispatchvalue.cxx @@ -13,6 +13,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/table/BorderLine2.hpp> using namespace ::com::sun::star; @@ -72,6 +73,35 @@ CPPUNIT_TEST_FIXTURE(Test, testFollowStyle) // i.e. \snext was ignored. CPPUNIT_ASSERT_EQUAL(OUString("Standard"), aFollowStyle); } + +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.rtf"; + + // 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 : 342 + // i.e. the border negative distance was lost. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-646), nTopBorderDistance); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx index eb5370223aaa..a77e22a09ea5 100644 --- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx +++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx @@ -1803,6 +1803,19 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) } } break; + case RTFKeyword::PGBRDROPT: + { + sal_Int16 nOffsetFrom = (nParam & 0xe0) >> 5; + bool bFromEdge = nOffsetFrom == 1; + if (bFromEdge) + { + Id nId = NS_ooxml::LN_Value_doc_ST_PageBorderOffset_page; + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgBorders, + NS_ooxml::LN_CT_PageBorders_offsetFrom, new RTFValue(nId)); + } + } + break; default: { SAL_INFO("writerfilter", "TODO handle value '" << keywordToString(nKeyword) << "'"); |