]> git.sur5r.net Git - glabels/blobdiff - glabels2/src/xml-label.c
2009-09-17 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / xml-label.c
index 0f8e104cc0ca861efcc927294c3bc362eaa36e1b..d1d53423d4dfd1850eba97375d4b7acf15a1b352 100644 (file)
@@ -1,25 +1,21 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
 /*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  label.c:  GLabels xml label module
+ *  xml-label.c
+ *  Copyright (C) 2001-2009  Jim Evins <evins@snaught.com>.
  *
- *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
+ *  This file is part of gLabels.
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  gLabels 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
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
+ *  gLabels 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
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <config.h>
 #include "xml-label.h"
 
 #include <glib/gi18n.h>
+#include <glib.h>
 #include <libxml/tree.h>
 #include <libxml/parser.h>
 #include <libxml/xinclude.h>
 #include <gdk-pixbuf/gdk-pixdata.h>
 
+#include <libglabels/libglabels.h>
 #include "label.h"
 #include "label-object.h"
 #include "label-text.h"
 #include "label-ellipse.h"
 #include "label-image.h"
 #include "label-barcode.h"
-#include "base64.h"
 #include "xml-label-04.h"
-#include <libglabels/db.h>
-#include <libglabels/xml-template.h>
-#include <libglabels/xml.h>
 #include "util.h"
 
 #include "debug.h"
 
+
 /*========================================================*/
 /* Private macros and constants.                          */
 /*========================================================*/
 #define COMPAT04_NAME_SPACE "http://snaught.com/glabels/0.4/"
 #define COMPAT20_NAME_SPACE "http://snaught.com/glabels/2.0/"
 
+
 /*========================================================*/
 /* Private types.                                         */
 /*========================================================*/
 
+
 /*========================================================*/
 /* Private globals.                                       */
 /*========================================================*/
 
+
 /*========================================================*/
 /* Private function prototypes.                           */
 /*========================================================*/
