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>
38#include <sfx2/sfxsids.hrc>
45#include <document.hxx>
48#include <unomodel.hxx>
75 SAL_WARN_IF(xContext ==
nullptr,
"starmath",
"Missing context");
76 if (
m_xModel ==
nullptr || xContext ==
nullptr)
81 if (pDocShell ==
nullptr)
83 SAL_WARN(
"starmath",
"Failed to fetch sm document");
88 bool bEmbedded = SfxObjectCreateMode::EMBEDDED == pDocShell->
GetCreateMode();
92 if (pDocShell ==
nullptr)
94 SAL_WARN(
"starmath",
"Failed to get medium item set");
99 uno::Reference<task::XStatusIndicator> xStatusIndicator;
106 SAL_WARN(
"starmath",
"Input medium and sm document medium do not match");
115 pItem->
GetValue() >>= xStatusIndicator;
116 xStatusIndicator->start(
SmResId(STR_STATSTR_WRITING), 3);
117 xStatusIndicator->setValue(0);
124 beans::PropertyAttribute::MAYBEVOID, 0 },
126 beans::PropertyAttribute::MAYBEVOID, 0 },
128 beans::PropertyAttribute::MAYBEVOID, 0 },
130 beans::PropertyAttribute::MAYBEVOID, 0 }
132 uno::Reference<beans::XPropertySet> xInfoSet(
136 xInfoSet->setPropertyValue(
"UsePrettyPrinting",
Any(
true));
139 xInfoSet->setPropertyValue(
u"BaseURI",
Any(rMedium.
GetBaseURL(
true)));
147 SAL_WARN(
"starmath",
"Failed to fetch output storage");
155 = rMediumItemSet.
GetItem(SID_DOC_HIERARCHICALNAME);
156 if (pDocHierarchItem !=
nullptr)
159 if (!
aName.isEmpty())
160 xInfoSet->setPropertyValue(
"StreamRelPath",
Any(
aName));
167 if (xStatusIndicator.is())
168 xStatusIndicator->setValue(1);
171 u"com.sun.star.comp.Math.MLOasisMetaExporter", 6);
178 if (xStatusIndicator.is())
179 xStatusIndicator->setValue(2);
183 u"com.sun.star.comp.Math.XMLContentExporter", 5);
186 u"com.sun.star.comp.Math.MLContentExporter", 6);
193 if (xStatusIndicator.is())
194 xStatusIndicator->setValue(3);
197 u"com.sun.star.comp.Math.MLOasisSettingsExporter", 6);
204 if (pStream ==
nullptr)
206 SAL_WARN(
"starmath",
"Missing output stream");
211 if (xStatusIndicator.is())
212 xStatusIndicator->setValue(1);
218 u"com.sun.star.comp.Math.XMLContentExporter", 5);
221 u"com.sun.star.comp.Math.MLContentExporter", 6);
224 if (xStatusIndicator.is())
225 xStatusIndicator->end();
236 SAL_WARN_IF(xContext ==
nullptr,
"starmath",
"Missing context");
237 if (
m_xModel ==
nullptr || xContext ==
nullptr)
241 uno::Reference<lang::XComponent> xModelComp =
m_xModel;
242 SAL_WARN_IF(xModelComp ==
nullptr,
"starmath",
"Missing model component");
244 SAL_WARN_IF(pModel ==
nullptr,
"starmath",
"Failed to get threw uno tunnel");
245 if (xModelComp ==
nullptr || pModel ==
nullptr)
250 if (pDocShell ==
nullptr)
252 SAL_WARN(
"starmath",
"Failed to fetch sm document");
259 beans::PropertyAttribute::MAYBEVOID, 0 },
261 beans::PropertyAttribute::MAYBEVOID, 0 },
263 beans::PropertyAttribute::MAYBEVOID, 0 },
265 beans::PropertyAttribute::MAYBEVOID, 0 }
267 uno::Reference<beans::XPropertySet> xInfoSet(
271 xInfoSet->setPropertyValue(
"UsePrettyPrinting",
Any(
true));
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)
296 Reference<xml::sax::XWriter> xSaxWriter = xml::sax::Writer::create(rxContext);
299 xSaxWriter->setOutputStream(xOutputStream);
304 Sequence<Any> aArgs{
Any(xSaxWriter),
Any(rPropSet) };
307 auto xExporterData = rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
308 OUString(pComponentName), aArgs, rxContext);
309 Reference<document::XExporter> xExporter(xExporterData, UNO_QUERY);
314 SAL_WARN(
"starmath",
"can't instantiate export filter component");
319 xExporter->setSourceDocument(xComponent);
320 Reference<XFilter> xFilter(xExporter, UNO_QUERY);
321 uno::Sequence<PropertyValue> aProps(0);
324 if (nSyntaxVersion == 5)
327 if (pFilter ==
nullptr)
329 SAL_WARN(
"starmath",
"Failed to fetch SmMLExport");
332 xFilter->filter(aProps);
340 if (pFilter ==
nullptr)
342 SAL_WARN(
"starmath",
"Failed to fetch SmMLExport");
349 xFilter->filter(aProps);
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)
370 Reference<io::XStream>
xStream;
373 xStream = xStorage->openStreamElement(
374 OUString(pStreamName), embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE);
376 catch (
const uno::Exception&)
378 SAL_WARN(
"starmath",
"Can't create output stream in package");
383 uno::Reference<beans::XPropertySet> xSet(
xStream, uno::UNO_QUERY);
384 xSet->setPropertyValue(
"MediaType",
Any(OUString(
u"text/xml")));
387 xSet->setPropertyValue(
"UseCommonStoragePasswordEncryption",
Any(
true));
390 rPropSet->setPropertyValue(
"StreamName",
Any(OUString(pStreamName)));
395 pComponentName, nSyntaxVersion);
401 Reference<uno::XComponentContext>
const& rxContext,
402 Reference<beans::XPropertySet>
const& rPropSet)
413 uno::Reference<beans::XPropertySet> xSet(
xStream, uno::UNO_QUERY);
414 xSet->setPropertyValue(
"MediaType",
Any(OUString(
"text/xml")));
419 u"com.sun.star.comp.Mathml.MLContentExporter", 6);
426 OString aString(
static_cast<const char*
>(aMemoryStream.
GetData()),
427 aMemoryStream.
GetSize() /
sizeof(
char));
428 return OStringToOUString(aString, RTL_TEXTENCODING_UTF8);
434extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
436 css::uno::Sequence<css::uno::Any>
const&)
438 return cppu::acquire(
new SmMLExport(context,
"com.sun.star.comp.Math.XMLExporter",
439 SvXMLExportFlags::OASIS | SvXMLExportFlags::ALL));
442extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
444 css::uno::Sequence<css::uno::Any>
const&)
446 return cppu::acquire(
new SmMLExport(context,
"com.sun.star.comp.Math.XMLOasisMetaExporter",
447 SvXMLExportFlags::OASIS | SvXMLExportFlags::META));
450extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
452 css::uno::Sequence<css::uno::Any>
const&)
454 return cppu::acquire(
new SmMLExport(context,
"com.sun.star.comp.Math.XMLOasisSettingsExporter",
455 SvXMLExportFlags::OASIS | SvXMLExportFlags::SETTINGS));
458extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
460 css::uno::Sequence<css::uno::Any>
const&)
462 return cppu::acquire(
new SmMLExport(context,
"com.sun.star.comp.Math.XMLContentExporter",
463 SvXMLExportFlags::OASIS | SvXMLExportFlags::CONTENT));
469 if (pModel !=
nullptr)
488 if (pDocShell !=
nullptr)
524 if (pDocShell ==
nullptr)
526 SAL_WARN(
"starmath",
"Missing document shell so no view settings");
532 PropertyValue* pValue = aProps.getArray();
537 pValue[0].Name =
"ViewAreaTop";
538 pValue[0].Value <<= aRect.
Top();
540 pValue[1].Name =
"ViewAreaLeft";
541 pValue[1].Value <<= aRect.
Left();
543 pValue[2].Name =
"ViewAreaWidth";
544 pValue[2].Value <<= aRect.
GetWidth();
546 pValue[3].Name =
"ViewAreaHeight";
553 Reference<XPropertySet> xProps(
GetModel(), UNO_QUERY);
556 SAL_WARN(
"starmath",
"Missing model properties so no configuration settings");
561 Reference<XPropertySetInfo> xPropertySetInfo = xProps->getPropertySetInfo();
562 if (!xPropertySetInfo.is())
564 SAL_WARN(
"starmath",
"Missing model properties info so no configuration settings");
569 Sequence<Property> aProps = xPropertySetInfo->getProperties();
570 const sal_Int32
nCount = aProps.getLength();
572 auto pProps = rProps.getArray();
579 if (aProps[
i].
Name !=
"Formula" && aProps[
i].
Name !=
"BasicLibraries"
580 && aProps[
i].
Name !=
"DialogLibraries" && aProps[
i].
Name !=
"RuntimeUID")
582 pProps[
i].Name = aProps[
i].Name;
583 pProps[
i].Value = xProps->getPropertyValue(aProps[
i].
Name);
591 , m_pElementTree(nullptr)
593 , m_bUseExportTag(true)
602 SAL_WARN(
"starmath",
"Invalid use of mathml.");
615 OUStringBuffer aSizeBuffer(64);
620 aSizeBuffer.append(
u"em");
623 aSizeBuffer.append(
u"ex");
626 aSizeBuffer.append(
u"px");
629 aSizeBuffer.append(
u"in");
632 aSizeBuffer.append(
u"cm");
635 aSizeBuffer.append(
u"mm");
638 aSizeBuffer.append(
u"pt");
641 aSizeBuffer.append(
u"pc");
644 aSizeBuffer.append(
u"%");
652 addAttribute(pAttribute, aSizeBuffer.makeStringAndClear());
659 for (
size_t i = 0;
i < nAttributeCount; ++
i)
662 if (!aAttribute.
isSet())
670 switch (aAttributeValue->m_aAccent)
686 auto aAttributeValue = aAttribute.
getMlDir();
687 switch (aAttributeValue->m_aDir)
704 switch (aAttributeValue->m_aDisplaystyle)
720 auto aAttributeValue = aAttribute.
getMlFence();
721 switch (aAttributeValue->m_aFence)
737 auto aAttributeValue = aAttribute.
getMlHref();
738 switch (aAttributeValue->m_aHref)
761 switch (aAttributeValue->m_aMathbackground)
769 sal_uInt32(aAttributeValue->m_aCol))
783 switch (aAttributeValue->m_aMathcolor)
790 sal_uInt32(aAttributeValue->m_aCol))
811 switch (aAttributeValue->m_aMathvariant)
877 switch (aSizeData->m_aMaxsize)
902 switch (aAttributeValue->m_aMovablelimits)
926 switch (aAttributeValue->m_aSeparator)
943 switch (aAttributeValue->m_aStretchy)
960 switch (aAttributeValue->m_aSymmetric)
1011 pElementExport =
nullptr;
1013 const OUString& aElementText = pMlElement->
getText();
1015 if (aElementText.isEmpty())
1017 return pElementExport;
1022struct exportMlElementTreeExecData
1026 std::vector<SvXMLElementExport*> m_aSvXMLElementExportList;
1030 inline exportMlElementTreeExecData(
SmMLExport* pSmMLExport)
1031 : m_pSmMLExport(pSmMLExport)
1032 , m_aSvXMLElementExportList(1024)
1037 inline void deleteDepthData()
1039 delete m_aSvXMLElementExportList[m_nDepth];
1045 if (m_nDepth == m_aSvXMLElementExportList.size())
1046 m_aSvXMLElementExportList.resize(m_aSvXMLElementExportList.size() + 1024);
1047 m_aSvXMLElementExportList[m_nDepth] = aSvXMLElementExportList;
1050 inline void incrementDepth() { ++m_nDepth; }
1052 inline SmMLExport* getSmMLExport() {
return m_pSmMLExport; };
1060 exportMlElementTreeExecData*
pData =
static_cast<exportMlElementTreeExecData*
>(
aData);
1061 pData->setDepthData(
pData->getSmMLExport()->exportMlElement(aSmMlElement));
1066 pData->incrementDepth();
1073 pData->deleteDepthData();
1078 aSmMlElement = pParent;
1085 exportMlElementTreeExecData*
aData =
new exportMlElementTreeExecData(
this);
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()
sal_uInt16 GetSmSyntaxVersion() const
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)
bool Export(SfxMedium &rMedium)
Export to an archive.
rtl::Reference< SmModel > m_xModel
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)
bool m_bUseHTMLMLEntities
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)
SmMlElement * m_pElementTree
void setUseExportTag(bool bUseExportTag)
Set's if xmlns field is added.
SmMLExport(const css::uno::Reference< css::uno::XComponentContext > &rContext, OUString const &implementationName, SvXMLExportFlags nExportFlags)
Constructor.
void setElementTree(SmMlElement *pElementTree)
Set's the element tree to be exported.
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.
void exportMlElementTree()
Exports an element tree.
void declareMlError()
Handles an error on the mathml structure.
void ExportContent_() override
Exports formula Handler used from exportDoc.
virtual void GetConfigurationSettings(css::uno::Sequence< css::beans::PropertyValue > &aProps) override
Get's configuration settings and prepares them to export.
SvXMLElementExport * createElementExport(xmloff::token::XMLTokenEnum nElement)
Adds an element.
SvXMLElementExport * exportMlElement(const SmMlElement *pMlElement)
Exports an element and all it's attributes.
virtual void GetViewSettings(css::uno::Sequence< css::beans::PropertyValue > &aProps) override
Get's view settings and prepares them to export.
bool getSuccess() const
Everything was allright.
void exportMlAttributes(const SmMlElement *pMlElement)
Exports attributes of an element.
SmDocShell * getSmDocShell()
Get's document shell.
void exportMlAttributeLength(xmloff::token::XMLTokenEnum pAttribute, const SmLengthValue &aLengthValue)
Exports an attribute of type "length".
SmMlElement * m_pElementTree
void addAttribute(xmloff::token::XMLTokenEnum pAttribute, xmloff::token::XMLTokenEnum pAttributeValue)
Adds an attribute.
const struct SmMlMathcolor * getMlMathcolor() const
const struct SmMlRspace * getMlRspace() const
bool isSet() const
Check if the attribute has been set.
const struct SmMlDisplaystyle * getMlDisplaystyle() const
const struct SmMlMovablelimits * getMlMovablelimits() const
const struct SmMlSeparator * getMlSeparator() const
const struct SmMlStretchy * getMlStretchy() const
const struct SmMlLspace * getMlLspace() const
const struct SmMlFence * getMlFence() const
const struct SmMlAccent * getMlAccent() const
const struct SmMlDir * getMlDir() const
const struct SmMlSymmetric * getMlSymmetric() const
SmMlAttributeValueType getMlAttributeValueType() const
Returns the type of attribute we are dealing with.
const struct SmMlMinsize * getMlMinsize() const
const struct SmMlMathbackground * getMlMathbackground() const
const struct SmMlMathvariant * getMlMathvariant() const
const struct SmMlHref * getMlHref() const
const struct SmMlMaxsize * getMlMaxsize() const
const struct SmMlMathsize * getMlMathsize() const
size_t getAttributeCount() const
Returns the amount of available attributes.
SmMlAttribute getAttribute(size_t nAttributePos) const
Gets a given attribute.
SmMlElement * getParentElement()
Returns the parent element.
SmMlElementType getMlElementType() const
Returns the mathml element type.
const OUString & getText() const
Returns the element text.
size_t getSubElementId() const
Gets subelement id.
size_t getSubElementsCount() const
Returns the sub elements count.
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()
#define SVSTREAM_INVALID_PARAMETER
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_MLExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_MLOasisSettingsExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_MLContentExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_MLOasisMetaExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
static void exportMlElementTreeExec(SmMlElement *aSmMlElement, void *aData)
#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()
constexpr OUStringLiteral implementationName
void SmMlIteratorTopToBottom(SmMlElement *pMlElementTree, runType aRunType, void *aData)
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.
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
OUString SmResId(TranslateId aId)
SmLengthUnit m_aLengthUnit
OUString * m_aOriginalText
SmLengthValue m_aLengthValue
SmLengthValue m_aLengthValue
SmLengthValue m_aLengthValue
SmLengthValue m_aLengthValue
SmLengthValue m_aLengthValue
constexpr sal_uInt16 XML_NAMESPACE_MATH