3 * Copyright (C) 2003-2010 Jim Evins <evins@snaught.com>.
5 * This file is part of libglabels.
7 * libglabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * libglabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with libglabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "lgl-xml-paper.h"
25 #include <glib/gi18n.h>
30 #include "libglabels-private.h"
34 /*===========================================*/
36 /*===========================================*/
38 /*===========================================*/
40 /*===========================================*/
42 /*===========================================*/
43 /* Local function prototypes */
44 /*===========================================*/
48 * lgl_xml_paper_read_papers_from_file:
49 * @utf8_filename: Filename of papers file (name encoded as UTF-8)
51 * Read paper definitions from a file.
53 * Returns: a list of #lglPaper structures.
57 lgl_xml_paper_read_papers_from_file (gchar *utf8_filename)
65 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
68 g_message ("Utf8 filename conversion error");
72 papers_doc = xmlParseFile (filename);
75 g_message ("\"%s\" is not a glabels paper file (not XML)",
80 papers = lgl_xml_paper_parse_papers_doc (papers_doc);
83 xmlFreeDoc (papers_doc);
90 * lgl_xml_paper_parse_papers_doc:
91 * @papers_doc: libxml #xmlDocPtr tree, representing a papers definition file.
93 * Read paper definitions from a libxml #xmlDocPtr tree.
95 * Returns: a list of #lglPaper structures.
99 lgl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc)
101 GList *papers = NULL;
102 xmlNodePtr root, node;
107 root = xmlDocGetRootElement (papers_doc);
108 if (!root || !root->name)
110 g_message ("\"%s\" is not a glabels paper file (no root node)",
112 xmlFreeDoc (papers_doc);
115 if (!lgl_xml_is_node (root, "Glabels-paper-sizes"))
117 g_message ("\"%s\" is not a glabels paper file (wrong root node)",
119 xmlFreeDoc (papers_doc);
123 for (node = root->xmlChildrenNode; node != NULL; node = node->next)
126 if (lgl_xml_is_node (node, "Paper-size"))
128 paper = lgl_xml_paper_parse_paper_node (node);
129 papers = g_list_append (papers, paper);
133 if ( !xmlNodeIsText(node) )
135 if (!lgl_xml_is_node (node, "comment"))
137 g_message ("bad node = \"%s\"",node->name);
148 * lgl_xml_paper_parse_paper_node:
149 * @paper_node: libxml #xmlNodePtr paper node from a #xmlDocPtr tree.
151 * Read a single paper definition from a libxml #xmlNodePtr node.
153 * Returns: a pointer to a newly created #lglPaper structure.
157 lgl_xml_paper_parse_paper_node (xmlNodePtr paper_node)
160 gchar *id, *name, *pwg_size;
161 gdouble width, height;
165 id = lgl_xml_get_prop_string (paper_node, "id", NULL);
167 name = lgl_xml_get_prop_i18n_string (paper_node, "name", NULL);
169 width = lgl_xml_get_prop_length (paper_node, "width", 0);
170 height = lgl_xml_get_prop_length (paper_node, "height", 0);
172 pwg_size = lgl_xml_get_prop_string (paper_node, "pwg_size", NULL);
174 paper = lgl_paper_new (id, name, width, height, pwg_size);
186 * Local Variables: -- emacs
188 * c-basic-offset: 8 -- emacs
189 * tab-width: 8 -- emacs
190 * indent-tabs-mode: nil -- emacs