2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * label.c: GLabels xml label module
6 * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <libxml/tree.h>
28 #include <libxml/parser.h>
31 #include "label-object.h"
32 #include "label-text.h"
33 #include "label-box.h"
34 #include "label-line.h"
35 #include "label-ellipse.h"
36 #include "label-image.h"
37 #include "label-barcode.h"
39 #include "xml-label.h"
40 #include "xml-label-04.h"
45 /*========================================================*/
46 /* Private macros and constants. */
47 /*========================================================*/
48 #define NAME_SPACE "http://snaught.com/glabels/1.90/"
49 #define COMPAT01_NAME_SPACE "http://snaught.com/glabels/0.1/"
50 #define COMPAT04_NAME_SPACE "http://snaught.com/glabels/0.4/"
52 /*========================================================*/
54 /*========================================================*/
56 /*========================================================*/
57 /* Private globals. */
58 /*========================================================*/
60 /*========================================================*/
61 /* Private function prototypes. */
62 /*========================================================*/
64 static glLabel *xml_doc_to_label (xmlDocPtr doc, glXMLLabelStatus *status);
65 static glLabel *xml_parse_label (xmlNodePtr root, glXMLLabelStatus *status);
66 static void xml_parse_objects (xmlNodePtr node, glLabel * label);
67 static void xml_parse_object(xmlNodePtr node, glLabel *label);
68 static glLabelObject *xml_parse_text_props (xmlNodePtr node, glLabel *label);
69 static glLabelObject *xml_parse_box_props (xmlNodePtr node, glLabel *label);
70 static glLabelObject *xml_parse_line_props (xmlNodePtr node, glLabel *label);
71 static glLabelObject *xml_parse_ellipse_props (xmlNodePtr node, glLabel *label);
72 static glLabelObject *xml_parse_image_props (xmlNodePtr node, glLabel *label);
73 static glLabelObject *xml_parse_barcode_props (xmlNodePtr node, glLabel *label);
74 static void xml_parse_merge_fields (xmlNodePtr node, glLabel *label);
76 static xmlDocPtr xml_label_to_doc (glLabel * label, glXMLLabelStatus *status);
77 static void xml_create_objects (xmlNodePtr root, xmlNsPtr ns, glLabel * label);
78 static void xml_create_object (xmlNodePtr root, xmlNsPtr ns,
79 glLabelObject * object);
80 static void xml_create_text_props (xmlNodePtr root, xmlNsPtr ns,
81 glLabelObject * object);
82 static void xml_create_box_props (xmlNodePtr root, xmlNsPtr ns,
83 glLabelObject * object);
84 static void xml_create_line_props (xmlNodePtr root, xmlNsPtr ns,
85 glLabelObject * object);
86 static void xml_create_ellipse_props (xmlNodePtr root, xmlNsPtr ns,
87 glLabelObject * object);
88 static void xml_create_image_props (xmlNodePtr root, xmlNsPtr ns,
89 glLabelObject * object);
90 static void xml_create_barcode_props (xmlNodePtr root, xmlNsPtr ns,
91 glLabelObject * object);
92 static void xml_create_merge_fields (xmlNodePtr root, xmlNsPtr ns,
95 /****************************************************************************/
96 /* Open and read label from xml file. */
97 /****************************************************************************/
99 gl_xml_label_open (const gchar * filename,
100 glXMLLabelStatus *status)
105 gl_debug (DEBUG_XML, "START");
107 doc = xmlParseFile (filename);
109 g_warning (_("xmlParseFile error"));
110 *status = XML_LABEL_ERROR_OPEN_PARSE;
114 label = xml_doc_to_label (doc, status);
118 gl_label_set_filename (label, filename);
119 gl_label_clear_modified (label);
121 gl_debug (DEBUG_XML, "END");
126 /****************************************************************************/
127 /* Read label from xml buffer. */
128 /****************************************************************************/
130 gl_xml_label_open_buffer (const gchar * buffer,
131 glXMLLabelStatus *status)
136 gl_debug (DEBUG_XML, "START");
138 doc = xmlParseDoc ((xmlChar *) buffer);
140 g_warning (_("xmlParseFile error"));
141 *status = XML_LABEL_ERROR_OPEN_PARSE;
145 label = xml_doc_to_label (doc, status);
147 gl_label_clear_modified (label);
151 gl_debug (DEBUG_XML, "END");
156 /*--------------------------------------------------------------------------*/
157 /* PRIVATE. Parse xml doc structure and create label. */
158 /*--------------------------------------------------------------------------*/
160 xml_doc_to_label (xmlDocPtr doc,
161 glXMLLabelStatus *status)
163 xmlNodePtr root, node;
167 gl_debug (DEBUG_XML, "START");
171 *status = XML_LABEL_OK;
173 root = xmlDocGetRootElement (doc);
174 if (!root || !root->name) {
175 g_warning (_("No document root"));
176 *status = XML_LABEL_ERROR_OPEN_PARSE;
180 ns = xmlSearchNsByHref (doc, root, NAME_SPACE);
182 label = xml_parse_label (root, status);
184 /* Try compatability mode 0.1 */
185 ns = xmlSearchNsByHref (doc, root, COMPAT01_NAME_SPACE);
187 g_warning (_("Importing from glabels 0.1 format"));
189 label = NULL; /* TODO */
191 /* Try compatability mode 0.4 */
192 ns = xmlSearchNsByHref (doc, root,
193 COMPAT04_NAME_SPACE);
195 g_warning (_("Importing from glabels 0.4 format"));
196 label = gl_xml_label_04_parse (root, status);
198 g_warning (_("bad document, unknown glabels Namespace"));
199 *status = XML_LABEL_ERROR_OPEN_PARSE;
205 gl_debug (DEBUG_XML, "END");
210 /*--------------------------------------------------------------------------*/
211 /* PRIVATE. Parse xml root node and create label. */
212 /*--------------------------------------------------------------------------*/
214 xml_parse_label (xmlNodePtr root,
215 glXMLLabelStatus *status)
219 glTemplate *template;
221 gl_debug (DEBUG_XML, "START");
223 *status = XML_LABEL_OK;
225 if (g_strcasecmp (root->name, "Document") != 0) {
226 g_warning (_("Bad root node = \"%s\""), root->name);
227 *status = XML_LABEL_ERROR_OPEN_PARSE;
231 label = GL_LABEL(gl_label_new ());
233 for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
235 if (g_strcasecmp (node->name, "Sheet") == 0) {
236 template = gl_template_xml_parse_sheet (node);
238 *status = XML_LABEL_UNKNOWN_MEDIA;
241 gl_label_set_template (label, template);
242 gl_template_free (&template);
243 } else if (g_strcasecmp (node->name, "Objects") == 0) {
244 xml_parse_objects (node, label);
245 } else if (g_strcasecmp (node->name, "Merge_Fields") == 0) {
246 xml_parse_merge_fields (node, label);
248 if (!xmlNodeIsText (node)) {
249 g_warning (_("bad node = \"%s\""), node->name);
254 gl_debug (DEBUG_XML, "END");
259 /*--------------------------------------------------------------------------*/
260 /* PRIVATE. Parse Objects node. */
261 /*--------------------------------------------------------------------------*/
263 xml_parse_objects (xmlNodePtr objects_node,
266 gboolean rotate_flag;
269 gl_debug (DEBUG_XML, "START");
272 !(g_strcasecmp (xmlGetProp (objects_node, "rotate"), "false") == 0);
273 gl_label_set_rotate_flag (label, rotate_flag);
275 for (node = objects_node->xmlChildrenNode; node != NULL; node = node->next) {
277 if (g_strcasecmp (node->name, "Object") == 0) {
278 xml_parse_object (node, label);
280 if (!xmlNodeIsText (node)) {
281 g_warning (_("bad node = \"%s\""), node->name);
286 gl_debug (DEBUG_XML, "END");
289 /*--------------------------------------------------------------------------*/
290 /* PRIVATE. Parse XML Object Node */
291 /*--------------------------------------------------------------------------*/
293 xml_parse_object (xmlNodePtr object_node,
296 glLabelObject *object;
301 gl_debug (DEBUG_XML, "START");
303 type_string = xmlGetProp (object_node, "type");
305 if ( g_strcasecmp (type_string, "text") == 0 ) {
306 object = xml_parse_text_props (object_node, label);
307 } else if ( g_strcasecmp (type_string, "box") == 0 ) {
308 object = xml_parse_box_props (object_node, label);
309 } else if ( g_strcasecmp (type_string, "line") == 0 ) {
310 object = xml_parse_line_props (object_node, label);
311 } else if ( g_strcasecmp (type_string, "ellipse") == 0 ) {
312 object = xml_parse_ellipse_props (object_node, label);
313 } else if ( g_strcasecmp (type_string, "image") == 0 ) {
314 object = xml_parse_image_props (object_node, label);
315 } else if ( g_strcasecmp (type_string, "barcode") == 0 ) {
316 object = xml_parse_barcode_props (object_node, label);
318 g_warning ("Unknown label object type \"%s\"", type_string);
322 x = g_strtod (xmlGetProp (object_node, "x"), NULL);
323 y = g_strtod (xmlGetProp (object_node, "y"), NULL);
325 gl_label_object_set_position (object, x, y);
327 affine[0] = g_strtod (xmlGetProp (object_node, "a0"), NULL);
328 affine[1] = g_strtod (xmlGetProp (object_node, "a1"), NULL);
329 affine[2] = g_strtod (xmlGetProp (object_node, "a2"), NULL);
330 affine[3] = g_strtod (xmlGetProp (object_node, "a3"), NULL);
331 affine[4] = g_strtod (xmlGetProp (object_node, "a4"), NULL);
332 affine[5] = g_strtod (xmlGetProp (object_node, "a5"), NULL);
334 gl_label_object_set_affine (object, affine);
336 gl_debug (DEBUG_XML, "END");
339 /*--------------------------------------------------------------------------*/
340 /* PRIVATE. Parse XML Label->Text Node Properties */
341 /*--------------------------------------------------------------------------*/
342 static glLabelObject *
343 xml_parse_text_props (xmlNodePtr object_node,
350 GnomeFontWeight font_weight;
351 gboolean font_italic_flag;
353 GtkJustification just;
354 xmlNodePtr line_node, text_node;
355 glTextNode *node_text;
358 gl_debug (DEBUG_XML, "START");
360 object = gl_label_text_new (label);
362 font_family = xmlGetProp (object_node, "font_family");
363 font_size = g_strtod (xmlGetProp (object_node, "font_size"), NULL);
364 font_weight = gl_util_string_to_weight (xmlGetProp (object_node,
367 !(g_strcasecmp (xmlGetProp (object_node, "font_italic"), "false") ==
370 just = gl_util_string_to_just (xmlGetProp (object_node, "justify"));
372 sscanf (xmlGetProp (object_node, "color"), "%x", &color);
375 for (line_node = object_node->xmlChildrenNode;
377 line_node = line_node->next) {
379 if (g_strcasecmp (line_node->name, "Line") == 0) {
382 for (text_node = line_node->xmlChildrenNode;
383 text_node != NULL; text_node = text_node->next) {
385 if (g_strcasecmp (text_node->name, "Field") ==
387 node_text = g_new0 (glTextNode, 1);
388 node_text->field_flag = TRUE;
390 xmlGetProp (text_node, "name");
392 g_list_append (nodes, node_text);
393 } else if (xmlNodeIsText (text_node)) {
394 node_text = g_new0 (glTextNode, 1);
395 node_text->field_flag = FALSE;
397 xmlNodeGetContent (text_node);
399 g_list_append (nodes, node_text);
401 g_warning ("Unexpected Text Line child: \"%s\"",
406 lines = g_list_append (lines, nodes);
408 } else if (!xmlNodeIsText (line_node)) {
409 g_warning ("Unexpected Text child: \"%s\"",
415 gl_label_text_set_lines (GL_LABEL_TEXT(object), lines);
416 gl_label_text_set_props (GL_LABEL_TEXT(object),
417 font_family, font_size, font_weight,
421 gl_text_node_lines_free (&lines);
422 g_free (font_family);
424 gl_debug (DEBUG_XML, "END");
426 return GL_LABEL_OBJECT(object);
429 /*--------------------------------------------------------------------------*/
430 /* PRIVATE. Parse XML Label->Box Node Properties */
431 /*--------------------------------------------------------------------------*/
432 static glLabelObject *
433 xml_parse_box_props (xmlNodePtr node,
438 guint line_color, fill_color;
441 gl_debug (DEBUG_XML, "START");
443 object = gl_label_box_new (label);
445 w = g_strtod (xmlGetProp (node, "w"), NULL);
446 h = g_strtod (xmlGetProp (node, "h"), NULL);
448 line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
450 sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
451 sscanf (xmlGetProp (node, "fill_color"), "%x", &fill_color);
453 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
454 gl_label_box_set_line_width (GL_LABEL_BOX(object), line_width);
455 gl_label_box_set_line_color (GL_LABEL_BOX(object), line_color);
456 gl_label_box_set_fill_color (GL_LABEL_BOX(object), fill_color);
458 gl_debug (DEBUG_XML, "END");
460 return GL_LABEL_OBJECT(object);
463 /*--------------------------------------------------------------------------*/
464 /* PRIVATE. Parse XML Label->Line Node Properties */
465 /*--------------------------------------------------------------------------*/
466 static glLabelObject *
467 xml_parse_line_props (xmlNodePtr node,
475 gl_debug (DEBUG_XML, "START");
477 object = gl_label_line_new (label);
479 w = g_strtod (xmlGetProp (node, "dx"), NULL);
480 h = g_strtod (xmlGetProp (node, "dy"), NULL);
482 line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
484 sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
486 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
487 gl_label_line_set_line_width (GL_LABEL_LINE(object), line_width);
488 gl_label_line_set_line_color (GL_LABEL_LINE(object), line_color);
490 gl_debug (DEBUG_XML, "END");
492 return GL_LABEL_OBJECT(object);
495 /*--------------------------------------------------------------------------*/
496 /* PRIVATE. Parse XML Label->Ellipse Node Properties */
497 /*--------------------------------------------------------------------------*/
498 static glLabelObject *
499 xml_parse_ellipse_props (xmlNodePtr node,
504 guint line_color, fill_color;
507 gl_debug (DEBUG_XML, "START");
509 object = gl_label_ellipse_new (label);
511 w = g_strtod (xmlGetProp (node, "w"), NULL);
512 h = g_strtod (xmlGetProp (node, "h"), NULL);
514 line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
516 sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
517 sscanf (xmlGetProp (node, "fill_color"), "%x", &fill_color);
519 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
520 gl_label_ellipse_set_line_width (GL_LABEL_ELLIPSE(object), line_width);
521 gl_label_ellipse_set_line_color (GL_LABEL_ELLIPSE(object), line_color);
522 gl_label_ellipse_set_fill_color (GL_LABEL_ELLIPSE(object), fill_color);
524 gl_debug (DEBUG_XML, "END");
526 return GL_LABEL_OBJECT(object);
529 /*--------------------------------------------------------------------------*/
530 /* PRIVATE. Parse XML Label->Image Node Properties */
531 /*--------------------------------------------------------------------------*/
532 static glLabelObject *
533 xml_parse_image_props (xmlNodePtr node,
540 gl_debug (DEBUG_XML, "START");
542 object = gl_label_image_new (label);
544 w = g_strtod (xmlGetProp (node, "w"), NULL);
545 h = g_strtod (xmlGetProp (node, "h"), NULL);
547 filename = xmlNodeGetContent (node);
549 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
550 gl_label_image_set_filename (GL_LABEL_IMAGE(object), filename);
554 gl_debug (DEBUG_XML, "END");
556 return GL_LABEL_OBJECT(object);
559 /*--------------------------------------------------------------------------*/
560 /* PRIVATE. Parse XML Label->Barcode Node Properties */
561 /*--------------------------------------------------------------------------*/
562 static glLabelObject *
563 xml_parse_barcode_props (xmlNodePtr node,
568 glTextNode *text_node;
569 glBarcodeStyle style;
574 gl_debug (DEBUG_XML, "START");
576 object = gl_label_barcode_new (label);
578 sscanf (xmlGetProp (node, "color"), "%x", &color);
580 style = gl_barcode_text_to_style (xmlGetProp (node, "style"));
581 text_flag = !(g_strcasecmp (xmlGetProp (node, "text"), "false") == 0);
582 scale = g_strtod (xmlGetProp (node, "scale"), NULL);
584 child = node->xmlChildrenNode;
585 text_node = g_new0 (glTextNode, 1);
586 if (g_strcasecmp (child->name, "Field") == 0) {
587 text_node->field_flag = TRUE;
588 text_node->data = xmlGetProp (child, "name");
589 } else if (xmlNodeIsText (child)) {
590 text_node->field_flag = FALSE;
591 text_node->data = xmlNodeGetContent (child);
593 g_warning ("Unexpected Barcode child: \"%s\"", child->name);
596 gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
597 gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
598 style, text_flag, color, scale);
600 gl_text_node_free (&text_node);
602 gl_debug (DEBUG_XML, "END");
604 return GL_LABEL_OBJECT(object);
607 /*--------------------------------------------------------------------------*/
608 /* PRIVATE. Parse XML merge fields tag. */
609 /*--------------------------------------------------------------------------*/
611 xml_parse_merge_fields (xmlNodePtr node,
616 glMergeFieldDefinition *field_def;
618 gl_debug (DEBUG_XML, "START");
620 merge = gl_merge_new ();
622 merge->type = gl_merge_text_to_type (xmlGetProp (node, "type"));
623 merge->src = xmlGetProp (node, "src");
625 for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
627 if (g_strcasecmp (child->name, "Field") == 0) {
628 field_def = g_new0 (glMergeFieldDefinition, 1);
629 field_def->key = xmlGetProp (child, "key");
630 field_def->loc = xmlGetProp (child, "loc");
632 g_list_append (merge->field_defs,
634 } else if (!xmlNodeIsText (child)) {
635 g_warning ("Unexpected Merge_Fields child: \"%s\"",
641 gl_label_set_merge (label, merge);
643 gl_merge_free (&merge);
645 gl_debug (DEBUG_XML, "END");
648 /****************************************************************************/
649 /* Save label to xml label file. */
650 /****************************************************************************/
652 gl_xml_label_save (glLabel *label,
653 const gchar *filename,
654 glXMLLabelStatus *status)
659 gl_debug (DEBUG_XML, "START");
661 doc = xml_label_to_doc (label, status);
663 xml_ret = xmlSaveFormatFile (filename, doc, TRUE);
667 g_warning (_("Problem saving xml file."));
668 *status = XML_LABEL_ERROR_SAVE_FILE;
672 gl_label_set_filename (label, filename);
673 gl_label_clear_modified (label);
677 gl_debug (DEBUG_XML, "END");
680 /****************************************************************************/
681 /* Save label to xml buffer. */
682 /****************************************************************************/
684 gl_xml_label_save_buffer (glLabel *label,
685 glXMLLabelStatus *status)
691 gl_debug (DEBUG_XML, "START");
693 doc = xml_label_to_doc (label, status);
695 xmlDocDumpMemory (doc, (xmlChar **)&buffer, &size);
698 gl_label_clear_modified (label);
700 gl_debug (DEBUG_XML, "END");
705 /*--------------------------------------------------------------------------*/
706 /* PRIVATE. Convert label to xml doc structure. */
707 /*--------------------------------------------------------------------------*/
709 xml_label_to_doc (glLabel * label,
710 glXMLLabelStatus *status)
714 glTemplate *template;
717 gl_debug (DEBUG_XML, "START");
721 doc = xmlNewDoc ("1.0");
722 doc->xmlRootNode = xmlNewDocNode (doc, NULL, "Document", NULL);
724 ns = xmlNewNs (doc->xmlRootNode, NAME_SPACE, "glabels");
725 xmlSetNs (doc->xmlRootNode, ns);
727 template = gl_label_get_template (label);
728 gl_template_xml_add_sheet (template, doc->xmlRootNode, ns);
730 xml_create_objects (doc->xmlRootNode, ns, label);
732 merge = gl_label_get_merge (label);
733 gl_debug (DEBUG_XML, "merge=%p", merge);
734 if (merge->type != GL_MERGE_NONE) {
735 xml_create_merge_fields (doc->xmlRootNode, ns, label);
737 gl_merge_free (&merge);
739 gl_debug (DEBUG_XML, "END");
741 *status = XML_LABEL_OK;
745 /*--------------------------------------------------------------------------*/
746 /* PRIVATE. Add XML Label->Objects Node */
747 /*--------------------------------------------------------------------------*/
749 xml_create_objects (xmlNodePtr root,
754 gboolean rotate_flag;
757 gl_debug (DEBUG_XML, "START");
759 rotate_flag = gl_label_get_rotate_flag (label);
761 node = xmlNewChild (root, ns, "Objects", NULL);
762 xmlSetProp (node, "id", "0");
763 xmlSetProp (node, "rotate", rotate_flag ? "True" : "False");
765 for (p = label->objects; p != NULL; p = p->next) {
766 xml_create_object (node, ns, GL_LABEL_OBJECT(p->data));
769 gl_debug (DEBUG_XML, "END");
772 /*--------------------------------------------------------------------------*/
773 /* PRIVATE. Add XML label object Node */
774 /*--------------------------------------------------------------------------*/
776 xml_create_object (xmlNodePtr root,
778 glLabelObject * object)
780 xmlNodePtr object_node;
785 gl_debug (DEBUG_XML, "START");
787 object_node = xmlNewChild (root, ns, "Object", NULL);
789 gl_label_object_get_position (object, &x, &y);
790 string = g_strdup_printf ("%g", x);
791 xmlSetProp (object_node, "x", string);
793 string = g_strdup_printf ("%g", y);
794 xmlSetProp (object_node, "y", string);
797 gl_label_object_get_affine (object, affine);
798 string = g_strdup_printf ("%g", affine[0]);
799 xmlSetProp (object_node, "a0", string);
801 string = g_strdup_printf ("%g", affine[1]);
802 xmlSetProp (object_node, "a1", string);
804 string = g_strdup_printf ("%g", affine[2]);
805 xmlSetProp (object_node, "a2", string);
807 string = g_strdup_printf ("%g", affine[3]);
808 xmlSetProp (object_node, "a3", string);
810 string = g_strdup_printf ("%g", affine[4]);
811 xmlSetProp (object_node, "a4", string);
813 string = g_strdup_printf ("%g", affine[5]);
814 xmlSetProp (object_node, "a5", string);
817 if ( GL_IS_LABEL_TEXT(object) ) {
818 xml_create_text_props (object_node, ns, object);
819 } else if ( GL_IS_LABEL_BOX(object) ) {
820 xml_create_box_props (object_node, ns, object);
821 } else if ( GL_IS_LABEL_LINE(object) ) {
822 xml_create_line_props (object_node, ns, object);
823 } else if ( GL_IS_LABEL_ELLIPSE(object) ) {
824 xml_create_ellipse_props (object_node, ns, object);
825 } else if ( GL_IS_LABEL_IMAGE(object) ) {
826 xml_create_image_props (object_node, ns, object);
827 } else if ( GL_IS_LABEL_BARCODE(object) ) {
828 xml_create_barcode_props (object_node, ns, object);
830 g_warning ("Unknown label object");
833 gl_debug (DEBUG_XML, "END");
836 /*--------------------------------------------------------------------------*/
837 /* PRIVATE. Add XML Label->Text Node Properties */
838 /*--------------------------------------------------------------------------*/
840 xml_create_text_props (xmlNodePtr object_node,
842 glLabelObject * object)
844 xmlNodePtr line_node, field_node;
848 GnomeFontWeight font_weight;
849 gboolean font_italic_flag;
851 GtkJustification just;
853 GList *p_line, *p_node;
854 glTextNode *node_text;
856 gl_debug (DEBUG_XML, "START");
858 xmlSetProp (object_node, "type", "Text");
860 lines = gl_label_text_get_lines (GL_LABEL_TEXT(object));
861 gl_label_text_get_props (GL_LABEL_TEXT(object),
862 &font_family, &font_size, &font_weight,
866 xmlSetProp (object_node, "font_family", font_family);
867 string = g_strdup_printf ("%g", font_size);
868 xmlSetProp (object_node, "font_size", string);
870 xmlSetProp (object_node, "font_weight",
871 gl_util_weight_to_string (font_weight));
872 xmlSetProp (object_node, "font_italic",
873 font_italic_flag?"True":"False");
875 xmlSetProp (object_node, "justify", gl_util_just_to_string (just));
877 string = g_strdup_printf ("0x%08x", color);
878 xmlSetProp (object_node, "color", string);
881 for (p_line = lines; p_line != NULL; p_line = p_line->next) {
882 line_node = xmlNewChild (object_node, ns, "Line", NULL);
884 for (p_node = (GList *) p_line->data; p_node != NULL;
885 p_node = p_node->next) {
886 node_text = (glTextNode *) p_node->data;
888 if (node_text->field_flag) {
890 xmlNewChild (line_node, ns, "Field", NULL);
891 xmlSetProp (field_node, "name",
894 xmlNodeAddContent (line_node, node_text->data);
901 gl_text_node_lines_free (&lines);
902 g_free (font_family);
904 gl_debug (DEBUG_XML, "END");
907 /*--------------------------------------------------------------------------*/
908 /* PRIVATE. Add XML Label->Box Node Properties */
909 /*--------------------------------------------------------------------------*/
911 xml_create_box_props (xmlNodePtr object_node,
913 glLabelObject * object)
917 guint line_color, fill_color;
920 gl_debug (DEBUG_XML, "START");
922 xmlSetProp (object_node, "type", "Box");
924 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
925 line_width = gl_label_box_get_line_width (GL_LABEL_BOX(object));
926 line_color = gl_label_box_get_line_color (GL_LABEL_BOX(object));
927 fill_color = gl_label_box_get_fill_color (GL_LABEL_BOX(object));
929 string = g_strdup_printf ("%g", w);
930 xmlSetProp (object_node, "w", string);
932 string = g_strdup_printf ("%g", h);
933 xmlSetProp (object_node, "h", string);
936 string = g_strdup_printf ("%g", line_width);
937 xmlSetProp (object_node, "line_width", string);
940 string = g_strdup_printf ("0x%08x", line_color);
941 xmlSetProp (object_node, "line_color", string);
944 string = g_strdup_printf ("0x%08x", fill_color);
945 xmlSetProp (object_node, "fill_color", string);
948 gl_debug (DEBUG_XML, "END");
951 /*--------------------------------------------------------------------------*/
952 /* PRIVATE. Add XML Label->Line Node Properties */
953 /*--------------------------------------------------------------------------*/
955 xml_create_line_props (xmlNodePtr object_node,
957 glLabelObject * object)
964 gl_debug (DEBUG_XML, "START");
966 xmlSetProp (object_node, "type", "Line");
968 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
969 line_width = gl_label_line_get_line_width (GL_LABEL_LINE(object));
970 line_color = gl_label_line_get_line_color (GL_LABEL_LINE(object));
972 string = g_strdup_printf ("%g", w);
973 xmlSetProp (object_node, "dx", string);
975 string = g_strdup_printf ("%g", h);
976 xmlSetProp (object_node, "dy", string);
979 string = g_strdup_printf ("%g", line_width);
980 xmlSetProp (object_node, "line_width", string);
983 string = g_strdup_printf ("0x%08x", line_color);
984 xmlSetProp (object_node, "line_color", string);
987 gl_debug (DEBUG_XML, "END");
990 /*--------------------------------------------------------------------------*/
991 /* PRIVATE. Add XML Label->Ellipse Node Properties */
992 /*--------------------------------------------------------------------------*/
994 xml_create_ellipse_props (xmlNodePtr object_node,
996 glLabelObject * object)
1000 guint line_color, fill_color;
1003 gl_debug (DEBUG_XML, "START");
1005 xmlSetProp (object_node, "type", "Ellipse");
1007 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
1008 line_width = gl_label_ellipse_get_line_width (GL_LABEL_ELLIPSE(object));
1009 line_color = gl_label_ellipse_get_line_color (GL_LABEL_ELLIPSE(object));
1010 fill_color = gl_label_ellipse_get_fill_color (GL_LABEL_ELLIPSE(object));
1012 string = g_strdup_printf ("%g", w);
1013 xmlSetProp (object_node, "w", string);
1015 string = g_strdup_printf ("%g", h);
1016 xmlSetProp (object_node, "h", string);
1019 string = g_strdup_printf ("%g", line_width);
1020 xmlSetProp (object_node, "line_width", string);
1023 string = g_strdup_printf ("0x%08x", line_color);
1024 xmlSetProp (object_node, "line_color", string);
1027 string = g_strdup_printf ("0x%08x", fill_color);
1028 xmlSetProp (object_node, "fill_color", string);
1031 gl_debug (DEBUG_XML, "END");
1034 /*--------------------------------------------------------------------------*/
1035 /* PRIVATE. Add XML Label->Image Node Properties */
1036 /*--------------------------------------------------------------------------*/
1038 xml_create_image_props (xmlNodePtr object_node,
1040 glLabelObject * object)
1046 gl_debug (DEBUG_XML, "START");
1048 xmlSetProp (object_node, "type", "Image");
1050 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
1051 filename = gl_label_image_get_filename (GL_LABEL_IMAGE(object));
1053 string = g_strdup_printf ("%g", w);
1054 xmlSetProp (object_node, "w", string);
1056 string = g_strdup_printf ("%g", h);
1057 xmlSetProp (object_node, "h", string);
1060 xmlNodeSetContent (object_node, filename);
1064 gl_debug (DEBUG_XML, "END");
1067 /*--------------------------------------------------------------------------*/
1068 /* PRIVATE. Add XML Label->Barcode Node Properties */
1069 /*--------------------------------------------------------------------------*/
1071 xml_create_barcode_props (xmlNodePtr object_node,
1073 glLabelObject * object)
1075 glTextNode *text_node;
1076 glBarcodeStyle style;
1083 gl_debug (DEBUG_XML, "START");
1085 xmlSetProp (object_node, "type", "Barcode");
1087 text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE(object));
1088 gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
1089 &style, &text_flag, &color, &scale);
1091 string = g_strdup_printf ("0x%08x", color);
1092 xmlSetProp (object_node, "color", string);
1095 xmlSetProp (object_node, "style", gl_barcode_style_to_text (style));
1096 xmlSetProp (object_node, "text", text_flag?"True":"False");
1097 string = g_strdup_printf ("%g", scale);
1098 xmlSetProp (object_node, "scale", string);
1101 if (text_node->field_flag) {
1102 child = xmlNewChild (object_node, ns, "Field", NULL);
1103 xmlSetProp (child, "name", text_node->data);
1105 xmlNodeSetContent (object_node, text_node->data);
1108 gl_text_node_free (&text_node);
1110 gl_debug (DEBUG_XML, "END");
1113 /*--------------------------------------------------------------------------*/
1114 /* PRIVATE. Add XML Label Merge Fields Node */
1115 /*--------------------------------------------------------------------------*/
1117 xml_create_merge_fields (xmlNodePtr root,
1121 xmlNodePtr node, child;
1125 glMergeFieldDefinition *field_def;
1127 gl_debug (DEBUG_XML, "START");
1129 merge = gl_label_get_merge (label);
1131 node = xmlNewChild (root, ns, "Merge_Fields", NULL);
1133 string = gl_merge_type_to_text (merge->type);
1134 xmlSetProp (node, "type", string);
1137 xmlSetProp (node, "src", merge->src);
1139 for (p = merge->field_defs; p != NULL; p = p->next) {
1140 field_def = (glMergeFieldDefinition *) p->data;
1142 child = xmlNewChild (node, ns, "Field", NULL);
1143 xmlSetProp (child, "key", field_def->key);
1144 xmlSetProp (child, "loc", field_def->loc);
1147 gl_merge_free (&merge);
1149 gl_debug (DEBUG_XML, "END");