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/+/158351
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
This commit is contained in:
Skyler Grey
2023-10-30 20:07:01 +01:00
committed by Caolán McNamara
parent e195c22533
commit 6412a74b35
9 changed files with 87 additions and 3 deletions
+2
View File
@@ -1607,6 +1607,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,
@@ -2195,6 +2195,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>
+28
View File
@@ -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
+9
View File
@@ -34,6 +34,8 @@
#include <memory>
#include <string_view>
#include "txtfld.hxx"
class SvXMLExport;
struct XMLPropertyState;
@@ -239,6 +241,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)
+2
View File
@@ -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;
+2
View File
@@ -1620,6 +1620,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 ),
+19 -3
View File
@@ -349,6 +349,7 @@ constexpr OUString gsPropertyNumberingType(u"NumberingType"_ustr);
constexpr OUString gsPropertyOffset(u"Offset"_ustr);
constexpr OUStringLiteral gsPropertyOn(u"On");
constexpr OUStringLiteral gsPropertyPlaceholderType(u"PlaceHolderType");
constexpr OUString gsPropertyReferenceFieldFlags(u"ReferenceFieldFlags"_ustr);
constexpr OUString gsPropertyReferenceFieldPart(u"ReferenceFieldPart"_ustr);
constexpr OUString gsPropertyReferenceFieldSource(u"ReferenceFieldSource"_ustr);
constexpr OUString gsPropertyReferenceFieldLanguage(u"ReferenceFieldLanguage"_ustr);
@@ -1657,6 +1658,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,
+13
View File
@@ -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):
+2
View File
@@ -1520,6 +1520,8 @@ ref-name
reference
reference-end
reference-format
reference-from-bottom
reference-hide-non-numerical
reference-mark
reference-mark-end
reference-mark-start