27#include <com/sun/star/xml/sax/Writer.hpp>
28#include <com/sun/star/beans/PropertyAttribute.hpp>
29#include <com/sun/star/embed/ElementModes.hpp>
30#include <com/sun/star/util/MeasureUnit.hpp>
31#include <com/sun/star/task/XStatusIndicator.hpp>
32#include <com/sun/star/uno/Any.h>
34#include <officecfg/Office/Common.hxx>
35#include <rtl/math.hxx>
38#include <sfx2/sfxsids.hrc>
39#include <osl/diagnose.h>
62#include <unomodel.hxx>
63#include <document.hxx>
77bool IsInPrivateUseArea(
sal_Unicode cChar) {
return 0xE000 <= cChar && cChar <= 0xF8FF; }
82 if (IsInPrivateUseArea(cChar))
84 SAL_WARN(
"starmath",
"Error: private use area characters should no longer be in use!");
97 uno::Reference<lang::XComponent> xModelComp =
xModel;
99 bool bEmbedded =
false;
100 SmModel* pModel = comphelper::getFromUnoTunnel<SmModel>(
xModel);
103 if (pDocShell && SfxObjectCreateMode::EMBEDDED == pDocShell->
GetCreateMode())
106 uno::Reference<task::XStatusIndicator> xStatusIndicator;
111 OSL_ENSURE(pDocShell->
GetMedium() == &rMedium,
"different SfxMedium found");
116 pItem->
GetValue() >>= xStatusIndicator;
120 if (xStatusIndicator.is())
122 sal_Int32 nProgressRange =
bFlat ? 1 : 3;
123 xStatusIndicator->start(
SmResId(STR_STATSTR_WRITING), nProgressRange);
127 static constexpr OUStringLiteral sUsePrettyPrinting(
u"UsePrettyPrinting");
128 static constexpr OUStringLiteral sBaseURI(
u"BaseURI");
129 static constexpr OUStringLiteral sStreamRelPath(
u"StreamRelPath");
130 static constexpr OUStringLiteral sStreamName(
u"StreamName");
141 uno::Reference<beans::XPropertySet> xInfoSet(
144 bool bUsePrettyPrinting
145 =
bFlat || officecfg::Office::Common::Save::Document::PrettyPrinting::get();
146 xInfoSet->setPropertyValue(sUsePrettyPrinting,
Any(bUsePrettyPrinting));
149 xInfoSet->setPropertyValue(sBaseURI,
Any(rMedium.
GetBaseURL(
true)));
151 sal_Int32 nSteps = 0;
152 if (xStatusIndicator.is())
153 xStatusIndicator->setValue(nSteps++);
165 if (pDocHierarchItem)
168 if (!
aName.isEmpty())
170 xInfoSet->setPropertyValue(sStreamRelPath,
Any(
aName));
176 if (xStatusIndicator.is())
177 xStatusIndicator->setValue(nSteps++);
180 (bOASIS ?
"com.sun.star.comp.Math.XMLOasisMetaExporter"
181 :
"com.sun.star.comp.Math.XMLMetaExporter"));
185 if (xStatusIndicator.is())
186 xStatusIndicator->setValue(nSteps++);
189 "com.sun.star.comp.Math.XMLContentExporter");
194 if (xStatusIndicator.is())
195 xStatusIndicator->setValue(nSteps++);
198 (bOASIS ?
"com.sun.star.comp.Math.XMLOasisSettingsExporter"
199 :
"com.sun.star.comp.Math.XMLSettingsExporter"));
207 if (xStatusIndicator.is())
208 xStatusIndicator->setValue(nSteps++);
211 "com.sun.star.comp.Math.XMLContentExporter");
214 if (xStatusIndicator.is())
215 xStatusIndicator->end();
222 const Reference<XComponent>& xComponent,
223 Reference<uno::XComponentContext>
const& rxContext,
224 Reference<beans::XPropertySet>
const& rPropSet,
225 const char* pComponentName)
227 OSL_ENSURE(xOutputStream.is(),
"I really need an output stream!");
228 OSL_ENSURE(xComponent.is(),
"Need component!");
229 OSL_ENSURE(
nullptr != pComponentName,
"Need component name!");
232 Reference<xml::sax::XWriter> xSaxWriter = xml::sax::Writer::create(rxContext);
235 xSaxWriter->setOutputStream(xOutputStream);
240 Sequence<Any> aArgs{
Any(xSaxWriter),
Any(rPropSet) };
243 Reference<document::XExporter> xExporter(
244 rxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
245 OUString::createFromAscii(pComponentName), aArgs, rxContext),
247 OSL_ENSURE(xExporter.is(),
"can't instantiate export filter component");
252 xExporter->setSourceDocument(xComponent);
255 Reference<XFilter> xFilter(xExporter, UNO_QUERY);
256 uno::Sequence<PropertyValue> aProps(0);
257 xFilter->filter(aProps);
259 auto pFilter =
dynamic_cast<SmXMLExport*
>(xFilter.get());
260 return pFilter ==
nullptr || pFilter->
GetSuccess();
265 const Reference<XComponent>& xComponent,
266 const char* pStreamName,
267 Reference<uno::XComponentContext>
const& rxContext,
268 Reference<beans::XPropertySet>
const& rPropSet,
269 const char* pComponentName)
271 OSL_ENSURE(xStorage.is(),
"Need storage!");
272 OSL_ENSURE(
nullptr != pStreamName,
"Need stream name!");
275 Reference<io::XStream>
xStream;
276 OUString sStreamName = OUString::createFromAscii(pStreamName);
279 xStream = xStorage->openStreamElement(sStreamName, embed::ElementModes::READWRITE
280 | embed::ElementModes::TRUNCATE);
282 catch (
const uno::Exception&)
288 uno::Reference<beans::XPropertySet> xSet(xStream, uno::UNO_QUERY);
289 static constexpr OUStringLiteral
sMediaType =
u"MediaType";
290 static constexpr OUStringLiteral sTextXml =
u"text/xml";
291 xSet->setPropertyValue(sMediaType,
Any(OUString(sTextXml)));
294 static constexpr OUStringLiteral sUseCommonStoragePasswordEncryption
295 =
u"UseCommonStoragePasswordEncryption";
296 xSet->setPropertyValue(sUseCommonStoragePasswordEncryption,
Any(
true));
301 rPropSet->setPropertyValue(
"StreamName",
Any(sStreamName));
319extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
321 css::uno::Sequence<css::uno::Any>
const&)
323 return cppu::acquire(
new SmXMLExport(context,
"com.sun.star.comp.Math.XMLExporter",
324 SvXMLExportFlags::OASIS | SvXMLExportFlags::ALL));
327extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
329 css::uno::Sequence<css::uno::Any>
const&)
331 return cppu::acquire(
332 new SmXMLExport(context,
"com.sun.star.comp.Math.XMLMetaExporter", SvXMLExportFlags::META));
335extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
337 css::uno::Sequence<css::uno::Any>
const&)
339 return cppu::acquire(
new SmXMLExport(context,
"com.sun.star.comp.Math.XMLOasisMetaExporter",
340 SvXMLExportFlags::OASIS | SvXMLExportFlags::META));
343extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
345 css::uno::Sequence<css::uno::Any>
const&)
347 return cppu::acquire(
new SmXMLExport(context,
"com.sun.star.comp.Math.XMLSettingsExporter",
348 SvXMLExportFlags::SETTINGS));
351extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
353 css::uno::Sequence<css::uno::Any>
const&)
355 return cppu::acquire(
new SmXMLExport(context,
"com.sun.star.comp.Math.XMLOasisSettingsExporter",
356 SvXMLExportFlags::OASIS | SvXMLExportFlags::SETTINGS));
359extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
361 css::uno::Sequence<css::uno::Any>
const&)
363 return cppu::acquire(
new SmXMLExport(context,
"com.sun.star.comp.Math.XMLContentExporter",
364 SvXMLExportFlags::OASIS | SvXMLExportFlags::CONTENT));
376 SmModel* pModel = comphelper::getFromUnoTunnel<SmModel>(
xModel);
411 SmModel* pModel = comphelper::getFromUnoTunnel<SmModel>(
xModel);
413 OSL_ENSURE(pDocShell,
"doc shell missing");
423 std::unique_ptr<SvXMLElementExport> pSemantics;
425 if (!
aText.isEmpty())
452 OUStringBuffer sStrBuf(12);
453 sStrBuf.append(
u"StarMath ");
454 if (nSmSyntaxVersion == 5)
455 sStrBuf.append(
u"5.0");
457 sStrBuf.append(
static_cast<sal_Int32
>(nSmSyntaxVersion));
470 SmModel* pModel = comphelper::getFromUnoTunnel<SmModel>(
xModel);
480 PropertyValue* pValue = aProps.getArray();
485 pValue[
nIndex].Name =
"ViewAreaTop";
488 pValue[
nIndex].Name =
"ViewAreaLeft";
491 pValue[
nIndex].Name =
"ViewAreaWidth";
494 pValue[
nIndex].Name =
"ViewAreaHeight";
500 Reference<XPropertySet> xProps(
GetModel(), UNO_QUERY);
504 Reference<XPropertySetInfo> xPropertySetInfo = xProps->getPropertySetInfo();
505 if (!xPropertySetInfo.is())
508 const Sequence<Property> aProps = xPropertySetInfo->getProperties();
509 const sal_Int32
nCount = aProps.getLength();
517 std::transform(aProps.begin(), aProps.end(), rProps.getArray(),
518 [bUsedSymbolsOnly, &xProps](
const Property& prop) {
520 if (prop.Name !=
"Formula" && prop.Name !=
"BasicLibraries"
521 && prop.Name !=
"DialogLibraries" && prop.Name !=
"RuntimeUID")
523 aRet.Name = prop.Name;
524 OUString aActualName(prop.Name);
526 static constexpr OUStringLiteral sUserDefinedSymbolsInUse
527 = u
"UserDefinedSymbolsInUse";
528 if (bUsedSymbolsOnly && prop.Name ==
"Symbols")
529 aActualName = sUserDefinedSymbolsInUse;
530 aRet.Value = xProps->getPropertyValue(aActualName);
552 ::std::stack<const SmNode*> s;
556 const SmNode* node = s.top();
565 s.push(binNode->
Symbol());
576 bool bNoMrowContainer )
578 std::unique_ptr<SvXMLElementExport> pRow;
585 for (
size_t i = 0;
i < nSize; ++
i)
648 std::unique_ptr<SvXMLElementExport> pTable;
667 if (nLevel || (nSize > 1))
670 for (
size_t i = 0;
i < nSize; ++
i)
674 std::unique_ptr<SvXMLElementExport> pRow;
675 std::unique_ptr<SvXMLElementExport> pCell;
686 eAlign = pTemp->GetToken().eType;
688 else if (pTemp->GetType() ==
SmNodeType::Line && pTemp->GetNumSubNodes() == 1
689 && pTemp->GetSubNode(0)
695 eAlign = pTemp->GetSubNode(0)->GetToken().eType;
714 std::unique_ptr<SvXMLElementExport> pMath;
745 OSL_ENSURE(nArse != 0xffff,
"Non existent symbol");
751 std::unique_ptr<SvXMLElementExport> pText;
761 if ((pTemp->
GetText().getLength() > 1) && bIsItalic)
763 else if ((pTemp->
GetText().getLength() == 1) && !bIsItalic)
790 OUStringBuffer sStrBuf;
792 sStrBuf.append(
"em");
803 const SmNode* pSub =
nullptr;
804 const SmNode* pSup =
nullptr;
805 const SmNode* pCSub =
nullptr;
806 const SmNode* pCSup =
nullptr;
807 const SmNode* pLSub =
nullptr;
808 const SmNode* pLSup =
nullptr;
809 std::unique_ptr<SvXMLElementExport> pThing2;
884 std::unique_ptr<SvXMLElementExport> pThing;
960 if (
nullptr != (pTemp = pNode->
GetSubNode(1)))
1009 std::unique_ptr<SvXMLElementExport> pElement;
1035 static constexpr OUStringLiteral nArse =
u"\u00AF";
1043 static constexpr OUStringLiteral nArse =
u"\u0332";
1078 int nSansSerifFixed = -1;
1101 nSansSerifFixed = 0;
1104 nSansSerifFixed = 1;
1107 nSansSerifFixed = 2;
1110 SAL_WARN(
"starmath",
"unexpected case");
1154 OUStringBuffer sStrBuf;
1159 static_cast<double>(aFrac *
Fraction(100, 1)));
1160 sStrBuf.append(
'%');
1164 static_cast<double>(
Fraction(100, 1) / aFrac));
1165 sStrBuf.append(
'%');
1184 mytest -=
static_cast<double>(aFrac);
1186 mytest +=
static_cast<double>(aFrac);
1188 mytest = ::rtl::math::round(mytest, 1);
1195 OUString sStr(sStrBuf.makeStringAndClear());
1210 const char* pText =
"normal";
1211 if (nSansSerifFixed == -1 || nSansSerifFixed == 1)
1214 if (nBold == 1 && nItalic != 1)
1216 else if (nBold != 1 && nItalic == 1)
1218 else if (nBold == 1 && nItalic == 1)
1219 pText =
"bold-italic";
1221 else if (nSansSerifFixed == 0)
1223 pText =
"sans-serif";
1224 if (nBold == 1 && nItalic != 1)
1225 pText =
"bold-sans-serif";
1226 else if (nBold != 1 && nItalic == 1)
1227 pText =
"sans-serif-italic";
1228 else if (nBold == 1 && nItalic == 1)
1229 pText =
"sans-serif-bold-italic";
1231 else if (nSansSerifFixed == 2)
1232 pText =
"monospace";
1235 SAL_WARN(
"starmath",
"unexpected case");
1344 if (!pTemp->
GetText().isEmpty())
1345 cTmp = ConvertMathToMathML(pTemp->
GetText()[0]);
1366 bool bAddStretch =
true;
1369 OUString sLocalName;
1375 bAddStretch =
false;
1433 SAL_WARN(
"starmath",
"Warning: failed to export a node?");
constexpr OUStringLiteral sMediaType
virtual void SetExportSymbolNames(bool bVal)=0
virtual std::unique_ptr< SmTableNode > Parse(const OUString &rBuffer)=0
Parse rBuffer to formula tree.
virtual bool IsExportSymbolNames() const =0
virtual const OUString & GetText() const =0
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
constexpr tools::Long Height() const
const SmNode * Symbol() const
Returns the node containing the data of the binary operator.
const SmNode * LeftOperand() const
Returns the node containing the data of the left operand.
const SmNode * RightOperand() const
Returns the node containing the data of the right operand.
sal_uInt16 GetBlankNum() const
const SmTableNode * GetFormulaTree() const
const OUString & GetText() const
const SmFormat & GetFormat() const
sal_uInt16 GetSmSyntaxVersion() const
AbstractSmParser * GetParser()
const Fraction & GetSizeParameter() const
Returns the font size.
FontSizeType GetSizeType() const
Returns the font size type.
bool IsSaveOnlyUsedSymbols() const
sal_uInt16 GetDefaultSmSyntaxVersion() const
sal_uInt16 GetNumRows() const
Gets the number of rows of the matrix.
sal_uInt16 GetNumCols() const
Gets the number of columns of the matrix.
SmMathConfig * GetConfig()
SmScaleMode GetScaleMode() const
Gets the scale mode.
virtual size_t GetNumSubNodes() const =0
Gets the number of subnodes.
const SmToken & GetToken() const
Gets the token.
virtual SmNode * GetSubNode(size_t nIndex)=0
Gets the subnode of index nIndex.
SmNodeType GetType() const
Gets the node type.
const SmFace & GetFont() const
Gets the font.
const OUString & GetText() const
Gets the node text.
Node for vertical brace construction.
const SmMathSymbolNode * Brace() const
Returns the node containing the data of the brace.
const SmNode * Script() const
Returns the node containing the data of what is in the brace.
const SmNode * Body() const
Returns the node containing the data of what the brace is pointing for.
bool WriteThroughComponent(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 char *pComponentName)
css::uno::Reference< css::frame::XModel > xModel
bool m_bUseHTMLMLEntities
bool Export(SfxMedium &rMedium)
void ExportBinaryHorizontal(const SmNode *pNode, int nLevel)
void ExportTable(const SmNode *pNode, int nLevel)
ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass=::xmloff::token::XML_TOKEN_INVALID) override
void ExportText(const SmNode *pNode)
void ExportLine(const SmNode *pNode, int nLevel)
void ExportBinaryVertical(const SmNode *pNode, int nLevel)
void ExportVerticalBrace(const SmVerticalBraceNode *pNode, int nLevel)
SmXMLExport(const css::uno::Reference< css::uno::XComponentContext > &rContext, OUString const &implementationName, SvXMLExportFlags nExportFlags)
void ExportNodes(const SmNode *pNode, int nLevel)
void ExportMatrix(const SmNode *pNode, int nLevel)
virtual void GetConfigurationSettings(css::uno::Sequence< css::beans::PropertyValue > &aProps) override
void ExportExpression(const SmNode *pNode, int nLevel, bool bNoMrowContainer=false)
void ExportBlank(const SmNode *pNode)
void ExportContent_() override
void ExportBrace(const SmNode *pNode, int nLevel)
void ExportSubSupScript(const SmNode *pNode, int nLevel)
void ExportRoot(const SmNode *pNode, int nLevel)
void ExportFont(const SmNode *pNode, int nLevel)
virtual void GetViewSettings(css::uno::Sequence< css::beans::PropertyValue > &aProps) override
void ExportUnaryHorizontal(const SmNode *pNode, int nLevel)
void ExportBinaryDiagonal(const SmNode *pNode, int nLevel)
void ExportMath(const SmNode *pNode)
void ExportAttributes(const SmNode *pNode, int nLevel)
void ExportOperator(const SmNode *pNode, int nLevel)
sal_Int32 GetVersion() const
const SvXMLNamespaceMap & GetNamespaceMap() const
virtual ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass=::xmloff::token::XML_TOKEN_INVALID)
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
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 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
void AddAttribute(const OUString &sName, const OUString &sValue)
virtual sal_Int16 SAL_CALL getLength() override
css::uno::Type const & get()
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
const Size & GetFontSize() const
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_XMLContentExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_XMLOasisMetaExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_XMLExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_XMLOasisSettingsExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_XMLMetaExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Math_XMLSettingsExporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
static bool lcl_HasEffectOnMathvariant(const SmTokenType eType)
COMPHELPER_DLLPUBLIC css::uno::Reference< css::beans::XPropertySet > GenericPropertySet_CreateInstance(PropertySetInfo *pInfo)
Reference< XComponentContext > getProcessComponentContext()
constexpr OUStringLiteral implementationName
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.
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
OUString SmResId(TranslateId aId)
Reference< XModel > xModel
TG
The tokens contain the information gathered by the parser.
sal_Unicode const MS_BACKSLASH
bool IsItalic(const vcl::Font &rFont)
o3tl::Length SmO3tlLengthUnit()
constexpr sal_uInt16 XML_NAMESPACE_MATH