/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// Check all fine
SAL_WARN_IF(m_xModel == nullptr, "starmath", "Missing model");
SAL_WARN_IF(xContext == nullptr, "starmath", "Missing context"); if (m_xModel == nullptr || xContext == nullptr) returnfalse;
// Get doc shell
SmDocShell* pDocShell = static_cast<SmDocShell*>(m_xModel->GetObjectShell()); if (pDocShell == nullptr)
{
SAL_WARN("starmath", "Failed to fetch sm document"); returnfalse;
}
// Check if it is a standalone window or embed object bool bEmbedded = SfxObjectCreateMode::EMBEDDED == pDocShell->GetCreateMode();
// Medium item set
SfxItemSet& rMediumItemSet = rMedium.GetItemSet();
// Progress bar ~
uno::Reference<task::XStatusIndicator> xStatusIndicator;
if (!bEmbedded)
{ // Extra check to ensure everything is fine if (pDocShell->GetMedium() != &rMedium)
{
SAL_WARN("starmath", "Input medium and sm document medium do not match"); //return false;
}
// Fetch progress bar const SfxUnoAnyItem* pItem = rMediumItemSet.GetItem(SID_PROGRESS_STATUSBAR_CONTROL); if (pItem)
{ // set progress range and start status indicator
pItem->GetValue() >>= xStatusIndicator;
xStatusIndicator->start(SmResId(STR_STATSTR_WRITING), 3);
xStatusIndicator->setValue(0);
}
}
// Set base URI
xInfoSet->setPropertyValue(u"BaseURI"_ustr, Any(rMedium.GetBaseURL(true)));
if (!m_bFlat) //Storage (Package) of Stream
{ // Fetch the output storage
uno::Reference<embed::XStorage> xStg = rMedium.GetOutputStorage(); if (xStg == nullptr)
{
SAL_WARN("starmath", "Failed to fetch output storage"); returnfalse;
}
// TODO/LATER: handle the case of embedded links gracefully if (bEmbedded) //&& !pStg->IsRoot() )
{ const SfxStringItem* pDocHierarchItem
= rMediumItemSet.GetItem(SID_DOC_HIERARCHICALNAME); if (pDocHierarchItem != nullptr)
{
OUString aName = pDocHierarchItem->GetValue(); if (!aName.isEmpty())
xInfoSet->setPropertyValue(u"StreamRelPath"_ustr, Any(aName));
}
} else
{ // Write file metadata ( data, LO version ... ) // Note: export through an XML exporter component (storage version) if (xStatusIndicator.is())
xStatusIndicator->setValue(1);
// Write starmath formula // Note: export through an XML exporter component (storage version) if (bRet)
{ if (xStatusIndicator.is())
xStatusIndicator->setValue(2);
// Write starmath settings // Note: export through an XML exporter component (storage version) if (bRet)
{ if (xStatusIndicator.is())
xStatusIndicator->setValue(3);
if (xStatusIndicator.is())
xStatusIndicator->setValue(1);
// Write everything in the same place // Note: export through an XML exporter component (output stream version) if (pDocShell->GetSmSyntaxVersion() == 5)
bRet = WriteThroughComponentOS(xOut, m_xModel, xContext, xInfoSet,
u"com.sun.star.comp.Math.XMLContentExporter", 5); else
bRet = WriteThroughComponentOS(xOut, m_xModel, xContext, xInfoSet,
u"com.sun.star.comp.Math.MLContentExporter", 6);
}
if (xStatusIndicator.is())
xStatusIndicator->end(); return bRet;
}
// Check all fine
m_pElementTree = nullptr;
SAL_WARN_IF(m_xModel == nullptr, "starmath", "Missing model");
SAL_WARN_IF(xContext == nullptr, "starmath", "Missing context"); if (m_xModel == nullptr || xContext == nullptr) return u""_ustr;
//Get model
SmModel* pModel = m_xModel.get();
SAL_WARN_IF(pModel == nullptr, "starmath", "Failed to get threw uno tunnel"); if (pModel == nullptr) return u""_ustr;
// Get doc shell
SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell()); if (pDocShell == nullptr)
{
SAL_WARN("starmath", "Failed to fetch sm document"); return u""_ustr;
}
// Fetch mathml tree
m_pElementTree = pElementTree;
// Write stuff // Note: export through an XML exporter component (memory stream version) return WriteThroughComponentMS(uno::Reference<lang::XComponent>(m_xModel), xContext, xInfoSet);
}
// export through an XML exporter component (output stream version) bool SmMLExportWrapper::WriteThroughComponentOS(const Reference<io::XOutputStream>& xOutputStream, const Reference<XComponent>& xComponent,
Reference<uno::XComponentContext> const& rxContext,
Reference<beans::XPropertySet> const& rPropSet, const char16_t* pComponentName,
int_fast16_t nSyntaxVersion)
{ // We need a output stream but it is already checked by caller // We need a component but it is already checked by caller // We need a context but it is already checked by caller // We need a property set but it is already checked by caller // We need a component name but it is already checked by caller
// get sax writer
Reference<xml::sax::XWriter> xSaxWriter = xml::sax::Writer::create(rxContext);
// connect XML writer to output stream
xSaxWriter->setOutputStream(xOutputStream); if (m_bUseHTMLMLEntities)
xSaxWriter->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntitiesExport);
// prepare arguments (prepend doc handler to given arguments)
Sequence<Any> aArgs{ Any(xSaxWriter), Any(rPropSet) };
// get filter component auto xExporterData = rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
OUString(pComponentName), aArgs, rxContext);
Reference<document::XExporter> xExporter(xExporterData, UNO_QUERY);
// Check everything is fine if (!xExporter.is())
{
SAL_WARN("starmath", "can't instantiate export filter component"); returnfalse;
}
// connect model and filter
xExporter->setSourceDocument(xComponent);
Reference<XFilter> xFilter(xExporter, UNO_QUERY);
uno::Sequence<PropertyValue> aProps(0);
// filter if (nSyntaxVersion == 5)
{
SmXMLExport* pFilter = dynamic_cast<SmXMLExport*>(xFilter.get()); if (pFilter == nullptr)
{
SAL_WARN("starmath", "Failed to fetch SmMLExport"); returnfalse;
}
xFilter->filter(aProps); return pFilter->GetSuccess();
}
// export through an XML exporter component (storage version) bool SmMLExportWrapper::WriteThroughComponentS(const Reference<embed::XStorage>& xStorage, const Reference<XComponent>& xComponent, const char16_t* pStreamName,
Reference<uno::XComponentContext> const& rxContext,
Reference<beans::XPropertySet> const& rPropSet, const char16_t* pComponentName,
int_fast16_t nSyntaxVersion)
{ // We need a storage name but it is already checked by caller // We need a component name but it is already checked by caller // We need a stream name but it is already checked by caller // We need a context but it is already checked by caller // We need a property set but it is already checked by caller // We need a component but it is already checked by caller
// Set stream as text / xml
uno::Reference<beans::XPropertySet> xSet(xStream, uno::UNO_QUERY);
xSet->setPropertyValue(u"MediaType"_ustr, Any(u"text/xml"_ustr));
// all streams must be encrypted in encrypted document
xSet->setPropertyValue(u"UseCommonStoragePasswordEncryption"_ustr, Any(true));
// set Base URL
rPropSet->setPropertyValue(u"StreamName"_ustr, Any(OUString(pStreamName)));
// write the stuff // Note: export through an XML exporter component (output stream version) return WriteThroughComponentOS(xStream->getOutputStream(), xComponent, rxContext, rPropSet,
pComponentName, nSyntaxVersion);
}
// export through an XML exporter component (memory stream version)
OUString
SmMLExportWrapper::WriteThroughComponentMS(const Reference<XComponent>& xComponent,
Reference<uno::XComponentContext> const& rxContext,
Reference<beans::XPropertySet> const& rPropSet)
{ // We need a component but it is already checked by caller // We need a context but it is already checked by caller // We need a property set it is already checked by caller
// open stream
SvMemoryStream aMemoryStream(8192, 1024);
uno::Reference<io::XOutputStream> xStream(new utl::OOutputStreamWrapper(aMemoryStream));
// Set the stream as text
uno::Reference<beans::XPropertySet> xSet(xStream, uno::UNO_QUERY);
xSet->setPropertyValue(u"MediaType"_ustr, Any(u"text/xml"_ustr));
// write the stuff // Note: export through an XML exporter component (output stream version) bool bOk = WriteThroughComponentOS(xStream, xComponent, rxContext, rPropSet,
u"com.sun.star.comp.Mathml.MLContentExporter", 6);
// We don't want to read uninitialized data if (!bOk) return u""_ustr;
// Recover data and generate string
OString aString(static_cast<constchar*>(aMemoryStream.GetData()),
aMemoryStream.GetSize() / sizeof(char)); return OStringToOUString(aString, RTL_TEXTENCODING_UTF8);
}
ErrCode SmMLExport::exportDoc(enum XMLTokenEnum eClass)
{ if (!(getExportFlags() & SvXMLExportFlags::CONTENT))
{ // Everything that isn't the formula itself get's default export
SvXMLExport::exportDoc(eClass); return ERRCODE_NONE;
}
// Checks if it has to export a particular tree if (m_pElementTree == nullptr)
{ // Set element tree
SmDocShell* pDocShell = getSmDocShell(); if (pDocShell != nullptr)
m_pElementTree = pDocShell->GetMlElementTree(); else
{
m_bSuccess = false; return SVSTREAM_INVALID_PARAMETER;
}
}
// Start document and encrypt if necessary
GetDocHandler()->startDocument();
addChaffWhenEncryptedStorage();
// make use of a default namespace // Math doesn't need namespaces from xmloff, since it now uses default namespaces // Because that is common with current MathML usage in the web -> ResetNamespaceMap();
GetNamespaceMap_().Add(u""_ustr, GetXMLToken(XML_N_MATH), XML_NAMESPACE_MATH);
// Add xmlns line if (m_bUseExportTag)
{
GetAttrList().AddAttribute(GetNamespaceMap().GetAttrNameByKey(XML_NAMESPACE_MATH),
GetNamespaceMap().GetNameByKey(XML_NAMESPACE_MATH));
}
// Export and close document
ExportContent_();
GetDocHandler()->endDocument();
return ERRCODE_NONE;
}
void SmMLExport::GetViewSettings(Sequence<PropertyValue>& aProps)
{ // Get the document shell
SmDocShell* pDocShell = getSmDocShell(); if (pDocShell == nullptr)
{
SAL_WARN("starmath", "Missing document shell so no view settings"); return;
}
void SmMLExport::GetConfigurationSettings(Sequence<PropertyValue>& rProps)
{ // Get model property set (settings)
Reference<XPropertySet> xProps(GetModel(), UNO_QUERY); if (!xProps.is())
{
SAL_WARN("starmath", "Missing model properties so no configuration settings"); return;
}
// Get model property set info (settings values)
Reference<XPropertySetInfo> xPropertySetInfo = xProps->getPropertySetInfo(); if (!xPropertySetInfo.is())
{
SAL_WARN("starmath", "Missing model properties info so no configuration settings"); return;
}
// Allocate to store the properties
Sequence<Property> aProps = xPropertySetInfo->getProperties(); const sal_Int32 nCount = aProps.getLength();
rProps.realloc(nCount); auto pProps = rProps.getArray();
// Copy properties // This needs further revision // Based in code mathmlexport.cxx::GetConfigurationSettings for (sal_Int32 i = 0; i < nCount; ++i)
{ if (aProps[i].Name != "Formula" && aProps[i].Name != "BasicLibraries"
&& aProps[i].Name != "DialogLibraries" && aProps[i].Name != "RuntimeUID")
{
pProps[i].Name = aProps[i].Name;
pProps[i].Value = xProps->getPropertyValue(aProps[i].Name);
}
}
}
// Prepare for following // If it has sub elements, then it will be the next if (aSmMlElement->getSubElementsCount() != 0)
pData->incrementDepth(); else// Otherwise remounts up to where it should be
{ while (aSmMlElement->getParentElement() != nullptr)
{ // get parent
SmMlElement* pParent = aSmMlElement->getParentElement();
pData->deleteDepthData(); // was this the last branch ? if (aSmMlElement->getSubElementId() + 1 != pParent->getSubElementsCount()) // yes -> up break; // no -> stop going up // Prepare for next round
aSmMlElement = pParent;
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.