3 * Copyright (C) 2003-2009 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 "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);
67 g_message ("Utf8 filename conversion error");
71 papers_doc = xmlParseFile (filename);
73 g_message ("\"%s\" is not a glabels paper file (not XML)",
78 papers = lgl_xml_paper_parse_papers_doc (papers_doc);
81 xmlFreeDoc (papers_doc);
88 * lgl_xml_paper_parse_papers_doc:
89 * @papers_doc: libxml #xmlDocPtr tree, representing a papers definition file.
91 * Read paper definitions from a libxml #xmlDocPtr tree.
93 * Returns: a list of #lglPaper structures.
97 lgl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc)
100 xmlNodePtr root, node;
105 root = xmlDocGetRootElement (papers_doc);
106 if (!root || !root->name) {
107 g_message ("\"%s\" is not a glabels paper file (no root node)",
109 xmlFreeDoc (papers_doc);
112 if (!lgl_xml_is_node (root, "Glabels-paper-sizes")) {
113 g_message ("\"%s\" is not a glabels paper file (wrong root node)",
115 xmlFreeDoc (papers_doc);
119 for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
121 if (lgl_xml_is_node (node, "Paper-size")) {
122 paper = lgl_xml_paper_parse_paper_node (node);
123 papers = g_list_append (papers, paper);
125 if ( !xmlNodeIsText(node) ) {
126 if (!lgl_xml_is_node (node, "comment")) {
127 g_message ("bad node = \"%s\"",node->name);
138 * lgl_xml_paper_parse_paper_node:
139 * @paper_node: libxml #xmlNodePtr paper node from a #xmlDocPtr tree.
141 * Read a single paper definition from a libxml #xmlNodePtr node.
143 * Returns: a pointer to a newly created #lglPaper structure.
147 lgl_xml_paper_parse_paper_node (xmlNodePtr paper_node)
150 gchar *id, *name, *pwg_size;
151 gdouble width, height;
155 id = lgl_xml_get_prop_string (paper_node, "id", NULL);
157 name = lgl_xml_get_prop_i18n_string (paper_node, "name", NULL);
159 width = lgl_xml_get_prop_length (paper_node, "width", 0);
160 height = lgl_xml_get_prop_length (paper_node, "height", 0);
162 pwg_size = lgl_xml_get_prop_string (paper_node, "pwg_size", NULL);
164 paper = lgl_paper_new (id, name, width, height, pwg_size);
176 * Local Variables: -- emacs
178 * c-basic-offset: 8 -- emacs
179 * tab-width: 8 -- emacs
180 * indent-tabs-mode: nil -- emacs