summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sax/source/fastparser/fastparser.cxx11
-rw-r--r--starmath/Library_sm.mk1
-rw-r--r--starmath/source/mathmlattr.hxx1
-rw-r--r--starmath/source/mathmlimport.cxx6
-rw-r--r--starmath/source/xparsmlbase.cxx40
-rw-r--r--starmath/source/xparsmlbase.hxx46
6 files changed, 102 insertions, 3 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 9b2d9bd97458..04bf69a1705b 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -933,6 +933,7 @@ void FastSaxParserImpl::setNamespaceHandler( const Reference< XFastNamespaceHand
maData.mxNamespaceHandler = Handler;
}
+#include <stdio.h>
void FastSaxParserImpl::setCustomEntityNames( const ::css::uno::Sequence< ::rtl::OUString >& names, const ::css::uno::Sequence< ::rtl::OUString >& replacements )
{
mEntityNames = names;
@@ -1368,6 +1369,11 @@ xmlEntityPtr FastSaxParserImpl::callbackGetEntity( const xmlChar *name )
if( !name )
return xmlGetPredefinedEntity(name);
const char* dname = XML_CAST(name);
+ int lname = strlen(dname);
+ if( lname == 0 )
+ return xmlGetPredefinedEntity(name);
+ if( !mEntityNames.hasElements() )
+ return xmlGetPredefinedEntity(name);
for( size_t i = 0; i < mEntityNames.size(); ++i )
{
if( mEntityNames[i].compareToAscii(dname) == 0 )
@@ -1378,12 +1384,11 @@ xmlEntityPtr FastSaxParserImpl::callbackGetEntity( const xmlChar *name )
BAD_CAST(OUStringToOString(mEntityReplacements[i],RTL_TEXTENCODING_UTF8).getStr()));
}
}
+ if( lname < 2 )
+ return xmlGetPredefinedEntity(name);
if ( dname[0] == '#' )
{
sal_uInt32 cval = 0;
- int_fast16_t lname = strlen(dname);
- if( lname < 2 )
- return xmlGetPredefinedEntity(name);
if( dname[1] == 'x' || dname[1] == 'X' )
{
if( lname < 3 )
diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk
index a63b506783e1..cc3dab8875e7 100644
--- a/starmath/Library_sm.mk
+++ b/starmath/Library_sm.mk
@@ -74,6 +74,7 @@ $(eval $(call gb_Library_add_exception_objects,sm,\
starmath/source/document \
starmath/source/edit \
starmath/source/format \
+ starmath/source/xparsmlbase \
starmath/source/mathmlattr \
starmath/source/mathmlexport \
starmath/source/mathmlimport \
diff --git a/starmath/source/mathmlattr.hxx b/starmath/source/mathmlattr.hxx
index 104495d2c878..fba6f3bc4195 100644
--- a/starmath/source/mathmlattr.hxx
+++ b/starmath/source/mathmlattr.hxx
@@ -13,6 +13,7 @@
#include <rtl/ustring.hxx>
#include <sal/types.h>
#include <tools/fract.hxx>
+#include "xparsmlbase.hxx"
// MathML 3: 2.1.5.1 Syntax notation used in the MathML specification
// <https://www.w3.org/TR/MathML/chapter2.html#id.2.1.5.1>
diff --git a/starmath/source/mathmlimport.cxx b/starmath/source/mathmlimport.cxx
index 5fa4a96ad406..c06d0043dee7 100644
--- a/starmath/source/mathmlimport.cxx
+++ b/starmath/source/mathmlimport.cxx
@@ -268,11 +268,17 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(const Reference<io::XInputStrea
Reference<css::xml::sax::XFastParser> xFastParser(xFilter, UNO_QUERY);
Reference<css::xml::sax::XFastDocumentHandler> xFastDocHandler(xFilter, UNO_QUERY);
if (xFastParser)
+ {
+ xFastParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntitiesNames,
+ starmathdatabase::icustomMathmlHtmlEntitiesValues);
xFastParser->parseStream(aParserInput);
+ }
else if (xFastDocHandler)
{
Reference<css::xml::sax::XFastParser> xParser
= css::xml::sax::FastParser::create(rxContext);
+ xParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntitiesNames,
+ starmathdatabase::icustomMathmlHtmlEntitiesValues);
xParser->setFastDocumentHandler(xFastDocHandler);
xParser->parseStream(aParserInput);
}
diff --git a/starmath/source/xparsmlbase.cxx b/starmath/source/xparsmlbase.cxx
new file mode 100644
index 000000000000..8fbf6f9117f3
--- /dev/null
+++ b/starmath/source/xparsmlbase.cxx
@@ -0,0 +1,40 @@
+/* -*- 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 .
+ */
+#include "xparsmlbase.hxx"
+
+static OUString icustomMathmlHtmlEntitiesNamesData[2] = { u"sigma", u"infin" };
+
+static OUString icustomMathmlHtmlEntitiesValuesData[2] = { u"\u03C3", u"\u221E" };
+
+const ::css::uno::Sequence<::rtl::OUString>
+ starmathdatabase::icustomMathmlHtmlEntitiesNames(icustomMathmlHtmlEntitiesNamesData, 2);
+
+const ::css::uno::Sequence<::rtl::OUString>
+ starmathdatabase::icustomMathmlHtmlEntitiesValues(icustomMathmlHtmlEntitiesValuesData, 2);
+
+/*
+#include "xparsmlbase.hxx"
+
+const com::sun::star::uno::Sequence<OUString> starmathdatabase::icustomMathmlHtmlEntitiesNames
+ = { { OUString::createFromAscii("sigma") }, { OUString::createFromAscii("infin") } };
+
+const com::sun::star::uno::Sequence<OUString> starmathdatabase::icustomMathmlHtmlEntitiesValues
+ = { { OUString("\u03C3!", 2, RTL_TEXTENCODING_UTF8) },
+ { OUString("\u221E!", 2, RTL_TEXTENCODING_UTF8) } };
+ */
diff --git a/starmath/source/xparsmlbase.hxx b/starmath/source/xparsmlbase.hxx
new file mode 100644
index 000000000000..4bca389a4961
--- /dev/null
+++ b/starmath/source/xparsmlbase.hxx
@@ -0,0 +1,46 @@
+/* -*- 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 .
+ */
+
+#ifndef XPARSEMLBASE
+#define XPARSEMLBASE
+
+#include <com/sun/star/uno/Sequence.hxx>
+namespace starmathdatabase
+{
+/**
+ * w3 documentation has been used for this.
+ * See: https://www.w3.org/2003/entities/2007/htmlmathml-f.ent
+ * Copyright 1998 - 2011 W3C.
+ * We allow the import of HTML5 entities because are compatible with mathml
+ * and ill formated are expected.
+ * On export only mathml entities are allowed.
+ */
+/**
+ * Entity names for mathml. Example: &infin;
+ * Must be in sync with customMathmlHtmlEntitiesNames.
+ */
+const extern ::css::uno::Sequence<::rtl::OUString> icustomMathmlHtmlEntitiesNames;
+/**
+ * Entity values for mathml. Example: &infin; -> "\u8734";
+ * Must be in sync with customMathmlHtmlEntitiesNames.
+ */
+const extern ::css::uno::Sequence<::rtl::OUString> icustomMathmlHtmlEntitiesValues;
+};
+
+#endif /*XPARSEMLBASE*/