[Libreoffice-commits] core.git: starmath/mathml starmath/source

dante (via logerrit) logerrit at kemper.freedesktop.org
Tue Jan 19 06:31:15 UTC 2021


 starmath/mathml/inc/mathmlexport.hxx    |   21 ++++++++++++++------
 starmath/mathml/inc/mathmlimport.hxx    |   20 +++++++++++++------
 starmath/mathml/source/mathmlexport.cxx |   21 ++++++++++++--------
 starmath/mathml/source/mathmlimport.cxx |   33 +++++++++++++++++++-------------
 starmath/source/document.cxx            |    2 +
 5 files changed, 64 insertions(+), 33 deletions(-)

New commits:
commit 03d86b55967bd1c7aac448373e3c01d45ec54554
Author:     dante <dante19031999 at gmail.com>
AuthorDate: Fri Jan 15 01:02:15 2021 +0100
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Jan 19 07:30:36 2021 +0100

    Use custom HTML Mathml entities only when needed.
    
    Change-Id: Id2120aec8738286d31d79638b46beac2f0e53780
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109317
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/starmath/mathml/inc/mathmlexport.hxx b/starmath/mathml/inc/mathmlexport.hxx
index 32afe9f9aff1..ed5a598d6abf 100644
--- a/starmath/mathml/inc/mathmlexport.hxx
+++ b/starmath/mathml/inc/mathmlexport.hxx
@@ -43,28 +43,37 @@ class SmXMLExportWrapper
     css::uno::Reference<css::frame::XModel> xModel;
     bool bFlat; //set true for export to flat .mml, set false for
         //export to a .sxm (or whatever) package
+
+private:
+    // Use customized entities
+    bool bbUseHTMLMLEntities;
+
 public:
     explicit SmXMLExportWrapper(css::uno::Reference<css::frame::XModel> const& rRef)
         : xModel(rRef)
         , bFlat(true)
+        , bbUseHTMLMLEntities(false)
     {
     }
 
     bool Export(SfxMedium& rMedium);
     void SetFlat(bool bIn) { bFlat = bIn; }
+    void useHTMLMLEntities(bool bUseHTMLMLEntities) { bbUseHTMLMLEntities = bUseHTMLMLEntities; }
 
     static 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);
+                          const char* pComponentName, bool bUseHTMLMLEntities);
 
-    static bool WriteThroughComponent(
-        const css::uno::Reference<css::embed::XStorage>& xStor,
-        const css::uno::Reference<css::lang::XComponent>& xComponent, const char* pStreamName,
-        css::uno::Reference<css::uno::XComponentContext> const& rxContext,
-        css::uno::Reference<css::beans::XPropertySet> const& rPropSet, const char* pComponentName);
+    static bool
+    WriteThroughComponent(const css::uno::Reference<css::embed::XStorage>& xStor,
+                          const css::uno::Reference<css::lang::XComponent>& xComponent,
+                          const char* pStreamName,
+                          css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+                          css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
+                          const char* pComponentName, bool bUseHTMLMLEntities);
 };
 
 class SmXMLExport final : public SvXMLExport
diff --git a/starmath/mathml/inc/mathmlimport.hxx b/starmath/mathml/inc/mathmlimport.hxx
index f390483e9be0..af7611852adc 100644
--- a/starmath/mathml/inc/mathmlimport.hxx
+++ b/starmath/mathml/inc/mathmlimport.hxx
@@ -42,26 +42,34 @@ class SmXMLImportWrapper
 {
     css::uno::Reference<css::frame::XModel> xModel;
 
+private:
+    // Use customized entities
+    bool bbUseHTMLMLEntities;
+
 public:
     explicit SmXMLImportWrapper(css::uno::Reference<css::frame::XModel> const& rRef)
         : xModel(rRef)
+        , bbUseHTMLMLEntities(false)
     {
     }
 
     ErrCode Import(SfxMedium& rMedium);
+    void useHTMLMLEntities(bool bUseHTMLMLEntities) { bbUseHTMLMLEntities = bUseHTMLMLEntities; }
 
     static ErrCode
     ReadThroughComponent(const css::uno::Reference<css::io::XInputStream>& xInputStream,
                          const css::uno::Reference<css::lang::XComponent>& xModelComponent,
                          css::uno::Reference<css::uno::XComponentContext> const& rxContext,
                          css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
-                         const char* pFilterName, bool bEncrypted);
+                         const char* pFilterName, bool bEncrypted, bool bUseHTMLMLEntities);
 
-    static ErrCode ReadThroughComponent(
-        const css::uno::Reference<css::embed::XStorage>& xStorage,
-        const css::uno::Reference<css::lang::XComponent>& xModelComponent, const char* pStreamName,
-        css::uno::Reference<css::uno::XComponentContext> const& rxContext,
-        css::uno::Reference<css::beans::XPropertySet> const& rPropSet, const char* pFilterName);
+    static ErrCode
+    ReadThroughComponent(const css::uno::Reference<css::embed::XStorage>& xStorage,
+                         const css::uno::Reference<css::lang::XComponent>& xModelComponent,
+                         const char* pStreamName,
+                         css::uno::Reference<css::uno::XComponentContext> const& rxContext,
+                         css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
+                         const char* pFilterName, bool bUseHTMLMLEntities);
 };
 
 class SmXMLImport : public SvXMLImport
diff --git a/starmath/mathml/source/mathmlexport.cxx b/starmath/mathml/source/mathmlexport.cxx
index fed4ac8a549d..2936b7fba5be 100644
--- a/starmath/mathml/source/mathmlexport.cxx
+++ b/starmath/mathml/source/mathmlexport.cxx
@@ -186,7 +186,8 @@ bool SmXMLExportWrapper::Export(SfxMedium& rMedium)
 
             bRet = WriteThroughComponent(xStg, xModelComp, "meta.xml", xContext, xInfoSet,
                                          (bOASIS ? "com.sun.star.comp.Math.XMLOasisMetaExporter"
-                                                 : "com.sun.star.comp.Math.XMLMetaExporter"));
+                                                 : "com.sun.star.comp.Math.XMLMetaExporter"),
+                                         bbUseHTMLMLEntities);
         }
         if (bRet)
         {
@@ -194,7 +195,8 @@ bool SmXMLExportWrapper::Export(SfxMedium& rMedium)
                 xStatusIndicator->setValue(nSteps++);
 
             bRet = WriteThroughComponent(xStg, xModelComp, "content.xml", xContext, xInfoSet,
-                                         "com.sun.star.comp.Math.XMLContentExporter");
+                                         "com.sun.star.comp.Math.XMLContentExporter",
+                                         bbUseHTMLMLEntities);
         }
 
         if (bRet)
@@ -204,7 +206,8 @@ bool SmXMLExportWrapper::Export(SfxMedium& rMedium)
 
             bRet = WriteThroughComponent(xStg, xModelComp, "settings.xml", xContext, xInfoSet,
                                          (bOASIS ? "com.sun.star.comp.Math.XMLOasisSettingsExporter"
-                                                 : "com.sun.star.comp.Math.XMLSettingsExporter"));
+                                                 : "com.sun.star.comp.Math.XMLSettingsExporter"),
+                                         bbUseHTMLMLEntities);
         }
     }
     else
@@ -216,7 +219,8 @@ bool SmXMLExportWrapper::Export(SfxMedium& rMedium)
             xStatusIndicator->setValue(nSteps++);
 
         bRet = WriteThroughComponent(xOut, xModelComp, xContext, xInfoSet,
-                                     "com.sun.star.comp.Math.XMLContentExporter");
+                                     "com.sun.star.comp.Math.XMLContentExporter",
+                                     bbUseHTMLMLEntities);
     }
 
     if (xStatusIndicator.is())
@@ -230,7 +234,7 @@ bool SmXMLExportWrapper::WriteThroughComponent(const Reference<io::XOutputStream
                                                const Reference<XComponent>& xComponent,
                                                Reference<uno::XComponentContext> const& rxContext,
                                                Reference<beans::XPropertySet> const& rPropSet,
-                                               const char* pComponentName)
+                                               const char* pComponentName, bool bUseHTMLMLEntities)
 {
     OSL_ENSURE(xOutputStream.is(), "I really need an output stream!");
     OSL_ENSURE(xComponent.is(), "Need component!");
@@ -241,7 +245,8 @@ bool SmXMLExportWrapper::WriteThroughComponent(const Reference<io::XOutputStream
 
     // connect XML writer to output stream
     xSaxWriter->setOutputStream(xOutputStream);
-    xSaxWriter->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntitiesExport);
+    if (bUseHTMLMLEntities)
+        xSaxWriter->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntitiesExport);
 
     // prepare arguments (prepend doc handler to given arguments)
     Sequence<Any> aArgs(2);
@@ -275,7 +280,7 @@ bool SmXMLExportWrapper::WriteThroughComponent(const Reference<embed::XStorage>&
                                                const char* pStreamName,
                                                Reference<uno::XComponentContext> const& rxContext,
                                                Reference<beans::XPropertySet> const& rPropSet,
-                                               const char* pComponentName)
+                                               const char* pComponentName, bool bUseHTMLMLEntities)
 {
     OSL_ENSURE(xStorage.is(), "Need storage!");
     OSL_ENSURE(nullptr != pStreamName, "Need stream name!");
@@ -308,7 +313,7 @@ bool SmXMLExportWrapper::WriteThroughComponent(const Reference<embed::XStorage>&
 
     // write the stuff
     bool bRet = WriteThroughComponent(xStream->getOutputStream(), xComponent, rxContext, rPropSet,
-                                      pComponentName);
+                                      pComponentName, bUseHTMLMLEntities);
 
     return bRet;
 }
diff --git a/starmath/mathml/source/mathmlimport.cxx b/starmath/mathml/source/mathmlimport.cxx
index 2b341028ef0c..cbdfcc52abb1 100644
--- a/starmath/mathml/source/mathmlimport.cxx
+++ b/starmath/mathml/source/mathmlimport.cxx
@@ -187,7 +187,8 @@ ErrCode SmXMLImportWrapper::Import(SfxMedium& rMedium)
         auto nWarn
             = ReadThroughComponent(rMedium.GetStorage(), xModelComp, "meta.xml", xContext, xInfoSet,
                                    (bOASIS ? "com.sun.star.comp.Math.XMLOasisMetaImporter"
-                                           : "com.sun.star.comp.Math.XMLMetaImporter"));
+                                           : "com.sun.star.comp.Math.XMLMetaImporter"),
+                                   bbUseHTMLMLEntities);
 
         if (nWarn != ERRCODE_IO_BROKENPACKAGE)
         {
@@ -197,16 +198,17 @@ ErrCode SmXMLImportWrapper::Import(SfxMedium& rMedium)
             nWarn = ReadThroughComponent(rMedium.GetStorage(), xModelComp, "settings.xml", xContext,
                                          xInfoSet,
                                          (bOASIS ? "com.sun.star.comp.Math.XMLOasisSettingsImporter"
-                                                 : "com.sun.star.comp.Math.XMLSettingsImporter"));
+                                                 : "com.sun.star.comp.Math.XMLSettingsImporter"),
+                                         bbUseHTMLMLEntities);
 
             if (nWarn != ERRCODE_IO_BROKENPACKAGE)
             {
                 if (xStatusIndicator.is())
                     xStatusIndicator->setValue(nSteps++);
 
-                nError = ReadThroughComponent(rMedium.GetStorage(), xModelComp, "content.xml",
-                                              xContext, xInfoSet,
-                                              "com.sun.star.comp.Math.XMLImporter");
+                nError = ReadThroughComponent(
+                    rMedium.GetStorage(), xModelComp, "content.xml", xContext, xInfoSet,
+                    "com.sun.star.comp.Math.XMLImporter", bbUseHTMLMLEntities);
             }
             else
                 nError = ERRCODE_IO_BROKENPACKAGE;
@@ -223,7 +225,8 @@ ErrCode SmXMLImportWrapper::Import(SfxMedium& rMedium)
             xStatusIndicator->setValue(nSteps++);
 
         nError = ReadThroughComponent(xInputStream, xModelComp, xContext, xInfoSet,
-                                      "com.sun.star.comp.Math.XMLImporter", false);
+                                      "com.sun.star.comp.Math.XMLImporter", false,
+                                      bbUseHTMLMLEntities);
     }
 
     if (xStatusIndicator.is())
@@ -236,7 +239,8 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(const Reference<io::XInputStrea
                                                  const Reference<XComponent>& xModelComponent,
                                                  Reference<uno::XComponentContext> const& rxContext,
                                                  Reference<beans::XPropertySet> const& rPropSet,
-                                                 const char* pFilterName, bool bEncrypted)
+                                                 const char* pFilterName, bool bEncrypted,
+                                                 bool bUseHTMLMLEntities)
 {
     ErrCode nError = ERRCODE_SFX_DOLOADFAILED;
     OSL_ENSURE(xInputStream.is(), "input stream missing");
@@ -270,14 +274,16 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(const Reference<io::XInputStrea
         Reference<css::xml::sax::XFastDocumentHandler> xFastDocHandler(xFilter, UNO_QUERY);
         if (xFastParser)
         {
-            xFastParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntities);
+            if (bUseHTMLMLEntities)
+                xFastParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntities);
             xFastParser->parseStream(aParserInput);
         }
         else if (xFastDocHandler)
         {
             Reference<css::xml::sax::XFastParser> xParser
                 = css::xml::sax::FastParser::create(rxContext);
-            xParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntities);
+            if (bUseHTMLMLEntities)
+                xParser->setCustomEntityNames(starmathdatabase::icustomMathmlHtmlEntities);
             xParser->setFastDocumentHandler(xFastDocHandler);
             xParser->parseStream(aParserInput);
         }
@@ -345,7 +351,7 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(const uno::Reference<embed::XSt
                                                  const char* pStreamName,
                                                  Reference<uno::XComponentContext> const& rxContext,
                                                  Reference<beans::XPropertySet> const& rPropSet,
-                                                 const char* pFilterName)
+                                                 const char* pFilterName, bool bUseHTMLMLEntities)
 {
     OSL_ENSURE(xStorage.is(), "Need storage!");
     OSL_ENSURE(nullptr != pStreamName, "Please, please, give me a name!");
@@ -374,7 +380,7 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(const uno::Reference<embed::XSt
 
         Reference<io::XInputStream> xStream = xEventsStream->getInputStream();
         return ReadThroughComponent(xStream, xModelComponent, rxContext, rPropSet, pFilterName,
-                                    bEncrypted);
+                                    bEncrypted, bUseHTMLMLEntities);
     }
     catch (packages::WrongPasswordException&)
     {
@@ -2674,8 +2680,9 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportMML(SvStream& rStream)
 
     try
     {
-        nRet = SmXMLImportWrapper::ReadThroughComponent(
-            xStream, xModel, xContext, xInfoSet, "com.sun.star.comp.Math.XMLImporter", false);
+        nRet = SmXMLImportWrapper::ReadThroughComponent(xStream, xModel, xContext, xInfoSet,
+                                                        "com.sun.star.comp.Math.XMLImporter", false,
+                                                        false);
     }
     catch (...)
     {
diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx
index a7f6ac6b31ea..d44c41f2a6f4 100644
--- a/starmath/source/document.cxx
+++ b/starmath/source/document.cxx
@@ -663,6 +663,7 @@ bool SmDocShell::ConvertFrom(SfxMedium &rMedium)
         }
         Reference<css::frame::XModel> xModel(GetModel());
         SmXMLImportWrapper aEquation(xModel);
+        aEquation.useHTMLMLEntities(true);
         bSuccess = ( ERRCODE_NONE == aEquation.Import(rMedium) );
     }
     else
@@ -844,6 +845,7 @@ bool SmDocShell::ConvertTo( SfxMedium &rMedium )
             Reference<css::frame::XModel> xModel(GetModel());
             SmXMLExportWrapper aEquation(xModel);
             aEquation.SetFlat(true);
+            aEquation.useHTMLMLEntities(true);
             bRet = aEquation.Export(rMedium);
         }
         else if (pFlt->GetFilterName() == "MathType 3.x")


More information about the Libreoffice-commits mailing list