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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
/* -*- 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 <utility>
#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 SmModel;
class SmMLExportWrapper
{
private:
// Model
rtl::Reference<SmModel> 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(rtl::Reference<SmModel> xRef)
: m_xModel(std::move(xRef))
, 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:
/** 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: */
|