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:
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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: */
|
||||
|
||||
@@ -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*/
|
||||
|
||||
Reference in New Issue
Block a user