[Libreoffice-commits] core.git: starmath/inc starmath/source

dante (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 15 07:10:46 UTC 2021


 starmath/inc/mathml/attribute.hxx    |   30 +++++++++++++++++++++++++-----
 starmath/inc/mathml/element.hxx      |    7 ++++++-
 starmath/source/mathml/attribute.cxx |   18 ++++++++++++++++++
 starmath/source/mathml/element.cxx   |   15 +++++++++++++--
 starmath/source/mathml/export.cxx    |    3 +++
 5 files changed, 65 insertions(+), 8 deletions(-)

New commits:
commit ffaaec23ad94f9bec5fd0fcb02603270eb660b81
Author:     dante <dante19031999 at gmail.com>
AuthorDate: Fri Aug 13 19:51:33 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Aug 15 09:10:13 2021 +0200

    Add the possibility to check if a mathml attribute is manually set
    
    Change-Id: I9c5eaee8e2cce47d9286306031e807ca2c0eed57
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120473
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/starmath/inc/mathml/attribute.hxx b/starmath/inc/mathml/attribute.hxx
index cbe042827d85..946e9f463e9c 100644
--- a/starmath/inc/mathml/attribute.hxx
+++ b/starmath/inc/mathml/attribute.hxx
@@ -49,6 +49,7 @@ class SmMlAttribute
 private:
     SmMlAttributeValueType m_aSmMlAttributeValueType;
     SmMlAttributeValue m_aAttributeValue;
+    bool m_bSet;
 
 private:
     void clearPreviousAttributeValue();
@@ -56,28 +57,42 @@ private:
     void setAttributeValue(const SmMlAttribute* aMlAttribute);
 
 public:
-    SmMlAttribute() { m_aSmMlAttributeValueType = SmMlAttributeValueType::NMlEmpty; };
+    SmMlAttribute()
+        : m_aSmMlAttributeValueType(SmMlAttributeValueType::NMlEmpty)
+        , m_bSet(false){};
 
     ~SmMlAttribute() { clearPreviousAttributeValue(); };
 
     SmMlAttribute(SmMlAttributeValueType)
+        : m_aSmMlAttributeValueType(SmMlAttributeValueType::NMlEmpty)
+        , m_bSet(false)
     {
-        m_aSmMlAttributeValueType = SmMlAttributeValueType::NMlEmpty;
         setDefaultAttributeValue();
     };
 
     SmMlAttribute(const SmMlAttribute& aMlAttribute)
+        : m_aSmMlAttributeValueType(SmMlAttributeValueType::NMlEmpty)
+        , m_bSet(aMlAttribute.isSet())
     {
-        m_aSmMlAttributeValueType = SmMlAttributeValueType::NMlEmpty;
         setAttributeValue(&aMlAttribute);
     }
 
     SmMlAttribute(const SmMlAttribute* aMlAttribute)
+        : m_aSmMlAttributeValueType(SmMlAttributeValueType::NMlEmpty)
+        , m_bSet(aMlAttribute->isSet())
     {
-        m_aSmMlAttributeValueType = SmMlAttributeValueType::NMlEmpty;
         setAttributeValue(aMlAttribute);
     }
 
+public:
+    /** Check if the attribute has been set
+    */
+    bool isSet() const { return m_bSet; }
+
+    /** Set if the attribute has been set
+    */
+    void setSet(bool bSet) { m_bSet = bSet; }
+
 public:
     /**
       * Returns the type of attribute we are dealing with.
@@ -116,10 +131,15 @@ public:
 
     void setMlAttributeValue(const SmMlAttribute& aMlAttribute)
     {
+        m_bSet = true;
         setAttributeValue(&aMlAttribute);
     }
 
-    void setMlAttributeValue(const SmMlAttribute* aMlAttribute) { setAttributeValue(aMlAttribute); }
+    void setMlAttributeValue(const SmMlAttribute* aMlAttribute)
+    {
+        m_bSet = true;
+        setAttributeValue(aMlAttribute);
+    }
 
 public:
     // Get values
diff --git a/starmath/inc/mathml/element.hxx b/starmath/inc/mathml/element.hxx
index 2c5ec40ab019..513b5d84b7ea 100644
--- a/starmath/inc/mathml/element.hxx
+++ b/starmath/inc/mathml/element.hxx
@@ -164,7 +164,7 @@ public: // attributes
       * @param nAttributePos
       * @return given attribute.
       */
-    SmMlAttribute getAttribute(SmMlAttributeValueType aElementType) const;
+    SmMlAttribute getAttribute(SmMlAttributeValueType aAttributeType) const;
 
     /**
       * Set's a given attribute.
@@ -174,6 +174,11 @@ public: // attributes
       */
     void setAttribute(const SmMlAttribute* aAttribute);
 
+    /** Checks if an attribute has been manually set
+    * @param aElementType
+    */
+    bool isAttributeSet(SmMlAttributeValueType aAttributeType) const;
+
 protected: // attributes
     /**
       * Get's a given attribute.
diff --git a/starmath/source/mathml/attribute.cxx b/starmath/source/mathml/attribute.cxx
index 61c4df609452..a1be708ae656 100644
--- a/starmath/source/mathml/attribute.cxx
+++ b/starmath/source/mathml/attribute.cxx
@@ -321,36 +321,42 @@ const struct SmMlSymmetric* SmMlAttribute::getMlSymmetric() const
 
 void SmMlAttribute::setMlAccent(const SmMlAccent* aAccent)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aAccent.m_aAccent = aAccent->m_aAccent;
 }
 
 void SmMlAttribute::setMlDir(const SmMlDir* aDir)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aDir.m_aDir = aDir->m_aDir;
 }
 
 void SmMlAttribute::setMlDisplaystyle(const SmMlDisplaystyle* aDisplaystyle)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aDisplaystyle.m_aDisplaystyle = aDisplaystyle->m_aDisplaystyle;
 }
 
 void SmMlAttribute::setMlFence(const SmMlFence* aFence)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aFence.m_aFence = aFence->m_aFence;
 }
 
 void SmMlAttribute::setMlForm(const SmMlForm* aForm)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aForm.m_aForm = aForm->m_aForm;
 }
 
 void SmMlAttribute::setMlHref(const SmMlHref* aHref)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aHref.m_aHref = aHref->m_aHref;
     m_aAttributeValue.m_aHref.m_aLnk = new OUString(*aHref->m_aLnk);
@@ -358,6 +364,7 @@ void SmMlAttribute::setMlHref(const SmMlHref* aHref)
 
 void SmMlAttribute::setMlLspace(const SmMlLspace* aLspace)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aLspace.m_aLengthValue.m_aLengthUnit
         = aLspace->m_aLengthValue.m_aLengthUnit;
@@ -369,18 +376,21 @@ void SmMlAttribute::setMlLspace(const SmMlLspace* aLspace)
 
 void SmMlAttribute::setMlMathbackground(const SmMlMathbackground* aMathbackground)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aMathbackground.m_aMathbackground = aMathbackground->m_aMathbackground;
 }
 
 void SmMlAttribute::setMlMathcolor(const SmMlMathcolor* aMathcolor)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aMathcolor.m_aMathcolor = aMathcolor->m_aMathcolor;
 }
 
 void SmMlAttribute::setMlMathsize(const SmMlMathsize* aMathsize)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aMathsize.m_aLengthValue.m_aLengthUnit
         = aMathsize->m_aLengthValue.m_aLengthUnit;
@@ -392,12 +402,14 @@ void SmMlAttribute::setMlMathsize(const SmMlMathsize* aMathsize)
 
 void SmMlAttribute::setMlMathvariant(const SmMlMathvariant* aMathvariant)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aMathvariant.m_aMathvariant = aMathvariant->m_aMathvariant;
 }
 
 void SmMlAttribute::setMlMaxsize(const SmMlMaxsize* aMaxsize)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aMaxsize.m_aMaxsize = aMaxsize->m_aMaxsize;
     m_aAttributeValue.m_aMaxsize.m_aLengthValue.m_aLengthUnit
@@ -410,6 +422,7 @@ void SmMlAttribute::setMlMaxsize(const SmMlMaxsize* aMaxsize)
 
 void SmMlAttribute::setMlMinsize(const SmMlMinsize* aMinsize)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aMinsize.m_aLengthValue.m_aLengthUnit
         = aMinsize->m_aLengthValue.m_aLengthUnit;
@@ -421,12 +434,14 @@ void SmMlAttribute::setMlMinsize(const SmMlMinsize* aMinsize)
 
 void SmMlAttribute::setMlMovablelimits(const SmMlMovablelimits* aMovablelimits)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aMovablelimits.m_aMovablelimits = aMovablelimits->m_aMovablelimits;
 }
 
 void SmMlAttribute::setMlRspace(const SmMlRspace* aRspace)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aRspace.m_aLengthValue.m_aLengthUnit
         = aRspace->m_aLengthValue.m_aLengthUnit;
@@ -438,18 +453,21 @@ void SmMlAttribute::setMlRspace(const SmMlRspace* aRspace)
 
 void SmMlAttribute::setMlSeparator(const SmMlSeparator* aSeparator)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aSeparator.m_aSeparator = aSeparator->m_aSeparator;
 }
 
 void SmMlAttribute::setMlStretchy(const SmMlStretchy* aStretchy)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aStretchy.m_aStretchy = aStretchy->m_aStretchy;
 }
 
 void SmMlAttribute::setMlSymmetric(const SmMlSymmetric* aSymmetric)
 {
+    m_bSet = true;
     clearPreviousAttributeValue();
     m_aAttributeValue.m_aSymmetric.m_aSymmetric = aSymmetric->m_aSymmetric;
 }
diff --git a/starmath/source/mathml/element.cxx b/starmath/source/mathml/element.cxx
index e1109c267c7d..4f8f2a64ff95 100644
--- a/starmath/source/mathml/element.cxx
+++ b/starmath/source/mathml/element.cxx
@@ -68,17 +68,28 @@ void SmMlElement::SmImplAttributeType()
     m_aAttributeList = starmathdatabase::makeMlAttributeList(m_aAttributePosList);
 }
 
-SmMlAttribute SmMlElement::getAttribute(SmMlAttributeValueType aElementType) const
+SmMlAttribute SmMlElement::getAttribute(SmMlAttributeValueType aAttributeType) const
 {
     // Look for the attribute position and return if exists
     for (size_t i = 0; i < m_aAttributePosList.size(); ++i)
     {
-        if (m_aAttributePosList[i].m_aAttributeValueType == aElementType)
+        if (m_aAttributePosList[i].m_aAttributeValueType == aAttributeType)
             return m_aAttributeList[m_aAttributePosList[i].m_nPos];
     }
     return SmMlAttribute();
 }
 
+bool SmMlElement::isAttributeSet(SmMlAttributeValueType aAttributeType) const
+{
+    // Look for the attribute position and return if exists
+    for (size_t i = 0; i < m_aAttributePosList.size(); ++i)
+    {
+        if (m_aAttributePosList[i].m_aAttributeValueType == aAttributeType)
+            return m_aAttributeList[m_aAttributePosList[i].m_nPos].isSet();
+    }
+    return false;
+}
+
 void SmMlElement::setAttribute(const SmMlAttribute* aAttribute)
 {
     // Look for the attribute position and assign if exists
diff --git a/starmath/source/mathml/export.cxx b/starmath/source/mathml/export.cxx
index 9287df360fa6..dc8458aaafd2 100644
--- a/starmath/source/mathml/export.cxx
+++ b/starmath/source/mathml/export.cxx
@@ -683,6 +683,9 @@ void SmMlExport::exportMlAttributtes(const SmMlElement* pMlElement)
     for (size_t i = 0; i < nAttributeCount; ++i)
     {
         SmMlAttribute aAttribute = pMlElement->getAttribute(i);
+        if (!aAttribute.isSet())
+            continue;
+
         switch (aAttribute.getMlAttributeValueType())
         {
             case SmMlAttributeValueType::MlAccent:


More information about the Libreoffice-commits mailing list