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 "xml-paper.h"
29 #include <glib/gi18n.h>
30 #include <glib/gmessages.h>
34 #include "libglabels-private.h"
38 /*===========================================*/
40 /*===========================================*/
42 /*===========================================*/
44 /*===========================================*/
46 /*===========================================*/
47 /* Local function prototypes */
48 /*===========================================*/
52 * lgl_xml_paper_read_papers_from_file:
53 * @utf8_filename: Filename of papers file (name encoded as UTF-8)
55 * Read paper definitions from a file.
57 * Returns: a list of #lglPaper structures.
61 lgl_xml_paper_read_papers_from_file (gchar *utf8_filename)
69 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
71 g_message ("Utf8 filename conversion error");
75 papers_doc = xmlParseFile (filename);
77 g_message ("\"%s\" is not a glabels paper file (not XML)",
82 papers = lgl_xml_paper_parse_papers_doc (papers_doc);
85 xmlFreeDoc (papers_doc);
92 * lgl_xml_paper_parse_papers_doc:
93 * @papers_doc: libxml #xmlDocPtr tree, representing a papers definition file.
95 * Read paper definitions from a libxml #xmlDocPtr tree.
97 * Returns: a list of #lglPaper structures.
101 lgl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc)
103 GList *papers = NULL;
104 xmlNodePtr root, node;
109 root = xmlDocGetRootElement (papers_doc);
110 if (!root || !root->name) {
111 g_message ("\"%s\" is not a glabels paper file (no root node)",
113 xmlFreeDoc (papers_doc);
116 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) {
125 if (lgl_xml_is_node (node, "Paper-size")) {
126 paper = lgl_xml_paper_parse_paper_node (node);
127 papers = g_list_append (papers, paper);
129 if ( !xmlNodeIsText(node) ) {
130 if (!lgl_xml_is_node (node, "comment")) {
131 g_message ("bad node = \"%s\"",node->name);
142 * lgl_xml_paper_parse_paper_node:
143 * @paper_node: libxml #xmlNodePtr paper node from a #xmlDocPtr tree.
145 * Read a single paper definition from a libxml #xmlNodePtr node.
147 * Returns: a pointer to a newly created #lglPaper structure.
151 lgl_xml_paper_parse_paper_node (xmlNodePtr paper_node)
155 gdouble width, height;
159 id = lgl_xml_get_prop_string (paper_node, "id", NULL);
161 name = lgl_xml_get_prop_i18n_string (paper_node, "name", NULL);
163 width = lgl_xml_get_prop_length (paper_node, "width", 0);
164 height = lgl_xml_get_prop_length (paper_node, "height", 0);
166 paper = lgl_paper_new (id, name, width, height);