diff options
author | dante <dante19031999@gmail.com> | 2021-08-13 20:23:13 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-08-17 09:04:29 +0200 |
commit | 6ff56167cb2e6ae6e354663c8c07810d432819c1 (patch) | |
tree | f55caff90aedcad6933f4a7c59e88fd40069a256 /starmath/inc | |
parent | 39e969ac53b7e0b2c4889a3f910d97521ec4251f (diff) |
Add import for new starmath mathml elements
Change-Id: Ie867cda8780747e715d642a9b007faafb33b4d99
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120474
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath/inc')
-rw-r--r-- | starmath/inc/mathml/element.hxx | 10 | ||||
-rw-r--r-- | starmath/inc/mathml/import.hxx | 148 |
2 files changed, 157 insertions, 1 deletions
diff --git a/starmath/inc/mathml/element.hxx b/starmath/inc/mathml/element.hxx index 513b5d84b7ea..d51f5b07e01c 100644 --- a/starmath/inc/mathml/element.hxx +++ b/starmath/inc/mathml/element.hxx @@ -34,7 +34,7 @@ public: }; /* Mathml stuff */ -protected: +public: SmMlElement(SmMlElementType aElementType) : m_aElementType(aElementType) , m_aText(u"\u00B6") @@ -174,6 +174,14 @@ public: // attributes */ 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 */ diff --git a/starmath/inc/mathml/import.hxx b/starmath/inc/mathml/import.hxx new file mode 100644 index 000000000000..916f929440a8 --- /dev/null +++ b/starmath/inc/mathml/import.hxx @@ -0,0 +1,148 @@ +/* -*- 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 +#include <com/sun/star/beans/PropertyAttribute.hpp> + +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 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 char16_t* pFilterName, bool bEncrypted); + + /** read a component from storage + */ + ErrCode ReadThroughComponent(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); + + /** read a component from text + */ + ErrCode ReadThroughComponent(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 : public SvXMLImport +{ +private: + SmMlElement* m_pElementTree = new SmMlElement(SmMlElementType::NMlEmpty); + bool m_bSuccess; + size_t m_nSmSyntaxVersion; + +public: + /** Get's parsed element tree + */ + SmMlElement* getElementTree() { return m_pElementTree; } + + /** Checks out if parse was a success + */ + bool getSuccess() { 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: */ |