diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-03-31 13:59:38 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-03-31 14:56:49 +0200 |
commit | fac65bb9d831a854298d6cba09ad6159d15b8323 (patch) | |
tree | 1a12ad1710bd28f9c0eac25ed52ef114f5a87d4b /xmloff | |
parent | b802ab694a8a7357d4657f3e11b571144fa7c7bf (diff) |
tdf#140343 sw page rtl gutter margin: add ODF import
See <https://issues.oasis-open.org/browse/OFFICE-4105>, the proposal is
to not map this to a new attribute of the <style:page-layout-properties>
XML element, rather only write writing mode on export and infer
RtlGutter from that writing mode in import.
This is similar to how FillBitmapOffsetX and FillBitmapOffsetY are two
UNO properties, but there is a single draw:tile-repeat-offset attribute
for them.
This has the benefit of simpler ODF markup, at the cost of more
complicated xmloff code.
Change-Id: I189a7ec62d4e5624e20252b7259a36133594fe40
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113405
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/Library_xo.mk | 1 | ||||
-rw-r--r-- | xmloff/inc/PageMasterStyleMap.hxx | 2 | ||||
-rw-r--r-- | xmloff/inc/XMLRtlGutterPropertyHandler.hxx | 39 | ||||
-rw-r--r-- | xmloff/qa/unit/data/rtl-gutter.fodt | 16 | ||||
-rw-r--r-- | xmloff/qa/unit/style.cxx | 24 | ||||
-rw-r--r-- | xmloff/source/style/PageMasterPropHdlFactory.cxx | 4 | ||||
-rw-r--r-- | xmloff/source/style/PageMasterStyleMap.cxx | 3 | ||||
-rw-r--r-- | xmloff/source/style/XMLRtlGutterPropertyHandler.cxx | 51 |
8 files changed, 139 insertions, 1 deletions
diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk index 175bb834e37d..b33455b3c464 100644 --- a/xmloff/Library_xo.mk +++ b/xmloff/Library_xo.mk @@ -221,6 +221,7 @@ $(eval $(call gb_Library_add_exception_objects,xo,\ xmloff/source/style/XMLBackgroundImageExport \ xmloff/source/style/XMLBitmapLogicalSizePropertyHandler \ xmloff/source/style/XMLBitmapRepeatOffsetPropertyHandler \ + xmloff/source/style/XMLRtlGutterPropertyHandler \ xmloff/source/style/XMLClipPropertyHandler \ xmloff/source/style/XMLConstantsPropertyHandler \ xmloff/source/style/XMLElementPropertyContext \ diff --git a/xmloff/inc/PageMasterStyleMap.hxx b/xmloff/inc/PageMasterStyleMap.hxx index a52b2e3aeb59..97f32ecae002 100644 --- a/xmloff/inc/PageMasterStyleMap.hxx +++ b/xmloff/inc/PageMasterStyleMap.hxx @@ -79,6 +79,8 @@ #define CTF_PM_MARGINBOTTOM (XML_PM_CTF_START + 0x001C) #define CTF_PM_MARGINLEFT (XML_PM_CTF_START + 0x001D) #define CTF_PM_MARGINRIGHT (XML_PM_CTF_START + 0x001E) +#define CTF_PM_WRITINGMODE (XML_PM_CTF_START + 0x001F) +#define CTF_PM_RTLGUTTER (XML_PM_CTF_START + 0x0020) #define CTF_PM_PAGEUSAGE (XML_PM_CTF_START + 0x0031) #define CTF_PM_GRAPHICPOSITION (XML_PM_CTF_START + 0x0032) diff --git a/xmloff/inc/XMLRtlGutterPropertyHandler.hxx b/xmloff/inc/XMLRtlGutterPropertyHandler.hxx new file mode 100644 index 000000000000..513320e154bc --- /dev/null +++ b/xmloff/inc/XMLRtlGutterPropertyHandler.hxx @@ -0,0 +1,39 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <xmloff/xmlprhdl.hxx> + +/// Maps <style:page-layout-properties style:writing-mode="..."> to RtlGutter. +class XMLRtlGutterPropertyHandler final : public XMLPropertyHandler +{ +public: + XMLRtlGutterPropertyHandler(); + + ~XMLRtlGutterPropertyHandler() override; + + bool importXML(const OUString& rStrImpValue, css::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter) const override; + + bool exportXML(OUString& rStrExpValue, const css::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter) const override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/qa/unit/data/rtl-gutter.fodt b/xmloff/qa/unit/data/rtl-gutter.fodt new file mode 100644 index 000000000000..ad08d4f33d1a --- /dev/null +++ b/xmloff/qa/unit/data/rtl-gutter.fodt @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:automatic-styles> + <style:page-layout style:name="pm1"> + <style:page-layout-properties fo:page-width="21.0cm" fo:page-height="29.7cm" fo:margin-top="2.54cm" fo:margin-bottom="2.54cm" fo:margin-left="2.54cm" fo:margin-right="2.54cm" style:writing-mode="rl-tb" loext:margin-gutter="2.54cm"/> + </style:page-layout> + </office:automatic-styles> + <office:master-styles> + <style:master-page style:name="Standard" style:page-layout-name="pm1"/> + </office:master-styles> + <office:body> + <office:text> + <text:p>hello</text:p> + </office:text> + </office:body> +</office:document> diff --git a/xmloff/qa/unit/style.cxx b/xmloff/qa/unit/style.cxx index c3c120de0e7f..c6dd4ecd8bc2 100644 --- a/xmloff/qa/unit/style.cxx +++ b/xmloff/qa/unit/style.cxx @@ -19,6 +19,8 @@ #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/frame/XStorable.hpp> #include <com/sun/star/packages/zip/ZipFileAccess.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <comphelper/propertysequence.hxx> #include <unotools/tempfile.hxx> @@ -132,6 +134,28 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testFontSorting) xmlXPathFreeObject(pXPath); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testRtlGutter) +{ + // Given a document with a gutter margin and an RTL writing mode: + // When loading that document from ODF: + load(u"rtl-gutter.fodt"); + + // Then make sure the page style's RtlGutter property is true. + 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> xStandard(xStyleFamily->getByName("Standard"), + uno::UNO_QUERY); + bool bRtlGutter{}; + xStandard->getPropertyValue("RtlGutter") >>= bRtlGutter; + // Without the accompanying fix in place, this test would have failed as + // <style:page-layout-properties>'s style:writing-mode="..." did not affect RtlGutter. + CPPUNIT_ASSERT(bRtlGutter); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterPropHdlFactory.cxx b/xmloff/source/style/PageMasterPropHdlFactory.cxx index 00500194b68a..ab03fd1c36be 100644 --- a/xmloff/source/style/PageMasterPropHdlFactory.cxx +++ b/xmloff/source/style/PageMasterPropHdlFactory.cxx @@ -35,6 +35,7 @@ #include <XMLBitmapLogicalSizePropertyHandler.hxx> #include <com/sun/star/drawing/BitmapMode.hpp> #include <XMLBitmapRepeatOffsetPropertyHandler.hxx> +#include <XMLRtlGutterPropertyHandler.hxx> using namespace ::xmloff::token; using namespace ::com::sun::star; @@ -150,6 +151,9 @@ const XMLPropertyHandler* XMLPageMasterPropHdlFactory::GetPropertyHandler( sal_I case XML_SW_TYPE_BITMAPREPOFFSETY: pHdl = new XMLBitmapRepeatOffsetPropertyHandler(XML_SW_TYPE_BITMAPREPOFFSETX == nType); break; + case XML_SW_TYPE_RTLGUTTER: + pHdl = new XMLRtlGutterPropertyHandler(); + break; default: { diff --git a/xmloff/source/style/PageMasterStyleMap.cxx b/xmloff/source/style/PageMasterStyleMap.cxx index 754c7d284baf..dabea33b93ee 100644 --- a/xmloff/source/style/PageMasterStyleMap.cxx +++ b/xmloff/source/style/PageMasterStyleMap.cxx @@ -97,7 +97,8 @@ const XMLPropertyMapEntry aXMLPageMasterStyleMap[] = PLMAP( "TextColumns", XML_NAMESPACE_STYLE, XML_COLUMNS, MID_FLAG_ELEMENT_ITEM|XML_TYPE_TEXT_COLUMNS, CTF_PM_TEXTCOLUMNS ), PLMAP( "RegisterModeActive", XML_NAMESPACE_STYLE, XML_REGISTER_TRUE, XML_TYPE_BOOL, 0 ), PLMAP( "RegisterParagraphStyle", XML_NAMESPACE_STYLE, XML_REGISTER_TRUTH_REF_STYLE_NAME, XML_TYPE_STYLENAME| MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_PM_REGISTER_STYLE ), - PLMAP( "WritingMode", XML_NAMESPACE_STYLE, XML_WRITING_MODE, XML_TYPE_TEXT_WRITING_MODE, 0 ), + PLMAP( "WritingMode", XML_NAMESPACE_STYLE, XML_WRITING_MODE, XML_TYPE_TEXT_WRITING_MODE | MID_FLAG_MULTI_PROPERTY, CTF_PM_WRITINGMODE ), + PLMAP( "RtlGutter", XML_NAMESPACE_STYLE, XML_WRITING_MODE, XML_SW_TYPE_RTLGUTTER | MID_FLAG_MULTI_PROPERTY, CTF_PM_RTLGUTTER ), // Index 53: Grid definitions PLMAP( "GridColor", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_COLOR, XML_TYPE_COLOR, 0 ), diff --git a/xmloff/source/style/XMLRtlGutterPropertyHandler.cxx b/xmloff/source/style/XMLRtlGutterPropertyHandler.cxx new file mode 100644 index 000000000000..4b8bcfb9d849 --- /dev/null +++ b/xmloff/source/style/XMLRtlGutterPropertyHandler.cxx @@ -0,0 +1,51 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <set> + +#include <com/sun/star/uno/Any.hxx> + +#include <xmloff/xmluconv.hxx> + +#include <XMLRtlGutterPropertyHandler.hxx> + +using namespace com::sun::star; + +XMLRtlGutterPropertyHandler::XMLRtlGutterPropertyHandler() = default; + +XMLRtlGutterPropertyHandler::~XMLRtlGutterPropertyHandler() = default; + +bool XMLRtlGutterPropertyHandler::importXML(const OUString& rStrImpValue, uno::Any& rValue, + const SvXMLUnitConverter&) const +{ + // Infer RtlGutter from WritingMode. + std::set<OUString> aRtlModes = { "rl-tb", "tb-rl", "rl", "tb" }; + auto it = aRtlModes.find(rStrImpValue); + rValue <<= (it != aRtlModes.end()); + return true; +} + +bool XMLRtlGutterPropertyHandler::exportXML(OUString&, const uno::Any&, + const SvXMLUnitConverter&) const +{ + // No need to export RtlGutter. + return false; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |