[lasem] itex: export new functions for itex to matml conversion.



commit c646b41c48fbb7c5aaafbc7bba8af56ba9cb838b
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Sun Mar 24 16:43:42 2013 +0100

    itex: export new functions for itex to matml conversion.
    
    These are just wrappers around itex2MML_parse and itex2MML_free_string.

 docs/reference/lasem/Makefile.am |    1 +
 src/Makefile.am                  |    2 +
 src/lsm.h                        |    1 +
 src/lsmitex.c                    |   76 ++++++++++++++++++++++++++++++++++++++
 src/lsmitex.h                    |   36 ++++++++++++++++++
 src/lsmmathmldocument.c          |   12 ++---
 6 files changed, 121 insertions(+), 7 deletions(-)
---
diff --git a/docs/reference/lasem/Makefile.am b/docs/reference/lasem/Makefile.am
index 05b8a8f..aa7a367 100644
--- a/docs/reference/lasem/Makefile.am
+++ b/docs/reference/lasem/Makefile.am
@@ -72,6 +72,7 @@ IGNORE_HFILES=\
        lsmtraits.h                             \
        lsmproperties.h                         \
        lsmattributes.h                         \
+       lsmitex.h                               \
        lsmmathml.h                             \
        lsmmathmltypes.h                        \
        lsmmathmlenums.h                        \
diff --git a/src/Makefile.am b/src/Makefile.am
index c534788..f65ec10 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,6 +37,7 @@ LASEM_DOM_SRCS =                              \
        lsmproperties.c                         \
        lsmattributes.c                         \
        lsmcairo.c                              \
+       lsmitex.c                               \
        lsmdomentities.c                        \
        lsmdomnode.c                            \
        lsmdomnodelist.c                        \
@@ -152,6 +153,7 @@ LASEM_DOM_HDRS =                            \
        lsmtraits.h                             \
        lsmproperties.h                         \
        lsmattributes.h                         \
+       lsmitex.h                               \
        lsmdomentities.h                        \
        lsmdom.h                                \
        lsmdomtypes.h                           \
diff --git a/src/lsm.h b/src/lsm.h
index 7d3156c..803d2b2 100644
--- a/src/lsm.h
+++ b/src/lsm.h
@@ -32,6 +32,7 @@
 #include <lsmtraits.h>
 #include <lsmattributes.h>
 #include <lsmproperties.h>
+#include <lsmitex.h>
 
 void lsm_shutdown (void);
 
diff --git a/src/lsmitex.c b/src/lsmitex.c
new file mode 100644
index 0000000..24a3c7c
--- /dev/null
+++ b/src/lsmitex.c
@@ -0,0 +1,76 @@
+/* Lasem - SVG and Mathml library
+ *
+ * Copyright © 2013 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author:
+ *     Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#include <lsmitex.h>
+#include <string.h>
+#include <../itex2mml/itex2MML.h>
+
+/**
+ * lsm_itex_to_mathml:
+ * @itex: (allow-none): an itex string
+ * @size: itex string length, -1 if unknown
+ *
+ * Converts an itex string to a Mathml representation.
+ *
+ * Return value: a newly allocated string, NULL on parse error. The returned data must be freed using 
@lsm_itex_free_mathml_buffer.
+ */
+
+char *
+lsm_itex_to_mathml (const char *itex, int size)
+{
+       char *mathml;
+
+       if (itex == NULL)
+               return NULL;
+
+       if (size < 0)
+               size = strlen (itex);
+
+       mathml = itex2MML_parse (itex, size);
+       if (mathml == NULL)
+               return NULL;
+
+       if (mathml[0] == '\0') {
+               itex2MML_free_string (mathml);
+               return NULL;
+       }
+
+       return mathml;
+}
+
+/**
+ * lsm_itex_free_mathml_buffer:
+ * @mathml: (allow-none): a mathml buffer
+ *
+ * Free the buffer returned by @lsm_itex_to_mathml.
+ */
+
+void
+lsm_itex_free_mathml_buffer (char *mathml)
+{
+       if (mathml == NULL)
+               return;
+
+       itex2MML_free_string (mathml);
+}
+
diff --git a/src/lsmitex.h b/src/lsmitex.h
new file mode 100644
index 0000000..0386d6d
--- /dev/null
+++ b/src/lsmitex.h
@@ -0,0 +1,36 @@
+/* Lasem - SVG and Mathml library
+ *
+ * Copyright © 2013 Emmanuel Pacaud
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author:
+ *     Emmanuel Pacaud <emmanuel gnome org>
+ */
+
+#ifndef LSM_ITEX_H
+#define LSM_ITEX_H
+
+#include <lsmtypes.h>
+
+G_BEGIN_DECLS
+
+char *         lsm_itex_to_mathml              (const char *itex, int size);
+void           lsm_itex_free_mathml_buffer     (char *mathml);
+
+G_END_DECLS
+
+#endif
diff --git a/src/lsmmathmldocument.c b/src/lsmmathmldocument.c
index 8f84498..8a9525d 100644
--- a/src/lsmmathmldocument.c
+++ b/src/lsmmathmldocument.c
@@ -216,13 +216,11 @@ LsmMathmlDocument *
 lsm_mathml_document_new_from_itex (const char *itex, int size, GError **error)
 {
        LsmDomDocument *document;
-       char *xml;
+       char *mathml;
 
-       g_return_val_if_fail (itex != NULL, NULL);
+       mathml = lsm_itex_to_mathml (itex, size);
 
-       xml = itex2MML_parse (itex, size);
-
-       if (xml == NULL) {
+       if (mathml == NULL) {
                lsm_debug_dom ("[LsmMathmlDocument::new_from_itex] Invalid document");
 
                g_set_error (error,
@@ -233,9 +231,9 @@ lsm_mathml_document_new_from_itex (const char *itex, int size, GError **error)
                return NULL;
        }
 
-       document = lsm_dom_document_new_from_memory (xml, -1, error);
+       document = lsm_dom_document_new_from_memory (mathml, -1, error);
 
-       itex2MML_free_string (xml);
+       lsm_itex_free_mathml_buffer (mathml);
 
        if (document == NULL)
                return NULL;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]