@@ -184,7 +182,7 @@ gl_xml_label_open (const gchar      *utf8_filename,
        filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
        g_return_val_if_fail (filename, NULL);
 
-       doc = xmlParseFile (filename);
+        doc = xmlReadFile (filename, NULL, XML_PARSE_HUGE);
        if (!doc) {
                g_message (_("xmlParseFile error"));
                *status = XML_LABEL_ERROR_OPEN_PARSE;
@@ -209,6 +207,7 @@ gl_xml_label_open (const gchar      *utf8_filename,
        return label;
 }
 
+
 /****************************************************************************/
 /* Read label from xml buffer.                                              */
 /****************************************************************************/
@@ -221,7 +220,7 @@ gl_xml_label_open_buffer (const gchar      *buffer,
 
        gl_debug (DEBUG_XML, "START");
 
-       doc = xmlParseDoc ((xmlChar *) buffer);
+        doc = xmlReadDoc ((xmlChar *) buffer, NULL, NULL, XML_PARSE_HUGE);
        if (!doc) {
                g_message (_("xmlParseFile error"));
                *status = XML_LABEL_ERROR_OPEN_PARSE;
@@ -241,6 +240,7 @@ gl_xml_label_open_buffer (const gchar      *buffer,
        return label;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse xml doc structure and create label.                      */
 /*--------------------------------------------------------------------------*/
@@ -300,6 +300,7 @@ xml_doc_to_label (xmlDocPtr         doc,
        return label;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse xml root node and create label.                          */
 /*--------------------------------------------------------------------------*/
@@ -367,6 +368,7 @@ xml_parse_label (xmlNodePtr        root,
        return label;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse Objects node.                                            */
 /*--------------------------------------------------------------------------*/
@@ -407,6 +409,7 @@ xml_parse_objects (xmlNodePtr  node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse XML Objects->Object-text Node                            */
 /*--------------------------------------------------------------------------*/
@@ -468,6 +471,7 @@ xml_parse_object_text (xmlNodePtr  node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse XML Objects->Object-box Node                             */
 /*--------------------------------------------------------------------------*/
@@ -534,6 +538,7 @@ xml_parse_object_box (xmlNodePtr  node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse XML Objects->Object-ellipse Node                         */
 /*--------------------------------------------------------------------------*/
@@ -600,6 +605,7 @@ xml_parse_object_ellipse (xmlNodePtr  node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse XML Objects->Object-line Node                            */
 /*--------------------------------------------------------------------------*/
@@ -652,6 +658,7 @@ xml_parse_object_line (xmlNodePtr  node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse XML Objects->Object-image Node                           */
 /*--------------------------------------------------------------------------*/
@@ -711,6 +718,7 @@ xml_parse_object_image (xmlNodePtr  node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse XML Objects->Object-barcode Node                         */
 /*--------------------------------------------------------------------------*/
@@ -793,6 +801,7 @@ xml_parse_object_barcode (xmlNodePtr  node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse XML merge fields tag.                                    */
 /*--------------------------------------------------------------------------*/
@@ -820,6 +829,7 @@ xml_parse_merge_fields (xmlNodePtr  node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse XML data tag.                                            */
 /*--------------------------------------------------------------------------*/
@@ -846,6 +856,7 @@ xml_parse_data (xmlNodePtr  node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse XML pixbuf data tag.                                     */
 /*--------------------------------------------------------------------------*/
@@ -855,7 +866,7 @@ xml_parse_pixdata (xmlNodePtr  node,
 {
        gchar      *name, *base64;
        guchar     *stream;
-       guint       stream_length;
+       gsize       stream_length;
        gboolean    ret;
        GdkPixdata *pixdata;
        GdkPixbuf  *pixbuf;
@@ -866,7 +877,7 @@ xml_parse_pixdata (xmlNodePtr  node,
        name = lgl_xml_get_prop_string (node, "name", NULL);
        base64 = lgl_xml_get_node_content (node);
 
-       stream = gl_base64_decode ((gchar *)base64, &stream_length);
+       stream = g_base64_decode ((gchar *)base64, &stream_length);
        pixdata = g_new0 (GdkPixdata, 1);
        ret = gdk_pixdata_deserialize (pixdata, stream_length, stream, NULL);
 
@@ -886,6 +897,7 @@ xml_parse_pixdata (xmlNodePtr  node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse top-level Span tag.                                      */
 /*--------------------------------------------------------------------------*/
@@ -995,6 +1007,7 @@ xml_parse_toplevel_span  (xmlNodePtr        node,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse affine attributes.                                       */
 /*--------------------------------------------------------------------------*/
@@ -1017,6 +1030,7 @@ xml_parse_affine_attrs (xmlNodePtr        node,
        gl_label_object_set_matrix (object, &matrix);
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Parse shadow attributes.                                       */
 /*--------------------------------------------------------------------------*/
@@ -1056,6 +1070,7 @@ xml_parse_shadow_attrs (xmlNodePtr        node,
        }
 }
 
+
 /****************************************************************************/
 /* Save label to xml label file.                                            */
 /****************************************************************************/
@@ -1096,6 +1111,7 @@ gl_xml_label_save (glLabel          *label,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /****************************************************************************/
 /* Save label to xml buffer.                                                */
 /****************************************************************************/
@@ -1121,6 +1137,7 @@ gl_xml_label_save_buffer (glLabel          *label,
        return (gchar *)buffer;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Convert label to xml doc structure.                            */
 /*--------------------------------------------------------------------------*/
@@ -1161,6 +1178,7 @@ xml_label_to_doc (glLabel          *label,
        return doc;
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Add XML Objects Node                                           */
 /*--------------------------------------------------------------------------*/
@@ -1204,6 +1222,7 @@ xml_create_objects (xmlNodePtr  root,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Add XML Objects->Object-text Node                              */
 /*--------------------------------------------------------------------------*/
@@ -1252,6 +1271,7 @@ xml_create_object_text (xmlNodePtr     root,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Add XML Objects->Object-box Node                               */
 /*--------------------------------------------------------------------------*/
@@ -1317,6 +1337,7 @@ xml_create_object_box (xmlNodePtr     root,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Add XML Objects->Object-ellipse Node                           */
 /*--------------------------------------------------------------------------*/
@@ -1383,6 +1404,7 @@ xml_create_object_ellipse (xmlNodePtr     root,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Add XML Objects->Object-line Node                              */
 /*--------------------------------------------------------------------------*/
@@ -1436,6 +1458,7 @@ xml_create_object_line (xmlNodePtr     root,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Add XML Objects->Object-image Node                             */
 /*--------------------------------------------------------------------------*/
@@ -1481,6 +1504,7 @@ xml_create_object_image (xmlNodePtr     root,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Add XML Objects->Object-barcode Node                           */
 /*--------------------------------------------------------------------------*/
@@ -1553,6 +1577,7 @@ xml_create_object_barcode (xmlNodePtr     root,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Add XML Label Merge Fields Node                                */
 /*--------------------------------------------------------------------------*/
@@ -1584,6 +1609,7 @@ xml_create_merge_fields (xmlNodePtr  root,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Add XML Label Data Node                                        */
 /*--------------------------------------------------------------------------*/
@@ -1613,6 +1639,7 @@ xml_create_data (xmlNodePtr  root,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Add XML Label Data Pixbuf Node                                 */
 /*--------------------------------------------------------------------------*/
@@ -1640,7 +1667,7 @@ xml_create_pixdata (xmlNodePtr  root,
                pixdata = g_new0 (GdkPixdata, 1);
                gdk_pixdata_from_pixbuf (pixdata, pixbuf, FALSE);
                stream = gdk_pixdata_serialize (pixdata, &stream_length);
-               base64 = gl_base64_encode (stream, stream_length);
+               base64 = g_base64_encode (stream, stream_length);
 
                node = xmlNewChild (root, ns, (xmlChar *)"Pixdata", (xmlChar *)base64);
                lgl_xml_set_prop_string (node, "name", name);
@@ -1657,6 +1684,7 @@ xml_create_pixdata (xmlNodePtr  root,
        gl_debug (DEBUG_XML, "END");
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Create top-level Span node.                                    */
 /*--------------------------------------------------------------------------*/
@@ -1733,6 +1761,7 @@ xml_create_toplevel_span (xmlNodePtr        root,
 
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Create affine attributes.                                      */
 /*--------------------------------------------------------------------------*/
@@ -1752,6 +1781,7 @@ xml_create_affine_attrs (xmlNodePtr        node,
        lgl_xml_set_prop_double (node, "a5", matrix.y0);
 }
 
+
 /*--------------------------------------------------------------------------*/
 /* PRIVATE.  Create shadow attributes.                                      */
 /*--------------------------------------------------------------------------*/
@@ -1792,3 +1822,12 @@ xml_create_shadow_attrs (xmlNodePtr        node,
 }
 
 
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */