diff options
author | dante <dante19031999@gmail.com> | 2021-03-16 20:21:51 +0100 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-04-21 10:25:26 +0200 |
commit | 565bbd2e46e57117eb401344689858c3d749dc5c (patch) | |
tree | e12674204be6e0fdaf37cc8a4782a0687f21a512 /starmath/inc | |
parent | 3c230b0a440ab4d434c4ddabd6959fb1654b6eff (diff) |
Add mathml structures
Change-Id: I8324456b9a6775842f39e984c569c068381dc952
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112593
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath/inc')
-rw-r--r-- | starmath/inc/mathml/attribute.hxx | 190 | ||||
-rw-r--r-- | starmath/inc/mathml/def.hxx | 333 | ||||
-rw-r--r-- | starmath/inc/mathml/element.hxx | 236 |
3 files changed, 759 insertions, 0 deletions
diff --git a/starmath/inc/mathml/attribute.hxx b/starmath/inc/mathml/attribute.hxx new file mode 100644 index 000000000000..c30053c9d037 --- /dev/null +++ b/starmath/inc/mathml/attribute.hxx @@ -0,0 +1,190 @@ +/* -*- 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 "def.hxx" + +/* All possible data needed to do the job outside mathml limits */ +// Ml prefix means it is part of mathml standar +// NMl means it is not part of mathml standar 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 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; + +private: + void clearPreviousAttributeValue(); + void setDefaultAttributeValue(); + void setAttributeValue(const SmMlAttribute* aMlAttribute); + +public: + SmMlAttribute() { m_aSmMlAttributeValueType = SmMlAttributeValueType::NMlEmpty; }; + + virtual ~SmMlAttribute() { clearPreviousAttributeValue(); }; + + SmMlAttribute(SmMlAttributeValueType) + { + m_aSmMlAttributeValueType = SmMlAttributeValueType::NMlEmpty; + setDefaultAttributeValue(); + }; + + SmMlAttribute(const SmMlAttribute& aMlAttribute) + { + m_aSmMlAttributeValueType = SmMlAttributeValueType::NMlEmpty; + setAttributeValue(&aMlAttribute); + } + + SmMlAttribute(const SmMlAttribute* aMlAttribute) + { + m_aSmMlAttributeValueType = SmMlAttributeValueType::NMlEmpty; + setAttributeValue(aMlAttribute); + } + +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) + { + setAttributeValue(&aMlAttribute); + } + + void setMlAttributeValue(const SmMlAttribute* aMlAttribute) { 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 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 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[17]; +extern SmMlAttributePos MlAttributeListMrow[4]; +extern SmMlAttributePos MlAttributeListMtext[7]; +extern SmMlAttributePos MlAttributeListMstyle[17]; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/starmath/inc/mathml/def.hxx b/starmath/inc/mathml/def.hxx new file mode 100644 index 000000000000..6fccf79d6fab --- /dev/null +++ b/starmath/inc/mathml/def.hxx @@ -0,0 +1,333 @@ +/* -*- 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 <tools/color.hxx> + +/* All possible data needed to do the job outside mathml limits */ +// Ml prefix means it is part of mathml standar +// NMl means it is not part of mathml standar but needed info to work + +/* For now empty, don't know yet what's needed besides default font size. */ +struct SmGlobalData +{ +}; + +/* Mthml length tools */ +/*************************************************************************************************/ + +enum class SmLengthUnit : uint_fast8_t +{ + MlEm, + MlEx, + MlPx, + MlIn, + MlCm, + MlMM, + MlPt, + MlPc, + MlP // Percent +}; + +struct SmLengthValue +{ + SmLengthUnit m_aLengthUnit; + double m_aLengthValue; + // Keeps original text value to avoid numerial 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, + 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 SmMlAttributeValueHref : uint_fast8_t +{ + NMlEmpty = 0x00, + NMlValie = 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 = 0x001 | 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 +}; + +enum class SmMlAttributeValueMinsize : 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 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 +{ + SmMlAttributeValueMinsize m_aMinsize; + 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: */ diff --git a/starmath/inc/mathml/element.hxx b/starmath/inc/mathml/element.hxx new file mode 100644 index 000000000000..e58506077e33 --- /dev/null +++ b/starmath/inc/mathml/element.hxx @@ -0,0 +1,236 @@ +/* -*- 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 "attribute.hxx" +#include <rect.hxx> + +#include <editeng/editdata.hxx> + +class SmMlElement : 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) + { + SmImplAttributeType(); + }; + /* Mathml stuff */ + +protected: + SmMlElement(SmMlElementType aElementType) + : m_aElementType(aElementType) + , m_aText(u"\u00B6") + , m_aESelection(0, 0, 0, 0) + , m_aSubElements(0) + , m_aParentElement(nullptr) + { + SmImplAttributeType(); + }; + +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; + +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 + */ + ESelection getESelection() 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(); }; + + /** + * Get's 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(); + } + + /** + * Get's a given attribute. + * If no available returns empty attribute. + * @param nAttributePos + * @return given attribute. + */ + SmMlAttribute getAttribute(SmMlAttributeValueType aElementType) const; + + /** + * Set's a given attribute. + * If no available does nothing. + * @param nAttributePos + * @return given attribute. + */ + void setAttribute(const SmMlAttribute* 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); + +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 + */ + 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: */ |