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,
26 #include "libglabels-private.h"
32 #include "xml-paper.h"
34 /*===========================================*/
36 /*===========================================*/
38 /*===========================================*/
40 /*===========================================*/
42 /*===========================================*/
43 /* Local function prototypes */
44 /*===========================================*/
47 /*****************************************************************************/
48 /* Read papers from paper file. */
49 /*****************************************************************************/
51 gl_xml_paper_read_papers_from_file (gchar *utf8_filename)
59 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
61 g_warning ("Utf8 filename conversion error");
65 papers_doc = xmlParseFile (filename);
67 g_warning ("\"%s\" is not a glabels paper file (not XML)",
72 papers = gl_xml_paper_parse_papers_doc (papers_doc);
75 xmlFreeDoc (papers_doc);
80 /*****************************************************************************/
81 /* Read papers from paper xml doc tree. */
82 /*****************************************************************************/
84 gl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc)
87 xmlNodePtr root, node;
92 root = xmlDocGetRootElement (papers_doc);
93 if (!root || !root->name) {
94 g_warning ("\"%s\" is not a glabels paper file (no root node)",
96 xmlFreeDoc (papers_doc);
99 if (!xmlStrEqual (root->name, "Glabels-paper-sizes")) {
100 g_warning ("\"%s\" is not a glabels paper file (wrong root node)",
102 xmlFreeDoc (papers_doc);
106 for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
108 if (xmlStrEqual (node->name, "Paper-size")) {
109 paper = gl_xml_paper_parse_paper_node (node);
110 papers = g_list_append (papers, paper);
112 if ( !xmlNodeIsText(node) ) {
113 if (!xmlStrEqual (node->name,"comment")) {
114 g_warning ("bad node = \"%s\"",node->name);
123 /*****************************************************************************/
124 /* Parse XML paper Node. */
125 /*****************************************************************************/
127 gl_xml_paper_parse_paper_node (xmlNodePtr paper_node)
131 gdouble width, height;
135 id = xmlGetProp (paper_node, "id");
137 name = xmlGetProp (paper_node, "_name");
139 name = gettext (name);
141 name = xmlGetProp (paper_node, "name");
144 width = gl_xml_get_prop_length (paper_node, "width", 0);
145 height = gl_xml_get_prop_length (paper_node, "height", 0);
147 paper = gl_paper_new (id, name, width, height);