include/xmloff/xmltoken.hxx | 2 schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng | 10 ++++ xmloff/inc/txtfld.hxx | 28 ++++++++++++ xmloff/inc/txtflde.hxx | 8 +++ xmloff/inc/txtfldi.hxx | 2 xmloff/source/core/xmltoken.cxx | 2 xmloff/source/text/txtflde.cxx | 22 ++++++++- xmloff/source/text/txtfldi.cxx | 13 +++++ xmloff/source/token/tokens.txt | 2 9 files changed, 86 insertions(+), 3 deletions(-)
New commits: commit 7c13e0337f3a784d6f81296f12ae5d3e6aa5370d Author: Skyler Grey <skyler.g...@collabora.com> AuthorDate: Fri Oct 20 14:30:31 2023 +0000 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Oct 25 08:22:01 2023 +0200 Enable STYLEREF flag export/import with ODF This commit enables exporting the following STYLEREF flags with ODF - Search from bottom to top - Hide non numerical After this commit, the following steps have been implemented - The document model (I7d8f455ffe90cface4f3b1acf6b9bef6a045ed19) - The layout (I7d8f455ffe90cface4f3b1acf6b9bef6a045ed19) - The UI (I7d8f455ffe90cface4f3b1acf6b9bef6a045ed19) - UNO (Ib664fec059aa1f7f130acc76c253d5d298fa59f7) - DOCX/ODF filters (here and Ib664fec059aa1f7f130acc76c253d5d298fa59f7) Change-Id: Iad8e8001807f5ceeaedc9665838672695174a936 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158265 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx index 5bb8528c81e6..1fb203e3469c 100644 --- a/include/xmloff/xmltoken.hxx +++ b/include/xmloff/xmltoken.hxx @@ -1604,6 +1604,8 @@ namespace xmloff::token { XML_REFERENCE, XML_REFERENCE_END, XML_REFERENCE_FORMAT, + XML_REFERENCE_FROM_BOTTOM, + XML_REFERENCE_HIDE_NON_NUMERICAL, XML_REFERENCE_MARK, XML_REFERENCE_MARK_END, XML_REFERENCE_MARK_START, diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng index 5f5040173bb8..c02dcf8925be 100644 --- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng +++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng @@ -2078,6 +2078,16 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. </rng:choice> </rng:attribute> </rng:optional> + <rng:optional> + <rng:attribute name="loext:reference-hide-non-numerical"> + <rng:ref name="boolean"/> + </rng:attribute> + </rng:optional> + <rng:optional> + <rng:attribute name="loext:reference-from-bottom"> + <rng:ref name="boolean"/> + </rng:attribute> + </rng:optional> </rng:interleave> </rng:element> </rng:define> diff --git a/xmloff/inc/txtfld.hxx b/xmloff/inc/txtfld.hxx new file mode 100644 index 000000000000..c562644a5f18 --- /dev/null +++ b/xmloff/inc/txtfld.hxx @@ -0,0 +1,28 @@ +/* -*- 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 . + */ + +/** @#file + * Constants, helpers etc. that need to be shared between text field import + * and export + */ + +#pragma once + +#define REFFLDFLAG_STYLE_FROM_BOTTOM 0xc100 +#define REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL 0xc200 diff --git a/xmloff/inc/txtflde.hxx b/xmloff/inc/txtflde.hxx index 459dea29f550..dd4f3c698c73 100644 --- a/xmloff/inc/txtflde.hxx +++ b/xmloff/inc/txtflde.hxx @@ -28,6 +28,7 @@ #include <rtl/ustring.hxx> #include <xmloff/xmltoken.hxx> +#include <txtfld.hxx> #include <map> #include <set> @@ -239,6 +240,13 @@ private: bool i_bAutoStyles, bool i_bProgress, bool & rPrevCharIsSpace); + + void ProcessBoolean( + enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token + bool bBool, /// attribute value + bool bDefault, + sal_uInt16 nPrefix); /// namespace + /// export a boolean attribute void ProcessBoolean( enum ::xmloff::token::XMLTokenEnum eXmlName, /// attribute token (namespace text) diff --git a/xmloff/inc/txtfldi.hxx b/xmloff/inc/txtfldi.hxx index 0a15329c31ec..3f87010e022d 100644 --- a/xmloff/inc/txtfldi.hxx +++ b/xmloff/inc/txtfldi.hxx @@ -34,6 +34,7 @@ #include <xmloff/xmltkmap.hxx> #include <rtl/ustrbuf.hxx> #include <vector> +#include <txtfld.hxx> namespace com::sun::star { namespace xml::sax { class XAttributeList; } @@ -795,6 +796,7 @@ class XMLReferenceFieldImportContext final : public XMLTextFieldImportContext sal_Int32 nElementToken; sal_Int16 nSource; sal_Int16 nType; + sal_uInt16 nFlags; bool bNameOK; bool bTypeOK; diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 6c0eb58b9ef7..230a1bde8e12 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -1617,6 +1617,8 @@ namespace xmloff::token { TOKEN( "reference", XML_REFERENCE ), TOKEN( "reference-end", XML_REFERENCE_END ), TOKEN( "reference-format", XML_REFERENCE_FORMAT ), + TOKEN( "reference-from-bottom", XML_REFERENCE_FROM_BOTTOM ), + TOKEN( "reference-hide-non-numerical", XML_REFERENCE_HIDE_NON_NUMERICAL ), TOKEN( "reference-mark", XML_REFERENCE_MARK ), TOKEN( "reference-mark-end", XML_REFERENCE_MARK_END ), TOKEN( "reference-mark-start", XML_REFERENCE_MARK_START ), diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx index d27cb0e2f6a7..2d629a79c2be 100644 --- a/xmloff/source/text/txtflde.cxx +++ b/xmloff/source/text/txtflde.cxx @@ -350,6 +350,7 @@ constexpr OUStringLiteral gsPropertyNumberingType(u"NumberingType"); constexpr OUStringLiteral gsPropertyOffset(u"Offset"); constexpr OUStringLiteral gsPropertyOn(u"On"); constexpr OUStringLiteral gsPropertyPlaceholderType(u"PlaceHolderType"); +constexpr OUStringLiteral gsPropertyReferenceFieldFlags(u"ReferenceFieldFlags"); constexpr OUStringLiteral gsPropertyReferenceFieldPart(u"ReferenceFieldPart"); constexpr OUStringLiteral gsPropertyReferenceFieldSource(u"ReferenceFieldSource"); constexpr OUStringLiteral gsPropertyReferenceFieldLanguage(u"ReferenceFieldLanguage"); @@ -1658,6 +1659,16 @@ void XMLTextFieldExport::ExportFieldHelper( MapReferenceType(GetInt16Property(gsPropertyReferenceFieldPart, rPropSet)), XML_TEMPLATE); ProcessString(XML_REF_NAME, GetStringProperty(gsPropertySourceName, rPropSet)); + + sal_uInt16 referenceFieldFlags = GetIntProperty(gsPropertyReferenceFieldFlags, rPropSet); + // In reality gsPropertyReferenceFieldFlags is a uInt16... but there is no GetUInt16Property + + bool fromBottom = (referenceFieldFlags & REFFLDFLAG_STYLE_FROM_BOTTOM) == REFFLDFLAG_STYLE_FROM_BOTTOM; + bool hideNonNumerical = (referenceFieldFlags & REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL) == REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL; + + ProcessBoolean(XML_REFERENCE_FROM_BOTTOM, fromBottom, false, XML_NAMESPACE_LO_EXT); + ProcessBoolean(XML_REFERENCE_HIDE_NON_NUMERICAL, hideNonNumerical, false, XML_NAMESPACE_LO_EXT); + if (xPropSetInfo->hasPropertyByName(gsPropertyReferenceFieldLanguage) && GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) { @@ -2454,9 +2465,15 @@ void XMLTextFieldExport::ProcessDisplay(bool bIsVisible, } -/// export boolean property void XMLTextFieldExport::ProcessBoolean(enum XMLTokenEnum eName, bool bBool, bool bDefault) +{ + ProcessBoolean(eName, bBool, bDefault, XML_NAMESPACE_TEXT); +} + +/// export boolean property +void XMLTextFieldExport::ProcessBoolean(enum XMLTokenEnum eName, + bool bBool, bool bDefault, sal_uInt16 nPrefix) { SAL_WARN_IF( eName == XML_TOKEN_INVALID, "xmloff.text", "invalid element token"); if ( XML_TOKEN_INVALID == eName ) @@ -2465,12 +2482,11 @@ void XMLTextFieldExport::ProcessBoolean(enum XMLTokenEnum eName, // write attribute (if different than default) // negate to force 0/1 values (and make sal_Bool comparable) if ((!bBool) != (!bDefault)) { - GetExport().AddAttribute(XML_NAMESPACE_TEXT, eName, + GetExport().AddAttribute(nPrefix, eName, (bBool ? XML_TRUE : XML_FALSE) ); } } - /// export string attribute void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName, const OUString& sValue, diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index 63ac9c1511fc..4b43240878af 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -24,6 +24,7 @@ * (variable related text fields and database display fields) */ +#include "o3tl/safeint.hxx" #include <sal/config.h> #include <cassert> @@ -2470,6 +2471,7 @@ XMLReferenceFieldImportContext::XMLReferenceFieldImportContext( , nElementToken(nToken) , nSource(0) , nType(ReferenceFieldPart::PAGE_DESC) +, nFlags(0) , bNameOK(false) , bTypeOK(false) { @@ -2561,6 +2563,16 @@ void XMLReferenceFieldImportContext::ProcessAttribute( case XML_ELEMENT(TEXT, XML_REFERENCE_LANGUAGE): sLanguage = OUString::fromUtf8(sAttrValue); break; + case XML_ELEMENT(LO_EXT, XML_REFERENCE_HIDE_NON_NUMERICAL): + case XML_ELEMENT(TEXT, XML_REFERENCE_HIDE_NON_NUMERICAL): + if (OUString::fromUtf8(sAttrValue).toBoolean()) + nFlags |= REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL; + break; + case XML_ELEMENT(LO_EXT, XML_REFERENCE_FROM_BOTTOM): + case XML_ELEMENT(TEXT, XML_REFERENCE_FROM_BOTTOM): + if (OUString::fromUtf8(sAttrValue).toBoolean()) + nFlags |= REFFLDFLAG_STYLE_FROM_BOTTOM; + break; default: XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); } @@ -2583,6 +2595,7 @@ void XMLReferenceFieldImportContext::PrepareField( case XML_ELEMENT(TEXT, XML_BOOKMARK_REF): case XML_ELEMENT(LO_EXT, XML_STYLE_REF): xPropertySet->setPropertyValue("SourceName", Any(sName)); + xPropertySet->setPropertyValue("ReferenceFieldFlags", Any(nFlags)); break; case XML_ELEMENT(TEXT, XML_NOTE_REF): diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 50ef5d17f461..869c47567f5d 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -1517,6 +1517,8 @@ ref-name reference reference-end reference-format +reference-from-bottom +reference-hide-non-numerical reference-mark reference-mark-end reference-mark-start