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@collabora.com>
diff --git a/oox/inc/drawingml/textbody.hxx b/oox/inc/drawingml/textbody.hxx
index ac6c66b..8d0ce41 100644
--- a/oox/inc/drawingml/textbody.hxx
+++ b/oox/inc/drawingml/textbody.hxx
@@ -66,6 +66,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 90d01ec..2724af4 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 df39f88..4424eadf 100644
--- a/oox/inc/drawingml/textparagraph.hxx
+++ b/oox/inc/drawingml/textparagraph.hxx
@@ -79,6 +79,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 355b8a68..b3d1fe0 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 1326c79..9839f75 100644
--- a/oox/source/drawingml/textbody.cxx
+++ b/oox/source/drawingml/textbody.cxx
@@ -93,6 +93,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 8fecb8b..9363a69 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 88c086b..b1c5720 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: */