LibreOffice Module starmath (master) 1
import.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10// Our mathml
11#include <mathml/import.hxx>
12
13// LO tools to use
14#include <com/sun/star/beans/PropertyAttribute.hpp>
15#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
16#include <com/sun/star/embed/ElementModes.hpp>
17#include <com/sun/star/packages/WrongPasswordException.hpp>
18#include <com/sun/star/packages/zip/ZipIOException.hpp>
19#include <com/sun/star/task/XStatusIndicator.hpp>
20#include <com/sun/star/xml/sax/FastParser.hpp>
21#include <com/sun/star/xml/sax/InputSource.hpp>
22#include <com/sun/star/xml/sax/Parser.hpp>
23#include <com/sun/star/xml/sax/SAXParseException.hpp>
24
25// Extra LO tools
31#include <rtl/character.hxx>
32#include <sfx2/docfile.hxx>
33#include <sfx2/frame.hxx>
34#include <sfx2/sfxsids.hrc>
35#include <sot/storage.hxx>
36#include <svtools/sfxecode.hxx>
37#include <svl/itemset.hxx>
38#include <svl/stritem.hxx>
39#include <svx/dialmgr.hxx>
40#include <svx/strings.hrc>
43#include <xmloff/xmlmetai.hxx>
45#include <xmloff/xmltoken.hxx>
46#include <o3tl/string_view.hxx>
47
48// Our starmath tools
49#include <cfgitem.hxx>
50#include <document.hxx>
51#include <xparsmlbase.hxx>
52#include <smmod.hxx>
53#include <starmathdatabase.hxx>
54#include <unomodel.hxx>
55
56// Old parser
57#include <mathmlimport.hxx>
58
59using namespace ::com::sun::star;
60using namespace ::com::sun::star::beans;
61using namespace ::com::sun::star::container;
62using namespace ::com::sun::star::document;
63using namespace ::com::sun::star::lang;
64using namespace ::com::sun::star::uno;
65using namespace com::sun::star::xml::sax;
66using namespace ::xmloff::token;
67
68// SmMLImportContext
69/*************************************************************************************************/
70
72{
73 return m_pMlImport == nullptr ? nullptr : m_pMlImport->getElementTree();
74}
75
77{
78 // Fetch context
79 uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
80 if (!xContext.is())
81 {
82 SAL_WARN("starmath", "Failed to fetch model while file input");
84 }
85
86 // Check model
87 if (!m_xModel.is())
88 {
89 SAL_WARN("starmath", "Failed to fetch model while file input");
91 }
92
93 // Try to get an XStatusIndicator from the Medium
94 uno::Reference<task::XStatusIndicator> xStatusIndicator;
95
96 // Get model via uno
97 SmModel* pModel = m_xModel.get();
98 if (pModel == nullptr)
99 {
100 SAL_WARN("starmath", "Failed to fetch sm model while file input");
102 }
103
104 // Get doc shell
105 m_pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
106 if (m_pDocShell == nullptr)
107 {
108 SAL_WARN("starmath", "Failed to fetch smdoc shell while file input");
110 }
111
112 // Check if it is an embed object
113 bool bEmbedded = m_pDocShell->GetCreateMode() == SfxObjectCreateMode::EMBEDDED;
114
115 if (!bEmbedded)
116 {
117 // Extra check to ensure everything is fine
118 if (m_pDocShell->GetMedium() != &rMedium)
119 {
120 SAL_WARN("starmath", "Given medium and doc shell medium differ while file input");
122 }
123
124 // Fetch the item set
125 const SfxUnoAnyItem* pItem = rMedium.GetItemSet().GetItem(SID_PROGRESS_STATUSBAR_CONTROL);
126 if (pItem != nullptr)
127 pItem->GetValue() >>= xStatusIndicator;
128 }
129
130 // Create property list
131 static const comphelper::PropertyMapEntry aInfoMap[]
132 = { { u"PrivateData", 0, cppu::UnoType<XInterface>::get(),
133 beans::PropertyAttribute::MAYBEVOID, 0 },
134 { u"BaseURI", 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID,
135 0 },
136 { u"StreamRelPath", 0, ::cppu::UnoType<OUString>::get(),
137 beans::PropertyAttribute::MAYBEVOID, 0 },
138 { u"StreamName", 0, ::cppu::UnoType<OUString>::get(),
139 beans::PropertyAttribute::MAYBEVOID, 0 } };
140 uno::Reference<beans::XPropertySet> xInfoSet(
142
143 // Set base URI
144 // needed for relative URLs; but it's OK to import e.g. MathML from the clipboard without one
145 SAL_INFO_IF(rMedium.GetBaseURL().isEmpty(), "starmath", "SmMLImportWrapper: no base URL");
146 xInfoSet->setPropertyValue("BaseURI", Any(rMedium.GetBaseURL()));
147
148 // Fetch progress range
149 sal_Int32 nProgressRange(rMedium.IsStorage() ? 3 : 1);
150 if (xStatusIndicator.is())
151 {
152 xStatusIndicator->start(SvxResId(RID_SVXSTR_DOC_LOAD), nProgressRange);
153 xStatusIndicator->setValue(0);
154 }
155
156 // Get storage
157 if (rMedium.IsStorage())
158 {
159 // TODO/LATER: handle the case of embedded links gracefully
160 if (bEmbedded) // && !rMedium.GetStorage()->IsRoot() )
161 {
162 OUString aName(u"dummyObjName");
163 const SfxStringItem* pDocHierarchItem
164 = rMedium.GetItemSet().GetItem(SID_DOC_HIERARCHICALNAME);
165 if (pDocHierarchItem != nullptr)
166 aName = pDocHierarchItem->GetValue();
167
168 if (!aName.isEmpty())
169 xInfoSet->setPropertyValue("StreamRelPath", Any(aName));
170 }
171
172 // Check if use OASIS ( new document format )
174 if (xStatusIndicator.is())
175 xStatusIndicator->setValue(1);
176
177 // Error code in case of needed
178 ErrCode nWarn = ERRCODE_NONE;
179
180 // Read metadata
181 // read a component from storage
182 if (!bEmbedded)
183 {
184 if (bOASIS)
185 nWarn = ReadThroughComponentS(rMedium.GetStorage(), m_xModel, u"meta.xml", xContext,
186 xInfoSet,
187 u"com.sun.star.comp.Math.MLOasisMetaImporter", 6);
188 else
189 nWarn
190 = ReadThroughComponentS(rMedium.GetStorage(), m_xModel, u"meta.xml", xContext,
191 xInfoSet, u"com.sun.star.comp.Math.XMLMetaImporter", 5);
192 }
193
194 // Check if successful
195 if (nWarn != ERRCODE_NONE)
196 {
197 if (xStatusIndicator.is())
198 xStatusIndicator->end();
199 SAL_WARN("starmath", "Failed to read file");
200 return nWarn;
201 }
202
203 // Increase success indicator
204 if (xStatusIndicator.is())
205 xStatusIndicator->setValue(2);
206
207 // Read settings
208 // read a component from storage
209 if (bOASIS)
210 nWarn = ReadThroughComponentS(rMedium.GetStorage(), m_xModel, u"settings.xml", xContext,
211 xInfoSet,
212 u"com.sun.star.comp.Math.MLOasisSettingsImporter", 6);
213 else
214 nWarn
215 = ReadThroughComponentS(rMedium.GetStorage(), m_xModel, u"settings.xml", xContext,
216 xInfoSet, u"com.sun.star.comp.Math.XMLSettingsImporter", 5);
217
218 // Check if successful
219 if (nWarn != ERRCODE_NONE)
220 {
221 if (xStatusIndicator.is())
222 xStatusIndicator->end();
223 SAL_WARN("starmath", "Failed to read file");
224 return nWarn;
225 }
226
227 // Increase success indicator
228 if (xStatusIndicator.is())
229 xStatusIndicator->setValue(3);
230
231 // Read document
232 // read a component from storage
234 nWarn = ReadThroughComponentS(rMedium.GetStorage(), m_xModel, u"content.xml", xContext,
235 xInfoSet, u"com.sun.star.comp.Math.XMLImporter", 5);
236 else
237 nWarn = ReadThroughComponentS(rMedium.GetStorage(), m_xModel, u"content.xml", xContext,
238 xInfoSet, u"com.sun.star.comp.Math.MLImporter", 6);
239 // Check if successful
240 if (nWarn != ERRCODE_NONE)
241 {
242 if (xStatusIndicator.is())
243 xStatusIndicator->end();
244 SAL_WARN("starmath", "Failed to read file");
245 return nWarn;
246 }
247
248 // Finish
249 if (xStatusIndicator.is())
250 xStatusIndicator->end();
251 return ERRCODE_NONE;
252 }
253 else
254 {
255 // Create input stream
256 Reference<io::XInputStream> xInputStream
257 = new utl::OInputStreamWrapper(rMedium.GetInStream());
258
259 // Increase success indicator
260 if (xStatusIndicator.is())
261 xStatusIndicator->setValue(1);
262
263 // Read data
264 // read a component from input stream
265 ErrCode nError = ERRCODE_NONE;
267 nError = ReadThroughComponentIS(xInputStream, m_xModel, xContext, xInfoSet,
268 u"com.sun.star.comp.Math.XMLImporter", false, 5);
269 else
270 nError = ReadThroughComponentIS(xInputStream, m_xModel, xContext, xInfoSet,
271 u"com.sun.star.comp.Math.MLImporter", false, 6);
272
273 // Finish
274 if (xStatusIndicator.is())
275 xStatusIndicator->end();
276
277 // Declare any error
278 if (nError != ERRCODE_NONE)
279 SAL_WARN("starmath", "Failed to read file");
280
281 return nError;
282 }
283}
284
285ErrCode SmMLImportWrapper::Import(std::u16string_view aSource)
286{
287 // Fetch context
288 uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
289 if (!xContext.is())
290 {
291 SAL_WARN("starmath", "Failed to fetch model while file input");
293 }
294
295 // Check model
296 if (!m_xModel.is())
297 {
298 SAL_WARN("starmath", "Failed to fetch model while file input");
300 }
301
302 // Make a model component from our SmModel
303 uno::Reference<lang::XComponent> xModelComp = m_xModel;
304 if (!xModelComp.is())
305 {
306 SAL_WARN("starmath", "Failed to make model while file input");
308 }
309
310 // Get model via uno
311 SmModel* pModel = m_xModel.get();
312 if (pModel == nullptr)
313 {
314 SAL_WARN("starmath", "Failed to fetch sm model while file input");
316 }
317
318 // Get doc shell
319 m_pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
320 if (m_pDocShell == nullptr)
321 {
322 SAL_WARN("starmath", "Failed to fetch smdoc shell while file input");
324 }
325
326 // Create property list
327 static const comphelper::PropertyMapEntry aInfoMap[]
328 = { { u"PrivateData", 0, cppu::UnoType<XInterface>::get(),
329 beans::PropertyAttribute::MAYBEVOID, 0 },
330 { u"BaseURI", 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID,
331 0 },
332 { u"StreamRelPath", 0, ::cppu::UnoType<OUString>::get(),
333 beans::PropertyAttribute::MAYBEVOID, 0 },
334 { u"StreamName", 0, ::cppu::UnoType<OUString>::get(),
335 beans::PropertyAttribute::MAYBEVOID, 0 } };
336 uno::Reference<beans::XPropertySet> xInfoSet(
338
339 // Read data
340 // read a component from text
341 ErrCode nError = ReadThroughComponentMS(aSource, xModelComp, xContext, xInfoSet);
342
343 // Declare any error
344 if (nError != ERRCODE_NONE)
345 {
346 SAL_WARN("starmath", "Failed to read file");
347 return nError;
348 }
349
350 return ERRCODE_NONE;
351}
352
353// read a component from input stream
355 const Reference<io::XInputStream>& xInputStream, const Reference<XComponent>& xModelComponent,
356 Reference<uno::XComponentContext> const& rxContext,
357 Reference<beans::XPropertySet> const& rPropSet, const char16_t* pFilterName, bool bEncrypted,
358 int_fast16_t nSyntaxVersion)
359{
360 // Needs an input stream but checked by caller
361 // Needs a context but checked by caller
362 // Needs property set but checked by caller
363 // Needs a filter name but checked by caller
364
365 // Prepare ParserInputSource
366 xml::sax::InputSource aParserInput;
367 aParserInput.aInputStream = xInputStream;
368
369 // Prepare property list
370 Sequence<Any> aArgs{ Any(rPropSet) };
371
372 // Get filter
373 Reference<XInterface> xFilter
374 = rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
375 OUString(pFilterName), aArgs, rxContext);
376 if (!xFilter.is())
377 {
378 SAL_WARN("starmath", "Can't instantiate filter component " << OUString(pFilterName));
380 }
381
382 // Connect model and filter
383 Reference<XImporter> xImporter(xFilter, UNO_QUERY);
384 xImporter->setTargetDocument(xModelComponent);
385
386 // Finally, parser the stream
387 try
388 {
389 Reference<css::xml::sax::XFastParser> xFastParser(xFilter, UNO_QUERY);
390 Reference<css::xml::sax::XFastDocumentHandler> xFastDocHandler(xFilter, UNO_QUERY);
391 if (xFastParser)
392 {
393 xFastParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntities);
394 xFastParser->parseStream(aParserInput);
395 }
396 else if (xFastDocHandler)
397 {
398 Reference<css::xml::sax::XFastParser> xParser
399 = css::xml::sax::FastParser::create(rxContext);
400 xParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntities);
401 xParser->setFastDocumentHandler(xFastDocHandler);
402 xParser->parseStream(aParserInput);
403 }
404 else
405 {
406 Reference<css::xml::sax::XDocumentHandler> xDocHandler(xFilter, UNO_QUERY);
407 assert(xDocHandler);
408 Reference<css::xml::sax::XParser> xParser = css::xml::sax::Parser::create(rxContext);
409 xParser->setDocumentHandler(xDocHandler);
410 xParser->parseStream(aParserInput);
411 }
412
413 if (nSyntaxVersion == 5)
414 {
415 SmXMLImport* pXMlImport = dynamic_cast<SmXMLImport*>(xFilter.get());
416 if (pXMlImport != nullptr && pXMlImport->GetSuccess())
417 return ERRCODE_NONE;
418 else
419 {
420 SAL_WARN("starmath", "Filter failed on file input");
421 // However this can not be included since it's not public
422 if (pXMlImport == nullptr)
423 return ERRCODE_NONE;
425 }
426 }
427
428 m_pMlImport = dynamic_cast<SmMLImport*>(xFilter.get());
429 if (m_pMlImport != nullptr && m_pMlImport->getSuccess())
430 return ERRCODE_NONE;
431 else
432 {
433 SAL_WARN("starmath", "Filter failed on file input");
435 }
436 }
437 catch (const xml::sax::SAXParseException& r)
438 {
439 // Sax parser sends wrapped exceptions, try to find the original one
440 xml::sax::SAXException aTmp;
441 xml::sax::SAXException aSaxEx = *static_cast<const xml::sax::SAXException*>(&r);
442 while (aSaxEx.WrappedException >>= aTmp)
443 aSaxEx = aTmp;
444
445 packages::zip::ZipIOException aBrokenPackage;
446 if (aSaxEx.WrappedException >>= aBrokenPackage)
447 {
448 SAL_WARN("starmath", "Failed to read file SAXParseException");
450 }
451
452 if (bEncrypted)
453 {
454 SAL_WARN("starmath", "Wrong file password SAXParseException");
456 }
457 }
458 catch (const xml::sax::SAXException& r)
459 {
460 packages::zip::ZipIOException aBrokenPackage;
461 if (r.WrappedException >>= aBrokenPackage)
462 {
463 SAL_WARN("starmath", "Failed to read file SAXException");
465 }
466
467 if (bEncrypted)
468 {
469 SAL_WARN("starmath", "Wrong file password SAXException");
471 }
472 }
473 catch (const packages::zip::ZipIOException&)
474 {
475 SAL_WARN("starmath", "Failed to unzip file ZipIOException");
477 }
478 catch (const io::IOException&)
479 {
480 SAL_WARN("starmath", "Failed to read file ZipIOException");
481 return ERRCODE_IO_UNKNOWN;
482 }
483 catch (const std::range_error&)
484 {
485 SAL_WARN("starmath", "Failed to read file");
486 return ERRCODE_ABORT;
487 }
488
489 return ERRCODE_ABORT;
490}
491
492// read a component from storage
493ErrCode SmMLImportWrapper::ReadThroughComponentS(const uno::Reference<embed::XStorage>& xStorage,
494 const Reference<XComponent>& xModelComponent,
495 const char16_t* pStreamName,
496 Reference<uno::XComponentContext> const& rxContext,
497 Reference<beans::XPropertySet> const& rPropSet,
498 const char16_t* pFilterName,
499 int_fast16_t nSyntaxVersion)
500{
501 // Needs a storage but checked by caller
502 // Needs a model but checked by caller
503 // Needs a stream name but checked by caller
504 // Needs a context but checked by caller
505 // Needs a property set but checked by caller
506 // Needs a filter name but checked by caller
507
508 // Get the input stream
509 try
510 {
511 // Create the stream for the event read
512 uno::Reference<io::XStream> xEventsStream
513 = xStorage->openStreamElement(OUString(pStreamName), embed::ElementModes::READ);
514
515 // Determine if stream is encrypted or not
516 uno::Reference<beans::XPropertySet> xProps(xEventsStream, uno::UNO_QUERY);
517 Any aAny = xProps->getPropertyValue("Encrypted");
518 bool bEncrypted = false;
519 aAny >>= bEncrypted;
520
521 // Set base URL and open stream
522 rPropSet->setPropertyValue("StreamName", Any(OUString(pStreamName)));
523 Reference<io::XInputStream> xStream = xEventsStream->getInputStream();
524
525 // Execute read
526 return ReadThroughComponentIS(xStream, xModelComponent, rxContext, rPropSet, pFilterName,
527 bEncrypted, nSyntaxVersion);
528 }
529 catch (packages::WrongPasswordException&)
530 {
531 SAL_WARN("starmath", "Wrong file password");
533 }
534 catch (packages::zip::ZipIOException&)
535 {
536 SAL_WARN("starmath", "Failed to unzip file");
538 }
539 catch (uno::Exception&)
540 {
541 }
542
544}
545
546// read a component from text
548 std::u16string_view aText, const css::uno::Reference<css::lang::XComponent>& xModelComponent,
549 css::uno::Reference<css::uno::XComponentContext> const& rxContext,
550 css::uno::Reference<css::beans::XPropertySet> const& rPropSet)
551{
552 // Needs a storage but checked by caller
553 // Needs a model but checked by caller
554 // Needs a stream name but checked by caller
555 // Needs a context but checked by caller
556 // Needs a property set but checked by caller
557 // Needs a filter name but checked by caller
558
559 // Get the input stream
560 try
561 {
562 // Generate input memory stream
563 SvMemoryStream aMemoryStream;
564 aMemoryStream.WriteOString(OUStringToOString(aText, RTL_TEXTENCODING_UTF8));
565 uno::Reference<io::XInputStream> xStream(new utl::OInputStreamWrapper(aMemoryStream));
566
567 // Execute read
568 return ReadThroughComponentIS(xStream, xModelComponent, rxContext, rPropSet,
569 u"com.sun.star.comp.Math.MLImporter", false, 6);
570 }
571 catch (packages::WrongPasswordException&)
572 {
573 SAL_WARN("starmath", "Wrong file password");
575 }
576 catch (packages::zip::ZipIOException&)
577 {
578 SAL_WARN("starmath", "Failed to unzip file");
580 }
581 catch (uno::Exception&)
582 {
583 }
584
586}
587
588// SmMLImport technical
589/*************************************************************************************************/
590
591extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
592Math_MLImporter_get_implementation(uno::XComponentContext* pCtx,
593 uno::Sequence<uno::Any> const& /*rSeq*/)
594{
595 return cppu::acquire(
596 new SmMLImport(pCtx, "com.sun.star.comp.Math.XMLImporter", SvXMLImportFlags::ALL));
597}
598
599extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
601 uno::Sequence<uno::Any> const& /*rSeq*/)
602{
603 return cppu::acquire(new SmMLImport(pCtx, "com.sun.star.comp.Math.XMLOasisMetaImporter",
604 SvXMLImportFlags::META));
605}
606
607extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
609 uno::Sequence<uno::Any> const& /*rSeq*/)
610{
611 return cppu::acquire(new SmMLImport(pCtx, "com.sun.star.comp.Math.XMLOasisSettingsImporter",
612 SvXMLImportFlags::SETTINGS));
613}
614
615// SmMLImportContext
616/*************************************************************************************************/
617
618namespace
619{
620class SmMLImportContext : public SvXMLImportContext
621{
622private:
623 SmMlElement** m_pParent;
624 SmMlElement* m_pElement;
625 SmMlElement* m_pStyle;
626
627public:
628 SmMLImportContext(SmMLImport& rImport, SmMlElement** pParent)
629 : SvXMLImportContext(rImport)
630 , m_pParent(pParent)
631 , m_pElement(nullptr)
632 , m_pStyle(nullptr)
633 {
634 }
635
636private:
637 void declareMlError();
638
639public:
642 virtual void SAL_CALL characters(const OUString& aChars) override;
643
646 virtual void SAL_CALL startFastElement(
647 sal_Int32 nElement, const Reference<XFastAttributeList>& aAttributeList) override;
648
651 virtual void SAL_CALL endFastElement(sal_Int32 Element) override;
652
655 virtual uno::Reference<XFastContextHandler>
656 SAL_CALL createFastChildContext(sal_Int32 nElement,
657 const uno::Reference<XFastAttributeList>& Attribs) override;
658
661 void inheritStyle();
662
665 void inheritStyleEnd();
666
669 void handleAttributes(const Reference<XFastAttributeList>& aAttributeList);
670
673 SmLengthValue handleLengthAttribute(const OUString& aAttribute);
674};
675
676uno::Reference<XFastContextHandler> SAL_CALL
677SmMLImportContext::createFastChildContext(sal_Int32, const uno::Reference<XFastAttributeList>&)
678{
679 uno::Reference<xml::sax::XFastContextHandler> xContext;
680 xContext = new SmMLImportContext(static_cast<SmMLImport&>(GetImport()), &m_pElement);
681 return xContext;
682}
683
684void SmMLImportContext::declareMlError()
685{
686 SmMLImport& aSmMLImport = static_cast<SmMLImport&>(GetImport());
687 aSmMLImport.declareMlError();
688}
689
690void SmMLImportContext::inheritStyle()
691{
692 while ((m_pStyle = m_pStyle->getParentElement()) != nullptr)
693 {
694 if (m_pStyle->getParentElement()->getMlElementType() == SmMlElementType::MlMstyle
695 || m_pStyle->getParentElement()->getMlElementType() == SmMlElementType::MlMath)
696 break;
697 }
698
699 // Parent inheritation
700 // Mathcolor, mathsize, dir and displaystyle are inherited from parent
701 SmMlElement* pParent = *m_pParent;
703 m_pElement->setAttribute(pParent->getAttribute(SmMlAttributeValueType::MlMathsize));
704 m_pElement->setAttribute(pParent->getAttribute(SmMlAttributeValueType::MlDir));
705 m_pElement->setAttribute(pParent->getAttribute(SmMlAttributeValueType::MlDisplaystyle));
706
707 // Inherit operator dictionary overwrites
708 if (m_pStyle != nullptr
709 && (m_pElement->getMlElementType() == SmMlElementType::MlMo
710 || m_pElement->getMlElementType() == SmMlElementType::MlMstyle
711 || m_pElement->getMlElementType() == SmMlElementType::MlMath))
712 {
713 // TODO fetch operator dictionary first and then overwrite
714 if (m_pStyle->isAttributeSet(SmMlAttributeValueType::MlAccent))
715 m_pElement->setAttribute(m_pStyle->getAttribute(SmMlAttributeValueType::MlAccent));
716 if (m_pStyle->isAttributeSet(SmMlAttributeValueType::MlFence))
717 m_pElement->setAttribute(m_pStyle->getAttribute(SmMlAttributeValueType::MlFence));
718 if (m_pStyle->isAttributeSet(SmMlAttributeValueType::MlLspace))
719 m_pElement->setAttribute(m_pStyle->getAttribute(SmMlAttributeValueType::MlLspace));
720 if (m_pStyle->isAttributeSet(SmMlAttributeValueType::MlMaxsize))
721 m_pElement->setAttribute(m_pStyle->getAttribute(SmMlAttributeValueType::MlMaxsize));
722 if (m_pStyle->isAttributeSet(SmMlAttributeValueType::MlMinsize))
723 m_pElement->setAttribute(m_pStyle->getAttribute(SmMlAttributeValueType::MlMinsize));
724 if (m_pStyle->isAttributeSet(SmMlAttributeValueType::MlMovablelimits))
725 m_pElement->setAttribute(
726 m_pStyle->getAttribute(SmMlAttributeValueType::MlMovablelimits));
727 if (m_pStyle->isAttributeSet(SmMlAttributeValueType::MlRspace))
728 m_pElement->setAttribute(m_pStyle->getAttribute(SmMlAttributeValueType::MlRspace));
729 if (m_pStyle->isAttributeSet(SmMlAttributeValueType::MlSeparator))
730 m_pElement->setAttribute(m_pStyle->getAttribute(SmMlAttributeValueType::MlSeparator));
731 if (m_pStyle->isAttributeSet(SmMlAttributeValueType::MlStretchy))
732 m_pElement->setAttribute(m_pStyle->getAttribute(SmMlAttributeValueType::MlStretchy));
733 if (m_pStyle->isAttributeSet(SmMlAttributeValueType::MlSymmetric))
734 m_pElement->setAttribute(m_pStyle->getAttribute(SmMlAttributeValueType::MlSymmetric));
735
736 if (m_pElement->getMlElementType() == SmMlElementType::MlMo)
737 {
738 // Set form based in position
740 SmMlForm aForm;
741 if (m_pElement->getSubElementId() == 0)
743 else
745 aAttribute.setMlForm(&aForm);
746 m_pElement->setAttribute(aAttribute);
747 }
748 }
749
750 // Inherit mathvariant
751 if (m_pStyle && m_pStyle->isAttributeSet(SmMlAttributeValueType::MlMathvariant))
752 m_pElement->setAttribute(m_pStyle->getAttribute(SmMlAttributeValueType::MlMathvariant));
753}
754
755void SmMLImportContext::inheritStyleEnd()
756{
757 // Mo: check it is the end: postfix
758 if (m_pElement->getMlElementType() == SmMlElementType::MlMo)
759 {
760 if ((*m_pParent)->getSubElementsCount() == m_pElement->getSubElementId())
761 {
762 // Set form based in position
765 aAttribute.setMlForm(&aForm);
766 m_pElement->setAttribute(aAttribute);
767 }
768 }
769
770 // Mi: 1 char -> italic
771 if (m_pElement->getMlElementType() != SmMlElementType::MlMi)
772 return;
773
774 // Inherit mathvariant
775 if (!m_pStyle->isAttributeSet(SmMlAttributeValueType::MlMathvariant))
776 {
777 sal_Int32 nIndexUtf16 = 0;
778 // Check if there is only one code point
779 m_pElement->getText().iterateCodePoints(&nIndexUtf16, 1);
780 // Mathml says that 1 code point -> italic
781 if (nIndexUtf16 == m_pElement->getText().getLength())
782 {
785 aAttribute.setMlMathvariant(&aMathvariant);
786 aAttribute.setSet(false);
787 m_pElement->setAttribute(aAttribute);
788 }
789 }
790}
791
792SmLengthValue SmMLImportContext::handleLengthAttribute(const OUString& aAttribute)
793{
794 // Locate unit indication
795 int32_t nUnitPos;
796 for (nUnitPos = 0;
797 nUnitPos < aAttribute.getLength()
798 && (rtl::isAsciiHexDigit(aAttribute[nUnitPos]) || aAttribute[nUnitPos] == '.');
799 ++nUnitPos)
800 ;
801
802 // Find unit
804 if (nUnitPos != aAttribute.getLength())
805 {
806 OUString aUnit = aAttribute.copy(nUnitPos);
807 if (aUnit.compareToIgnoreAsciiCaseAscii("ex"))
808 nUnit = SmLengthUnit::MlEx;
809 if (aUnit.compareToIgnoreAsciiCaseAscii("px"))
810 nUnit = SmLengthUnit::MlPx;
811 if (aUnit.compareToIgnoreAsciiCaseAscii("in"))
812 nUnit = SmLengthUnit::MlIn;
813 if (aUnit.compareToIgnoreAsciiCaseAscii("cm"))
814 nUnit = SmLengthUnit::MlCm;
815 if (aUnit.compareToIgnoreAsciiCaseAscii("mm"))
816 nUnit = SmLengthUnit::MlMm;
817 if (aUnit.compareToIgnoreAsciiCaseAscii("pt"))
818 nUnit = SmLengthUnit::MlPt;
819 if (aUnit.compareToIgnoreAsciiCaseAscii("pc"))
820 nUnit = SmLengthUnit::MlPc;
821 if (aUnit.compareToIgnoreAsciiCaseAscii("%"))
822 nUnit = SmLengthUnit::MlP;
823 else
824 declareMlError();
825 }
826
827 // Get value
828 std::u16string_view aValue = aAttribute.subView(0, nUnitPos);
829 double nValue = o3tl::toDouble(aValue);
830 if (nValue == 0)
831 {
832 nUnit = SmLengthUnit::MlM;
833 nValue = 1.0;
834 declareMlError();
835 }
836
837 // Return
838 SmLengthValue aLengthValue = { nUnit, nValue, new OUString(aAttribute) };
839 return aLengthValue;
840}
841
842void SmMLImportContext::handleAttributes(const Reference<XFastAttributeList>& aAttributeList)
843{
844 for (auto& aIter : sax_fastparser::castToFastAttributeList(aAttributeList))
845 {
847 switch (aIter.getToken() & TOKEN_MASK)
848 {
849 case XML_ACCENT:
850 {
851 if (IsXMLToken(aIter, XML_TRUE))
852 {
853 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlAccent);
855 aAttribute.setMlAccent(&aAccent);
856 }
857 else if (IsXMLToken(aIter, XML_FALSE))
858 {
859 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlAccent);
861 aAttribute.setMlAccent(&aAccent);
862 }
863 else
864 {
865 declareMlError();
866 }
867 break;
868 }
869 case XML_DIR:
870 {
871 if (IsXMLToken(aIter, XML_RTL))
872 {
873 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlDir);
875 aAttribute.setMlDir(&aDir);
876 }
877 else if (IsXMLToken(aIter, XML_LTR))
878 {
879 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlDir);
881 aAttribute.setMlDir(&aDir);
882 }
883 else
884 {
885 declareMlError();
886 }
887 break;
888 }
889 case XML_DISPLAYSTYLE:
890 if (IsXMLToken(aIter, XML_TRUE))
891 {
892 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlDisplaystyle);
894 aAttribute.setMlDisplaystyle(&aDisplaystyle);
895 }
896 else if (IsXMLToken(aIter, XML_FALSE))
897 {
898 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlDisplaystyle);
900 aAttribute.setMlDisplaystyle(&aDisplaystyle);
901 }
902 else
903 {
904 declareMlError();
905 }
906 break;
907 case XML_FENCE:
908 if (IsXMLToken(aIter, XML_TRUE))
909 {
910 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlFence);
912 aAttribute.setMlFence(&aFence);
913 }
914 else if (IsXMLToken(aIter, XML_FALSE))
915 {
916 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlFence);
918 aAttribute.setMlFence(&aFence);
919 }
920 else
921 {
922 declareMlError();
923 }
924 break;
925 case XML_HREF:
926 {
927 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlHref);
928 OUString* aRef = new OUString(aIter.toString());
930 aAttribute.setMlHref(&aHref);
931 break;
932 }
933 case XML_LSPACE:
934 {
935 SmMlLspace aLspace;
936 aLspace.m_aLengthValue = handleLengthAttribute(aIter.toString());
937 aAttribute.setMlLspace(&aLspace);
938 break;
939 }
941 {
942 if (IsXMLToken(aIter, XML_TRANSPARENT))
943 {
944 SmMlMathbackground aMathbackground
946 aAttribute.setMlMathbackground(&aMathbackground);
947 }
948 else
949 {
950 Color aColor
952 SmMlMathbackground aMathbackground
954 aAttribute.setMlMathbackground(&aMathbackground);
955 }
956 break;
957 }
958 case XML_MATHCOLOR:
959 {
960 if (IsXMLToken(aIter, XML_DEFAULT))
961 {
962 SmMlMathcolor aMathcolor
964 aAttribute.setMlMathcolor(&aMathcolor);
965 }
966 else
967 {
968 Color aColor
970 SmMlMathcolor aMathcolor = { SmMlAttributeValueMathcolor::MlRgb, aColor };
971 aAttribute.setMlMathcolor(&aMathcolor);
972 }
973 break;
974 }
975 case XML_MATHSIZE:
976 {
977 SmMlMathsize aMathsize;
978 aMathsize.m_aLengthValue = handleLengthAttribute(aIter.toString());
979 aAttribute.setMlMathsize(&aMathsize);
980 break;
981 }
982 case XML_MATHVARIANT:
983 {
984 OUString aVariant = aIter.toString();
986 if (aVariant.compareTo(u"normal"))
988 else if (aVariant.compareTo(u"bold"))
990 else if (aVariant.compareTo(u"italic"))
992 else if (aVariant.compareTo(u"double-struck"))
994 else if (aVariant.compareTo(u"script"))
996 else if (aVariant.compareTo(u"fraktur"))
998 else if (aVariant.compareTo(u"sans-serif"))
1000 else if (aVariant.compareTo(u"monospace"))
1002 else if (aVariant.compareTo(u"bold-italic"))
1004 else if (aVariant.compareTo(u"bold-fracktur"))
1006 else if (aVariant.compareTo(u"bold-script"))
1008 else if (aVariant.compareTo(u"bold-sans-serif"))
1010 else if (aVariant.compareTo(u"sans-serif-italic"))
1012 else if (aVariant.compareTo(u"sans-serif-bold-italic"))
1014 else if (aVariant.compareTo(u"initial"))
1016 else if (aVariant.compareTo(u"tailed"))
1018 else if (aVariant.compareTo(u"looped"))
1020 else if (aVariant.compareTo(u"stretched"))
1022 else
1023 declareMlError();
1024 SmMlMathvariant aMathvariant = { nVariant };
1025 aAttribute.setMlMathvariant(&aMathvariant);
1026 break;
1027 }
1028 case XML_MAXSIZE:
1029 {
1030 SmMlMaxsize aMaxsize;
1031 if (IsXMLToken(aIter, XML_INFINITY))
1032 {
1034 aMaxsize.m_aLengthValue = { SmLengthUnit::MlP, 10000, new OUString(u"10000%") };
1035 }
1036 else
1037 {
1039 aMaxsize.m_aLengthValue = handleLengthAttribute(aIter.toString());
1040 }
1041 aAttribute.setMlMaxsize(&aMaxsize);
1042 break;
1043 }
1044 case XML_MINSIZE:
1045 {
1046 SmMlMinsize aMinsize;
1047 aMinsize.m_aLengthValue = handleLengthAttribute(aIter.toString());
1048 aAttribute.setMlMinsize(&aMinsize);
1049 break;
1050 }
1051 case XML_MOVABLELIMITS:
1052 if (IsXMLToken(aIter, XML_TRUE))
1053 {
1054 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlMovablelimits);
1056 aAttribute.setMlMovablelimits(&aMovablelimits);
1057 }
1058 else if (IsXMLToken(aIter, XML_FALSE))
1059 {
1060 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlMovablelimits);
1062 aAttribute.setMlMovablelimits(&aMovablelimits);
1063 }
1064 else
1065 {
1066 declareMlError();
1067 }
1068 break;
1069 case XML_RSPACE:
1070 {
1071 SmMlRspace aRspace;
1072 aRspace.m_aLengthValue = handleLengthAttribute(aIter.toString());
1073 aAttribute.setMlRspace(&aRspace);
1074 break;
1075 }
1076 case XML_SEPARATOR:
1077 if (IsXMLToken(aIter, XML_TRUE))
1078 {
1079 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlSeparator);
1081 aAttribute.setMlSeparator(&aSeparator);
1082 }
1083 else if (IsXMLToken(aIter, XML_FALSE))
1084 {
1085 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlSeparator);
1087 aAttribute.setMlSeparator(&aSeparator);
1088 }
1089 else
1090 {
1091 declareMlError();
1092 }
1093 break;
1094 case XML_STRETCHY:
1095 if (IsXMLToken(aIter, XML_TRUE))
1096 {
1097 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlStretchy);
1099 aAttribute.setMlStretchy(&aStretchy);
1100 }
1101 else if (IsXMLToken(aIter, XML_FALSE))
1102 {
1103 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlStretchy);
1105 aAttribute.setMlStretchy(&aStretchy);
1106 }
1107 else
1108 {
1109 declareMlError();
1110 }
1111 break;
1112 case XML_SYMMETRIC:
1113 if (IsXMLToken(aIter, XML_TRUE))
1114 {
1115 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlSymmetric);
1117 aAttribute.setMlSymmetric(&aSymmetric);
1118 }
1119 else if (IsXMLToken(aIter, XML_FALSE))
1120 {
1121 aAttribute.setMlAttributeValueType(SmMlAttributeValueType::MlSymmetric);
1123 aAttribute.setMlSymmetric(&aSymmetric);
1124 }
1125 else
1126 {
1127 declareMlError();
1128 }
1129 break;
1130 default:
1131 declareMlError();
1132 break;
1133 }
1134 if (aAttribute.isNullAttribute())
1135 declareMlError();
1136 else
1137 m_pElement->setAttribute(aAttribute);
1138 }
1139}
1140
1141void SmMLImportContext::characters(const OUString& aChars) { m_pElement->setText(aChars); }
1142
1143void SmMLImportContext::startFastElement(sal_Int32 nElement,
1144 const Reference<XFastAttributeList>& aAttributeList)
1145{
1146 switch (nElement)
1147 {
1148 case XML_ELEMENT(MATH, XML_MATH):
1149 m_pElement = new SmMlElement(SmMlElementType::MlMath);
1150 break;
1151 case XML_ELEMENT(MATH, XML_MI):
1152 m_pElement = new SmMlElement(SmMlElementType::MlMi);
1153 break;
1154 case XML_ELEMENT(MATH, XML_MERROR):
1155 m_pElement = new SmMlElement(SmMlElementType::MlMerror);
1156 break;
1157 case XML_ELEMENT(MATH, XML_MN):
1158 m_pElement = new SmMlElement(SmMlElementType::MlMn);
1159 break;
1160 case XML_ELEMENT(MATH, XML_MO):
1161 m_pElement = new SmMlElement(SmMlElementType::MlMo);
1162 break;
1163 case XML_ELEMENT(MATH, XML_MROW):
1164 m_pElement = new SmMlElement(SmMlElementType::MlMrow);
1165 break;
1166 case XML_ELEMENT(MATH, XML_MTEXT):
1167 m_pElement = new SmMlElement(SmMlElementType::MlMtext);
1168 break;
1169 case XML_ELEMENT(MATH, XML_MSTYLE):
1170 m_pElement = new SmMlElement(SmMlElementType::MlMstyle);
1171 break;
1172 default:
1173 m_pElement = new SmMlElement(SmMlElementType::NMlEmpty);
1174 declareMlError();
1175 break;
1176 }
1177 SmMlElement* pParent = *m_pParent;
1178 pParent->setSubElement(pParent->getSubElementsCount(), m_pElement);
1179 inheritStyle();
1180 handleAttributes(aAttributeList);
1181}
1182
1183void SmMLImportContext::endFastElement(sal_Int32) { inheritStyleEnd(); }
1184}
1185
1186// SmMLImport
1187/*************************************************************************************************/
1188
1191 const uno::Reference<xml::sax::XFastAttributeList>& /*xAttrList*/)
1192{
1193 SvXMLImportContext* pContext = nullptr;
1194
1195 switch (nElement)
1196 {
1198 {
1199 if (m_pElementTree == nullptr)
1201 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(),
1202 uno::UNO_QUERY_THROW);
1203 pContext = new SmMLImportContext(*this, &m_pElementTree);
1204 break;
1205 }
1207 {
1208 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(),
1209 uno::UNO_QUERY_THROW);
1210 pContext = new SvXMLMetaDocumentContext(*this, xDPS->getDocumentProperties());
1211 break;
1212 }
1214 {
1215 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(),
1216 uno::UNO_QUERY_THROW);
1217 pContext = new XMLDocumentSettingsContext(*this);
1218 break;
1219 }
1220 default:
1222 break;
1223 }
1224 return pContext;
1225}
1226
1228{
1229 uno::Reference<frame::XModel> xModel = GetModel();
1230 if (!xModel.is())
1231 {
1232 SAL_WARN("starmath", "Failed to set view settings because missing model");
1233 SvXMLImport::endDocument();
1234 return;
1235 }
1236
1237 SmModel* pModel = comphelper::getFromUnoTunnel<SmModel>(xModel);
1238 if (!pModel)
1239 {
1240 SAL_WARN("starmath", "Failed to set view settings because missing sm model");
1241 SvXMLImport::endDocument();
1242 return;
1243 }
1244
1245 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
1246 if (!pDocShell)
1247 {
1248 SAL_WARN("starmath", "Failed to set view settings because missing sm doc shell");
1249 SvXMLImport::endDocument();
1250 return;
1251 }
1252
1253 // Check if there is element tree
1254 if (m_pElementTree == nullptr)
1255 {
1256 m_bSuccess = true;
1257 SvXMLImport::endDocument();
1258 return;
1259 }
1260
1261 // Get element tree and setup
1262
1264 {
1265 delete m_pElementTree;
1266 m_pElementTree = nullptr;
1267 }
1268 else
1269 {
1270 SmMlElement* pTmpElememt = m_pElementTree->getSubElement(0);
1271 delete m_pElementTree;
1272 m_pElementTree = pTmpElememt;
1273 }
1274 pDocShell->SetMlElementTree(m_pElementTree);
1275
1276 m_bSuccess = true;
1277 SvXMLImport::endDocument();
1278}
1279
1280void SmMLImport::SetViewSettings(const Sequence<PropertyValue>& aViewProps)
1281{
1282 uno::Reference<frame::XModel> xModel = GetModel();
1283 if (!xModel.is())
1284 {
1285 SAL_WARN("starmath", "Failed to set view settings because missing model");
1286 return;
1287 }
1288
1289 SmModel* pModel = comphelper::getFromUnoTunnel<SmModel>(xModel);
1290 if (!pModel)
1291 {
1292 SAL_WARN("starmath", "Failed to set view settings because missing sm model");
1293 return;
1294 }
1295
1296 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
1297 if (!pDocShell)
1298 {
1299 SAL_WARN("starmath", "Failed to set view settings because missing sm doc shell");
1300 return;
1301 }
1302
1303 tools::Rectangle aRect(pDocShell->GetVisArea());
1304
1305 tools::Long nTmp = 0;
1306
1307 for (const PropertyValue& rValue : aViewProps)
1308 {
1309 if (rValue.Name == "ViewAreaTop")
1310 {
1311 rValue.Value >>= nTmp;
1312 aRect.SaturatingSetPosY(nTmp);
1313 }
1314 else if (rValue.Name == "ViewAreaLeft")
1315 {
1316 rValue.Value >>= nTmp;
1317 aRect.SaturatingSetPosX(nTmp);
1318 }
1319 else if (rValue.Name == "ViewAreaWidth")
1320 {
1321 rValue.Value >>= nTmp;
1322 Size aSize(aRect.GetSize());
1323 aSize.setWidth(nTmp);
1324 aRect.SaturatingSetSize(aSize);
1325 }
1326 else if (rValue.Name == "ViewAreaHeight")
1327 {
1328 rValue.Value >>= nTmp;
1329 Size aSize(aRect.GetSize());
1330 aSize.setHeight(nTmp);
1331 aRect.SaturatingSetSize(aSize);
1332 }
1333 }
1334
1335 pDocShell->SetVisArea(aRect);
1336}
1337
1338void SmMLImport::SetConfigurationSettings(const Sequence<PropertyValue>& aConfProps)
1339{
1340 uno::Reference<frame::XModel> xModel = GetModel();
1341 if (!xModel.is())
1342 {
1343 SAL_WARN("starmath", "Failed to set view settings because missing model");
1344 return;
1345 }
1346
1347 uno::Reference<XPropertySet> xProps(xModel, UNO_QUERY);
1348 if (!xProps.is())
1349 {
1350 SAL_WARN("starmath", "Failed to set view settings because missing model properties");
1351 return;
1352 }
1353
1354 Reference<XPropertySetInfo> xInfo(xProps->getPropertySetInfo());
1355 if (!xInfo.is())
1356 {
1357 SAL_WARN("starmath",
1358 "Failed to set view settings because missing model properties information");
1359 return;
1360 }
1361
1362 static constexpr OUStringLiteral sFormula(u"Formula");
1363 static constexpr OUStringLiteral sBasicLibraries(u"BasicLibraries");
1364 static constexpr OUStringLiteral sDialogLibraries(u"DialogLibraries");
1365 for (const PropertyValue& rValue : aConfProps)
1366 {
1367 if (rValue.Name != sFormula && rValue.Name != sBasicLibraries
1368 && rValue.Name != sDialogLibraries)
1369 {
1370 try
1371 {
1372 if (xInfo->hasPropertyByName(rValue.Name))
1373 xProps->setPropertyValue(rValue.Name, rValue.Value);
1374 }
1375 catch (const beans::PropertyVetoException&)
1376 {
1377 // dealing with read-only properties here. Nothing to do...
1378 }
1379 catch (const Exception&)
1380 {
1381 SAL_WARN("starmath", "Unexpected issue while loading document properties");
1382 }
1383 }
1384 }
1385}
1386
1387SmMLImport::SmMLImport(const css::uno::Reference<css::uno::XComponentContext>& rContext,
1388 OUString const& implementationName, SvXMLImportFlags nImportFlags)
1389 : SvXMLImport(rContext, implementationName, nImportFlags)
1390 , m_pElementTree(nullptr)
1391 , m_bSuccess(false)
1392 , m_nSmSyntaxVersion(SM_MOD()->GetConfig()->GetDefaultSmSyntaxVersion())
1393{
1394}
1395
1399{
1400 m_bSuccess = false;
1401 SAL_WARN("starmath", "MathML error");
1402}
1403
1404/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
Reference< XInputStream > xStream
const OUString & GetValue() const
SfxObjectShell * GetObjectShell() const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
OUString GetBaseURL(bool bForSaving=false)
SfxItemSet & GetItemSet() const
css::uno::Reference< css::embed::XStorage > GetStorage(bool bCreateTempFile=true)
bool IsStorage()
SvStream * GetInStream()
SfxMedium * GetMedium() const
virtual tools::Rectangle GetVisArea(sal_uInt16 nAspect) const
SfxObjectCreateMode GetCreateMode() const
const css::uno::Any & GetValue() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
virtual void SetVisArea(const tools::Rectangle &rVisArea) override
Definition: document.cxx:1153
sal_uInt16 GetSmSyntaxVersion() const
Definition: document.hxx:178
void SetMlElementTree(SmMlElement *pMlElementTree)
Definition: document.hxx:221
SmMLImport * m_pMlImport
Definition: import.hxx:31
SmDocShell * m_pDocShell
Definition: import.hxx:30
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)
read a component from text
Definition: import.cxx:547
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 input stream
Definition: import.cxx:354
ErrCode Import(SfxMedium &rMedium)
Imports the mathml.
Definition: import.cxx:76
rtl::Reference< SmModel > m_xModel
Definition: import.hxx:29
SmMlElement * getElementTree()
Get the element tree when parsed from text.
Definition: import.cxx:71
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 storage
Definition: import.cxx:493
SmMlElement * getElementTree()
Gets parsed element tree.
Definition: import.hxx:97
SmMlElement * m_pElementTree
Definition: import.hxx:90
bool m_bSuccess
Definition: import.hxx:91
SmMLImport(const css::uno::Reference< css::uno::XComponentContext > &rContext, OUString const &implementationName, SvXMLImportFlags nImportFlags)
Constructor.
Definition: import.cxx:1387
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps) override
Imports view settings formula.
Definition: import.cxx:1280
bool getSuccess() const
Checks out if parse was a success.
Definition: import.hxx:101
void SAL_CALL endDocument() override
End the document.
Definition: import.cxx:1227
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps) override
Imports configurations settings formula.
Definition: import.cxx:1338
SvXMLImportContext * CreateFastContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Create a fast context.
Definition: import.cxx:1190
void declareMlError()
Handles an error on the mathml structure.
Definition: import.cxx:1398
SmMlAttribute getAttribute(size_t nAttributePos) const
Gets a given attribute.
Definition: element.hxx:154
void setSubElement(size_t nPos, SmMlElement *aElement)
Sets a given sub element.
Definition: element.cxx:106
SmMlElement * getSubElement(size_t nPos)
Returns a given sub element.
Definition: element.hxx:225
void setAttribute(const SmMlAttribute *aAttribute)
Sets a given attribute.
Definition: element.cxx:93
size_t getSubElementsCount() const
Returns the sub elements count.
Definition: element.hxx:218
bool GetSuccess() const
sal_Int32 GetVersion() const
SvStream & WriteOString(std::string_view rStr)
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual void SAL_CALL characters(const OUString &aChars) override
css::uno::Type const & get()
void SaturatingSetPosX(tools::Long x)
void SaturatingSetPosY(tools::Long y)
constexpr Size GetSize() const
void SaturatingSetSize(const Size &rSize)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
SmLengthUnit
Definition: def.hxx:27
SmMlElementType
Definition: def.hxx:52
SmMlAttributeValueMathvariant
Definition: def.hxx:163
SVXCORE_DLLPUBLIC OUString SvxResId(TranslateId aId)
OString sFormula
float u
#define ERRCODE_IO_BROKENPACKAGE
#define ERRCODE_ABORT
#define ERRCODE_IO_UNKNOWN
#define ERRCODE_NONE
#define SOFFICE_FILEFORMAT_60
sal_Int16 nValue
SAL_DLLPUBLIC_EXPORT uno::XInterface * Math_MLOasisMetaImporter_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
Definition: import.cxx:600
SAL_DLLPUBLIC_EXPORT uno::XInterface * Math_MLImporter_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
Definition: import.cxx:592
SAL_DLLPUBLIC_EXPORT uno::XInterface * Math_MLOasisSettingsImporter_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
Definition: import.cxx:608
OUString aName
#define SAL_INFO_IF(condition, area, stream)
#define SAL_WARN(area, stream)
@ Exception
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
Reference< XComponentContext > getProcessComponentContext()
constexpr OUStringLiteral implementationName
double toDouble(std::u16string_view str)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString > > icustomMathmlHtmlEntities
Entity names for mathml.
SmColorTokenTableEntry Identify_ColorName_HTML(std::u16string_view colorname)
Identifies color from color name.
long Long
XML_MATHSIZE
XML_STRETCHY
XML_LSPACE
XML_DOCUMENT_SETTINGS
XML_DOCUMENT
XML_HREF
XML_FENCE
XML_DOCUMENT_META
XML_SEPARATOR
XML_RSPACE
XML_MATHCOLOR
XML_SYMMETRIC
XML_MATHVARIANT
XML_ACCENT
XML_MATHBACKGROUND
XML_DIR
XML_DISPLAYSTYLE
XML_MINSIZE
XML_MOVABLELIMITS
XML_MAXSIZE
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
#define ERRCODE_SFX_WRONGPASSWORD
#define ERRCODE_SFX_DOLOADFAILED
#define SM_MOD()
Definition: smmod.hxx:98
Definition: def.hxx:233
SmLengthValue m_aLengthValue
Definition: def.hxx:260
SmLengthValue m_aLengthValue
Definition: def.hxx:277
SmMlAttributeValueMaxsize m_aMaxsize
Definition: def.hxx:287
SmLengthValue m_aLengthValue
Definition: def.hxx:288
SmLengthValue m_aLengthValue
Definition: def.hxx:293
SmLengthValue m_aLengthValue
Definition: def.hxx:303
Reference< XModel > xModel
#define XML_ELEMENT(prefix, name)
SvXMLImportFlags