summaryrefslogtreecommitdiff
path: root/starmath/inc/mathml/import.hxx
blob: 764d5451c652768a14f200f19d0e67a718b5ab3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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 <utility>
#include <comphelper/errcode.hxx>
#include <xmloff/xmlimp.hxx>

// Extras

class SfxMedium;
class SmDocShell;
class SmMLImport;
class SmModel;

class SmMLImportWrapper
{
    rtl::Reference<SmModel> 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(rtl::Reference<SmModel> xRef)
        : m_xModel(std::move(xRef))
        , 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:
    /** 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_Int16 nSmSyntaxVersion) { m_nSmSyntaxVersion = nSmSyntaxVersion; }

    /** Get syntax version
    */
    sal_Int16 GetSmSyntaxVersion() const { return m_nSmSyntaxVersion; }
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */