FW: bafna_p - r31515 - abiword/branches/gsoc2012math/src/wp/impexp/xp

Martin Edmund Sevior <[email protected]>
Newsgroups gmane.editors.abiword.devel
Message-ID <323132D956C9584B8B1E9DC491FF9CB539912AC2@000S-EX-MBX-QS4.unimelb.edu.au>
Congratulations! This is a major new feature for abiword that I will find *extremely* useful.

Thank you :-)

Cheers

Martin

________________________________________
From: [email protected] [[email protected]] on behalf of [email protected] [[email protected]]
Sent: Tuesday, July 17, 2012 2:43 AM
To: [email protected]
Subject: bafna_p - r31515 - abiword/branches/gsoc2012math/src/wp/impexp/xp

Author: bafna_p
Date: 2012-07-16 18:43:45 +0200 (Mon, 16 Jul 2012)
New Revision: 31515

Modified:
   abiword/branches/gsoc2012math/src/wp/impexp/xp/ie_math_convert.cpp
   abiword/branches/gsoc2012math/src/wp/impexp/xp/ie_math_convert.h
Log:
Adding the OMML to MathML converter and minor changes to ie_math_convert

Modified: abiword/branches/gsoc2012math/src/wp/impexp/xp/ie_math_convert.cpp
===================================================================
--- abiword/branches/gsoc2012math/src/wp/impexp/xp/ie_math_convert.cpp  2012-07-16 16:39:46 UTC (rev 31514)
+++ abiword/branches/gsoc2012math/src/wp/impexp/xp/ie_math_convert.cpp  2012-07-16 16:43:45 UTC (rev 31515)
@@ -1,4 +1,22 @@
-// part of the code here taken from ie_exp_LaTeX.cpp in the latex plugin
+/* AbiWord
+ * Copyright (C) 2008 Xun Sun ([email protected])
+ * Copyright (C) 2012 Prashant Bafna ([email protected])
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */

 #include "ie_math_convert.h"
 #include "ut_debugmsg.h"
@@ -101,3 +119,67 @@
        }

 }
+
+// Function to convert OMML (from docx) to MathML
+
+static xsltStylesheet * cur2 = NULL;
+
+bool convertOMMLtoMathML(const std::string & pOMML, std::string & pMathML)
+{
+    xmlDocPtr doc,res;
+    xmlChar * qMathML = NULL;
+    int len;
+
+    if(pOMML.empty())
+    {
+        return false;
+    }
+
+    if(!cur2)
+    {
+        std::string path(XAP_App::getApp()->getAbiSuiteLibDir());
+        path+= "/omml_xslt/omml2mml.xsl";
+
+        // TO DO : add the post build event to the msvc project to copy the omml_xslt folder from openxml plugin to debug/release, after the gsoc2012math branch is merged with trunk
+
+        //path = "../../plugins/openxml/common/omml_xslt/omml2mml.xsl";
+
+        cur2 = xsltParseStylesheetFile((const xmlChar *)(path.c_str()));
+        if(!cur2)
+        {
+            UT_DEBUGMSG(("convertOMMLtoMathML : Parsing stylesheet failed\n"));
+            return false;
+        }
+
+    }
+
+    doc = xmlParseDoc((xmlChar*)(pOMML.c_str()));
+    if(!doc)
+    {
+        xxx_UT_DEBUGMSG(("convertOMMLtoMathML : Parsing OMML document failed\n"));
+        return false;
+    }
+
+    res = xsltApplyStylesheet(cur2, doc, NULL);
+    if(!res)
+    {
+        xxx_UT_DEBUGMSG(("convertOMMLtoMathML: Applying stylesheet failed\n"));
+        xmlFreeDoc(doc);
+        return false;
+    }
+
+    if(xsltSaveResultToString(&qMathML, &len, res, cur2) != 0)
+    {
+        xmlFreeDoc(res);
+        xmlFreeDoc(doc);
+        return false;
+    }
+
+    pMathML.assign((const char*)qMathML, len);
+
+    g_free(qMathML);
+    xmlFreeDoc(res);
+    xmlFreeDoc(doc);
+    return true;
+
+}

Modified: abiword/branches/gsoc2012math/src/wp/impexp/xp/ie_math_convert.h
===================================================================
--- abiword/branches/gsoc2012math/src/wp/impexp/xp/ie_math_convert.h    2012-07-16 16:39:46 UTC (rev 31514)
+++ abiword/branches/gsoc2012math/src/wp/impexp/xp/ie_math_convert.h    2012-07-16 16:43:45 UTC (rev 31515)
@@ -1,3 +1,22 @@
+/* AbiWord
+ * Copyright (C) 2012 Prashant Bafna ([email protected])
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
 #ifndef IE_MATH_CONVERT_H
 #define IE_MATH_CONVERT_H
 #endif
@@ -12,3 +31,5 @@
 ABI_EXPORT bool convertMathMLtoLaTeX(const UT_UTF8String & sMathML, UT_UTF8String & sLaTeX);

 ABI_EXPORT bool convertLaTeXtoEqn(const UT_UTF8String & sLaTeX,UT_UTF8String & eqnLaTeX);
+
+ABI_EXPORT bool convertOMMLtoMathML(const std::string & pOMML, std::string & pMathML);

-----------------------------------------------
To unsubscribe from this list, send a message to
[email protected] with the word
unsubscribe in the message body.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.