LibreOffice Module starmath (master) 1
export.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20// Our mathml
21#include <mathml/export.hxx>
22#include <mathml/iterator.hxx>
23
24// LO tools to use
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <com/sun/star/embed/ElementModes.hpp>
27#include <com/sun/star/task/XStatusIndicator.hpp>
28#include <com/sun/star/uno/Any.h>
29#include <com/sun/star/util/MeasureUnit.hpp>
30#include <com/sun/star/xml/sax/Writer.hpp>
31
32// Extra LO tools
36#include <sfx2/frame.hxx>
37#include <sfx2/docfile.hxx>
38#include <sfx2/sfxsids.hrc>
39#include <svl/itemset.hxx>
40#include <svl/stritem.hxx>
43
44// Our starmath tools
45#include <document.hxx>
46#include <smmod.hxx>
47#include <strings.hrc>
48#include <unomodel.hxx>
49#include <xparsmlbase.hxx>
50#include <starmathdatabase.hxx>
51
52// Old parser
53#include <mathmlexport.hxx>
54
55using namespace ::com::sun::star;
56using namespace xmloff::token;
57
58using namespace ::com::sun::star::beans;
59using namespace ::com::sun::star::document;
60using namespace ::com::sun::star::lang;
61using namespace ::com::sun::star::uno;
62using namespace ::com::sun::star;
63using namespace ::xmloff::token;
64
65// SmMLExportWrapper
66/*************************************************************************************************/
67
69{
70 bool bRet = true;
71 uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
72
73 // Check all fine
74 SAL_WARN_IF(m_xModel == nullptr, "starmath", "Missing model");
75 SAL_WARN_IF(xContext == nullptr, "starmath", "Missing context");
76 if (m_xModel == nullptr || xContext == nullptr)
77 return false;
78
79 // Get doc shell
80 SmDocShell* pDocShell = static_cast<SmDocShell*>(m_xModel->GetObjectShell());
81 if (pDocShell == nullptr)
82 {
83 SAL_WARN("starmath", "Failed to fetch sm document");
84 return false;
85 }
86
87 // Check if it is a standalone window or embed object
88 bool bEmbedded = SfxObjectCreateMode::EMBEDDED == pDocShell->GetCreateMode();
89
90 // Medium item set
91 SfxItemSet& rMediumItemSet = rMedium.GetItemSet();
92 if (pDocShell == nullptr)
93 {
94 SAL_WARN("starmath", "Failed to get medium item set");
95 return false;
96 }
97
98 // Progress bar ~
99 uno::Reference<task::XStatusIndicator> xStatusIndicator;
100
101 if (!bEmbedded)
102 {
103 // Extra check to ensure everything is fine
104 if (pDocShell->GetMedium() != &rMedium)
105 {
106 SAL_WARN("starmath", "Input medium and sm document medium do not match");
107 //return false;
108 }
109
110 // Fetch progress bar
111 const SfxUnoAnyItem* pItem = rMediumItemSet.GetItem(SID_PROGRESS_STATUSBAR_CONTROL);
112 if (pItem)
113 {
114 // set progress range and start status indicator
115 pItem->GetValue() >>= xStatusIndicator;
116 xStatusIndicator->start(SmResId(STR_STATSTR_WRITING), 3);
117 xStatusIndicator->setValue(0);
118 }
119 }
120
121 // create XPropertySet with three properties for status indicator
122 static const comphelper::PropertyMapEntry aInfoMap[]{
123 { OUString("UsePrettyPrinting"), 0, cppu::UnoType<bool>::get(),
124 beans::PropertyAttribute::MAYBEVOID, 0 },
125 { OUString("BaseURI"), 0, ::cppu::UnoType<OUString>::get(),
126 beans::PropertyAttribute::MAYBEVOID, 0 },
127 { OUString("StreamRelPath"), 0, ::cppu::UnoType<OUString>::get(),
128 beans::PropertyAttribute::MAYBEVOID, 0 },
129 { OUString("StreamName"), 0, ::cppu::UnoType<OUString>::get(),
130 beans::PropertyAttribute::MAYBEVOID, 0 }
131 };
132 uno::Reference<beans::XPropertySet> xInfoSet(
134
135 // Always print pretty
136 xInfoSet->setPropertyValue("UsePrettyPrinting", Any(true));
137
138 // Set base URI
139 xInfoSet->setPropertyValue(u"BaseURI", Any(rMedium.GetBaseURL(true)));
140
141 if (!m_bFlat) //Storage (Package) of Stream
142 {
143 // Fetch the output storage
144 uno::Reference<embed::XStorage> xStg = rMedium.GetOutputStorage();
145 if (xStg == nullptr)
146 {
147 SAL_WARN("starmath", "Failed to fetch output storage");
148 return false;
149 }
150
151 // TODO/LATER: handle the case of embedded links gracefully
152 if (bEmbedded) //&& !pStg->IsRoot() )
153 {
154 const SfxStringItem* pDocHierarchItem
155 = rMediumItemSet.GetItem(SID_DOC_HIERARCHICALNAME);
156 if (pDocHierarchItem != nullptr)
157 {
158 OUString aName = pDocHierarchItem->GetValue();
159 if (!aName.isEmpty())
160 xInfoSet->setPropertyValue("StreamRelPath", Any(aName));
161 }
162 }
163 else
164 {
165 // Write file metadata ( data, LO version ... )
166 // Note: export through an XML exporter component (storage version)
167 if (xStatusIndicator.is())
168 xStatusIndicator->setValue(1);
169
170 bRet = WriteThroughComponentS(xStg, m_xModel, u"meta.xml", xContext, xInfoSet,
171 u"com.sun.star.comp.Math.MLOasisMetaExporter", 6);
172 }
173
174 // Write starmath formula
175 // Note: export through an XML exporter component (storage version)
176 if (bRet)
177 {
178 if (xStatusIndicator.is())
179 xStatusIndicator->setValue(2);
180
181 if (pDocShell->GetSmSyntaxVersion() == 5)
182 bRet = WriteThroughComponentS(xStg, m_xModel, u"content.xml", xContext, xInfoSet,
183 u"com.sun.star.comp.Math.XMLContentExporter", 5);
184 else
185 bRet = WriteThroughComponentS(xStg, m_xModel, u"content.xml", xContext, xInfoSet,
186 u"com.sun.star.comp.Math.MLContentExporter", 6);
187 }
188
189 // Write starmath settings
190 // Note: export through an XML exporter component (storage version)
191 if (bRet)
192 {
193 if (xStatusIndicator.is())
194 xStatusIndicator->setValue(3);
195
196 bRet = WriteThroughComponentS(xStg, m_xModel, u"settings.xml", xContext, xInfoSet,
197 u"com.sun.star.comp.Math.MLOasisSettingsExporter", 6);
198 }
199 }
200 else
201 {
202 // Fetch the output stream
203 SvStream* pStream = rMedium.GetOutStream();
204 if (pStream == nullptr)
205 {
206 SAL_WARN("starmath", "Missing output stream");
207 return false;
208 }
209 uno::Reference<io::XOutputStream> xOut(new utl::OOutputStreamWrapper(*pStream));
210
211 if (xStatusIndicator.is())
212 xStatusIndicator->setValue(1);
213
214 // Write everything in the same place
215 // Note: export through an XML exporter component (output stream version)
216 if (pDocShell->GetSmSyntaxVersion() == 5)
217 bRet = WriteThroughComponentOS(xOut, m_xModel, xContext, xInfoSet,
218 u"com.sun.star.comp.Math.XMLContentExporter", 5);
219 else
220 bRet = WriteThroughComponentOS(xOut, m_xModel, xContext, xInfoSet,
221 u"com.sun.star.comp.Math.MLContentExporter", 6);
222 }
223
224 if (xStatusIndicator.is())
225 xStatusIndicator->end();
226 return bRet;
227}
228
230{
231 uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
232
233 // Check all fine
234 m_pElementTree = nullptr;
235 SAL_WARN_IF(m_xModel == nullptr, "starmath", "Missing model");
236 SAL_WARN_IF(xContext == nullptr, "starmath", "Missing context");
237 if (m_xModel == nullptr || xContext == nullptr)
238 return u"";
239
240 //Get model
241 uno::Reference<lang::XComponent> xModelComp = m_xModel;
242 SAL_WARN_IF(xModelComp == nullptr, "starmath", "Missing model component");
243 SmModel* pModel = m_xModel.get();
244 SAL_WARN_IF(pModel == nullptr, "starmath", "Failed to get threw uno tunnel");
245 if (xModelComp == nullptr || pModel == nullptr)
246 return u"";
247
248 // Get doc shell
249 SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
250 if (pDocShell == nullptr)
251 {
252 SAL_WARN("starmath", "Failed to fetch sm document");
253 return u"";
254 }
255
256 // create XPropertySet with three properties for status indicator
257 static const comphelper::PropertyMapEntry aInfoMap[]{
258 { OUString("UsePrettyPrinting"), 0, cppu::UnoType<bool>::get(),
259 beans::PropertyAttribute::MAYBEVOID, 0 },
260 { OUString("BaseURI"), 0, ::cppu::UnoType<OUString>::get(),
261 beans::PropertyAttribute::MAYBEVOID, 0 },
262 { OUString("StreamRelPath"), 0, ::cppu::UnoType<OUString>::get(),
263 beans::PropertyAttribute::MAYBEVOID, 0 },
264 { OUString("StreamName"), 0, ::cppu::UnoType<OUString>::get(),
265 beans::PropertyAttribute::MAYBEVOID, 0 }
266 };
267 uno::Reference<beans::XPropertySet> xInfoSet(
269
270 // Always print pretty
271 xInfoSet->setPropertyValue("UsePrettyPrinting", Any(true));
272
273 // Fetch mathml tree
274 m_pElementTree = pElementTree;
275
276 // Write stuff
277 // Note: export through an XML exporter component (memory stream version)
278 return WriteThroughComponentMS(xModelComp, xContext, xInfoSet);
279}
280
281// export through an XML exporter component (output stream version)
282bool SmMLExportWrapper::WriteThroughComponentOS(const Reference<io::XOutputStream>& xOutputStream,
283 const Reference<XComponent>& xComponent,
284 Reference<uno::XComponentContext> const& rxContext,
285 Reference<beans::XPropertySet> const& rPropSet,
286 const char16_t* pComponentName,
287 int_fast16_t nSyntaxVersion)
288{
289 // We need a output stream but it is already checked by caller
290 // We need a component but it is already checked by caller
291 // We need a context but it is already checked by caller
292 // We need a property set but it is already checked by caller
293 // We need a component name but it is already checked by caller
294
295 // get sax writer
296 Reference<xml::sax::XWriter> xSaxWriter = xml::sax::Writer::create(rxContext);
297
298 // connect XML writer to output stream
299 xSaxWriter->setOutputStream(xOutputStream);
301 xSaxWriter->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntitiesExport);
302
303 // prepare arguments (prepend doc handler to given arguments)
304 Sequence<Any> aArgs{ Any(xSaxWriter), Any(rPropSet) };
305
306 // get filter component
307 auto xExporterData = rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
308 OUString(pComponentName), aArgs, rxContext);
309 Reference<document::XExporter> xExporter(xExporterData, UNO_QUERY);
310
311 // Check everything is fine
312 if (!xExporter.is())
313 {
314 SAL_WARN("starmath", "can't instantiate export filter component");
315 return false;
316 }
317
318 // connect model and filter
319 xExporter->setSourceDocument(xComponent);
320 Reference<XFilter> xFilter(xExporter, UNO_QUERY);
321 uno::Sequence<PropertyValue> aProps(0);
322
323 // filter
324 if (nSyntaxVersion == 5)
325 {
326 SmXMLExport* pFilter = dynamic_cast<SmXMLExport*>(xFilter.get());
327 if (pFilter == nullptr)
328 {
329 SAL_WARN("starmath", "Failed to fetch SmMLExport");
330 return false;
331 }
332 xFilter->filter(aProps);
333 return pFilter->GetSuccess();
334 }
335
336 // filter
337 SmMLExport* pFilter = dynamic_cast<SmMLExport*>(xFilter.get());
338
339 // Setup filter
340 if (pFilter == nullptr)
341 {
342 SAL_WARN("starmath", "Failed to fetch SmMLExport");
343 return false;
344 }
347
348 // Execute operation
349 xFilter->filter(aProps);
350 return pFilter->getSuccess();
351}
352
353// export through an XML exporter component (storage version)
354bool SmMLExportWrapper::WriteThroughComponentS(const Reference<embed::XStorage>& xStorage,
355 const Reference<XComponent>& xComponent,
356 const char16_t* pStreamName,
357 Reference<uno::XComponentContext> const& rxContext,
358 Reference<beans::XPropertySet> const& rPropSet,
359 const char16_t* pComponentName,
360 int_fast16_t nSyntaxVersion)
361{
362 // We need a storage name but it is already checked by caller
363 // We need a component name but it is already checked by caller
364 // We need a stream name but it is already checked by caller
365 // We need a context but it is already checked by caller
366 // We need a property set but it is already checked by caller
367 // We need a component but it is already checked by caller
368
369 // open stream
370 Reference<io::XStream> xStream;
371 try
372 {
373 xStream = xStorage->openStreamElement(
374 OUString(pStreamName), embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE);
375 }
376 catch (const uno::Exception&)
377 {
378 SAL_WARN("starmath", "Can't create output stream in package");
379 return false;
380 }
381
382 // Set stream as text / xml
383 uno::Reference<beans::XPropertySet> xSet(xStream, uno::UNO_QUERY);
384 xSet->setPropertyValue("MediaType", Any(OUString(u"text/xml")));
385
386 // all streams must be encrypted in encrypted document
387 xSet->setPropertyValue("UseCommonStoragePasswordEncryption", Any(true));
388
389 // set Base URL
390 rPropSet->setPropertyValue("StreamName", Any(OUString(pStreamName)));
391
392 // write the stuff
393 // Note: export through an XML exporter component (output stream version)
394 return WriteThroughComponentOS(xStream->getOutputStream(), xComponent, rxContext, rPropSet,
395 pComponentName, nSyntaxVersion);
396}
397
398// export through an XML exporter component (memory stream version)
399OUString
400SmMLExportWrapper::WriteThroughComponentMS(const Reference<XComponent>& xComponent,
401 Reference<uno::XComponentContext> const& rxContext,
402 Reference<beans::XPropertySet> const& rPropSet)
403{
404 // We need a component but it is already checked by caller
405 // We need a context but it is already checked by caller
406 // We need a property set it is already checked by caller
407
408 // open stream
409 SvMemoryStream aMemoryStream(8192, 1024);
410 uno::Reference<io::XOutputStream> xStream(new utl::OOutputStreamWrapper(aMemoryStream));
411
412 // Set the stream as text
413 uno::Reference<beans::XPropertySet> xSet(xStream, uno::UNO_QUERY);
414 xSet->setPropertyValue("MediaType", Any(OUString("text/xml")));
415
416 // write the stuff
417 // Note: export through an XML exporter component (output stream version)
418 bool bOk = WriteThroughComponentOS(xStream, xComponent, rxContext, rPropSet,
419 u"com.sun.star.comp.Mathml.MLContentExporter", 6);
420
421 // We don't want to read uninitialized data
422 if (!bOk)
423 return u"";
424
425 // Recover data and generate string
426 OString aString(static_cast<const char*>(aMemoryStream.GetData()),
427 aMemoryStream.GetSize() / sizeof(char));
428 return OStringToOUString(aString, RTL_TEXTENCODING_UTF8);
429}
430
431// SmMLExport technical
432/*************************************************************************************************/
433
434extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
435Math_MLExporter_get_implementation(css::uno::XComponentContext* context,
436 css::uno::Sequence<css::uno::Any> const&)
437{
438 return cppu::acquire(new SmMLExport(context, "com.sun.star.comp.Math.XMLExporter",
439 SvXMLExportFlags::OASIS | SvXMLExportFlags::ALL));
440}
441
442extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
443Math_MLOasisMetaExporter_get_implementation(css::uno::XComponentContext* context,
444 css::uno::Sequence<css::uno::Any> const&)
445{
446 return cppu::acquire(new SmMLExport(context, "com.sun.star.comp.Math.XMLOasisMetaExporter",
447 SvXMLExportFlags::OASIS | SvXMLExportFlags::META));
448}
449
450extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
451Math_MLOasisSettingsExporter_get_implementation(css::uno::XComponentContext* context,
452 css::uno::Sequence<css::uno::Any> const&)
453{
454 return cppu::acquire(new SmMLExport(context, "com.sun.star.comp.Math.XMLOasisSettingsExporter",
455 SvXMLExportFlags::OASIS | SvXMLExportFlags::SETTINGS));
456}
457
458extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
459Math_MLContentExporter_get_implementation(css::uno::XComponentContext* context,
460 css::uno::Sequence<css::uno::Any> const&)
461{
462 return cppu::acquire(new SmMLExport(context, "com.sun.star.comp.Math.XMLContentExporter",
463 SvXMLExportFlags::OASIS | SvXMLExportFlags::CONTENT));
464}
465
467{
468 SmModel* pModel = comphelper::getFromUnoTunnel<SmModel>(GetModel());
469 if (pModel != nullptr)
470 return static_cast<SmDocShell*>(pModel->GetObjectShell());
471 return nullptr;
472}
473
475{
476 if (!(getExportFlags() & SvXMLExportFlags::CONTENT))
477 {
478 // Everything that isn't the formula itself get's default export
480 return ERRCODE_NONE;
481 }
482
483 // Checks if it has to export a particular tree
484 if (m_pElementTree == nullptr)
485 {
486 // Set element tree
487 SmDocShell* pDocShell = getSmDocShell();
488 if (pDocShell != nullptr)
489 m_pElementTree = pDocShell->GetMlElementTree();
490 else
491 {
492 m_bSuccess = false;
494 }
495 }
496
497 // Start document and encrypt if necessary
498 GetDocHandler()->startDocument();
500
501 // make use of a default namespace
502 // Math doesn't need namespaces from xmloff, since it now uses default namespaces
503 // Because that is common with current MathML usage in the web -> ResetNamespaceMap();
505
506 // Add xmlns line
507 if (m_bUseExportTag)
508 {
510 GetNamespaceMap().GetNameByKey(XML_NAMESPACE_MATH));
511 }
512
513 // Export and close document
515 GetDocHandler()->endDocument();
516
517 return ERRCODE_NONE;
518}
519
520void SmMLExport::GetViewSettings(Sequence<PropertyValue>& aProps)
521{
522 // Get the document shell
523 SmDocShell* pDocShell = getSmDocShell();
524 if (pDocShell == nullptr)
525 {
526 SAL_WARN("starmath", "Missing document shell so no view settings");
527 return;
528 }
529
530 // Allocate enough memory
531 aProps.realloc(4);
532 PropertyValue* pValue = aProps.getArray();
533
534 // The view settings are the formula display settings
535 tools::Rectangle aRect(pDocShell->GetVisArea());
536
537 pValue[0].Name = "ViewAreaTop";
538 pValue[0].Value <<= aRect.Top();
539
540 pValue[1].Name = "ViewAreaLeft";
541 pValue[1].Value <<= aRect.Left();
542
543 pValue[2].Name = "ViewAreaWidth";
544 pValue[2].Value <<= aRect.GetWidth();
545
546 pValue[3].Name = "ViewAreaHeight";
547 pValue[3].Value <<= aRect.GetHeight();
548}
549
550void SmMLExport::GetConfigurationSettings(Sequence<PropertyValue>& rProps)
551{
552 // Get model property set (settings)
553 Reference<XPropertySet> xProps(GetModel(), UNO_QUERY);
554 if (!xProps.is())
555 {
556 SAL_WARN("starmath", "Missing model properties so no configuration settings");
557 return;
558 }
559
560 // Get model property set info (settings values)
561 Reference<XPropertySetInfo> xPropertySetInfo = xProps->getPropertySetInfo();
562 if (!xPropertySetInfo.is())
563 {
564 SAL_WARN("starmath", "Missing model properties info so no configuration settings");
565 return;
566 }
567
568 // Allocate to store the properties
569 Sequence<Property> aProps = xPropertySetInfo->getProperties();
570 const sal_Int32 nCount = aProps.getLength();
571 rProps.realloc(nCount);
572 auto pProps = rProps.getArray();
573
574 // Copy properties
575 // This needs further revision
576 // Based in code mathmlexport.cxx::GetConfigurationSettings
577 for (sal_Int32 i = 0; i < nCount; ++i)
578 {
579 if (aProps[i].Name != "Formula" && aProps[i].Name != "BasicLibraries"
580 && aProps[i].Name != "DialogLibraries" && aProps[i].Name != "RuntimeUID")
581 {
582 pProps[i].Name = aProps[i].Name;
583 pProps[i].Value = xProps->getPropertyValue(aProps[i].Name);
584 }
585 }
586}
587
588SmMLExport::SmMLExport(const css::uno::Reference<css::uno::XComponentContext>& rContext,
589 OUString const& implementationName, SvXMLExportFlags nExportFlags)
590 : SvXMLExport(rContext, implementationName, util::MeasureUnit::INCH, XML_MATH, nExportFlags)
591 , m_pElementTree(nullptr)
592 , m_bSuccess(true)
593 , m_bUseExportTag(true)
594{
595}
596
597// SmMLExport
598/*************************************************************************************************/
599
601{
602 SAL_WARN("starmath", "Invalid use of mathml.");
603 m_bSuccess = false;
604}
605
607 const SmLengthValue& aLengthValue)
608{
609 if (!aLengthValue.m_aOriginalText->isEmpty())
610 {
611 addAttribute(pAttribute, *aLengthValue.m_aOriginalText);
612 }
613 else
614 {
615 OUStringBuffer aSizeBuffer(64);
616 aSizeBuffer.append(aLengthValue.m_aLengthValue);
617 switch (aLengthValue.m_aLengthUnit)
618 {
620 aSizeBuffer.append(u"em");
621 break;
623 aSizeBuffer.append(u"ex");
624 break;
626 aSizeBuffer.append(u"px");
627 break;
629 aSizeBuffer.append(u"in");
630 break;
632 aSizeBuffer.append(u"cm");
633 break;
635 aSizeBuffer.append(u"mm");
636 break;
638 aSizeBuffer.append(u"pt");
639 break;
641 aSizeBuffer.append(u"pc");
642 break;
644 aSizeBuffer.append(u"%");
645 break;
647 break;
648 default:
650 break;
651 }
652 addAttribute(pAttribute, aSizeBuffer.makeStringAndClear());
653 }
654}
655
657{
658 size_t nAttributeCount = pMlElement->getAttributeCount();
659 for (size_t i = 0; i < nAttributeCount; ++i)
660 {
661 SmMlAttribute aAttribute = pMlElement->getAttribute(i);
662 if (!aAttribute.isSet())
663 continue;
664
665 switch (aAttribute.getMlAttributeValueType())
666 {
668 {
669 auto aAttributeValue = aAttribute.getMlAccent();
670 switch (aAttributeValue->m_aAccent)
671 {
674 break;
677 break;
678 default:
680 break;
681 }
682 break;
683 }
685 {
686 auto aAttributeValue = aAttribute.getMlDir();
687 switch (aAttributeValue->m_aDir)
688 {
691 break;
694 break;
695 default:
697 break;
698 }
699 break;
700 }
702 {
703 auto aAttributeValue = aAttribute.getMlDisplaystyle();
704 switch (aAttributeValue->m_aDisplaystyle)
705 {
708 break;
711 break;
712 default:
714 break;
715 }
716 break;
717 }
719 {
720 auto aAttributeValue = aAttribute.getMlFence();
721 switch (aAttributeValue->m_aFence)
722 {
725 break;
728 break;
729 default:
731 break;
732 }
733 break;
734 }
736 {
737 auto aAttributeValue = aAttribute.getMlHref();
738 switch (aAttributeValue->m_aHref)
739 {
741 break;
743 addAttribute(XML_HREF, *aAttributeValue->m_aLnk);
744 break;
745 default:
747 break;
748 }
749 break;
750 }
752 {
753 auto aSizeData = aAttribute.getMlLspace();
754 auto aLengthData = aSizeData->m_aLengthValue;
756 break;
757 }
759 {
760 auto aAttributeValue = aAttribute.getMlMathbackground();
761 switch (aAttributeValue->m_aMathbackground)
762 {
764 addAttribute(XML_MATHBACKGROUND, "transparent");
765 break;
767 {
768 const OUString& rTextColor = starmathdatabase::Identify_Color_MATHML(
769 sal_uInt32(aAttributeValue->m_aCol))
770 .aIdent;
771 addAttribute(XML_MATHBACKGROUND, rTextColor);
772 break;
773 }
774 default:
776 break;
777 }
778 break;
779 }
781 {
782 auto aAttributeValue = aAttribute.getMlMathcolor();
783 switch (aAttributeValue->m_aMathcolor)
784 {
786 break;
788 {
789 const OUString& rTextColor = starmathdatabase::Identify_Color_MATHML(
790 sal_uInt32(aAttributeValue->m_aCol))
791 .aIdent;
792 addAttribute(XML_MATHCOLOR, rTextColor);
793 break;
794 }
795 default:
797 break;
798 }
799 break;
800 }
802 {
803 auto aSizeData = aAttribute.getMlMathsize();
804 auto aLengthData = aSizeData->m_aLengthValue;
806 break;
807 }
809 {
810 auto aAttributeValue = aAttribute.getMlMathvariant();
811 switch (aAttributeValue->m_aMathvariant)
812 {
814 addAttribute(XML_MATHVARIANT, "normal");
815 break;
818 break;
820 addAttribute(XML_MATHVARIANT, "italic");
821 break;
823 addAttribute(XML_MATHVARIANT, "double-struck");
824 break;
826 addAttribute(XML_MATHVARIANT, "script");
827 break;
829 addAttribute(XML_MATHVARIANT, "fraktur");
830 break;
832 addAttribute(XML_MATHVARIANT, "sans-serif");
833 break;
835 addAttribute(XML_MATHVARIANT, "monospace");
836 break;
838 addAttribute(XML_MATHVARIANT, "bold-italic");
839 break;
841 addAttribute(XML_MATHVARIANT, "bold-fracktur");
842 break;
844 addAttribute(XML_MATHVARIANT, "bold-script");
845 break;
847 addAttribute(XML_MATHVARIANT, "bold-sans-serif");
848 break;
850 addAttribute(XML_MATHVARIANT, "sans-serif-italic");
851 break;
853 addAttribute(XML_MATHVARIANT, "sans-serif-bold-italic");
854 break;
856 addAttribute(XML_MATHVARIANT, "initial");
857 break;
859 addAttribute(XML_MATHVARIANT, "tailed");
860 break;
862 addAttribute(XML_MATHVARIANT, "looped");
863 break;
865 addAttribute(XML_MATHVARIANT, "stretched");
866 break;
867 default:
869 break;
870 }
871 break;
872 }
874 {
875 auto aSizeData = aAttribute.getMlMaxsize();
876 auto aLengthData = aSizeData->m_aLengthValue;
877 switch (aSizeData->m_aMaxsize)
878 {
880 {
882 break;
883 }
885 {
887 break;
888 }
889 }
890 break;
891 }
893 {
894 auto aSizeData = aAttribute.getMlMinsize();
895 auto aLengthData = aSizeData->m_aLengthValue;
897 break;
898 }
900 {
901 auto aAttributeValue = aAttribute.getMlMovablelimits();
902 switch (aAttributeValue->m_aMovablelimits)
903 {
906 break;
909 break;
910 default:
912 break;
913 }
914 break;
915 }
917 {
918 auto aSizeData = aAttribute.getMlRspace();
919 auto aLengthData = aSizeData->m_aLengthValue;
921 break;
922 }
924 {
925 auto aAttributeValue = aAttribute.getMlSeparator();
926 switch (aAttributeValue->m_aSeparator)
927 {
930 break;
933 break;
934 default:
936 break;
937 }
938 break;
939 }
941 {
942 auto aAttributeValue = aAttribute.getMlStretchy();
943 switch (aAttributeValue->m_aStretchy)
944 {
947 break;
950 break;
951 default:
953 break;
954 }
955 break;
956 }
958 {
959 auto aAttributeValue = aAttribute.getMlSymmetric();
960 switch (aAttributeValue->m_aSymmetric)
961 {
964 break;
967 break;
968 default:
970 break;
971 }
972 break;
973 }
974 default:
976 break;
977 }
978 }
979}
980
982{
983 SvXMLElementExport* pElementExport;
984 switch (pMlElement->getMlElementType())
985 {
987 pElementExport = createElementExport(XML_MATH);
988 break;
990 pElementExport = createElementExport(XML_MI);
991 break;
993 pElementExport = createElementExport(XML_MERROR);
994 break;
996 pElementExport = createElementExport(XML_MN);
997 break;
999 pElementExport = createElementExport(XML_MO);
1000 break;
1002 pElementExport = createElementExport(XML_MROW);
1003 break;
1005 pElementExport = createElementExport(XML_MTEXT);
1006 break;
1008 pElementExport = createElementExport(XML_MSTYLE);
1009 break;
1010 default:
1011 pElementExport = nullptr;
1012 }
1013 const OUString& aElementText = pMlElement->getText();
1014 exportMlAttributes(pMlElement);
1015 if (aElementText.isEmpty())
1016 GetDocHandler()->characters(aElementText);
1017 return pElementExport;
1018}
1019
1020namespace
1021{
1022struct exportMlElementTreeExecData
1023{
1024private:
1025 SmMLExport* m_pSmMLExport;
1026 std::vector<SvXMLElementExport*> m_aSvXMLElementExportList;
1027 size_t m_nDepth;
1028
1029public:
1030 inline exportMlElementTreeExecData(SmMLExport* pSmMLExport)
1031 : m_pSmMLExport(pSmMLExport)
1032 , m_aSvXMLElementExportList(1024)
1033 , m_nDepth(0)
1034 {
1035 }
1036
1037 inline void deleteDepthData()
1038 {
1039 delete m_aSvXMLElementExportList[m_nDepth];
1040 --m_nDepth;
1041 }
1042
1043 inline void setDepthData(SvXMLElementExport* aSvXMLElementExportList)
1044 {
1045 if (m_nDepth == m_aSvXMLElementExportList.size())
1046 m_aSvXMLElementExportList.resize(m_aSvXMLElementExportList.size() + 1024);
1047 m_aSvXMLElementExportList[m_nDepth] = aSvXMLElementExportList;
1048 }
1049
1050 inline void incrementDepth() { ++m_nDepth; }
1051
1052 inline SmMLExport* getSmMLExport() { return m_pSmMLExport; };
1053};
1054
1055} // end unnamed namespace
1056
1057static inline void exportMlElementTreeExec(SmMlElement* aSmMlElement, void* aData)
1058{
1059 // Prepare data
1060 exportMlElementTreeExecData* pData = static_cast<exportMlElementTreeExecData*>(aData);
1061 pData->setDepthData(pData->getSmMLExport()->exportMlElement(aSmMlElement));
1062
1063 // Prepare for following
1064 // If it has sub elements, then it will be the next
1065 if (aSmMlElement->getSubElementsCount() != 0)
1066 pData->incrementDepth();
1067 else // Otherwise remounts up to where it should be
1068 {
1069 while (aSmMlElement->getParentElement() != nullptr)
1070 {
1071 // get parent
1072 SmMlElement* pParent = aSmMlElement->getParentElement();
1073 pData->deleteDepthData();
1074 // was this the last branch ?
1075 if (aSmMlElement->getSubElementId() + 1 != pParent->getSubElementsCount()) // yes -> up
1076 break; // no -> stop going up
1077 // Prepare for next round
1078 aSmMlElement = pParent;
1079 }
1080 }
1081}
1082
1084{
1085 exportMlElementTreeExecData* aData = new exportMlElementTreeExecData(this);
1087 delete aData;
1088}
1089
1090/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
SvStream * GetOutStream()
css::uno::Reference< css::embed::XStorage > GetOutputStorage()
SfxMedium * GetMedium() const
virtual tools::Rectangle GetVisArea(sal_uInt16 nAspect) const
SfxObjectCreateMode GetCreateMode() const
const css::uno::Any & GetValue() const
SmMlElement * GetMlElementTree()
Definition: document.hxx:220
sal_uInt16 GetSmSyntaxVersion() const
Definition: document.hxx:178
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 (storage version)
Definition: export.cxx:354
bool Export(SfxMedium &rMedium)
Export to an archive.
Definition: export.cxx:68
rtl::Reference< SmModel > m_xModel
Definition: export.hxx:42
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)
export through an XML exporter component (memory stream version)
Definition: export.cxx:400
bool m_bUseHTMLMLEntities
Definition: export.hxx:46
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 (output stream version)
Definition: export.cxx:282
bool m_bUseExportTag
Definition: export.hxx:50
SmMlElement * m_pElementTree
Definition: export.hxx:48
void setUseExportTag(bool bUseExportTag)
Set's if xmlns field is added.
Definition: export.hxx:143
SmMLExport(const css::uno::Reference< css::uno::XComponentContext > &rContext, OUString const &implementationName, SvXMLExportFlags nExportFlags)
Constructor.
Definition: export.cxx:588
void setElementTree(SmMlElement *pElementTree)
Set's the element tree to be exported.
Definition: export.hxx:148
ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass=::xmloff::token::XML_TOKEN_INVALID) override
Exports the document If m_pElementTree isn't null then exports m_pElementTree.
Definition: export.cxx:474
void exportMlElementTree()
Exports an element tree.
Definition: export.cxx:1083
void declareMlError()
Handles an error on the mathml structure.
Definition: export.cxx:600
void ExportContent_() override
Exports formula Handler used from exportDoc.
Definition: export.hxx:221
virtual void GetConfigurationSettings(css::uno::Sequence< css::beans::PropertyValue > &aProps) override
Get's configuration settings and prepares them to export.
Definition: export.cxx:550
SvXMLElementExport * createElementExport(xmloff::token::XMLTokenEnum nElement)
Adds an element.
Definition: export.hxx:153
bool m_bSuccess
Definition: export.hxx:129
SvXMLElementExport * exportMlElement(const SmMlElement *pMlElement)
Exports an element and all it's attributes.
Definition: export.cxx:981
virtual void GetViewSettings(css::uno::Sequence< css::beans::PropertyValue > &aProps) override
Get's view settings and prepares them to export.
Definition: export.cxx:520
bool getSuccess() const
Everything was allright.
Definition: export.hxx:135
void exportMlAttributes(const SmMlElement *pMlElement)
Exports attributes of an element.
Definition: export.cxx:656
SmDocShell * getSmDocShell()
Get's document shell.
Definition: export.cxx:466
void exportMlAttributeLength(xmloff::token::XMLTokenEnum pAttribute, const SmLengthValue &aLengthValue)
Exports an attribute of type "length".
Definition: export.cxx:606
SmMlElement * m_pElementTree
Definition: export.hxx:128
bool m_bUseExportTag
Definition: export.hxx:130
void addAttribute(xmloff::token::XMLTokenEnum pAttribute, xmloff::token::XMLTokenEnum pAttributeValue)
Adds an attribute.
Definition: export.hxx:161
const struct SmMlMathcolor * getMlMathcolor() const
Definition: attribute.cxx:249
const struct SmMlRspace * getMlRspace() const
Definition: attribute.cxx:291
bool isSet() const
Check if the attribute has been set.
Definition: attribute.hxx:90
const struct SmMlDisplaystyle * getMlDisplaystyle() const
Definition: attribute.cxx:207
const struct SmMlMovablelimits * getMlMovablelimits() const
Definition: attribute.cxx:284
const struct SmMlSeparator * getMlSeparator() const
Definition: attribute.cxx:298
const struct SmMlStretchy * getMlStretchy() const
Definition: attribute.cxx:305
const struct SmMlLspace * getMlLspace() const
Definition: attribute.cxx:235
const struct SmMlFence * getMlFence() const
Definition: attribute.cxx:214
const struct SmMlAccent * getMlAccent() const
Definition: attribute.cxx:193
const struct SmMlDir * getMlDir() const
Definition: attribute.cxx:200
const struct SmMlSymmetric * getMlSymmetric() const
Definition: attribute.cxx:312
SmMlAttributeValueType getMlAttributeValueType() const
Returns the type of attribute we are dealing with.
Definition: attribute.hxx:101
const struct SmMlMinsize * getMlMinsize() const
Definition: attribute.cxx:277
const struct SmMlMathbackground * getMlMathbackground() const
Definition: attribute.cxx:242
const struct SmMlMathvariant * getMlMathvariant() const
Definition: attribute.cxx:263
const struct SmMlHref * getMlHref() const
Definition: attribute.cxx:228
const struct SmMlMaxsize * getMlMaxsize() const
Definition: attribute.cxx:270
const struct SmMlMathsize * getMlMathsize() const
Definition: attribute.cxx:256
size_t getAttributeCount() const
Returns the amount of available attributes.
Definition: element.hxx:146
SmMlAttribute getAttribute(size_t nAttributePos) const
Gets a given attribute.
Definition: element.hxx:154
SmMlElement * getParentElement()
Returns the parent element.
Definition: element.hxx:263
SmMlElementType getMlElementType() const
Returns the mathml element type.
Definition: element.hxx:96
const OUString & getText() const
Returns the element text.
Definition: element.hxx:282
size_t getSubElementId() const
Gets subelement id.
Definition: element.hxx:250
size_t getSubElementsCount() const
Returns the sub elements count.
Definition: element.hxx:218
bool GetSuccess() const
const void * GetData()
sal_uInt64 GetSize()
const SvXMLNamespaceMap & GetNamespaceMap() const
virtual ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass=::xmloff::token::XML_TOKEN_INVALID)
SvXMLExportFlags getExportFlags() const
SvXMLNamespaceMap & GetNamespaceMap_()
const css::uno::Reference< css::frame::XModel > & GetModel() const
void addChaffWhenEncryptedStorage()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
comphelper::AttributeList & GetAttrList()
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
void AddAttribute(const OUString &sName, const OUString &sValue)
css::uno::Type const & get()
constexpr tools::Long GetWidth() const
constexpr tools::Long Top() const
constexpr tools::Long GetHeight() const
constexpr tools::Long Left() const
int nCount
float u
#define SVSTREAM_INVALID_PARAMETER
#define ERRCODE_NONE
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_MLExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: export.cxx:435
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_MLOasisSettingsExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: export.cxx:451
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_MLContentExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: export.cxx:459
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_MLOasisMetaExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: export.cxx:443
static void exportMlElementTreeExec(SmMlElement *aSmMlElement, void *aData)
Definition: export.cxx:1057
OUString aName
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
std::unique_ptr< sal_Int32[]> pData
constexpr OUStringLiteral aData
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
Reference< XComponentContext > getProcessComponentContext()
int i
constexpr OUStringLiteral implementationName
void SmMlIteratorTopToBottom(SmMlElement *pMlElementTree, runType aRunType, void *aData)
Definition: iterator.hxx:71
SmColorTokenTableEntry Identify_Color_MATHML(sal_uInt32 cColor)
Identifies color from color code cColor.
const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString > > icustomMathmlHtmlEntitiesExport
Entity names for mathml.
XMLTokenEnum
XML_MATHSIZE
XML_MI
XML_STRETCHY
XML_LSPACE
XML_MN
XML_MSTYLE
XML_RTL
XML_N_MATH
XML_MERROR
XML_HREF
XML_MTEXT
XML_MROW
XML_TRUE
XML_FENCE
XML_LTR
XML_SEPARATOR
XML_RSPACE
XML_MATHCOLOR
XML_SYMMETRIC
XML_MATHVARIANT
XML_FALSE
XML_ACCENT
XML_MATHBACKGROUND
XML_MATH
XML_DIR
XML_DISPLAYSTYLE
XML_INFINITY
XML_MINSIZE
XML_MOVABLELIMITS
XML_MO
XML_MAXSIZE
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
OUString SmResId(TranslateId aId)
Definition: smmod.cxx:42
SmLengthUnit m_aLengthUnit
Definition: def.hxx:42
OUString * m_aOriginalText
Definition: def.hxx:45
double m_aLengthValue
Definition: def.hxx:43
SmLengthValue m_aLengthValue
Definition: def.hxx:260
SmLengthValue m_aLengthValue
Definition: def.hxx:277
SmLengthValue m_aLengthValue
Definition: def.hxx:288
SmLengthValue m_aLengthValue
Definition: def.hxx:293
SmLengthValue m_aLengthValue
Definition: def.hxx:303
OUString Name
SvXMLExportFlags
constexpr sal_uInt16 XML_NAMESPACE_MATH