[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - oox/inc oox/source

Sarper Akdemir (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 23 09:49:03 UTC 2021


 oox/inc/drawingml/textbody.hxx                          |    6 +++
 oox/inc/drawingml/textcharacterproperties.hxx           |    4 ++
 oox/inc/drawingml/textparagraph.hxx                     |    6 +++
 oox/inc/drawingml/textrun.hxx                           |    6 +++
 oox/source/drawingml/textbody.cxx                       |   10 ++++++
 oox/source/drawingml/textcharacterpropertiescontext.cxx |   26 +++++++++++++++-
 oox/source/drawingml/textparagraph.cxx                  |   10 ++++++
 7 files changed, 67 insertions(+), 1 deletion(-)

New commits:
commit 60e0aee13af382105f88f67114d958af699e9b72
Author:     Sarper Akdemir <sarper.akdemir at collabora.com>
AuthorDate: Sun May 9 20:17:20 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Jun 23 11:48:28 2021 +0200

    tdf#59323: ooxml import: hasVisualRunProperties
    
    Introduces helper functions to determine whether a shape has non inherited run
    properties that change it visually.
    
    mbHasVisualRunProperties is set on import if there was a run property that
    alters visual appearance.
    
    Change-Id: Ie1e8e22d2757dc8594e7c6c3b8fc1dd7973c92af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117004
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117621
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/oox/inc/drawingml/textbody.hxx b/oox/inc/drawingml/textbody.hxx
index 5e6d156e7ce4..34b7fce40725 100644
--- a/oox/inc/drawingml/textbody.hxx
+++ b/oox/inc/drawingml/textbody.hxx
@@ -67,6 +67,12 @@ public:
     bool isEmpty() const;
     OUString toString() const;
 
+    /** Returns whether the textbody had a rPr tag in it that alters it visually
+     *
+     *  For instance _lang_ doesn't have a visual effect.
+     */
+    bool hasVisualRunProperties() const;
+
     void                ApplyStyleEmpty(
                             const ::oox::core::XmlFilterBase& rFilterBase,
                             const css::uno::Reference < css::text::XText > & xText,
diff --git a/oox/inc/drawingml/textcharacterproperties.hxx b/oox/inc/drawingml/textcharacterproperties.hxx
index 90d01ec9cde1..2724af43051b 100644
--- a/oox/inc/drawingml/textcharacterproperties.hxx
+++ b/oox/inc/drawingml/textcharacterproperties.hxx
@@ -58,6 +58,8 @@ struct TextCharacterProperties
     OptValue< bool >    moUnderlineLineFollowText;
     OptValue< bool >    moUnderlineFillFollowText;
     FillProperties      maFillProperties;
+    /// Set if there was a property set that alters run visually during import
+    bool mbHasVisualRunProperties;
 
     std::vector<css::beans::PropertyValue> maTextEffectsProperties;
 
@@ -78,6 +80,8 @@ struct TextCharacterProperties
     void                pushToPropSet(
                             PropertySet& rPropSet,
                             const ::oox::core::XmlFilterBase& rFilter ) const;
+
+    TextCharacterProperties() : mbHasVisualRunProperties(false) {}
 };
 
 
diff --git a/oox/inc/drawingml/textparagraph.hxx b/oox/inc/drawingml/textparagraph.hxx
index 22465355142c..e5486a0d1afe 100644
--- a/oox/inc/drawingml/textparagraph.hxx
+++ b/oox/inc/drawingml/textparagraph.hxx
@@ -78,6 +78,12 @@ public:
     }
     formulaimport::XmlStreamBuilder & GetMathXml();
 
+    /** Returns whether textparagraph had a rPr tag in it that alters it visually
+     *
+     *  For instance _lang_ doesn't have a visual effect.
+     */
+    bool hasVisualRunProperties() const;
+
 private:
     TextParagraphProperties     maProperties;
     TextCharacterProperties     maEndProperties;
diff --git a/oox/inc/drawingml/textrun.hxx b/oox/inc/drawingml/textrun.hxx
index 355b8a684cc1..b3d1fe041ff8 100644
--- a/oox/inc/drawingml/textrun.hxx
+++ b/oox/inc/drawingml/textrun.hxx
@@ -43,6 +43,12 @@ public:
     void                 setLineBreak() { mbIsLineBreak = true; }
     bool isLineBreak() const { return mbIsLineBreak; }
 
+    /** Returns whether the textrun had properties that alter it visually in its rPr tag
+     *
+     *  For instance _lang_ doesn't have a visual effect.
+     */
+    bool hasVisualRunProperties() const { return maTextCharacterProperties.mbHasVisualRunProperties; }
+
     virtual sal_Int32               insertAt(
                                     const ::oox::core::XmlFilterBase& rFilterBase,
                                     const css::uno::Reference < css::text::XText >& xText,
diff --git a/oox/source/drawingml/textbody.cxx b/oox/source/drawingml/textbody.cxx
index 1abe31db984e..78bb00c2acfa 100644
--- a/oox/source/drawingml/textbody.cxx
+++ b/oox/source/drawingml/textbody.cxx
@@ -98,6 +98,16 @@ OUString TextBody::toString() const
         return OUString();
 }
 
+bool TextBody::hasVisualRunProperties() const
+{
+    for ( auto& pTextParagraph : getParagraphs() )
+    {
+        if ( pTextParagraph->hasVisualRunProperties() )
+            return true;
+    }
+    return false;
+}
+
 void TextBody::ApplyStyleEmpty(
     const ::oox::core::XmlFilterBase& rFilterBase,
     const Reference < XText > & xText,
diff --git a/oox/source/drawingml/textcharacterpropertiescontext.cxx b/oox/source/drawingml/textcharacterpropertiescontext.cxx
index 8fecb8bd2735..9363a69673bb 100644
--- a/oox/source/drawingml/textcharacterpropertiescontext.cxx
+++ b/oox/source/drawingml/textcharacterpropertiescontext.cxx
@@ -27,6 +27,8 @@
 #include "hyperlinkcontext.hxx"
 #include <oox/token/namespaces.hxx>
 #include <oox/token/tokens.hxx>
+#include <sax/fastattribs.hxx>
+#include <sax/fastparser.hxx>
 
 #include <sal/log.hxx>
 
@@ -45,8 +47,16 @@ TextCharacterPropertiesContext::TextCharacterPropertiesContext(
 : ContextHandler2( rParent )
 , mrTextCharacterProperties( rTextCharacterProperties )
 {
-    if ( rAttribs.hasAttribute( XML_lang ) )
+    int nVisualTokenAmount = sax_fastparser::castToFastAttributeList(
+                rAttribs.getFastAttributeList() ).getFastAttributeTokens().size();
+
+    if ( rAttribs.hasAttribute( XML_lang ) ){
         mrTextCharacterProperties.moLang = rAttribs.getString( XML_lang );
+        --nVisualTokenAmount; // Not a visual attribute
+    }
+    if ( rAttribs.hasAttribute( XML_altLang )){
+        --nVisualTokenAmount; // Not a visual attribute
+    }
     if ( rAttribs.hasAttribute( XML_sz ) )
         mrTextCharacterProperties.moHeight = rAttribs.getInteger( XML_sz );
     if ( rAttribs.hasAttribute( XML_spc ) )
@@ -64,6 +74,17 @@ TextCharacterPropertiesContext::TextCharacterPropertiesContext(
         mrTextCharacterProperties.moItalic = rAttribs.getBool( XML_i );
     if( rAttribs.hasAttribute( XML_cap ) )
         mrTextCharacterProperties.moCaseMap = rAttribs.getToken( XML_cap );
+    if ( rAttribs.hasAttribute( XML_dirty ) )
+    {
+        --nVisualTokenAmount; // Not a visual attribute
+    }
+    if ( rAttribs.hasAttribute( XML_smtClean ) )
+    {
+        --nVisualTokenAmount; // Not a visual attribute
+    }
+
+    if ( nVisualTokenAmount > 0 )
+        mrTextCharacterProperties.mbHasVisualRunProperties = true;
 
     /* TODO / unhandled so far:
        A_TOKEN( kern )
@@ -85,6 +106,9 @@ TextCharacterPropertiesContext::~TextCharacterPropertiesContext()
 
 ContextHandlerRef TextCharacterPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
 {
+    if( aElementToken != A_TOKEN(lang) )
+        mrTextCharacterProperties.mbHasVisualRunProperties = true;
+
     switch( aElementToken )
     {
 // TODO unsupported yet
diff --git a/oox/source/drawingml/textparagraph.cxx b/oox/source/drawingml/textparagraph.cxx
index 8aa4d8895040..0eaebfd4c9cb 100644
--- a/oox/source/drawingml/textparagraph.cxx
+++ b/oox/source/drawingml/textparagraph.cxx
@@ -194,6 +194,16 @@ formulaimport::XmlStreamBuilder & TextParagraph::GetMathXml()
     return *m_pMathXml;
 }
 
+bool TextParagraph::hasVisualRunProperties() const
+{
+   for ( auto& pTextRun : getRuns() )
+   {
+       if ( pTextRun->hasVisualRunProperties() )
+           return true;
+   }
+   return false;
+}
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list