include/xmloff/xmltoken.hxx                                 |    2 
 schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng |   10 ++++
 xmloff/inc/txtfld.hxx                                       |   28 ++++++++++++
 xmloff/inc/txtflde.hxx                                      |    9 +++
 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, 87 insertions(+), 3 deletions(-)

New commits:
commit 6412a74b35a3e6089b65b4ad04549262e4bf93c8
Author:     Skyler Grey <skyler.g...@collabora.com>
AuthorDate: Fri Oct 20 14:30:31 2023 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Mon Oct 30 20:07:01 2023 +0100

    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.mcnam...@collabora.com>

diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index d3c1b93ea6e4..066a55960e0b 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -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,
diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng 
b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
index bf57af9b0be6..b9fbcfc7ce4b 100644
--- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
+++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng
@@ -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>
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..f98fb7c5c421 100644
--- a/xmloff/inc/txtflde.hxx
+++ b/xmloff/inc/txtflde.hxx
@@ -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)
diff --git a/xmloff/inc/txtfldi.hxx b/xmloff/inc/txtfldi.hxx
index 0a15329c31ec..3d56c547811e 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 5798120c5983..fa439f9f367b 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -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 ),
diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx
index 304572ff8e60..2c054d57e3f6 100644
--- a/xmloff/source/text/txtflde.cxx
+++ b/xmloff/source/text/txtflde.cxx
@@ -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,
diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx
index 2d966f10da89..e0f6a01ecca6 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 731bf917ff6b..85d947387e20 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -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

Reply via email to