[Libreoffice-commits] core.git: include/editeng offapi/com sax/source starmath/source
dante (via logerrit)
logerrit at kemper.freedesktop.org
Sun Dec 27 07:30:09 UTC 2020
include/editeng/editview.hxx | 2 -
offapi/com/sun/star/xml/sax/XWriter.idl | 7 ++++-
sax/source/expatwrap/saxwriter.cxx | 44 ++++++++++++++++++++++++++++++--
starmath/source/mathmlexport.cxx | 2 +
starmath/source/xparsmlbase.cxx | 10 +++++++
starmath/source/xparsmlbase.hxx | 10 +++++--
6 files changed, 69 insertions(+), 6 deletions(-)
New commits:
commit 78552cb9b167a677952bf80eb0c7af62baaf015a
Author: dante <dante19031999 at gmail.com>
AuthorDate: Sat Dec 26 18:53:18 2020 +0100
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Dec 27 08:29:27 2020 +0100
Preparations for customized xml entities on export
Change-Id: I8ad4af7e27ae5f8908f4c932242cb96abbf3de90
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108354
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/editeng/editview.hxx b/include/editeng/editview.hxx
index ae6ebd521a2a..debc7b6efe71 100644
--- a/include/editeng/editview.hxx
+++ b/include/editeng/editview.hxx
@@ -177,7 +177,7 @@ public:
void InvalidateWindow(const tools::Rectangle& rClipRect);
void InvalidateOtherViewWindows( const tools::Rectangle& rInvRect );
void Invalidate();
- Pair Scroll( tools::Long nHorzScroll, tools::Long nVertScroll, ScrollRangeCheck nRangeCheck = ScrollRangeCheck::NoNegative );
+ ::Pair Scroll( tools::Long nHorzScroll, tools::Long nVertScroll, ScrollRangeCheck nRangeCheck = ScrollRangeCheck::NoNegative );
void SetBroadcastLOKViewCursor(bool bSet);
tools::Rectangle GetEditCursor() const;
diff --git a/offapi/com/sun/star/xml/sax/XWriter.idl b/offapi/com/sun/star/xml/sax/XWriter.idl
index a79e7b156a1a..62d3d74256af 100644
--- a/offapi/com/sun/star/xml/sax/XWriter.idl
+++ b/offapi/com/sun/star/xml/sax/XWriter.idl
@@ -21,7 +21,7 @@
#include <com/sun/star/io/XActiveDataSource.idl>
#include <com/sun/star/xml/sax/XExtendedDocumentHandler.idl>
-
+#include <com/sun/star/beans/Pair.idl>
module com { module sun { module star { module xml { module sax {
@@ -35,6 +35,11 @@ interface XWriter
{
interface com::sun::star::io::XActiveDataSource;
interface com::sun::star::xml::sax::XExtendedDocumentHandler;
+
+ /** Adds support for custom entity names list
+ * @since LibreOffice 7.2
+ */
+ void setCustomEntityNames( [in] sequence< com::sun::star::beans::Pair<string,string> > replacements );
};
diff --git a/sax/source/expatwrap/saxwriter.cxx b/sax/source/expatwrap/saxwriter.cxx
index 8566cab2b7e6..03ca1f765d82 100644
--- a/sax/source/expatwrap/saxwriter.cxx
+++ b/sax/source/expatwrap/saxwriter.cxx
@@ -22,6 +22,7 @@
#include <cassert>
#include <set>
#include <stack>
+#include <vector>
#include <com/sun/star/io/IOException.hpp>
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
@@ -72,6 +73,17 @@ enum SaxInvalidCharacterError
SAX_ERROR
};
+// Stuff for custom entity names
+struct ReplacementPair
+{
+ OUString name;
+ OUString replacement;
+};
+inline bool operator<(const ReplacementPair& lhs, const ReplacementPair& rhs)
+{
+ return lhs.replacement.compareTo(rhs.replacement) < 0;
+}
+
class SaxWriterHelper
{
#ifdef DBG_UTIL
@@ -88,6 +100,8 @@ private:
sal_uInt32 nCurrentPos;
bool m_bStartElementFinished;
+ std::vector<ReplacementPair> m_Replacements;
+
/// @throws SAXException
sal_uInt32 writeSequence();
@@ -175,6 +189,10 @@ public:
/// @throws SAXException
void clearBuffer();
+
+ // Use custom entity names
+ void setCustomEntityNames(
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements);
};
const bool g_bValidCharsBelow32[32] =
@@ -239,6 +257,19 @@ void SaxWriterHelper::AddBytes(sal_Int8* pTarget, sal_uInt32& rPos,
AddBytes(pTarget, rPos, &pBytes[nCount], nRestCount);
}
+void SaxWriterHelper::setCustomEntityNames(
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements)
+{
+ m_Replacements.resize(replacements.size());
+ for (size_t i = 0; i < replacements.size(); ++i)
+ {
+ m_Replacements[i].name = replacements[i].First;
+ m_Replacements[i].replacement = replacements[i].Second;
+ }
+ if (replacements.size() > 1)
+ std::sort(m_Replacements.begin(), m_Replacements.end());
+}
+
/** Converts a UTF-16 string to UTF-8 and does XML normalization
@param pTarget
@@ -300,7 +331,7 @@ bool SaxWriterHelper::convertToXML( const sal_Unicode * pStr,
}
}
break;
- case 39: // 39 == '''
+ case '\'':
{
if ((rPos + 6) > SEQUENCESIZE)
AddBytes(pTarget, rPos, reinterpret_cast<sal_Int8 const *>("'"), 6);
@@ -855,7 +886,7 @@ sal_Int32 calcXMLByteLength( const OUString& rStr,
case '>': // >
nOutputLength +=4;
break;
- case 39: // 39 == ''', '
+ case '\'': // '
case '"': // "
case 13: // 
nOutputLength += 6;
@@ -988,6 +1019,9 @@ public: // XDocumentHandler
virtual void SAL_CALL processingInstruction(const OUString& aTarget,
const OUString& aData) override;
virtual void SAL_CALL setDocumentLocator(const Reference< XLocator > & xLocator) override;
+ virtual void SAL_CALL setCustomEntityNames(
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements)
+ override;
public: // XExtendedDocumentHandler
virtual void SAL_CALL startCDATA() override;
@@ -1304,6 +1338,12 @@ void SAXWriter::setDocumentLocator(const Reference< XLocator >&)
}
+void SAXWriter::setCustomEntityNames(
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements)
+{
+ m_pSaxWriterHelper->setCustomEntityNames(replacements);
+}
+
void SAXWriter::startCDATA()
{
if( ! m_bDocStarted || m_bIsCDATA)
diff --git a/starmath/source/mathmlexport.cxx b/starmath/source/mathmlexport.cxx
index 9a8f700af2ec..953bfb87f062 100644
--- a/starmath/source/mathmlexport.cxx
+++ b/starmath/source/mathmlexport.cxx
@@ -58,6 +58,7 @@
#include <stack>
#include "mathmlexport.hxx"
+#include "xparsmlbase.hxx"
#include <strings.hrc>
#include <smmod.hxx>
#include <unomodel.hxx>
@@ -240,6 +241,7 @@ bool SmXMLExportWrapper::WriteThroughComponent(const Reference<io::XOutputStream
// connect XML writer to output stream
xSaxWriter->setOutputStream(xOutputStream);
+ xSaxWriter->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntitiesExport);
// prepare arguments (prepend doc handler to given arguments)
Sequence<Any> aArgs(2);
diff --git a/starmath/source/xparsmlbase.cxx b/starmath/source/xparsmlbase.cxx
index 4c5651ae2c55..519fab844465 100644
--- a/starmath/source/xparsmlbase.cxx
+++ b/starmath/source/xparsmlbase.cxx
@@ -2153,4 +2153,14 @@ const ::css::uno::Sequence<::css::beans::Pair<OUString, OUString>>
starmathdatabase::icustomMathmlHtmlEntities(
icustomMathmlHtmlEntitiesData, starmathdatabase::STARMATH_MATHMLHTML_ENTITY_NUMBER);
+static ::css::beans::Pair<::rtl::OUString, ::rtl::OUString>
+ icustomMathmlHtmlEntitiesNamesExportData[2] = {
+ // clang-format off
+ { u"σ", u"\u03C3"},
+ { u"∞", u"\u221E"}
+ // clang-format on
+ };
+const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>
+ starmathdatabase::icustomMathmlHtmlEntitiesExport(icustomMathmlHtmlEntitiesNamesExportData, 2);
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/xparsmlbase.hxx b/starmath/source/xparsmlbase.hxx
index 8ec7b48ccab4..83650382e31b 100644
--- a/starmath/source/xparsmlbase.hxx
+++ b/starmath/source/xparsmlbase.hxx
@@ -37,12 +37,18 @@ namespace starmathdatabase
constexpr sal_Int32 STARMATH_MATHMLHTML_ENTITY_NUMBER = 2125;
/**
- * Entity names for mathml. Example: ∞
+ * Entity names for mathml. Example: &infin -> \u221E;
* These ones are to be used on import.
- * Must be in sync with customMathmlHtmlEntitiesNames.
*/
const extern ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>
icustomMathmlHtmlEntities;
+
+/**
+ * Entity names for mathml. Example: "\u221E"; -> ∞
+ * These ones are to be used on file export.
+ */
+const extern ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>
+ icustomMathmlHtmlEntitiesExport;
};
#endif /*XPARSEMLBASE*/
More information about the Libreoffice-commits
mailing list