summaryrefslogtreecommitdiffstats
path: root/starmath/inc/mathml
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /starmath/inc/mathml
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'starmath/inc/mathml')
-rw-r--r--starmath/inc/mathml/attribute.hxx203
-rw-r--r--starmath/inc/mathml/def.hxx330
-rw-r--r--starmath/inc/mathml/element.hxx300
-rw-r--r--starmath/inc/mathml/export.hxx241
-rw-r--r--starmath/inc/mathml/import.hxx150
-rw-r--r--starmath/inc/mathml/iterator.hxx125
-rw-r--r--starmath/inc/mathml/mathmlMo.hxx109
-rw-r--r--starmath/inc/mathml/mathmlattr.hxx79
-rw-r--r--starmath/inc/mathml/mathmlexport.hxx128
-rw-r--r--starmath/inc/mathml/mathmlimport.hxx114
-rw-r--r--starmath/inc/mathml/starmathdatabase.hxx332
-rw-r--r--starmath/inc/mathml/xparsmlbase.hxx53
12 files changed, 2164 insertions, 0 deletions
diff --git a/starmath/inc/mathml/attribute.hxx b/starmath/inc/mathml/attribute.hxx
new file mode 100644
index 000000000..946e9f463
--- /dev/null
+++ b/starmath/inc/mathml/attribute.hxx
@@ -0,0 +1,203 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+#include "def.hxx"
+
+/* All possible data needed to do the job outside mathml limits */
+// Ml prefix means it is part of mathml standard
+// NMl means it is not part of mathml standard but needed info to work
+
+/* Union for storing the mathml attribute value */
+/*************************************************************************************************/
+
+union SmMlAttributeValue {
+ SmMlAttributeValue(){};
+
+ struct SmMlAccent m_aAccent;
+ struct SmMlDir m_aDir;
+ struct SmMlDisplaystyle m_aDisplaystyle;
+ struct SmMlFence m_aFence;
+ struct SmMlForm m_aForm;
+ struct SmMlHref m_aHref;
+ struct SmMlLspace m_aLspace;
+ struct SmMlMathbackground m_aMathbackground;
+ struct SmMlMathcolor m_aMathcolor;
+ struct SmMlMathsize m_aMathsize;
+ struct SmMlMathvariant m_aMathvariant;
+ struct SmMlMaxsize m_aMaxsize;
+ struct SmMlMinsize m_aMinsize;
+ struct SmMlMovablelimits m_aMovablelimits;
+ struct SmMlRspace m_aRspace;
+ struct SmMlSeparator m_aSeparator;
+ struct SmMlStretchy m_aStretchy;
+ struct SmMlSymmetric m_aSymmetric;
+};
+
+/* Class managing the attribute value */
+/*************************************************************************************************/
+
+class SmMlAttribute
+{
+private:
+ SmMlAttributeValueType m_aSmMlAttributeValueType;
+ SmMlAttributeValue m_aAttributeValue;
+ bool m_bSet;
+
+private:
+ void clearPreviousAttributeValue();
+ void setDefaultAttributeValue();
+ void setAttributeValue(const SmMlAttribute* aMlAttribute);
+
+public:
+ SmMlAttribute()
+ : m_aSmMlAttributeValueType(SmMlAttributeValueType::NMlEmpty)
+ , m_bSet(false){};
+
+ ~SmMlAttribute() { clearPreviousAttributeValue(); };
+
+ SmMlAttribute(SmMlAttributeValueType)
+ : m_aSmMlAttributeValueType(SmMlAttributeValueType::NMlEmpty)
+ , m_bSet(false)
+ {
+ setDefaultAttributeValue();
+ };
+
+ SmMlAttribute(const SmMlAttribute& aMlAttribute)
+ : m_aSmMlAttributeValueType(SmMlAttributeValueType::NMlEmpty)
+ , m_bSet(aMlAttribute.isSet())
+ {
+ setAttributeValue(&aMlAttribute);
+ }
+
+ SmMlAttribute(const SmMlAttribute* aMlAttribute)
+ : m_aSmMlAttributeValueType(SmMlAttributeValueType::NMlEmpty)
+ , m_bSet(aMlAttribute->isSet())
+ {
+ 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.
+ * Attribute Value Type
+ */
+ SmMlAttributeValueType getMlAttributeValueType() const { return m_aSmMlAttributeValueType; };
+
+ /**
+ * Checks if the attribute contains information.
+ * Attribute Value Type
+ */
+ bool isNullAttribute() const
+ {
+ return m_aSmMlAttributeValueType == SmMlAttributeValueType::NMlEmpty;
+ };
+
+ /**
+ * Compares the type of attribute with a given one.
+ * Attribute Value Type
+ */
+ bool isMlAttributeValueType(SmMlAttributeValueType aAttributeValueType) const
+ {
+ return m_aSmMlAttributeValueType == aAttributeValueType;
+ };
+
+ /**
+ * Set the type of attribute we are dealing with.
+ * @param Attribute Value Type
+ */
+ void setMlAttributeValueType(SmMlAttributeValueType aAttributeValueType)
+ {
+ clearPreviousAttributeValue();
+ m_aSmMlAttributeValueType = aAttributeValueType;
+ setDefaultAttributeValue();
+ }
+
+ void setMlAttributeValue(const SmMlAttribute& aMlAttribute)
+ {
+ m_bSet = true;
+ setAttributeValue(&aMlAttribute);
+ }
+
+ void setMlAttributeValue(const SmMlAttribute* aMlAttribute)
+ {
+ m_bSet = true;
+ setAttributeValue(aMlAttribute);
+ }
+
+public:
+ // Get values
+ const struct SmMlAccent* getMlAccent() const;
+ const struct SmMlDir* getMlDir() const;
+ const struct SmMlDisplaystyle* getMlDisplaystyle() const;
+ const struct SmMlFence* getMlFence() const;
+ const struct SmMlForm* getMlForm() const;
+ const struct SmMlHref* getMlHref() const;
+ const struct SmMlLspace* getMlLspace() const;
+ const struct SmMlMathbackground* getMlMathbackground() const;
+ const struct SmMlMathcolor* getMlMathcolor() const;
+ const struct SmMlMathsize* getMlMathsize() const;
+ const struct SmMlMathvariant* getMlMathvariant() const;
+ const struct SmMlMaxsize* getMlMaxsize() const;
+ const struct SmMlMinsize* getMlMinsize() const;
+ const struct SmMlMovablelimits* getMlMovablelimits() const;
+ const struct SmMlRspace* getMlRspace() const;
+ const struct SmMlSeparator* getMlSeparator() const;
+ const struct SmMlStretchy* getMlStretchy() const;
+ const struct SmMlSymmetric* getMlSymmetric() const;
+
+ // Set values
+ // Note that content is copied.
+ void setMlAccent(const SmMlAccent* aAccent);
+ void setMlDir(const SmMlDir* aDir);
+ void setMlDisplaystyle(const SmMlDisplaystyle* aDisplaystyle);
+ void setMlFence(const SmMlFence* aFence);
+ void setMlForm(const SmMlForm* aForm);
+ void setMlHref(const SmMlHref* aHref);
+ void setMlLspace(const SmMlLspace* aLspace);
+ void setMlMathbackground(const SmMlMathbackground* aMathbackground);
+ void setMlMathcolor(const SmMlMathcolor* aMathcolor);
+ void setMlMathsize(const SmMlMathsize* aMathsize);
+ void setMlMathvariant(const SmMlMathvariant* aMathvariant);
+ void setMlMaxsize(const SmMlMaxsize* aMaxsize);
+ void setMlMinsize(const SmMlMinsize* aMinSize);
+ void setMlMovablelimits(const SmMlMovablelimits* aMovablelimits);
+ void setMlRspace(const SmMlRspace* aRspace);
+ void setMlSeparator(const SmMlSeparator* aSeparator);
+ void setMlStretchy(const SmMlStretchy* aStretchy);
+ void setMlSymmetric(const SmMlSymmetric* aSymmetric);
+};
+
+/* element's attributes */
+/*************************************************************************************************/
+
+namespace starmathdatabase
+{
+extern SmMlAttributePos MlAttributeListEmpty[1];
+extern SmMlAttributePos MlAttributeListMath[1];
+extern SmMlAttributePos MlAttributeListMi[7];
+extern SmMlAttributePos MlAttributeListMerror[4];
+extern SmMlAttributePos MlAttributeListMn[7];
+extern SmMlAttributePos MlAttributeListMo[18];
+extern SmMlAttributePos MlAttributeListMrow[4];
+extern SmMlAttributePos MlAttributeListMtext[7];
+extern SmMlAttributePos MlAttributeListMstyle[18];
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/starmath/inc/mathml/def.hxx b/starmath/inc/mathml/def.hxx
new file mode 100644
index 000000000..380736711
--- /dev/null
+++ b/starmath/inc/mathml/def.hxx
@@ -0,0 +1,330 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+#include <tools/color.hxx>
+
+/* All possible data needed to do the job outside mathml limits */
+// Ml prefix means it is part of mathml standard
+// NMl means it is not part of mathml standard but needed info to work
+
+/* For now empty, don't know yet what's needed besides default font size. */
+struct SmGlobalData
+{
+};
+
+/* Mhtml length tools */
+/*************************************************************************************************/
+
+enum class SmLengthUnit : uint_fast8_t
+{
+ MlEm,
+ MlEx,
+ MlPx,
+ MlIn,
+ MlCm,
+ MlMm,
+ MlPt,
+ MlPc,
+ MlP, // Percent
+ MlM // Multiplier
+};
+
+struct SmLengthValue
+{
+ SmLengthUnit m_aLengthUnit;
+ double m_aLengthValue;
+ // Keeps original text value to avoid numerical error data loss
+ OUString* m_aOriginalText;
+};
+
+/* Possible mathml elements */
+/*************************************************************************************************/
+
+enum class SmMlElementType : uint_fast8_t
+{
+ // Used for base element. Means no information contained.
+ NMlEmpty,
+ // Used for structural dependencies. Means no information contained.
+ NMlStructural,
+ NMlSmNode,
+ // Mathml real elements
+ MlMath,
+ MlMi,
+ MlMerror,
+ MlMn,
+ MlMo,
+ MlMrow,
+ MlMtext,
+ MlMstyle
+};
+
+/* Possible mathml attributes */
+/*************************************************************************************************/
+
+enum class SmMlAttributeValueType : uint_fast8_t
+{
+ NMlEmpty,
+ MlAccent,
+ MlDir,
+ MlDisplaystyle,
+ MlFence,
+ MlForm,
+ MlHref,
+ MlLspace,
+ MlMathbackground,
+ MlMathcolor,
+ MlMathsize,
+ MlMathvariant,
+ MlMaxsize,
+ MlMinsize,
+ MlMovablelimits,
+ MlRspace,
+ MlSeparator,
+ MlStretchy,
+ MlSymmetric
+};
+
+/* Possible values of mathml attributes */
+/*************************************************************************************************/
+
+enum class SmMlAttributeValueEmpty : uint_fast8_t
+{
+ MlEmpty = 0x00
+};
+
+enum class SmMlAttributeValueAccent : uint_fast8_t
+{
+ MlFalse = 0x00,
+ MlTrue = 0x01
+};
+
+enum class SmMlAttributeValueDir : uint_fast8_t
+{
+ MlLtr = 0x00,
+ MlRtl = 0x01
+};
+
+enum class SmMlAttributeValueDisplaystyle : uint_fast8_t
+{
+ MlFalse = 0x00,
+ MlTrue = 0x01
+};
+
+enum class SmMlAttributeValueFence : uint_fast8_t
+{
+ MlFalse = 0x00,
+ MlTrue = 0x01
+};
+
+enum class SmMlAttributeValueForm : uint_fast8_t
+{
+ MlPrefix = 0x01,
+ MlInfix = 0x02,
+ MlPosfix = 0x04
+};
+
+enum class SmMlAttributeValueHref : uint_fast8_t
+{
+ NMlEmpty = 0x00,
+ NMlValid = 0x01
+};
+
+enum class SmMlAttributeValueLspace : uint_fast8_t
+{
+ NMlEmpty = 0x00
+};
+
+enum class SmMlAttributeValueMathbackground : uint_fast32_t
+{
+ MlTransparent = 0x00,
+ MlRgb = 0x01
+};
+
+enum class SmMlAttributeValueMathcolor : uint_fast8_t
+{
+ MlDefault = 0x00,
+ MlRgb = 0x01
+};
+
+enum class SmMlAttributeValueMathsize : uint_fast8_t
+{
+ NMlEmpty = 0x00,
+};
+
+enum class SmMlAttributeValueMathvariant : uint_fast16_t
+{
+ normal = 0x000,
+ bold = 0x001,
+ italic = 0x002,
+ double_struck = 0x004,
+ script = 0x008,
+ fraktur = 0x010,
+ sans_serif = 0x020,
+ monospace = 0x040,
+ bold_italic = 0x001 | 0x002,
+ bold_fraktur = 0x001 | 0x010,
+ bold_script = 0x001 | 0x008,
+ bold_sans_serif = 0x001 | 0x020,
+ sans_serif_italic = 0x002 | 0x20,
+ sans_serif_bold_italic = 0x001 | 0x002 | 0x020,
+ // Non english
+ initial = 0x080,
+ tailed = 0x100,
+ looped = 0x200,
+ stretched = 0x400
+};
+
+enum class SmMlAttributeValueMaxsize : uint_fast8_t
+{
+ MlInfinity = 0x00,
+ MlFinite = 0x01
+};
+
+/*
+ * Specifies whether attached under- and overscripts move to sub- and superscript positions when displaystyle is false.
+ * Source: https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo
+ */
+enum class SmMlAttributeValueMovablelimits : uint_fast8_t
+{
+ MlFalse = 0x00,
+ MlTrue = 0x01
+};
+
+enum class SmMlAttributeValueRspace : uint_fast8_t
+{
+ NMlEmpty = 0x00
+};
+
+enum class SmMlAttributeValueSeparator : uint_fast8_t
+{
+ MlFalse = 0x00,
+ MlTrue = 0x01
+};
+
+enum class SmMlAttributeValueStretchy : uint_fast8_t
+{
+ MlFalse = 0x00,
+ MlTrue = 0x01
+};
+
+enum class SmMlAttributeValueSymmetric : uint_fast8_t
+{
+ MlFalse = 0x00,
+ MlTrue = 0x01
+};
+
+/* Structures for all possible attributes */
+/*************************************************************************************************/
+
+struct SmMlAccent
+{
+ SmMlAttributeValueAccent m_aAccent;
+};
+
+struct SmMlDir
+{
+ SmMlAttributeValueDir m_aDir;
+};
+
+struct SmMlDisplaystyle
+{
+ SmMlAttributeValueDisplaystyle m_aDisplaystyle;
+};
+
+struct SmMlFence
+{
+ SmMlAttributeValueFence m_aFence;
+};
+
+struct SmMlForm
+{
+ SmMlAttributeValueForm m_aForm;
+};
+
+struct SmMlHref
+{
+ SmMlAttributeValueHref m_aHref;
+ OUString* m_aLnk;
+};
+
+struct SmMlLspace
+{
+ SmLengthValue m_aLengthValue;
+};
+
+struct SmMlMathbackground
+{
+ SmMlAttributeValueMathbackground m_aMathbackground;
+ Color m_aCol;
+};
+
+struct SmMlMathcolor
+{
+ SmMlAttributeValueMathcolor m_aMathcolor;
+ Color m_aCol;
+};
+
+struct SmMlMathsize
+{
+ SmLengthValue m_aLengthValue;
+};
+
+struct SmMlMathvariant
+{
+ SmMlAttributeValueMathvariant m_aMathvariant;
+};
+
+struct SmMlMaxsize
+{
+ SmMlAttributeValueMaxsize m_aMaxsize;
+ SmLengthValue m_aLengthValue;
+};
+
+struct SmMlMinsize
+{
+ SmLengthValue m_aLengthValue;
+};
+
+struct SmMlMovablelimits
+{
+ SmMlAttributeValueMovablelimits m_aMovablelimits;
+};
+
+struct SmMlRspace
+{
+ SmLengthValue m_aLengthValue;
+};
+
+struct SmMlSeparator
+{
+ SmMlAttributeValueSeparator m_aSeparator;
+};
+
+struct SmMlStretchy
+{
+ SmMlAttributeValueStretchy m_aStretchy;
+};
+
+struct SmMlSymmetric
+{
+ SmMlAttributeValueSymmetric m_aSymmetric;
+};
+
+/* order attributes */
+/*************************************************************************************************/
+
+struct SmMlAttributePos
+{
+ SmMlAttributeValueType m_aAttributeValueType;
+ uint_fast8_t m_nPos;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/starmath/inc/mathml/element.hxx b/starmath/inc/mathml/element.hxx
new file mode 100644
index 000000000..ce5d7073b
--- /dev/null
+++ b/starmath/inc/mathml/element.hxx
@@ -0,0 +1,300 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+#include "attribute.hxx"
+#include <rect.hxx>
+
+#include <editeng/editdata.hxx>
+
+class SmMlElement final : public SmRect
+{
+ /* Technical stuff */
+
+public:
+ SmMlElement()
+ : m_aElementType(SmMlElementType::NMlEmpty)
+ , m_aText(u"")
+ , m_aESelection(0, 0, 0, 0)
+ , m_aAttributeList(0)
+ , m_aAttributePosList(0)
+ , m_aSubElements(0)
+ , m_aParentElement(nullptr)
+ , m_nSubElementId(0)
+ {
+ SmImplAttributeType();
+ };
+ /* Mathml stuff */
+
+public:
+ SmMlElement(SmMlElementType aElementType)
+ : m_aElementType(aElementType)
+ , m_aText(u"\u00B6")
+ , m_aESelection(0, 0, 0, 0)
+ , m_aSubElements(0)
+ , m_aParentElement(nullptr)
+ , m_nSubElementId(0)
+ {
+ SmImplAttributeType();
+ };
+
+public:
+ SmMlElement(const SmMlElement& aElement)
+ : SmRect(static_cast<SmRect>(aElement))
+ , m_aElementType(aElement.getMlElementType())
+ , m_aText(aElement.getText())
+ , m_aESelection(aElement.getESelectionReference())
+ , m_aSubElements(0)
+ , m_aParentElement(nullptr)
+ , m_nSubElementId(aElement.getSubElementId())
+ {
+ m_aAttributePosList = std::vector<SmMlAttributePos>(aElement.getAttributeCount());
+ for (size_t i = 0; i < aElement.getAttributeCount(); ++i)
+ setAttributeForce(i, aElement.getAttributePointer(i));
+ };
+
+private:
+ // Type of element
+ SmMlElementType m_aElementType;
+
+ // Element text
+ OUString m_aText;
+
+ // Location in source code
+ ESelection m_aESelection;
+
+ // Attribute list
+ std::vector<SmMlAttribute> m_aAttributeList;
+
+ // Attribute position list
+ std::vector<SmMlAttributePos> m_aAttributePosList;
+
+ // Sub elements
+ std::vector<SmMlElement*> m_aSubElements;
+
+ // Parent element
+ SmMlElement* m_aParentElement;
+
+ // Child id, so it is possible to iterate
+ size_t m_nSubElementId;
+
+private:
+ void SmImplAttributeType();
+
+public: // Element type
+ /**
+ * Returns the mathml element type
+ * @return mathml element type
+ */
+ SmMlElementType getMlElementType() const { return m_aElementType; };
+
+ /**
+ * Check if the mathml element is of a given type
+ * @param aElementType
+ * @return is mathml element type
+ */
+ bool isMlElementType(SmMlElementType aElementType) const
+ {
+ return m_aElementType == aElementType;
+ };
+
+public: // location in the source
+ /**
+ * Returns the location in the source code of the node type
+ * @return selection
+ */
+ const ESelection& getESelection() const { return m_aESelection; };
+
+ /**
+ * Returns the location in the source code of the node type
+ * @return selection
+ */
+ const ESelection& getESelectionReference() const { return m_aESelection; };
+
+ /**
+ * Sets the location in the source code of the node type
+ * @param aESelection
+ */
+ void setESelection(ESelection aESelection) { m_aESelection = aESelection; };
+
+ /**
+ * Gets the line in the text where the node is located.
+ * It is used to do the visual <-> text correspondence.
+ * @return line
+ */
+ sal_Int32 GetSourceCodeRow() const { return m_aESelection.nStartPara; }
+
+ /**
+ * Gets the column of the line in the text where the node is located.
+ * It is used to do the visual <-> text correspondence.
+ * @return column
+ */
+ sal_Int32 GetSourceCodeColumn() const { return m_aESelection.nStartPos; }
+
+public: // attributes
+ /**
+ * Returns the amount of available attributes
+ * @return attribute count
+ */
+ size_t getAttributeCount() const { return m_aAttributeList.size(); };
+
+ /**
+ * Gets a given attribute.
+ * If no available returns empty attribute.
+ * @param nAttributePos
+ * @return given attribute.
+ */
+ SmMlAttribute getAttribute(size_t nAttributePos) const
+ {
+ return nAttributePos < m_aAttributeList.size() ? m_aAttributeList[nAttributePos]
+ : SmMlAttribute();
+ }
+
+ /**
+ * Gets a given attribute.
+ * If no available returns empty attribute.
+ * @param nAttributePos
+ * @return given attribute.
+ */
+ SmMlAttribute getAttribute(SmMlAttributeValueType aAttributeType) const;
+
+ /**
+ * Sets a given attribute.
+ * If no available does nothing.
+ * @param nAttributePos
+ * @return given attribute.
+ */
+ void setAttribute(const SmMlAttribute* aAttribute);
+
+ /**
+ * Set's a given attribute.
+ * If no available does nothing.
+ * @param nAttributePos
+ * @return given attribute.
+ */
+ void setAttribute(const SmMlAttribute& aAttribute) { setAttribute(&aAttribute); }
+
+ /** Checks if an attribute has been manually set
+ * @param aElementType
+ */
+ bool isAttributeSet(SmMlAttributeValueType aAttributeType) const;
+
+private: // attributes
+ /**
+ * Gets a given attribute.
+ * If no available returns empty attribute.
+ * @param nAttributePos
+ * @return given attribute.
+ */
+ const SmMlAttribute* getAttributePointer(size_t nAttributePos) const
+ {
+ return nAttributePos < m_aAttributeList.size() ? &m_aAttributeList[nAttributePos] : nullptr;
+ }
+
+ /**
+ * Sets a given attribute.
+ * If no available undefined behaviour.
+ * @param nAttributePos
+ * @param aAttribute
+ * @return given attribute.
+ */
+ void setAttributeForce(size_t nAttributePos, const SmMlAttribute* aAttribute)
+ {
+ m_aAttributeList[nAttributePos].setMlAttributeValue(aAttribute);
+ }
+
+public: // sub elements
+ /**
+ * Returns the sub elements count
+ * @return sub elements count
+ */
+ size_t getSubElementsCount() const { return m_aSubElements.size(); };
+
+ /**
+ * Returns a given sub element
+ * @param nPos
+ * @return sub elements
+ */
+ SmMlElement* getSubElement(size_t nPos)
+ {
+ return nPos < m_aSubElements.size() ? m_aSubElements[nPos] : nullptr;
+ };
+
+ /**
+ * Returns a given sub element
+ * @param nPos
+ * @return sub elements
+ */
+ const SmMlElement* getSubElement(size_t nPos) const
+ {
+ return nPos < m_aSubElements.size() ? m_aSubElements[nPos] : nullptr;
+ };
+
+ /**
+ * Sets a given sub element
+ * @param nPos
+ * @param aElement
+ */
+ void setSubElement(size_t nPos, SmMlElement* aElement);
+
+ /**
+ * Gets subelement id
+ */
+ size_t getSubElementId() const { return m_nSubElementId; }
+
+ /**
+ * Sets subelement id
+ * @param nSubElementId
+ */
+ void setSubElementId(size_t nSubElementId) { m_nSubElementId = nSubElementId; }
+
+public: // parent elements
+ /**
+ * Returns the parent element
+ * @return parent element
+ */
+ SmMlElement* getParentElement() { return m_aParentElement; };
+
+ /**
+ * Returns the parent element
+ * @return parent element
+ */
+ const SmMlElement* getParentElement() const { return m_aParentElement; };
+
+ /**
+ * Sets the parent element
+ * No allocation / free is done.
+ * @param aParentElement
+ */
+ void setParentElement(SmMlElement* aParentElement) { m_aParentElement = aParentElement; };
+
+public: // text elements
+ /**
+ * Returns the element text
+ */
+ const OUString& getText() const { return m_aText; };
+
+ /**
+ * Returns the element text
+ */
+ void setText(OUString aText) { m_aText = aText; };
+};
+
+namespace starmathdatabase
+{
+/**
+ * Generates an attribute vector of default values from an attribute position list.
+ * @param aAttributePosList
+ * @return attribute vector
+ */
+std::vector<SmMlAttribute> makeMlAttributeList(std::vector<SmMlAttributePos> aAttributePosList);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/starmath/inc/mathml/export.hxx b/starmath/inc/mathml/export.hxx
new file mode 100644
index 000000000..0bd83e6ef
--- /dev/null
+++ b/starmath/inc/mathml/export.hxx
@@ -0,0 +1,241 @@
+/* -*- 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 .
+ */
+
+#pragma once
+
+// Our mathml
+#include "element.hxx"
+
+// Xml tools
+#include <xmloff/xmlnamespace.hxx>
+#include <xmloff/xmlexp.hxx>
+#include <xmloff/xmltoken.hxx>
+
+// Extras
+#include <com/sun/star/io/XOutputStream.hpp>
+
+class SfxMedium;
+class SmDocShell;
+
+class SmMLExportWrapper
+{
+private:
+ // Model
+ css::uno::Reference<css::frame::XModel> m_xModel;
+ // Save as a flat document ( mml, fodf ... )
+ bool m_bFlat;
+ // Use html / mathml entities
+ bool m_bUseHTMLMLEntities;
+ // Mathmml tree to parse
+ SmMlElement* m_pElementTree;
+ // Export xmlns tag
+ bool m_bUseExportTag;
+
+public:
+ /** Set's the writer to export to flat document
+ */
+ void setFlat(bool bFlat) { m_bFlat = bFlat; }
+
+ /** Checks if the writer is set to export to flat document
+ */
+ bool getFlat() const { return m_bFlat; }
+
+ /** Checks the use of HTML / MathML entities such as &infinity;
+ */
+ void setUseHTMLMLEntities(bool bUseHTMLMLEntities)
+ {
+ m_bUseHTMLMLEntities = bUseHTMLMLEntities;
+ }
+
+ /** Activates the use of HTML / MathML entities such as &infinity;
+ */
+ bool getUseHTMLMLEntities() const { return m_bUseHTMLMLEntities; }
+
+ /** Get's if xmlns field is added
+ */
+ bool getUseExportTag() const { return m_bUseExportTag; }
+
+ /** Set's if xmlns field is added
+ */
+ void setUseExportTag(bool bUseExportTag) { m_bUseExportTag = bUseExportTag; }
+
+public:
+ explicit SmMLExportWrapper(css::uno::Reference<css::frame::XModel> const& rRef)
+ : m_xModel(rRef)
+ , m_bFlat(true)
+ , m_bUseHTMLMLEntities(false)
+ , m_pElementTree(nullptr)
+ , m_bUseExportTag(false)
+ {
+ }
+
+ /** Export to an archive
+ */
+ bool Export(SfxMedium& rMedium);
+
+ /** Just export a mathml tree
+ */
+ OUString Export(SmMlElement* pElementTree);
+
+ // Making this protected we can keep it from getting trash as input
+protected:
+ /** export through an XML exporter component (output stream version)
+ */
+ bool WriteThroughComponentOS(const css::uno::Reference<css::io::XOutputStream>& xOutputStream,
+ const css::uno::Reference<css::lang::XComponent>& xComponent,
+ css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+ css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
+ const char16_t* pComponentName, int_fast16_t nSyntaxVersion);
+
+ /** export through an XML exporter component (storage version)
+ */
+ bool WriteThroughComponentS(const css::uno::Reference<css::embed::XStorage>& xStor,
+ const css::uno::Reference<css::lang::XComponent>& xComponent,
+ const char16_t* pStreamName,
+ css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+ css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
+ const char16_t* pComponentName, int_fast16_t nSyntaxVersion);
+
+ /** export through an XML exporter component (memory stream version)
+ */
+ OUString
+ WriteThroughComponentMS(const css::uno::Reference<css::lang::XComponent>& xComponent,
+ css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+ css::uno::Reference<css::beans::XPropertySet> const& rPropSet);
+};
+
+class SmMLExport final : public SvXMLExport
+{
+private:
+ SmMlElement* m_pElementTree;
+ bool m_bSuccess;
+ bool m_bUseExportTag;
+
+public:
+ /** Everything was allright
+ */
+ bool getSuccess() const { return m_bSuccess; }
+
+ /** Get's if xmlns field is added
+ */
+ bool getUseExportTag() const { return m_bUseExportTag; }
+
+ /** Set's if xmlns field is added
+ */
+ void setUseExportTag(bool bUseExportTag) { m_bUseExportTag = bUseExportTag; }
+
+ /** Set's the element tree to be exported.
+ * If it isn't nullptr the this will be exported instead of the document
+ */
+ void setElementTree(SmMlElement* pElementTree) { m_pElementTree = pElementTree; }
+
+private:
+ /** Adds an element
+ */
+ SvXMLElementExport* createElementExport(xmloff::token::XMLTokenEnum nElement)
+ {
+ // We can't afford to ignore white spaces. They are part of the code.
+ return new SvXMLElementExport(*this, XML_NAMESPACE_MATH, nElement, false, false);
+ }
+
+ /** Adds an attribute
+ */
+ void addAttribute(xmloff::token::XMLTokenEnum pAttribute,
+ xmloff::token::XMLTokenEnum pAttributeValue)
+ {
+ AddAttribute(XML_NAMESPACE_MATH, pAttribute, pAttributeValue);
+ }
+
+ /** Adds an attribute
+ */
+ void addAttribute(xmloff::token::XMLTokenEnum pAttribute, const OUString& pAttributeValue)
+ {
+ AddAttribute(XML_NAMESPACE_MATH, pAttribute, pAttributeValue);
+ }
+
+public:
+ /** Exports an attribute of type "length"
+ */
+ void exportMlAttributeLength(xmloff::token::XMLTokenEnum pAttribute,
+ const SmLengthValue& aLengthValue);
+
+ /** Exports attributes of an element
+ */
+ void exportMlAttributes(const SmMlElement* pMlElement);
+
+ /** Exports an element and all it's attributes
+ */
+ SvXMLElementExport* exportMlElement(const SmMlElement* pMlElement);
+
+ /** Exports an element tree
+ */
+ void exportMlElementTree();
+
+ /** Handles an error on the mathml structure
+ */
+ void declareMlError();
+
+public:
+ /** Constructor
+ */
+ SmMLExport(const css::uno::Reference<css::uno::XComponentContext>& rContext,
+ OUString const& implementationName, SvXMLExportFlags nExportFlags);
+
+private:
+ /** Get's document shell
+ */
+ SmDocShell* getSmDocShell();
+
+public:
+ // XUnoTunnel
+ sal_Int64 SAL_CALL getSomething(const css::uno::Sequence<sal_Int8>& rId) override;
+ static const css::uno::Sequence<sal_Int8>& getUnoTunnelId() noexcept;
+
+ /** Exports auto styles
+ * However math doesn't have any
+ */
+ void ExportAutoStyles_() override {}
+
+ /** Exports master styles
+ * However math doesn't have any
+ */
+ void ExportMasterStyles_() override {}
+
+ /** Exports formula
+ * Handler used from exportDoc
+ */
+ void ExportContent_() override { exportMlElementTree(); };
+
+ /** Exports the document
+ * If m_pElementTree isn't null then exports m_pElementTree
+ */
+ ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass
+ = ::xmloff::token::XML_TOKEN_INVALID) override;
+
+ /** Get's view settings and prepares them to export
+ */
+ virtual void GetViewSettings(css::uno::Sequence<css::beans::PropertyValue>& aProps) override;
+
+ /** Get's configuration settings and prepares them to export
+ */
+ virtual void
+ GetConfigurationSettings(css::uno::Sequence<css::beans::PropertyValue>& aProps) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/inc/mathml/import.hxx b/starmath/inc/mathml/import.hxx
new file mode 100644
index 000000000..d98cc8cf4
--- /dev/null
+++ b/starmath/inc/mathml/import.hxx
@@ -0,0 +1,150 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+// Our mathml
+#include "element.hxx"
+
+// XML tools
+#include <vcl/errcode.hxx>
+#include <xmloff/xmlimp.hxx>
+
+// Extras
+
+class SfxMedium;
+class SmDocShell;
+class SmMLImport;
+
+class SmMLImportWrapper
+{
+ css::uno::Reference<css::frame::XModel> m_xModel;
+ SmDocShell* m_pDocShell;
+ SmMLImport* m_pMlImport;
+
+private:
+ // Use customized entities
+
+public:
+ /** Get the element tree when parsed from text
+ */
+ SmMlElement* getElementTree();
+
+public:
+ /** Constructor
+ */
+ explicit SmMLImportWrapper(css::uno::Reference<css::frame::XModel> const& rRef)
+ : m_xModel(rRef)
+ , m_pDocShell(nullptr)
+ , m_pMlImport(nullptr)
+ {
+ }
+
+ /** Imports the mathml
+ */
+ ErrCode Import(SfxMedium& rMedium);
+
+ /** Imports the mathml
+ */
+ ErrCode Import(std::u16string_view aSource);
+
+ /** read a component from input stream
+ */
+ ErrCode
+ ReadThroughComponentIS(const css::uno::Reference<css::io::XInputStream>& xInputStream,
+ const css::uno::Reference<css::lang::XComponent>& xModelComponent,
+ css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+ css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
+ const char16_t* pFilterName, bool bEncrypted,
+ int_fast16_t nSyntaxVersion);
+
+ /** read a component from storage
+ */
+ ErrCode ReadThroughComponentS(const css::uno::Reference<css::embed::XStorage>& xStorage,
+ const css::uno::Reference<css::lang::XComponent>& xModelComponent,
+ const char16_t* pStreamName,
+ css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+ css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
+ const char16_t* pFilterName, int_fast16_t nSyntaxVersion);
+
+ /** read a component from text
+ */
+ ErrCode
+ ReadThroughComponentMS(std::u16string_view aText,
+ const css::uno::Reference<css::lang::XComponent>& xModelComponent,
+ css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+ css::uno::Reference<css::beans::XPropertySet> const& rPropSet);
+};
+
+class SmMLImport final : public SvXMLImport
+{
+private:
+ SmMlElement* m_pElementTree = new SmMlElement(SmMlElementType::NMlEmpty);
+ bool m_bSuccess;
+ size_t m_nSmSyntaxVersion;
+
+public:
+ /** Gets parsed element tree
+ */
+ SmMlElement* getElementTree() { return m_pElementTree; }
+
+ /** Checks out if parse was a success
+ */
+ bool getSuccess() const { return m_bSuccess; }
+
+public:
+ /** Handles an error on the mathml structure
+ */
+ void declareMlError();
+
+public:
+ /** Constructor
+ */
+ SmMLImport(const css::uno::Reference<css::uno::XComponentContext>& rContext,
+ OUString const& implementationName, SvXMLImportFlags nImportFlags);
+
+ /** Destructor
+ */
+ virtual ~SmMLImport() noexcept override { cleanup(); };
+
+public:
+ // XUnoTunnel
+ sal_Int64 SAL_CALL getSomething(const css::uno::Sequence<sal_Int8>& rId) override;
+ static const css::uno::Sequence<sal_Int8>& getUnoTunnelId() noexcept;
+
+ /** End the document
+ */
+ void SAL_CALL endDocument() override;
+
+ /** Create a fast context
+ */
+ SvXMLImportContext* CreateFastContext(
+ sal_Int32 nElement,
+ const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) override;
+
+ /** Imports view settings formula
+ */
+ virtual void
+ SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
+
+ /** Imports configurations settings formula
+ */
+ virtual void SetConfigurationSettings(
+ const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
+
+ /** Set syntax version
+ */
+ void SetSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion) { m_nSmSyntaxVersion = nSmSyntaxVersion; }
+
+ /** Get syntax version
+ */
+ sal_uInt16 GetSmSyntaxVersion() const { return m_nSmSyntaxVersion; }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/starmath/inc/mathml/iterator.hxx b/starmath/inc/mathml/iterator.hxx
new file mode 100644
index 000000000..559829ce8
--- /dev/null
+++ b/starmath/inc/mathml/iterator.hxx
@@ -0,0 +1,125 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+#include "element.hxx"
+
+/** The purpose of this iterator is to be able to iterate threw an infinite element tree
+ * infinite -> as much as your memory can hold
+ * No call-backs that will end up in out of stack
+ */
+
+namespace mathml
+{
+template <typename runType>
+void SmMlIteratorBottomToTop(SmMlElement* pMlElementTree, runType aRunType, void* aData)
+{
+ if (pMlElementTree == nullptr)
+ return;
+
+ SmMlElement* pCurrent;
+
+ // Fetch the deepest element
+ pCurrent = pMlElementTree;
+ while (pCurrent->getSubElementsCount() != 0)
+ {
+ if (pCurrent->getSubElement(0) == nullptr)
+ break;
+ pCurrent = pCurrent->getSubElement(0);
+ }
+
+ do
+ {
+ // Fetch next element
+ size_t nId = pCurrent->getSubElementId();
+ // We are back to the top.
+ if (pCurrent->getParentElement() == nullptr)
+ break;
+ // If this was the last, then turn back to the parent
+ if (nId + 1 == pCurrent->getParentElement()->getSubElementsCount())
+ pCurrent = pCurrent->getParentElement();
+ else // If not, next is the one near it
+ {
+ // It could have sub elements
+ if (pCurrent->getParentElement()->getSubElement(nId + 1) == nullptr)
+ break;
+ pCurrent = pCurrent->getParentElement()->getSubElement(nId + 1);
+ // Fetch the deepest element
+ while (pCurrent->getSubElementsCount() != 0)
+ {
+ if (pCurrent->getSubElement(0) == nullptr)
+ break;
+ pCurrent = pCurrent->getSubElement(0);
+ }
+ }
+
+ // Just in case of, but should be forbidden
+ if (pCurrent != nullptr)
+ aRunType(pCurrent, aData);
+
+ } while (pCurrent != nullptr);
+}
+
+template <typename runType>
+void SmMlIteratorTopToBottom(SmMlElement* pMlElementTree, runType aRunType, void* aData)
+{
+ if (pMlElementTree == nullptr)
+ return;
+
+ SmMlElement* pCurrent;
+
+ // Fetch the deepest element
+ pCurrent = pMlElementTree;
+ aRunType(pCurrent, aData);
+ while (pCurrent->getSubElementsCount() != 0)
+ {
+ if (pCurrent->getSubElement(0) == nullptr)
+ break;
+ pCurrent = pCurrent->getSubElement(0);
+ aRunType(pCurrent, aData);
+ }
+
+ do
+ {
+ // Fetch next element
+ size_t nId = pCurrent->getSubElementId();
+ // We are back to the top.
+ if (pCurrent->getParentElement() == nullptr)
+ break;
+ // If this was the last, then turn back to the parent
+ if (nId + 1 == pCurrent->getParentElement()->getSubElementsCount())
+ pCurrent = pCurrent->getParentElement();
+ else // If not, next is the one near it
+ {
+ // It could have sub elements
+ if (pCurrent->getParentElement()->getSubElement(nId + 1) == nullptr)
+ break;
+ pCurrent = pCurrent->getParentElement()->getSubElement(nId + 1);
+ aRunType(pCurrent, aData);
+ // Fetch the deepest element
+ while (pCurrent->getSubElementsCount() != 0)
+ {
+ if (pCurrent->getSubElement(0) == nullptr)
+ break;
+ pCurrent = pCurrent->getSubElement(0);
+ aRunType(pCurrent, aData);
+ }
+ }
+
+ } while (pCurrent != nullptr);
+}
+
+void SmMlIteratorFree(SmMlElement* pMlElementTree);
+
+SmMlElement* SmMlIteratorCopy(SmMlElement* pMlElementTree);
+
+} // end namespace mathml
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/starmath/inc/mathml/mathmlMo.hxx b/starmath/inc/mathml/mathmlMo.hxx
new file mode 100644
index 000000000..10a8b0001
--- /dev/null
+++ b/starmath/inc/mathml/mathmlMo.hxx
@@ -0,0 +1,109 @@
+/* -*- 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 .
+ */
+
+/*
+ Warning: The SvXMLElementExport helper class creates the beginning and
+ closing tags of xml elements in its constructor and destructor, so there's
+ hidden stuff going on, on occasion the ordering of these classes declarations
+ may be significant
+*/
+
+#pragma once
+
+#include <sal/types.h>
+#include <rtl/ustring.hxx>
+#include <vector>
+
+// https://www.w3.org/TR/MathML3/appendixc.html
+
+enum class moOpDP : sal_uInt16
+{ // moOperatorDataProperty
+ nonedp = 0x0000,
+ accent = 0x0001,
+ fence = 0x0002,
+ stretchy = 0x0004,
+ symmetric = 0x0008,
+ separator = 0x0010,
+ linebreakstyleAfter = 0x0020,
+ largeop = 0x0080,
+ movablelimits = 0x0100,
+ starmathCustom = 0x0200,
+ starmathCustomMo = 0x0400,
+ stretchyfence = 0x0006,
+ movablelargeop = 0x0180
+};
+
+enum class moOpDF : sal_uInt16
+{ // moOperatorDataForm
+ nonedf = 0x0000,
+ prefix = 0x0001,
+ infix = 0x0002,
+ postfix = 0x0004,
+ prepostfix = 0x0005
+};
+
+struct moOperatorData
+{
+ OUString m_motxt;
+ moOpDF m_form;
+ sal_uInt16 m_priority;
+ sal_uInt16 m_lspace;
+ sal_uInt16 m_rspace;
+ moOpDP m_properties;
+
+ moOperatorData(OUString motxt, moOpDF form, sal_uInt16 priority, sal_uInt16 lspace,
+ sal_uInt16 rspace, moOpDP properties)
+ : m_motxt(motxt)
+ , m_form(form)
+ , m_priority(priority)
+ , m_lspace(lspace)
+ , m_rspace(rspace)
+ , m_properties(properties)
+ {
+ }
+};
+
+inline moOpDF operator|(moOpDF a, moOpDF b)
+{
+ return static_cast<moOpDF>(static_cast<sal_uInt16>(a) | static_cast<sal_uInt16>(b));
+}
+
+inline moOpDF operator&(moOpDF a, moOpDF b)
+{
+ return static_cast<moOpDF>(static_cast<sal_uInt16>(a) & static_cast<sal_uInt16>(b));
+}
+
+inline moOpDP operator|(moOpDP a, moOpDP b)
+{
+ return static_cast<moOpDP>(static_cast<sal_uInt16>(a) | static_cast<sal_uInt16>(b));
+}
+
+inline moOpDP operator&(moOpDP a, moOpDP b)
+{
+ return static_cast<moOpDP>(static_cast<sal_uInt16>(a) & static_cast<sal_uInt16>(b));
+}
+
+namespace starmathdatabase
+{
+constexpr size_t MATHML_MO_COUNT = 1100;
+
+extern std::vector<moOperatorData> moOperatorDataDictionary;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/inc/mathml/mathmlattr.hxx b/starmath/inc/mathml/mathmlattr.hxx
new file mode 100644
index 000000000..b7d1160bb
--- /dev/null
+++ b/starmath/inc/mathml/mathmlattr.hxx
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <string_view>
+
+#include <rtl/ustring.hxx>
+#include <tools/fract.hxx>
+
+// MathML 3: 2.1.5.1 Syntax notation used in the MathML specification
+// <https://www.w3.org/TR/MathML/chapter2.html#id.2.1.5.1>
+// MathML 2: 2.4.4.2 Attributes with units
+// <https://www.w3.org/TR/MathML2/chapter2.html#fund.attval>
+// MathML 3: 2.1.5.2 Length Valued Attributes
+// <https://www.w3.org/TR/MathML/chapter2.html#fund.units>
+
+enum class MathMLLengthUnit
+{
+ None,
+ Em,
+ Ex,
+ Px,
+ In,
+ Cm,
+ Mm,
+ Pt,
+ Pc,
+ Percent
+};
+
+struct MathMLAttributeLengthValue
+{
+ Fraction aNumber;
+ MathMLLengthUnit eUnit;
+ MathMLAttributeLengthValue()
+ : eUnit(MathMLLengthUnit::None)
+ {
+ }
+};
+
+bool ParseMathMLAttributeLengthValue(std::u16string_view rStr, MathMLAttributeLengthValue& rV);
+
+// MathML 3: 3.2.2 Mathematics style attributes common to token elements
+// <https://www.w3.org/TR/MathML3/chapter3.html#presm.commatt>
+
+enum class MathMLMathvariantValue
+{
+ Normal,
+ Bold,
+ Italic,
+ BoldItalic,
+ DoubleStruck,
+ BoldFraktur,
+ Script,
+ BoldScript,
+ Fraktur,
+ SansSerif,
+ BoldSansSerif,
+ SansSerifItalic,
+ SansSerifBoldItalic,
+ Monospace,
+ Initial,
+ Tailed,
+ Looped,
+ Stretched
+};
+
+bool GetMathMLMathvariantValue(const OUString& rStr, MathMLMathvariantValue& rV);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/starmath/inc/mathml/mathmlexport.hxx b/starmath/inc/mathml/mathmlexport.hxx
new file mode 100644
index 000000000..b7c054440
--- /dev/null
+++ b/starmath/inc/mathml/mathmlexport.hxx
@@ -0,0 +1,128 @@
+/* -*- 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 .
+ */
+
+#pragma once
+
+#include <xmloff/xmlexp.hxx>
+#include <xmloff/xmltoken.hxx>
+
+class SfxMedium;
+class SmNode;
+class SmVerticalBraceNode;
+namespace com::sun::star
+{
+namespace io
+{
+class XOutputStream;
+}
+namespace beans
+{
+class XPropertySet;
+}
+}
+
+class SmXMLExportWrapper
+{
+ css::uno::Reference<css::frame::XModel> xModel;
+ bool bFlat; //set true for export to flat .mml, set false for
+ //export to a .sxm (or whatever) package
+
+private:
+ // Use customized entities
+ bool m_bUseHTMLMLEntities;
+
+public:
+ explicit SmXMLExportWrapper(css::uno::Reference<css::frame::XModel> const& rRef)
+ : xModel(rRef)
+ , bFlat(true)
+ , m_bUseHTMLMLEntities(false)
+ {
+ }
+
+ bool Export(SfxMedium& rMedium);
+ void SetFlat(bool bIn) { bFlat = bIn; }
+
+ bool IsUseHTMLMLEntities() const { return m_bUseHTMLMLEntities; }
+ void SetUseHTMLMLEntities(bool bUseHTMLMLEntities)
+ {
+ m_bUseHTMLMLEntities = bUseHTMLMLEntities;
+ }
+
+ bool WriteThroughComponent(const css::uno::Reference<css::io::XOutputStream>& xOutputStream,
+ const css::uno::Reference<css::lang::XComponent>& xComponent,
+ css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+ css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
+ const char* pComponentName);
+
+ bool WriteThroughComponent(const css::uno::Reference<css::embed::XStorage>& xStor,
+ const css::uno::Reference<css::lang::XComponent>& xComponent,
+ const char* pStreamName,
+ css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+ css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
+ const char* pComponentName);
+};
+
+class SmXMLExport final : public SvXMLExport
+{
+ const SmNode* pTree;
+ OUString aText;
+ bool bSuccess;
+
+ void ExportNodes(const SmNode* pNode, int nLevel);
+ void ExportTable(const SmNode* pNode, int nLevel);
+ void ExportLine(const SmNode* pNode, int nLevel);
+ void ExportExpression(const SmNode* pNode, int nLevel, bool bNoMrowContainer = false);
+ void ExportText(const SmNode* pNode);
+ void ExportMath(const SmNode* pNode);
+ void ExportBinaryHorizontal(const SmNode* pNode, int nLevel);
+ void ExportUnaryHorizontal(const SmNode* pNode, int nLevel);
+ void ExportBrace(const SmNode* pNode, int nLevel);
+ void ExportBinaryVertical(const SmNode* pNode, int nLevel);
+ void ExportBinaryDiagonal(const SmNode* pNode, int nLevel);
+ void ExportSubSupScript(const SmNode* pNode, int nLevel);
+ void ExportRoot(const SmNode* pNode, int nLevel);
+ void ExportOperator(const SmNode* pNode, int nLevel);
+ void ExportAttributes(const SmNode* pNode, int nLevel);
+ void ExportFont(const SmNode* pNode, int nLevel);
+ void ExportVerticalBrace(const SmVerticalBraceNode* pNode, int nLevel);
+ void ExportMatrix(const SmNode* pNode, int nLevel);
+ void ExportBlank(const SmNode* pNode);
+
+public:
+ SmXMLExport(const css::uno::Reference<css::uno::XComponentContext>& rContext,
+ OUString const& implementationName, SvXMLExportFlags nExportFlags);
+
+ // XUnoTunnel
+ sal_Int64 SAL_CALL getSomething(const css::uno::Sequence<sal_Int8>& rId) override;
+ static const css::uno::Sequence<sal_Int8>& getUnoTunnelId() noexcept;
+
+ void ExportAutoStyles_() override {}
+ void ExportMasterStyles_() override {}
+ void ExportContent_() override;
+ ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass
+ = ::xmloff::token::XML_TOKEN_INVALID) override;
+
+ virtual void GetViewSettings(css::uno::Sequence<css::beans::PropertyValue>& aProps) override;
+ virtual void
+ GetConfigurationSettings(css::uno::Sequence<css::beans::PropertyValue>& aProps) override;
+
+ bool GetSuccess() const { return bSuccess; }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/inc/mathml/mathmlimport.hxx b/starmath/inc/mathml/mathmlimport.hxx
new file mode 100644
index 000000000..0a963a1b0
--- /dev/null
+++ b/starmath/inc/mathml/mathmlimport.hxx
@@ -0,0 +1,114 @@
+/* -*- 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 .
+ */
+
+#pragma once
+
+#include <xmloff/xmlimp.hxx>
+#include <vcl/errcode.hxx>
+
+#include <deque>
+
+class SmNode;
+class SfxMedium;
+namespace com::sun::star
+{
+namespace beans
+{
+class XPropertySet;
+}
+}
+
+typedef std::deque<std::unique_ptr<SmNode>> SmNodeStack;
+
+class SmXMLImportWrapper
+{
+ css::uno::Reference<css::frame::XModel> xModel;
+
+private:
+ // Use customized entities
+ bool m_bUseHTMLMLEntities;
+
+public:
+ explicit SmXMLImportWrapper(css::uno::Reference<css::frame::XModel> const& rRef)
+ : xModel(rRef)
+ , m_bUseHTMLMLEntities(false)
+ {
+ }
+
+ ErrCode Import(SfxMedium& rMedium);
+ void useHTMLMLEntities(bool bUseHTMLMLEntities) { m_bUseHTMLMLEntities = bUseHTMLMLEntities; }
+
+ static ErrCode
+ ReadThroughComponent(const css::uno::Reference<css::io::XInputStream>& xInputStream,
+ const css::uno::Reference<css::lang::XComponent>& xModelComponent,
+ css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+ css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
+ const char* pFilterName, bool bEncrypted, bool bUseHTMLMLEntities);
+
+ static ErrCode
+ ReadThroughComponent(const css::uno::Reference<css::embed::XStorage>& xStorage,
+ const css::uno::Reference<css::lang::XComponent>& xModelComponent,
+ const char* pStreamName,
+ css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+ css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
+ const char* pFilterName, bool bUseHTMLMLEntities);
+};
+
+class SmXMLImport final : public SvXMLImport
+{
+ SmNodeStack aNodeStack;
+ bool bSuccess;
+ int nParseDepth;
+ OUString aText;
+ sal_uInt16 mnSmSyntaxVersion;
+
+public:
+ SmXMLImport(const css::uno::Reference<css::uno::XComponentContext>& rContext,
+ OUString const& implementationName, SvXMLImportFlags nImportFlags);
+ virtual ~SmXMLImport() noexcept override;
+
+ // XUnoTunnel
+ sal_Int64 SAL_CALL getSomething(const css::uno::Sequence<sal_Int8>& rId) override;
+ static const css::uno::Sequence<sal_Int8>& getUnoTunnelId() noexcept;
+
+ void SAL_CALL endDocument() override;
+
+ SvXMLImportContext* CreateFastContext(
+ sal_Int32 nElement,
+ const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) override;
+
+ SmNodeStack& GetNodeStack() { return aNodeStack; }
+
+ bool GetSuccess() const { return bSuccess; }
+ [[nodiscard]] const OUString& GetText() const { return aText; }
+ void SetText(const OUString& rStr) { aText = rStr; }
+
+ virtual void
+ SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
+ virtual void SetConfigurationSettings(
+ const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
+
+ void IncParseDepth() { ++nParseDepth; }
+ bool TooDeep() const { return nParseDepth >= 2048; }
+ void DecParseDepth() { --nParseDepth; }
+ void SetSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion) { mnSmSyntaxVersion = nSmSyntaxVersion; }
+ sal_uInt16 GetSmSyntaxVersion() const { return mnSmSyntaxVersion; }
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/inc/mathml/starmathdatabase.hxx b/starmath/inc/mathml/starmathdatabase.hxx
new file mode 100644
index 000000000..b4d3d6d3f
--- /dev/null
+++ b/starmath/inc/mathml/starmathdatabase.hxx
@@ -0,0 +1,332 @@
+/* -*- 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 .
+ */
+
+#pragma once
+
+#include <token.hxx>
+
+// Starmath color types
+// In order to add them to starmath, edit the SmColorTokenTableEntry lists on
+// /core/starmath/source/starmathdatabase.css .
+
+// HTML
+// https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#Color_Keywords
+/* CSS Level 1 */
+constexpr Color COL_SM_BLACK(0x000000);
+constexpr Color COL_SM_SILVER(0xC0C0C0);
+constexpr Color COL_SM_GRAY(0x808080);
+constexpr Color COL_SM_WHITE(0xFFFFFF);
+constexpr Color COL_SM_MAROON(0x800000);
+constexpr Color COL_SM_RED(0xFF0000);
+constexpr Color COL_SM_PURPLE(0x800080);
+constexpr Color COL_SM_FUCHSIA(0xFF00FF);
+constexpr Color COL_SM_GREEN(0x008000);
+constexpr Color COL_SM_LIME(0x00FF00);
+constexpr Color COL_SM_OLIVE(0x808000);
+constexpr Color COL_SM_YELLOW(0xFFFF00);
+constexpr Color COL_SM_NAVY(0x000080);
+constexpr Color COL_SM_BLUE(0x0000FF);
+constexpr Color COL_SM_TEAL(0x008080);
+constexpr Color COL_SM_AQUA(0x00FFFF);
+/* CSS Level 2 */
+constexpr Color COL_SM_ORANGE(0xFFA500);
+/* CSS Level 3 */
+constexpr Color COL_SM_ALICEBLUE(0xF0F8FF);
+constexpr Color COL_SM_ANTIQUEWHITE(0xFAEBD7);
+constexpr Color COL_SM_AQUAMARINE(0x7FFFD4);
+constexpr Color COL_SM_AZURE(0xF0FFFF);
+constexpr Color COL_SM_BEIGE(0xF5F5DC);
+constexpr Color COL_SM_BISQUE(0xFFE4C4);
+constexpr Color COL_SM_BLANCHEDALMOND(0xFFEBCD);
+constexpr Color COL_SM_BLUEVIOLET(0x8A2BE2);
+constexpr Color COL_SM_BROWN(0xA52A2A);
+constexpr Color COL_SM_BURLYWOOD(0xDEB887);
+constexpr Color COL_SM_CADETBLUE(0x5F9EA0);
+constexpr Color COL_SM_CHARTREUSE(0x7FFF00);
+constexpr Color COL_SM_CHOCOLATE(0xD2691E);
+constexpr Color COL_SM_CORAL(0xFF7F50);
+constexpr Color COL_SM_CORNFLOWERBLUE(0x6495ED);
+constexpr Color COL_SM_CORNSILK(0xFFF8DC);
+constexpr Color COL_SM_CRIMSON(0xDC143C);
+constexpr Color COL_SM_CYAN(0x00FFFF);
+constexpr Color COL_SM_DARKBLUE(0x00008B);
+constexpr Color COL_SM_DARKCYAN(0x008B8B);
+constexpr Color COL_SM_DARKGOLDENROD(0xB8860B);
+constexpr Color COL_SM_DARKGRAY(0xA9A9A9);
+constexpr Color COL_SM_DARKGREEN(0x006400);
+constexpr Color COL_SM_DARKGREY(0xA9A9A9);
+constexpr Color COL_SM_DARKKHAKI(0xBDB76B);
+constexpr Color COL_SM_DARKMAGENTA(0x8B008B);
+constexpr Color COL_SM_DARKOLIVEGREEN(0x556B2F);
+constexpr Color COL_SM_DARKORANGE(0xFF8C00);
+constexpr Color COL_SM_DARKORCHID(0x9932CC);
+constexpr Color COL_SM_DARKRED(0x8B0000);
+constexpr Color COL_SM_DARKSALMON(0xE9967A);
+constexpr Color COL_SM_DARKSEAGREEN(0x8FBC8F);
+constexpr Color COL_SM_DARKSLATEBLUE(0x483D8B);
+constexpr Color COL_SM_DARKSLATEGRAY(0x2F4F4F);
+constexpr Color COL_SM_DARKSLATEGREY(0x2F4F4F);
+constexpr Color COL_SM_DARKTURQUOISE(0x00CED1);
+constexpr Color COL_SM_DARKVIOLET(0x9400D3);
+constexpr Color COL_SM_DEEPPINK(0xFF1493);
+constexpr Color COL_SM_DEEPSKYBLUE(0x00BFFF);
+constexpr Color COL_SM_DIMGRAY(0x696969);
+constexpr Color COL_SM_DIMGREY(0x696969);
+constexpr Color COL_SM_DODGERBLUE(0x1E90FF);
+constexpr Color COL_SM_FIREBRICK(0xB22222);
+constexpr Color COL_SM_FLORALWHITE(0xFFFAF0);
+constexpr Color COL_SM_FORESTGREEN(0x228B22);
+constexpr Color COL_SM_GAINSBORO(0xDCDCDC);
+constexpr Color COL_SM_GHOSTWHITE(0xF8F8FF);
+constexpr Color COL_SM_GOLD(0xFFD700);
+constexpr Color COL_SM_GOLDENROD(0xDAA520);
+constexpr Color COL_SM_GREENYELLOW(0xADFF2F);
+constexpr Color COL_SM_GREY(0x808080);
+constexpr Color COL_SM_HONEYDEW(0xF0FFF0);
+constexpr Color COL_SM_HOTPINK(0xFF69B4);
+constexpr Color COL_SM_INDIANRED(0xCD5C5C);
+constexpr Color COL_SM_INDIGO(0x4B0082);
+constexpr Color COL_SM_IVORY(0xFFFFF0);
+constexpr Color COL_SM_KHAKI(0xF0E68C);
+constexpr Color COL_SM_LAVENDER(0xE6E6FA);
+constexpr Color COL_SM_LAVENDERBLUSH(0xFFF0F5);
+constexpr Color COL_SM_LAWNGREEN(0x7CFC00);
+constexpr Color COL_SM_LEMONCHIFFON(0xFFFACD);
+constexpr Color COL_SM_LIGHTBLUE(0xADD8E6);
+constexpr Color COL_SM_LIGHTCORAL(0xF08080);
+constexpr Color COL_SM_LIGHTCYAN(0xE0FFFF);
+constexpr Color COL_SM_LIGHTGOLDENRODYELLOW(0xFAFAD2);
+constexpr Color COL_SM_LIGHTGRAY(0xD3D3D3);
+constexpr Color COL_SM_LIGHTGREEN(0x90EE90);
+constexpr Color COL_SM_LIGHTGREY(0xD3D3D3);
+constexpr Color COL_SM_LIGHTPINK(0xFFB6C1);
+constexpr Color COL_SM_LIGHTSALMON(0xFFA07A);
+constexpr Color COL_SM_LIGHTSEAGREEN(0x20B2AA);
+constexpr Color COL_SM_LIGHTSKYBLUE(0x87CEFA);
+constexpr Color COL_SM_LIGHTSLATEGRAY(0x778899);
+constexpr Color COL_SM_LIGHTSLATEGREY(0x778899);
+constexpr Color COL_SM_LIGHTSTEELBLUE(0xB0C4DE);
+constexpr Color COL_SM_LIGHTYELLOW(0xFFFFE0);
+constexpr Color COL_SM_LIMEGREEN(0x32CD32);
+constexpr Color COL_SM_LINEN(0xFAF0E6);
+constexpr Color COL_SM_MAGENTA(0xFF00FF);
+constexpr Color COL_SM_MEDIUMAQUAMARINE(0x66CDAA);
+constexpr Color COL_SM_MEDIUMBLUE(0x0000CD);
+constexpr Color COL_SM_MEDIUMORCHID(0xBA55D3);
+constexpr Color COL_SM_MEDIUMPURPLE(0x9370DB);
+constexpr Color COL_SM_MEDIUMSEAGREEN(0x3CB371);
+constexpr Color COL_SM_MEDIUMSLATEBLUE(0x7B68EE);
+constexpr Color COL_SM_MEDIUMSPRINGGREEN(0x00FA9A);
+constexpr Color COL_SM_MEDIUMTURQUOISE(0x48D1CC);
+constexpr Color COL_SM_MEDIUMVIOLETRED(0xC71585);
+constexpr Color COL_SM_MIDNIGHTBLUE(0x191970);
+constexpr Color COL_SM_MINTCREAM(0xF5FFFA);
+constexpr Color COL_SM_MISTYROSE(0xFFE4E1);
+constexpr Color COL_SM_MOCCASIN(0xFFE4B5);
+constexpr Color COL_SM_NAVAJOWHITE(0xFFDEAD);
+constexpr Color COL_SM_OLDLACE(0xFDF5E6);
+constexpr Color COL_SM_OLIVEDRAB(0x6B8E23);
+constexpr Color COL_SM_ORANGERED(0xFF4500);
+constexpr Color COL_SM_ORCHID(0xDA70D6);
+constexpr Color COL_SM_PALEGOLDENROD(0xEEE8AA);
+constexpr Color COL_SM_PALEGREEN(0x98FB98);
+constexpr Color COL_SM_PALETURQUOISE(0xAFEEEE);
+constexpr Color COL_SM_PALEVIOLETRED(0xDB7093);
+constexpr Color COL_SM_PAPAYAWHIP(0xFFEFD5);
+constexpr Color COL_SM_PEACHPUFF(0xFFDAB9);
+constexpr Color COL_SM_PERU(0xCD853F);
+constexpr Color COL_SM_PINK(0xFFC0CB);
+constexpr Color COL_SM_PLUM(0xDDA0DD);
+constexpr Color COL_SM_POWDERBLUE(0xB0E0E6);
+constexpr Color COL_SM_ROSYBROWN(0xBC8F8F);
+constexpr Color COL_SM_ROYALBLUE(0x4169E1);
+constexpr Color COL_SM_SADDLEBROWN(0x8B4513);
+constexpr Color COL_SM_SALMON(0xFA8072);
+constexpr Color COL_SM_SANDYBROWN(0xF4A460);
+constexpr Color COL_SM_SEAGREEN(0x2E8B57);
+constexpr Color COL_SM_SEASHELL(0xFFF5EE);
+constexpr Color COL_SM_SIENNA(0xA0522D);
+constexpr Color COL_SM_SKYBLUE(0x87CEEB);
+constexpr Color COL_SM_SLATEBLUE(0x6A5ACD);
+constexpr Color COL_SM_SLATEGRAY(0x708090);
+constexpr Color COL_SM_SLATEGREY(0x708090);
+constexpr Color COL_SM_SNOW(0xFFFAFA);
+constexpr Color COL_SM_SPRINGGREEN(0x00FF7F);
+constexpr Color COL_SM_STEELBLUE(0x4682B4);
+constexpr Color COL_SM_TAN(0xD2B48C);
+constexpr Color COL_SM_THISTLE(0xD8BFD8);
+constexpr Color COL_SM_TOMATO(0xFF6347);
+constexpr Color COL_SM_TURQUOISE(0x40E0D0);
+constexpr Color COL_SM_VIOLET(0xEE82EE);
+constexpr Color COL_SM_WHEAT(0xF5DEB3);
+constexpr Color COL_SM_WHITESMOKE(0xF5F5F5);
+constexpr Color COL_SM_YELLOWGREEN(0x9ACD32);
+/* CSS Level 4 */
+constexpr Color COL_SM_REBECCAPURPLE(0x663399);
+/* dvipsnames */
+// For now only five colors.
+// In a future all of them.
+// https://www.overleaf.com/learn/latex/Using_colours_in_LaTeX
+constexpr Color COL_SM_DIV_APRICOT(0xFFB781);
+constexpr Color COL_SM_DIV_AQUAMARINE(0x1BBEC1);
+constexpr Color COL_SM_DIV_BITTERSWEET(0xCF4B16);
+constexpr Color COL_SM_DIV_BLACK(0xCF4B16);
+constexpr Color COL_SM_DIV_BLUE(0x102694);
+/* Iconic colors */
+// https://design.ubuntu.com/brand/colour-palette/
+constexpr Color COL_SM_UBUNTU_ORANGE(0xE95420);
+// https://www.debian.org/logos/ Picked from SVG logo
+constexpr Color COL_SM_DEBIAN_MAGENTA(0xA80030);
+// https://libreoffice.org/
+constexpr Color COL_SM_LO_GREEN(0x00A500);
+
+namespace starmathdatabase
+{
+// Variables containing color information.
+extern const SmColorTokenTableEntry aColorTokenTableParse[159];
+extern const SmColorTokenTableEntry aColorTokenTableHTML[148];
+extern const SmColorTokenTableEntry aColorTokenTableMATHML[16];
+extern const SmColorTokenTableEntry aColorTokenTableDVIPS[5];
+extern const SmColorTokenTableEntry aColorTokenTableERROR[1];
+
+/**
+ * Identifies operator chars tokens for importing mathml.
+ * Identifies from char cChar
+ *
+ * While loading MO or MI elements might find an unicode16 symbol.
+ * This code allows to generate appropriate token for them.
+ *
+ * @param cChar
+ * @return closing fences' token
+ */
+SmToken Identify_SmXMLOperatorContext_Impl(sal_Unicode cChar, bool bIsStretchy = true);
+
+/**
+ * Identifies opening / closing brace tokens for importing mathml.
+ * Identifies from char cChar
+ *
+ * While loading MO fenced elements might find braces symbols.
+ * This code allows to generate appropriate token for them.
+ *
+ * @param cChar
+ * @return closing fences' token
+ */
+SmToken Identify_PrefixPostfix_SmXMLOperatorContext_Impl(sal_Unicode cChar);
+
+/**
+ * Identifies opening brace tokens for importing mathml.
+ * Identifies from char cChar
+ *
+ * While loading MO elements ( with prefix value for form attribute ) might find braces symbols.
+ * This code allows to generate appropriate token for them.
+ *
+ * @param cChar
+ * @return closing fences' token
+ */
+SmToken Identify_Prefix_SmXMLOperatorContext_Impl(sal_Unicode cChar);
+
+/**
+ * Identifies closing brace tokens for importing mathml.
+ * Identifies from char cChar
+ *
+ * While loading MO elements ( with postfix value for form attribute ) might find braces symbols.
+ * This code allows to generate appropriate token for them.
+ *
+ * @param cChar
+ * @return closing fences' token
+ */
+SmToken Identify_Postfix_SmXMLOperatorContext_Impl(sal_Unicode cChar);
+
+/**
+ * Identifies color from color code cColor.
+ * It will be returned with the parser syntax.
+ *
+ * For a given color returns the way it would be in the parser.
+ * Used for nodes to text visitors.
+ *
+ * @param cColor
+ * @param parser color
+ */
+SmColorTokenTableEntry Identify_Color_Parser(sal_uInt32 cColor);
+
+/**
+ * Identifies color from color code cColor.
+ * It will be returned with the HTML syntax.
+ * @param cColor
+ * @param parser color
+ */
+SmColorTokenTableEntry Identify_Color_HTML(sal_uInt32 cColor);
+
+/**
+ * Identifies color from color code cColor.
+ * It will be returned with the MATHML syntax.
+ *
+ * This is used to export mathml.
+ * Identifies the color and allows it to export it in proper mathml code.
+ *
+ * @param cColor
+ * @param parser color
+ */
+SmColorTokenTableEntry Identify_Color_MATHML(sal_uInt32 cColor);
+
+/**
+ * Identifies color from color code cColor.
+ * It will be returned with the dvipsnames syntax.
+ * @param cColor
+ * @param parser color
+ */
+SmColorTokenTableEntry Identify_Color_DVIPSNAMES(sal_uInt32 cColor);
+
+/**
+ * Identifies color from color name.
+ * It will be returned with the parser syntax.
+ *
+ * This finds color values for the color names loaded by the parser.
+ *
+ * @param cColor
+ * @param parser color
+ */
+const SmColorTokenTableEntry* Identify_ColorName_Parser(std::u16string_view colorname);
+
+/**
+ * Identifies color from color name.
+ * It will be returned with the HTML syntax.
+ *
+ * This finds color values for the color names loaded by mathmlimport.
+ * In theory mathml only supports HTML4 colors, but most browsers support all HTML5 colors.
+ * That's why there is an high risk of finding them inside mathml and have to give support.
+ *
+ * @param cColor
+ * @param parser color
+ */
+SmColorTokenTableEntry Identify_ColorName_HTML(std::u16string_view colorname);
+
+/**
+ * Identifies color from color name.
+ * It will be returned with the dvipsnames syntax.
+ *
+ * This code has been implemented to add a compatibility layer to import / export latex.
+ *
+ * @param cColor
+ * @param parser color
+ */
+const SmColorTokenTableEntry* Identify_ColorName_DVIPSNAMES(std::u16string_view colorname);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/inc/mathml/xparsmlbase.hxx b/starmath/inc/mathml/xparsmlbase.hxx
new file mode 100644
index 000000000..6c645a55e
--- /dev/null
+++ b/starmath/inc/mathml/xparsmlbase.hxx
@@ -0,0 +1,53 @@
+/* -*- 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 .
+ */
+
+#pragma once
+
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/Pair.hpp>
+namespace starmathdatabase
+{
+/**
+ * w3 documentation has been used for this.
+ * See: https://www.w3.org/2003/entities/2007/htmlmathml-f.ent
+ * Copyright 1998 - 2011 W3C.
+ * We allow the import of HTML5 entities because are compatible with mathml
+ * and ill formatted are expected.
+ * On export only mathml entities are allowed.
+ * Some documentation: https://www.w3.org/TR/MathML3/chapter7.html
+ */
+
+constexpr sal_Int32 STARMATH_MATHMLHTML_ENTITY_NUMBER = 2125;
+
+/**
+ * Entity names for mathml. Example: &infin -> \u221E;
+ * These ones are to be used on import.
+ */
+const extern ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>
+ icustomMathmlHtmlEntities;
+
+/**
+ * Entity names for mathml. Example: "\u221E"; -> &infin;
+ * These ones are to be used on file export.
+ */
+const extern ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>
+ icustomMathmlHtmlEntitiesExport;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */