sc/source/filter/inc/richstring.hxx        |    7 ++++++-
 sc/source/filter/oox/richstring.cxx        |   12 +++++++++++-
 sc/source/filter/oox/richstringcontext.cxx |    4 +++-
 3 files changed, 20 insertions(+), 3 deletions(-)

New commits:
commit 94297e037dd963b7e74dfff369145d0e0db30c97
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Tue May 9 17:43:48 2023 -0400
Commit:     Henry Castro <hcas...@collabora.com>
CommitDate: Thu Jun 22 19:29:38 2023 +0200

    sc: filter: oox: fix preserve space, single line case
    
    The unit test testPreserveTextWhitespace2XLSX fails
    when a single line is enabled
    
    Test name: ScExportTest::testPreserveTextWhitespace2XLSX
    equality assertion failed
    - Expected: 1
    - Actual  : 0
    - In <>, XPath '/x:sst/x:si[2]/x:r[1]/x:t' number of nodes is incorrect
    
    In order to fix, the single line cell should not be enabled and
    import the attribute:
    
    <t xml:space="preserve">abc</t>
    
    Signed-off-by: Henry Castro <hcas...@collabora.com>
    Change-Id: I380ba8726c03abc40bdc745ea74eceb80fec6e54
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151599
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    (cherry picked from commit 2dd86aa3f365057494bf41f4da7f2f410ea3bf2e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151615
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153459
    Tested-by: Jenkins

diff --git a/sc/source/filter/inc/richstring.hxx 
b/sc/source/filter/inc/richstring.hxx
index 7c233507b419..b74e3036f473 100644
--- a/sc/source/filter/inc/richstring.hxx
+++ b/sc/source/filter/inc/richstring.hxx
@@ -208,7 +208,7 @@ class RichString
 public:
 
     /** Appends and returns an index of a portion object for a plain string (t 
element). */
-    sal_Int32 importText();
+    sal_Int32 importText(const AttributeList& rAttribs);
     /** Appends and returns an index of a portion object for a new formatting 
run (r element). */
     sal_Int32 importRun();
     /** Appends and returns a phonetic text object for a new phonetic run (rPh 
element). */
@@ -236,6 +236,10 @@ public:
 
     RichStringPortion& getPortion(sal_Int32 nPortionIdx) { return 
maTextPortions[nPortionIdx]; }
 
+    void                setAttributes(const AttributeList& rAttribs);
+
+    bool                isPreserveSpace() const { return mbPreserveSpace; }
+
 private:
     /** Creates, appends, and returns a new empty string portion. */
     sal_Int32 createPortion();
@@ -253,6 +257,7 @@ private:
     std::vector<RichStringPortion>  maTextPortions; /// String portions with 
font data.
     std::unique_ptr<PhoneticSettings> mxPhonSettings; /// Phonetic settings 
for this string.
     PhoneticVector      maPhonPortions; /// Phonetic text portions.
+    bool mbPreserveSpace = false;
 };
 
 typedef std::shared_ptr< RichString > RichStringRef;
diff --git a/sc/source/filter/oox/richstring.cxx 
b/sc/source/filter/oox/richstring.cxx
index 8d2f964362d0..a1345179c19a 100644
--- a/sc/source/filter/oox/richstring.cxx
+++ b/sc/source/filter/oox/richstring.cxx
@@ -28,6 +28,7 @@
 #include <oox/helper/binaryinputstream.hxx>
 #include <oox/helper/attributelist.hxx>
 #include <oox/helper/propertyset.hxx>
+#include <oox/token/namespaces.hxx>
 #include <oox/token/tokens.hxx>
 #include <editutil.hxx>
 
@@ -293,8 +294,10 @@ void PhoneticPortionModelList::importPortions( 
SequenceInputStream& rStrm )
     }
 }
 
-sal_Int32 RichString::importText()
+sal_Int32 RichString::importText(const AttributeList& rAttribs)
 {
+    setAttributes(rAttribs);
+
     return createPortion();
 }
 
@@ -303,6 +306,13 @@ sal_Int32 RichString::importRun()
     return createPortion();
 }
 
+void  RichString::setAttributes(const AttributeList& rAttribs)
+{
+    auto aAttrSpace = rAttribs.getString(oox::NMSP_xml | oox::XML_space);
+    if (aAttrSpace && *aAttrSpace == "preserve")
+        mbPreserveSpace = true;
+}
+
 RichStringPhoneticRef RichString::importPhoneticRun( const AttributeList& 
rAttribs )
 {
     RichStringPhoneticRef xPhonetic = createPhonetic();
diff --git a/sc/source/filter/oox/richstringcontext.cxx 
b/sc/source/filter/oox/richstringcontext.cxx
index 280ac293a390..0c83fff2e9f3 100644
--- a/sc/source/filter/oox/richstringcontext.cxx
+++ b/sc/source/filter/oox/richstringcontext.cxx
@@ -33,7 +33,7 @@ ContextHandlerRef RichStringContext::onCreateContext( 
sal_Int32 nElement, const
         switch( nElement )
         {
             case XLS_TOKEN( t ):
-                mnPortionIdx = mxString->importText();
+                mnPortionIdx = mxString->importText(rAttribs);
                 return this;    // collect text in onCharacters()
             case XLS_TOKEN( r ):
                 mnPortionIdx = mxString->importRun();
@@ -57,6 +57,7 @@ ContextHandlerRef RichStringContext::onCreateContext( 
sal_Int32 nElement, const
                 break;
 
                 case XLS_TOKEN( t ):
+                    mxString->setAttributes(rAttribs);
                     return this;    // collect portion text in onCharacters()
             }
         break;
@@ -65,6 +66,7 @@ ContextHandlerRef RichStringContext::onCreateContext( 
sal_Int32 nElement, const
             switch( nElement )
             {
                 case XLS_TOKEN( t ):
+                    mxString->setAttributes(rAttribs);
                     return this;    // collect phonetic text in onCharacters()
             }
         break;

Reply via email to