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"
44 /*========================================================*/
45 /* Private macros and constants. */
46 /*========================================================*/
47 #define NAME_SPACE "http://snaught.com/glabels/1.90/"
48 #define COMPAT01_NAME_SPACE "http://snaught.com/glabels/0.1/"
49 #define COMPAT04_NAME_SPACE "http://snaught.com/glabels/0.4/"
51 /*========================================================*/
53 /*========================================================*/
55 /*========================================================*/
56 /* Private globals. */
57 /*========================================================*/
59 /*========================================================*/
60 /* Private function prototypes. */
61 /*========================================================*/
63 static glLabel *xml_doc_to_label (xmlDocPtr doc, glXMLLabelStatus *status);
64 static glLabel *xml_parse_label (xmlNodePtr root, glXMLLabelStatus *status);
65 static void xml_parse_objects (xmlNodePtr node, glLabel * label);
66 static void xml_parse_object(xmlNodePtr node, glLabel *label);
67 static glLabelObject *xml_parse_text_props (xmlNodePtr node, glLabel *label);
68 static glLabelObject *xml_parse_box_props (xmlNodePtr node, glLabel *label);
69 static glLabelObject *xml_parse_line_props (xmlNodePtr node, glLabel *label);
70 static glLabelObject *xml_parse_ellipse_props (xmlNodePtr node, glLabel *label);
71 static glLabelObject *xml_parse_image_props (xmlNodePtr node, glLabel *label);
72 static glLabelObject *xml_parse_barcode_props (xmlNodePtr node, glLabel *label);
73 static void xml_parse_merge_fields (xmlNodePtr node, glLabel *label);
75 static xmlDocPtr xml_label_to_doc (glLabel * label, glXMLLabelStatus *status);
76 static void xml_create_objects (xmlNodePtr root, xmlNsPtr ns, glLabel * label);
77 static void xml_create_object (xmlNodePtr root, xmlNsPtr ns,
78 glLabelObject * object);
79 static void xml_create_text_props (xmlNodePtr root, xmlNsPtr ns,
80 glLabelObject * object);
81 static void xml_create_box_props (xmlNodePtr root, xmlNsPtr ns,
82 glLabelObject * object);
83 static void xml_create_line_props (xmlNodePtr root, xmlNsPtr ns,
84 glLabelObject * object);
85 static void xml_create_ellipse_props (xmlNodePtr root, xmlNsPtr ns,
86 glLabelObject * object);
87 static void xml_create_image_props (xmlNodePtr root, xmlNsPtr ns,
88 glLabelObject * object);
89 static void xml_create_barcode_props (xmlNodePtr root, xmlNsPtr ns,
90 glLabelObject * object);
91 static void xml_create_merge_fields (xmlNodePtr root, xmlNsPtr ns,
94 /****************************************************************************/
95 /* Open and read label from xml file. */
96 /****************************************************************************/
98 gl_xml_label_open (const gchar * filename,
99 glXMLLabelStatus *status)
104 gl_debug (DEBUG_XML, "START");
106 doc = xmlParseFile (filename);
108 g_warning (_("xmlParseFile error"));
109 *status = XML_LABEL_ERROR_OPEN_PARSE;
113 label = xml_doc_to_label (doc, status);
117 gl_label_set_filename (label, filename);
118 gl_label_clear_modified (label);
120 gl_debug (DEBUG_XML, "END");
125 /****************************************************************************/
126 /* Read label from xml buffer. */
127 /****************************************************************************/
129 gl_xml_label_open_buffer (const gchar * buffer,
130 glXMLLabelStatus *status)
135 gl_debug (DEBUG_XML, "START");
137 doc = xmlParseDoc ((xmlChar *) buffer);
139 g_warning (_("xmlParseFile error"));
140 *status = XML_LABEL_ERROR_OPEN_PARSE;
144 label = xml_doc_to_label (doc, status);
146 gl_label_clear_modified (label);
150 gl_debug (DEBUG_XML, "END");
155 /*--------------------------------------------------------------------------*/
156 /* PRIVATE. Parse xml doc structure and create label. */
157 /*--------------------------------------------------------------------------*/
159 xml_doc_to_label (xmlDocPtr doc,
160 glXMLLabelStatus *status)
162 xmlNodePtr root, node;
166 gl_debug (DEBUG_XML, "START");
170 *status = XML_LABEL_OK;
172 root = xmlDocGetRootElement (doc);
173 if (!root || !root->name) {
174 g_warning (_("No document root"));
175 *status = XML_LABEL_ERROR_OPEN_PARSE;
179 ns = xmlSearchNsByHref (doc, root, NAME_SPACE);
181 label = xml_parse_label (root, status);
183 /* Try compatability mode 0.1 */
184 ns = xmlSearchNsByHref (doc, root, COMPAT01_NAME_SPACE);
186 g_warning (_("Importing from glabels 0.1 format"));
188 label = NULL; /* TODO */
190 /* Try compatability mode 0.4 */
191 ns = xmlSearchNsByHref (doc, root,
192 COMPAT04_NAME_SPACE);
194 g_warning (_("Importing from glabels 0.4 format"));
195 label = gl_xml_label_04_parse (root, status);
197 g_warning (_("bad document, unknown glabels Namespace"));
198 *status = XML_LABEL_ERROR_OPEN_PARSE;
204 gl_debug (DEBUG_XML, "END");
209 /*--------------------------------------------------------------------------*/
210 /* PRIVATE. Parse xml root node and create label. */
211 /*--------------------------------------------------------------------------*/
213 xml_parse_label (xmlNodePtr root,
214 glXMLLabelStatus *status)
218 glTemplate *template;
220 gl_debug (DEBUG_XML, "START");
222 *status = XML_LABEL_OK;
224 if (g_strcasecmp (root->name, "Document") != 0) {
225 g_warning (_("Bad root node = \"%s\""), root->name);
226 *status = XML_LABEL_ERROR_OPEN_PARSE;
230 label = GL_LABEL(gl_label_new ());
232 for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
234 if (g_strcasecmp (node->name, "Sheet") == 0) {
235 template = gl_template_xml_parse_sheet (node);
237 *status = XML_LABEL_UNKNOWN_MEDIA;
240 gl_label_set_template (label, template);
241 gl_template_free (&template);
242 } else if (g_strcasecmp (node->name, "Objects") == 0) {
243 xml_parse_objects (node, label);
244 } else if (g_strcasecmp (node->name, "Merge_Fields") == 0) {
245 xml_parse_merge_fields (node, label);
247 if (!xmlNodeIsText (node)) {
248 g_warning (_("bad node = \"%s\""), node->name);
253 gl_debug (DEBUG_XML, "END");
258 /*--------------------------------------------------------------------------*/
259 /* PRIVATE. Parse Objects node. */
260 /*--------------------------------------------------------------------------*/
262 xml_parse_objects (xmlNodePtr objects_node,
265 gboolean rotate_flag;
268 gl_debug (DEBUG_XML, "START");
271 !(g_strcasecmp (xmlGetProp (objects_node, "rotate"), "false") == 0);
272 gl_label_set_rotate_flag (label, rotate_flag);
274 for (node = objects_node->xmlChildrenNode; node != NULL; node = node->next) {
276 if (g_strcasecmp (node->name, "Object") == 0) {
277 xml_parse_object (node, label);
279 if (!xmlNodeIsText (node)) {
280 g_warning (_("bad node = \"%s\""), node->name);
285 gl_debug (DEBUG_XML, "END");
288 /*--------------------------------------------------------------------------*/
289 /* PRIVATE. Parse XML Object Node */
290 /*--------------------------------------------------------------------------*/
292 xml_parse_object (xmlNodePtr object_node,
295 glLabelObject *object;
299 gl_debug (DEBUG_XML, "START");
301 type_string = xmlGetProp (object_node, "type");
303 if ( g_strcasecmp (type_string, "text") == 0 ) {
304 object = xml_parse_text_props (object_node, label);
305 } else if ( g_strcasecmp (type_string, "box") == 0 ) {
306 object = xml_parse_box_props (object_node, label);
307 } else if ( g_strcasecmp (type_string, "line") == 0 ) {
308 object = xml_parse_line_props (object_node, label);
309 } else if ( g_strcasecmp (type_string, "ellipse") == 0 ) {
310 object = xml_parse_ellipse_props (object_node, label);
311 } else if ( g_strcasecmp (type_string, "image") == 0 ) {
312 object = xml_parse_image_props (object_node, label);
313 } else if ( g_strcasecmp (type_string, "barcode") == 0 ) {
314 object = xml_parse_barcode_props (object_node, label);
316 g_warning ("Unknown label object type \"%s\"", type_string);
320 x = g_strtod (xmlGetProp (object_node, "x"), NULL);
321 y = g_strtod (xmlGetProp (object_node, "y"), NULL);
323 gl_label_object_set_position (object, x, y);
325 gl_debug (DEBUG_XML, "END");
328 /*--------------------------------------------------------------------------*/
329 /* PRIVATE. Parse XML Label->Text Node Properties */
330 /*--------------------------------------------------------------------------*/
331 static glLabelObject *
332 xml_parse_text_props (xmlNodePtr object_node,
339 GnomeFontWeight font_weight;
340 gboolean font_italic_flag;
342 GtkJustification just;
343 xmlNodePtr line_node, text_node;
344 glTextNode *node_text;
347 gl_debug (DEBUG_XML, "START");
349 object = gl_label_text_new (label);
351 font_family = xmlGetProp (object_node, "font_family");
352 font_size = g_strtod (xmlGetProp (object_node, "font_size"), NULL);
353 font_weight = gl_util_string_to_weight (xmlGetProp (object_node,
356 !(g_strcasecmp (xmlGetProp (object_node, "font_italic"), "false") ==
359 just = gl_util_string_to_just (xmlGetProp (object_node, "justify"));
361 sscanf (xmlGetProp (object_node, "color"), "%x", &color);
364 for (line_node = object_node->xmlChildrenNode;
366 line_node = line_node->next) {
368 if (g_strcasecmp (line_node->name, "Line") == 0) {
371 for (text_node = line_node->xmlChildrenNode;
372 text_node != NULL; text_node = text_node->next) {
374 if (g_strcasecmp (text_node->name, "Field") ==
376 node_text = g_new0 (glTextNode, 1);
377 node_text->field_flag = TRUE;
379 xmlGetProp (text_node, "name");
381 g_list_append (nodes, node_text);
382 } else if (xmlNodeIsText (text_node)) {
383 node_text = g_new0 (glTextNode, 1);
384 node_text->field_flag = FALSE;
386 xmlNodeGetContent (text_node);
388 g_list_append (nodes, node_text);
390 g_warning ("Unexpected Text Line child: \"%s\"",
395 lines = g_list_append (lines, nodes);
397 } else if (!xmlNodeIsText (line_node)) {
398 g_warning ("Unexpected Text child: \"%s\"",
404 gl_label_text_set_lines (GL_LABEL_TEXT(object), lines);
405 gl_label_text_set_props (GL_LABEL_TEXT(object),
406 font_family, font_size, font_weight,
410 gl_text_node_lines_free (&lines);
411 g_free (font_family);
413 gl_debug (DEBUG_XML, "END");
415 return GL_LABEL_OBJECT(object);
418 /*--------------------------------------------------------------------------*/
419 /* PRIVATE. Parse XML Label->Box Node Properties */
420 /*--------------------------------------------------------------------------*/
421 static glLabelObject *
422 xml_parse_box_props (xmlNodePtr node,
427 guint line_color, fill_color;
430 gl_debug (DEBUG_XML, "START");
432 object = gl_label_box_new (label);
434 w = g_strtod (xmlGetProp (node, "w"), NULL);
435 h = g_strtod (xmlGetProp (node, "h"), NULL);
437 line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
439 sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
440 sscanf (xmlGetProp (node, "fill_color"), "%x", &fill_color);
442 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
443 gl_label_box_set_line_width (GL_LABEL_BOX(object), line_width);
444 gl_label_box_set_line_color (GL_LABEL_BOX(object), line_color);
445 gl_label_box_set_fill_color (GL_LABEL_BOX(object), fill_color);
447 gl_debug (DEBUG_XML, "END");
449 return GL_LABEL_OBJECT(object);
452 /*--------------------------------------------------------------------------*/
453 /* PRIVATE. Parse XML Label->Line Node Properties */
454 /*--------------------------------------------------------------------------*/
455 static glLabelObject *
456 xml_parse_line_props (xmlNodePtr node,
464 gl_debug (DEBUG_XML, "START");
466 object = gl_label_line_new (label);
468 w = g_strtod (xmlGetProp (node, "dx"), NULL);
469 h = g_strtod (xmlGetProp (node, "dy"), NULL);
471 line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
473 sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
475 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
476 gl_label_line_set_line_width (GL_LABEL_LINE(object), line_width);
477 gl_label_line_set_line_color (GL_LABEL_LINE(object), line_color);
479 gl_debug (DEBUG_XML, "END");
481 return GL_LABEL_OBJECT(object);
484 /*--------------------------------------------------------------------------*/
485 /* PRIVATE. Parse XML Label->Ellipse Node Properties */
486 /*--------------------------------------------------------------------------*/
487 static glLabelObject *
488 xml_parse_ellipse_props (xmlNodePtr node,
493 guint line_color, fill_color;
496 gl_debug (DEBUG_XML, "START");
498 object = gl_label_ellipse_new (label);
500 w = g_strtod (xmlGetProp (node, "w"), NULL);
501 h = g_strtod (xmlGetProp (node, "h"), NULL);
503 line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
505 sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
506 sscanf (xmlGetProp (node, "fill_color"), "%x", &fill_color);
508 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
509 gl_label_ellipse_set_line_width (GL_LABEL_ELLIPSE(object), line_width);
510 gl_label_ellipse_set_line_color (GL_LABEL_ELLIPSE(object), line_color);
511 gl_label_ellipse_set_fill_color (GL_LABEL_ELLIPSE(object), fill_color);
513 gl_debug (DEBUG_XML, "END");
515 return GL_LABEL_OBJECT(object);
518 /*--------------------------------------------------------------------------*/
519 /* PRIVATE. Parse XML Label->Image Node Properties */
520 /*--------------------------------------------------------------------------*/
521 static glLabelObject *
522 xml_parse_image_props (xmlNodePtr node,
529 gl_debug (DEBUG_XML, "START");
531 object = gl_label_image_new (label);
533 w = g_strtod (xmlGetProp (node, "w"), NULL);
534 h = g_strtod (xmlGetProp (node, "h"), NULL);
536 filename = xmlNodeGetContent (node);
538 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
539 gl_label_image_set_filename (GL_LABEL_IMAGE(object), filename);
543 gl_debug (DEBUG_XML, "END");
545 return GL_LABEL_OBJECT(object);
548 /*--------------------------------------------------------------------------*/
549 /* PRIVATE. Parse XML Label->Barcode Node Properties */
550 /*--------------------------------------------------------------------------*/
551 static glLabelObject *
552 xml_parse_barcode_props (xmlNodePtr node,
557 glTextNode *text_node;
558 glBarcodeStyle style;
563 gl_debug (DEBUG_XML, "START");
565 object = gl_label_barcode_new (label);
567 sscanf (xmlGetProp (node, "color"), "%x", &color);
569 style = gl_barcode_text_to_style (xmlGetProp (node, "style"));
570 text_flag = !(g_strcasecmp (xmlGetProp (node, "text"), "false") == 0);
571 scale = g_strtod (xmlGetProp (node, "scale"), NULL);
573 child = node->xmlChildrenNode;
574 text_node = g_new0 (glTextNode, 1);
575 if (g_strcasecmp (child->name, "Field") == 0) {
576 text_node->field_flag = TRUE;
577 text_node->data = xmlGetProp (child, "name");
578 } else if (xmlNodeIsText (child)) {
579 text_node->field_flag = FALSE;
580 text_node->data = xmlNodeGetContent (child);
582 g_warning ("Unexpected Barcode child: \"%s\"", child->name);
585 gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
586 gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
587 style, text_flag, color, scale);
589 gl_text_node_free (&text_node);
591 gl_debug (DEBUG_XML, "END");
593 return GL_LABEL_OBJECT(object);
596 /*--------------------------------------------------------------------------*/
597 /* PRIVATE. Parse XML merge fields tag. */
598 /*--------------------------------------------------------------------------*/
600 xml_parse_merge_fields (xmlNodePtr node,
605 glMergeFieldDefinition *field_def;
607 gl_debug (DEBUG_XML, "START");
609 merge = gl_merge_new ();
611 merge->type = gl_merge_text_to_type (xmlGetProp (node, "type"));
612 merge->src = xmlGetProp (node, "src");
614 for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
616 if (g_strcasecmp (child->name, "Field") == 0) {
617 field_def = g_new0 (glMergeFieldDefinition, 1);
618 field_def->key = xmlGetProp (child, "key");
619 field_def->loc = xmlGetProp (child, "loc");
621 g_list_append (merge->field_defs,
623 } else if (!xmlNodeIsText (child)) {
624 g_warning ("Unexpected Merge_Fields child: \"%s\"",
630 gl_label_set_merge (label, merge);
632 gl_merge_free (&merge);
634 gl_debug (DEBUG_XML, "END");
637 /****************************************************************************/
638 /* Save label to xml label file. */
639 /****************************************************************************/
641 gl_xml_label_save (glLabel *label,
642 const gchar *filename,
643 glXMLLabelStatus *status)
648 gl_debug (DEBUG_XML, "START");
650 doc = xml_label_to_doc (label, status);
652 xml_ret = xmlSaveFormatFile (filename, doc, TRUE);
655 g_warning (_("Problem saving xml file."));
656 *status = XML_LABEL_ERROR_SAVE_FILE;
659 gl_label_set_filename (label, filename);
660 gl_label_clear_modified (label);
662 gl_debug (DEBUG_XML, "END");
665 /****************************************************************************/
666 /* Save label to xml buffer. */
667 /****************************************************************************/
669 gl_xml_label_save_buffer (glLabel *label,
670 glXMLLabelStatus *status)
676 gl_debug (DEBUG_XML, "START");
678 doc = xml_label_to_doc (label, status);
680 xmlDocDumpMemory (doc, (xmlChar **)&buffer, &size);
683 gl_label_clear_modified (label);
685 gl_debug (DEBUG_XML, "END");
690 /*--------------------------------------------------------------------------*/
691 /* PRIVATE. Convert label to xml doc structure. */
692 /*--------------------------------------------------------------------------*/
694 xml_label_to_doc (glLabel * label,
695 glXMLLabelStatus *status)
699 glTemplate *template;
702 gl_debug (DEBUG_XML, "START");
706 doc = xmlNewDoc ("1.0");
707 doc->xmlRootNode = xmlNewDocNode (doc, NULL, "Document", NULL);
709 ns = xmlNewNs (doc->xmlRootNode, NAME_SPACE, "glabels");
710 xmlSetNs (doc->xmlRootNode, ns);
712 template = gl_label_get_template (label);
713 gl_template_xml_add_sheet (template, doc->xmlRootNode, ns);
715 xml_create_objects (doc->xmlRootNode, ns, label);
717 merge = gl_label_get_merge (label);
718 gl_debug (DEBUG_XML, "merge=%p", merge);
719 if (merge->type != GL_MERGE_NONE) {
720 xml_create_merge_fields (doc->xmlRootNode, ns, label);
722 gl_merge_free (&merge);
724 gl_debug (DEBUG_XML, "END");
726 *status = XML_LABEL_OK;
730 /*--------------------------------------------------------------------------*/
731 /* PRIVATE. Add XML Label->Objects Node */
732 /*--------------------------------------------------------------------------*/
734 xml_create_objects (xmlNodePtr root,
739 gboolean rotate_flag;
742 gl_debug (DEBUG_XML, "START");
744 rotate_flag = gl_label_get_rotate_flag (label);
746 node = xmlNewChild (root, ns, "Objects", NULL);
747 xmlSetProp (node, "id", "0");
748 xmlSetProp (node, "rotate", rotate_flag ? "True" : "False");
750 for (p = label->objects; p != NULL; p = p->next) {
751 xml_create_object (node, ns, GL_LABEL_OBJECT(p->data));
754 gl_debug (DEBUG_XML, "END");
757 /*--------------------------------------------------------------------------*/
758 /* PRIVATE. Add XML label object Node */
759 /*--------------------------------------------------------------------------*/
761 xml_create_object (xmlNodePtr root,
763 glLabelObject * object)
765 xmlNodePtr object_node;
769 gl_debug (DEBUG_XML, "START");
771 object_node = xmlNewChild (root, ns, "Object", NULL);
773 gl_label_object_get_position (object, &x, &y);
774 string = g_strdup_printf ("%g", x);
775 xmlSetProp (object_node, "x", string);
777 string = g_strdup_printf ("%g", y);
778 xmlSetProp (object_node, "y", string);
781 if ( GL_IS_LABEL_TEXT(object) ) {
782 xml_create_text_props (object_node, ns, object);
783 } else if ( GL_IS_LABEL_BOX(object) ) {
784 xml_create_box_props (object_node, ns, object);
785 } else if ( GL_IS_LABEL_LINE(object) ) {
786 xml_create_line_props (object_node, ns, object);
787 } else if ( GL_IS_LABEL_ELLIPSE(object) ) {
788 xml_create_ellipse_props (object_node, ns, object);
789 } else if ( GL_IS_LABEL_IMAGE(object) ) {
790 xml_create_image_props (object_node, ns, object);
791 } else if ( GL_IS_LABEL_BARCODE(object) ) {
792 xml_create_barcode_props (object_node, ns, object);
794 g_warning ("Unknown label object");
797 gl_debug (DEBUG_XML, "END");
800 /*--------------------------------------------------------------------------*/
801 /* PRIVATE. Add XML Label->Text Node Properties */
802 /*--------------------------------------------------------------------------*/
804 xml_create_text_props (xmlNodePtr object_node,
806 glLabelObject * object)
808 xmlNodePtr line_node, field_node;
812 GnomeFontWeight font_weight;
813 gboolean font_italic_flag;
815 GtkJustification just;
817 GList *p_line, *p_node;
818 glTextNode *node_text;
820 gl_debug (DEBUG_XML, "START");
822 xmlSetProp (object_node, "type", "Text");
824 lines = gl_label_text_get_lines (GL_LABEL_TEXT(object));
825 gl_label_text_get_props (GL_LABEL_TEXT(object),
826 &font_family, &font_size, &font_weight,
830 xmlSetProp (object_node, "font_family", font_family);
831 string = g_strdup_printf ("%g", font_size);
832 xmlSetProp (object_node, "font_size", string);
834 xmlSetProp (object_node, "font_weight",
835 gl_util_weight_to_string (font_weight));
836 xmlSetProp (object_node, "font_italic",
837 font_italic_flag?"True":"False");
839 xmlSetProp (object_node, "justify", gl_util_just_to_string (just));
841 string = g_strdup_printf ("0x%08x", color);
842 xmlSetProp (object_node, "color", string);
845 for (p_line = lines; p_line != NULL; p_line = p_line->next) {
846 line_node = xmlNewChild (object_node, ns, "Line", NULL);
848 for (p_node = (GList *) p_line->data; p_node != NULL;
849 p_node = p_node->next) {
850 node_text = (glTextNode *) p_node->data;
852 if (node_text->field_flag) {
854 xmlNewChild (line_node, ns, "Field", NULL);
855 xmlSetProp (field_node, "name",
858 xmlNodeAddContent (line_node, node_text->data);
865 gl_text_node_lines_free (&lines);
866 g_free (font_family);
868 gl_debug (DEBUG_XML, "END");
871 /*--------------------------------------------------------------------------*/
872 /* PRIVATE. Add XML Label->Box Node Properties */
873 /*--------------------------------------------------------------------------*/
875 xml_create_box_props (xmlNodePtr object_node,
877 glLabelObject * object)
881 guint line_color, fill_color;
884 gl_debug (DEBUG_XML, "START");
886 xmlSetProp (object_node, "type", "Box");
888 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
889 line_width = gl_label_box_get_line_width (GL_LABEL_BOX(object));
890 line_color = gl_label_box_get_line_color (GL_LABEL_BOX(object));
891 fill_color = gl_label_box_get_fill_color (GL_LABEL_BOX(object));
893 string = g_strdup_printf ("%g", w);
894 xmlSetProp (object_node, "w", string);
896 string = g_strdup_printf ("%g", h);
897 xmlSetProp (object_node, "h", string);
900 string = g_strdup_printf ("%g", line_width);
901 xmlSetProp (object_node, "line_width", string);
904 string = g_strdup_printf ("0x%08x", line_color);
905 xmlSetProp (object_node, "line_color", string);
908 string = g_strdup_printf ("0x%08x", fill_color);
909 xmlSetProp (object_node, "fill_color", string);
912 gl_debug (DEBUG_XML, "END");
915 /*--------------------------------------------------------------------------*/
916 /* PRIVATE. Add XML Label->Line Node Properties */
917 /*--------------------------------------------------------------------------*/
919 xml_create_line_props (xmlNodePtr object_node,
921 glLabelObject * object)
928 gl_debug (DEBUG_XML, "START");
930 xmlSetProp (object_node, "type", "Line");
932 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
933 line_width = gl_label_line_get_line_width (GL_LABEL_LINE(object));
934 line_color = gl_label_line_get_line_color (GL_LABEL_LINE(object));
936 string = g_strdup_printf ("%g", w);
937 xmlSetProp (object_node, "dx", string);
939 string = g_strdup_printf ("%g", h);
940 xmlSetProp (object_node, "dy", string);
943 string = g_strdup_printf ("%g", line_width);
944 xmlSetProp (object_node, "line_width", string);
947 string = g_strdup_printf ("0x%08x", line_color);
948 xmlSetProp (object_node, "line_color", string);
951 gl_debug (DEBUG_XML, "END");
954 /*--------------------------------------------------------------------------*/
955 /* PRIVATE. Add XML Label->Ellipse Node Properties */
956 /*--------------------------------------------------------------------------*/
958 xml_create_ellipse_props (xmlNodePtr object_node,
960 glLabelObject * object)
964 guint line_color, fill_color;
967 gl_debug (DEBUG_XML, "START");
969 xmlSetProp (object_node, "type", "Ellipse");
971 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
972 line_width = gl_label_ellipse_get_line_width (GL_LABEL_ELLIPSE(object));
973 line_color = gl_label_ellipse_get_line_color (GL_LABEL_ELLIPSE(object));
974 fill_color = gl_label_ellipse_get_fill_color (GL_LABEL_ELLIPSE(object));
976 string = g_strdup_printf ("%g", w);
977 xmlSetProp (object_node, "w", string);
979 string = g_strdup_printf ("%g", h);
980 xmlSetProp (object_node, "h", string);
983 string = g_strdup_printf ("%g", line_width);
984 xmlSetProp (object_node, "line_width", string);
987 string = g_strdup_printf ("0x%08x", line_color);
988 xmlSetProp (object_node, "line_color", string);
991 string = g_strdup_printf ("0x%08x", fill_color);
992 xmlSetProp (object_node, "fill_color", string);
995 gl_debug (DEBUG_XML, "END");
998 /*--------------------------------------------------------------------------*/
999 /* PRIVATE. Add XML Label->Image Node Properties */
1000 /*--------------------------------------------------------------------------*/
1002 xml_create_image_props (xmlNodePtr object_node,
1004 glLabelObject * object)
1010 gl_debug (DEBUG_XML, "START");
1012 xmlSetProp (object_node, "type", "Image");
1014 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
1015 filename = gl_label_image_get_filename (GL_LABEL_IMAGE(object));
1017 string = g_strdup_printf ("%g", w);
1018 xmlSetProp (object_node, "w", string);
1020 string = g_strdup_printf ("%g", h);
1021 xmlSetProp (object_node, "h", string);
1024 xmlNodeSetContent (object_node, filename);
1028 gl_debug (DEBUG_XML, "END");
1031 /*--------------------------------------------------------------------------*/
1032 /* PRIVATE. Add XML Label->Barcode Node Properties */
1033 /*--------------------------------------------------------------------------*/
1035 xml_create_barcode_props (xmlNodePtr object_node,
1037 glLabelObject * object)
1039 glTextNode *text_node;
1040 glBarcodeStyle style;
1047 gl_debug (DEBUG_XML, "START");
1049 xmlSetProp (object_node, "type", "Barcode");
1051 text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE(object));
1052 gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
1053 &style, &text_flag, &color, &scale);
1055 string = g_strdup_printf ("0x%08x", color);
1056 xmlSetProp (object_node, "color", string);
1059 xmlSetProp (object_node, "style", gl_barcode_style_to_text (style));
1060 xmlSetProp (object_node, "text", text_flag?"True":"False");
1061 string = g_strdup_printf ("%g", scale);
1062 xmlSetProp (object_node, "scale", string);
1065 if (text_node->field_flag) {
1066 child = xmlNewChild (object_node, ns, "Field", NULL);
1067 xmlSetProp (child, "name", text_node->data);
1069 xmlNodeSetContent (object_node, text_node->data);
1072 gl_text_node_free (&text_node);
1074 gl_debug (DEBUG_XML, "END");
1077 /*--------------------------------------------------------------------------*/
1078 /* PRIVATE. Add XML Label Merge Fields Node */
1079 /*--------------------------------------------------------------------------*/
1081 xml_create_merge_fields (xmlNodePtr root,
1085 xmlNodePtr node, child;
1089 glMergeFieldDefinition *field_def;
1091 gl_debug (DEBUG_XML, "START");
1093 merge = gl_label_get_merge (label);
1095 node = xmlNewChild (root, ns, "Merge_Fields", NULL);
1097 string = gl_merge_type_to_text (merge->type);
1098 xmlSetProp (node, "type", string);
1101 xmlSetProp (node, "src", merge->src);
1103 for (p = merge->field_defs; p != NULL; p = p->next) {
1104 field_def = (glMergeFieldDefinition *) p->data;
1106 child = xmlNewChild (node, ns, "Field", NULL);
1107 xmlSetProp (child, "key", field_def->key);
1108 xmlSetProp (child, "loc", field_def->loc);
1111 gl_merge_free (&merge);
1113 gl_debug (DEBUG_XML, "END");