2 * (LIBGLABELS) Template library for GLABELS
4 * xml-paper.c: paper xml module
6 * Copyright (C) 2003, 2004 Jim Evins <evins@snaught.com>.
8 * This file is part of the LIBGLABELS library.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the Free
22 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 #include <glib/gi18n.h>
31 #include "libglabels-private.h"
34 #include "xml-paper.h"
36 /*===========================================*/
38 /*===========================================*/
40 /*===========================================*/
42 /*===========================================*/
44 /*===========================================*/
45 /* Local function prototypes */
46 /*===========================================*/
49 /*****************************************************************************/
50 /* Read papers from paper file. */
51 /*****************************************************************************/
53 gl_xml_paper_read_papers_from_file (gchar *utf8_filename)
61 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
63 g_warning ("Utf8 filename conversion error");
67 papers_doc = xmlParseFile (filename);
69 g_warning ("\"%s\" is not a glabels paper file (not XML)",
74 papers = gl_xml_paper_parse_papers_doc (papers_doc);
77 xmlFreeDoc (papers_doc);
82 /*****************************************************************************/
83 /* Read papers from paper xml doc tree. */
84 /*****************************************************************************/
86 gl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc)
89 xmlNodePtr root, node;
94 root = xmlDocGetRootElement (papers_doc);
95 if (!root || !root->name) {
96 g_warning ("\"%s\" is not a glabels paper file (no root node)",
98 xmlFreeDoc (papers_doc);
101 if (!xmlStrEqual (root->name, "Glabels-paper-sizes")) {
102 g_warning ("\"%s\" is not a glabels paper file (wrong root node)",
104 xmlFreeDoc (papers_doc);
108 for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
110 if (xmlStrEqual (node->name, "Paper-size")) {
111 paper = gl_xml_paper_parse_paper_node (node);
112 papers = g_list_append (papers, paper);
114 if ( !xmlNodeIsText(node) ) {
115 if (!xmlStrEqual (node->name,"comment")) {
116 g_warning ("bad node = \"%s\"",node->name);
125 /*****************************************************************************/
126 /* Parse XML paper Node. */
127 /*****************************************************************************/
129 gl_xml_paper_parse_paper_node (xmlNodePtr paper_node)
133 gdouble width, height;
137 id = xmlGetProp (paper_node, "id");
139 name = xmlGetProp (paper_node, "_name");
142 gchar *tmp = gettext (name);
146 name = g_strdup (tmp);
150 name = xmlGetProp (paper_node, "name");
153 width = gl_xml_get_prop_length (paper_node, "width", 0);
154 height = gl_xml_get_prop_length (paper_node, "height", 0);
156 paper = gl_paper_new (id, name, width, height);