[Libreoffice-commits] core.git: starmath/CppunitTest_starmath_export.mk starmath/inc starmath/Module_starmath.mk starmath/qa starmath/source

Takeshi Abe tabe at fixedpoint.jp
Sun Jul 31 20:21:03 UTC 2016


 starmath/CppunitTest_starmath_export.mk |   89 +++++++++++++++++++++
 starmath/Module_starmath.mk             |    1 
 starmath/inc/document.hxx               |    6 +
 starmath/qa/extras/mmlexport-test.cxx   |  130 ++++++++++++++++++++++++++++++++
 starmath/source/mathmlexport.cxx        |    7 +
 5 files changed, 232 insertions(+), 1 deletion(-)

New commits:
commit ff4217e9e4f90a8dd09e635a35665a64846b4505
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Thu Jul 28 09:03:59 2016 +0900

    tdf#101022 Export Greek symbol to MathML with correct mathvariant
    
    In StarMath notation "{ital %GAMMA}" is recognized as italic, and
    "{nitalic %iGAMMA}" is non-italic. That is, the ital/nitalic directive
    takes priority over special characters' flavor.
    On the other hand, in MathML a mathvariant attribute given in <mi>
    overwrites inherited value.
    
    This does not handle "bold-italic" case etc. yet.
    
    Change-Id: I9c72dc4472f8cec553417d516d9d82aebd43d15c
    Reviewed-on: https://gerrit.libreoffice.org/27604
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/starmath/CppunitTest_starmath_export.mk b/starmath/CppunitTest_starmath_export.mk
new file mode 100644
index 0000000..1dffe45
--- /dev/null
+++ b/starmath/CppunitTest_starmath_export.mk
@@ -0,0 +1,89 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,starmath_export))
+
+$(eval $(call gb_CppunitTest_set_include,starmath_export,\
+    -I$(SRCDIR)/starmath/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,starmath_export,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,starmath_export))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,starmath_export,\
+    starmath/qa/extras/mmlexport-test \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,starmath_export,\
+    comphelper \
+    cppu \
+    cppuhelper \
+    editeng \
+    i18nlangtag \
+    i18nutil \
+    msfilter \
+    oox \
+    sal \
+    salhelper \
+    sax \
+    sfx \
+    sm \
+    smd \
+    sot \
+    svl \
+    svt \
+    svx \
+    svxcore \
+    test \
+    tk \
+    tl \
+    unotest \
+    unoxml \
+    utl \
+    vcl \
+    xo \
+    $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,starmath_export))
+$(eval $(call gb_CppunitTest_use_vcl,starmath_export))
+
+$(eval $(call gb_CppunitTest_use_components,starmath_export,\
+    configmgr/source/configmgr \
+    framework/util/fwk \
+    i18npool/util/i18npool \
+    package/source/xstor/xstor \
+    package/util/package2 \
+    sfx2/util/sfx \
+    starmath/util/sm \
+    starmath/util/smd \
+    toolkit/util/tk \
+    ucb/source/core/ucb1 \
+    ucb/source/ucp/file/ucpfile1 \
+    unotools/util/utl \
+    comphelper/util/comphelp \
+    filter/source/config/cache/filterconfig1 \
+    oox/util/oox \
+    sax/source/expatwrap/expwrap \
+    svl/source/fsstor/fsstorage \
+    svl/util/svl \
+    svx/util/svx \
+    unoxml/source/service/unoxml \
+    uui/util/uui \
+    xmloff/util/xo \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,starmath_export))
+
+# vim: set noet sw=4 ts=4:
diff --git a/starmath/Module_starmath.mk b/starmath/Module_starmath.mk
index 1a6af4c..86b4244 100644
--- a/starmath/Module_starmath.mk
+++ b/starmath/Module_starmath.mk
@@ -21,6 +21,7 @@ $(eval $(call gb_Module_add_l10n_targets,starmath,\
 ))
 
 $(eval $(call gb_Module_add_check_targets,starmath,\
+    CppunitTest_starmath_export \
     CppunitTest_starmath_import \
     CppunitTest_starmath_qa_cppunit \
 ))
diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx
index fa370de..a03ad0d 100644
--- a/starmath/inc/document.hxx
+++ b/starmath/inc/document.hxx
@@ -124,7 +124,6 @@ class SM_DLLPUBLIC SmDocShell : public SfxObjectShell, public SfxListener
     virtual bool        Load( SfxMedium& rMedium ) override;
     virtual bool        Save() override;
     virtual bool        SaveAs( SfxMedium& rMedium ) override;
-    virtual bool        ConvertTo( SfxMedium &rMedium ) override;
     virtual bool        SaveCompleted( const css::uno::Reference< css::embed::XStorage >& xStorage ) override;
 
     Printer             *GetPrt();
@@ -152,6 +151,11 @@ public:
     explicit SmDocShell( SfxModelFlags i_nSfxCreationFlags );
     virtual     ~SmDocShell();
 
+    virtual bool        ConvertTo( SfxMedium &rMedium ) override;
+
+    // For unit tests, not intended to use in other context
+    void SetGreekCharStyle(sal_Int16 nVal) { maFormat.SetGreekCharStyle(nVal); }
+
     static void LoadSymbols();
     static void SaveSymbols();
 
diff --git a/starmath/qa/extras/mmlexport-test.cxx b/starmath/qa/extras/mmlexport-test.cxx
new file mode 100644
index 0000000..ce1a467
--- /dev/null
+++ b/starmath/qa/extras/mmlexport-test.cxx
@@ -0,0 +1,130 @@
+/* -*- 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/.
+ */
+
+#include <sal/config.h>
+#include <test/bootstrapfixture.hxx>
+#include <test/xmltesttools.hxx>
+#include <unotools/tempfile.hxx>
+
+#include <sfx2/docfile.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/sfxmodelfactory.hxx>
+
+#include "document.hxx"
+#include "smdll.hxx"
+#include "node.hxx"
+#include "parse.hxx"
+
+#include <memory>
+
+namespace {
+
+using namespace ::com::sun::star;
+
+typedef tools::SvRef<SmDocShell> SmDocShellRef;
+
+class MathMLExportTest : public test::BootstrapFixture, public XmlTestTools
+{
+public:
+    virtual void setUp() override;
+    virtual void tearDown() override;
+
+    void testTdf101022();
+
+    CPPUNIT_TEST_SUITE(MathMLExportTest);
+    CPPUNIT_TEST(testTdf101022);
+    CPPUNIT_TEST_SUITE_END();
+
+protected:
+    virtual void registerNamespaces(xmlXPathContextPtr &pXmlXPathCtx) override;
+
+private:
+    xmlDocPtr exportAndParse();
+
+    SmDocShellRef mxDocShell;
+};
+
+void MathMLExportTest::setUp()
+{
+    BootstrapFixture::setUp();
+    SmGlobals::ensure();
+    mxDocShell = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT |
+                                SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
+                                SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
+}
+
+void MathMLExportTest::tearDown()
+{
+    if (mxDocShell)
+        mxDocShell->DoClose();
+    BootstrapFixture::tearDown();
+}
+
+void MathMLExportTest::registerNamespaces(xmlXPathContextPtr &pXmlXPathCtx)
+{
+    xmlXPathRegisterNs(pXmlXPathCtx, BAD_CAST("m"), BAD_CAST("http://www.w3.org/1998/Math/MathML"));
+}
+
+xmlDocPtr MathMLExportTest::exportAndParse()
+{
+    utl::TempFile aTempFile;
+    aTempFile.EnableKillingFile();
+    SfxMedium aStoreMedium(aTempFile.GetURL(), STREAM_STD_WRITE);
+    std::shared_ptr<const SfxFilter> pExportFilter = SfxFilter::GetFilterByName(MATHML_XML);
+    aStoreMedium.SetFilter(pExportFilter);
+    CPPUNIT_ASSERT(mxDocShell->ConvertTo(aStoreMedium));
+    aStoreMedium.Commit();
+    xmlDocPtr pDoc = parseXml(aTempFile);
+    CPPUNIT_ASSERT(pDoc);
+    return pDoc;
+}
+
+void MathMLExportTest::testTdf101022()
+{
+#define CHECK_MATHVARIANT(capital, small) do                            \
+    {                                                                   \
+        mxDocShell->SetText("%GAMMA %iGAMMA {ital %GAMMA} {nitalic %iGAMMA} " \
+                            "%gamma %igamma {ital %gamma} {nitalic %igamma}"); \
+        xmlDocPtr pDoc = exportAndParse();                              \
+        if (capital)                                                    \
+            assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant"); \
+        else                                                            \
+            assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[1]", "mathvariant", "normal"); \
+        assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[1]/m:mi[1]", "mathvariant"); \
+        assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[2]", "mathvariant"); \
+        assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[2]/m:mi[1]", "mathvariant", "normal"); \
+        if (small)                                                      \
+            assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant"); \
+        else                                                            \
+            assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mi[3]", "mathvariant", "normal"); \
+        assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[3]/m:mi[1]", "mathvariant"); \
+        assertXPathNoAttribute(pDoc, "/m:math/m:semantics/m:mrow/m:mi[4]", "mathvariant"); \
+        assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mstyle[4]/m:mi[1]", "mathvariant", "normal"); \
+        mxDocShell->SetText("");                                        \
+    }                                                                   \
+    while (false)
+
+    CHECK_MATHVARIANT(false, false); // default mode 0
+
+    mxDocShell->SetGreekCharStyle(1); // mode 1
+    CHECK_MATHVARIANT(true, true);
+
+    mxDocShell->SetGreekCharStyle(2); // mode 2
+    CHECK_MATHVARIANT(false, true);
+
+#undef CHECK_MATHVARIANT
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MathMLExportTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/mathmlexport.cxx b/starmath/source/mathmlexport.cxx
index 890f979..cb1ed0e 100644
--- a/starmath/source/mathmlexport.cxx
+++ b/starmath/source/mathmlexport.cxx
@@ -804,6 +804,13 @@ void SmXMLExport::ExportMath(const SmNode *pNode, int /*nLevel*/)
         // Export NMATH and NGLYPH_SPECIAL symbols as <mo> elements
         pMath = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MO, true, false);
     }
+    else if (pNode->GetType() == NSPECIAL)
+    {
+        bool bIsItalic = IsItalic(pNode->GetFont());
+        if (!bIsItalic)
+            AddAttribute(XML_NAMESPACE_MATH, XML_MATHVARIANT, XML_NORMAL);
+        pMath = new SvXMLElementExport(*this, XML_NAMESPACE_MATH, XML_MI, true, false);
+    }
     else
     {
         // Export NMATHIDENT and NPLACE symbols as <mi> elements:


More information about the Libreoffice-commits mailing list