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@collabora.co.uk>
This commit is contained in:
dante
2020-12-27 08:29:27 +01:00
committed by Noel Grandin
parent a26504cb57
commit 78552cb9b1
6 changed files with 69 additions and 6 deletions
+1 -1
View File
@@ -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;
+6 -1
View File
@@ -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 );
};
+42 -2
View File
@@ -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 *>("&apos;"), 6);
@@ -855,7 +886,7 @@ sal_Int32 calcXMLByteLength( const OUString& rStr,
case '>': // &gt;
nOutputLength +=4;
break;
case 39: // 39 == ''', &apos;
case '\'': // &apos;
case '"': // &quot;
case 13: // &#x0d;
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)
+2
View File
@@ -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);
+10
View File
@@ -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"&sigma;", u"\u03C3"},
{ u"&infin;", 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: */
+8 -2
View File
@@ -37,12 +37,18 @@ namespace starmathdatabase
constexpr sal_Int32 STARMATH_MATHMLHTML_ENTITY_NUMBER = 2125;
/**
* Entity names for mathml. Example: &infin;
* 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"; -> &infin;
* These ones are to be used on file export.
*/
const extern ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>
icustomMathmlHtmlEntitiesExport;
};
#endif /*XPARSEMLBASE*/