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"));
196 label = NULL; /* TODO */
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;
300 gl_debug (DEBUG_XML, "START");
302 type_string = xmlGetProp (object_node, "type");
304 if ( g_strcasecmp (type_string, "text") == 0 ) {
305 object = xml_parse_text_props (object_node, label);
306 } else if ( g_strcasecmp (type_string, "box") == 0 ) {
307 object = xml_parse_box_props (object_node, label);
308 } else if ( g_strcasecmp (type_string, "line") == 0 ) {
309 object = xml_parse_line_props (object_node, label);
310 } else if ( g_strcasecmp (type_string, "ellipse") == 0 ) {
311 object = xml_parse_ellipse_props (object_node, label);
312 } else if ( g_strcasecmp (type_string, "image") == 0 ) {
313 object = xml_parse_image_props (object_node, label);
314 } else if ( g_strcasecmp (type_string, "barcode") == 0 ) {
315 object = xml_parse_barcode_props (object_node, label);
317 g_warning ("Unknown label object type \"%s\"", type_string);
321 x = g_strtod (xmlGetProp (object_node, "x"), NULL);
322 y = g_strtod (xmlGetProp (object_node, "y"), NULL);
324 gl_label_object_set_position (object, x, y);
326 gl_debug (DEBUG_XML, "END");
329 /*--------------------------------------------------------------------------*/
330 /* PRIVATE. Parse XML Label->Text Node Properties */
331 /*--------------------------------------------------------------------------*/
332 static glLabelObject *
333 xml_parse_text_props (xmlNodePtr object_node,
340 GnomeFontWeight font_weight;
341 gboolean font_italic_flag;
343 GtkJustification just;
344 xmlNodePtr line_node, text_node;
345 glTextNode *node_text;
348 gl_debug (DEBUG_XML, "START");
350 object = gl_label_text_new (label);
352 font_family = xmlGetProp (object_node, "font_family");
353 font_size = g_strtod (xmlGetProp (object_node, "font_size"), NULL);
354 font_weight = gl_util_string_to_weight (xmlGetProp (object_node,
357 !(g_strcasecmp (xmlGetProp (object_node, "font_italic"), "false") ==
360 just = gl_util_string_to_just (xmlGetProp (object_node, "justify"));
362 sscanf (xmlGetProp (object_node, "color"), "%x", &color);
365 for (line_node = object_node->xmlChildrenNode;
367 line_node = line_node->next) {
369 if (g_strcasecmp (line_node->name, "Line") == 0) {
372 for (text_node = line_node->xmlChildrenNode;
373 text_node != NULL; text_node = text_node->next) {
375 if (g_strcasecmp (text_node->name, "Field") ==
377 node_text = g_new0 (glTextNode, 1);
378 node_text->field_flag = TRUE;
380 xmlGetProp (text_node, "name");
382 g_list_append (nodes, node_text);
383 } else if (xmlNodeIsText (text_node)) {
384 node_text = g_new0 (glTextNode, 1);
385 node_text->field_flag = FALSE;
387 xmlNodeGetContent (text_node);
389 g_list_append (nodes, node_text);
391 g_warning ("Unexpected Text Line child: \"%s\"",
396 lines = g_list_append (lines, nodes);
398 } else if (!xmlNodeIsText (line_node)) {
399 g_warning ("Unexpected Text child: \"%s\"",
405 gl_label_text_set_lines (GL_LABEL_TEXT(object), lines);
406 gl_label_text_set_props (GL_LABEL_TEXT(object),
407 font_family, font_size, font_weight,
411 gl_text_node_lines_free (&lines);
412 g_free (font_family);
414 gl_debug (DEBUG_XML, "END");
416 return GL_LABEL_OBJECT(object);
419 /*--------------------------------------------------------------------------*/
420 /* PRIVATE. Parse XML Label->Box Node Properties */
421 /*--------------------------------------------------------------------------*/
422 static glLabelObject *
423 xml_parse_box_props (xmlNodePtr node,
428 guint line_color, fill_color;
431 gl_debug (DEBUG_XML, "START");
433 object = gl_label_box_new (label);
435 w = g_strtod (xmlGetProp (node, "w"), NULL);
436 h = g_strtod (xmlGetProp (node, "h"), NULL);
438 line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
440 sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
441 sscanf (xmlGetProp (node, "fill_color"), "%x", &fill_color);
443 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
444 gl_label_box_set_line_width (GL_LABEL_BOX(object), line_width);
445 gl_label_box_set_line_color (GL_LABEL_BOX(object), line_color);
446 gl_label_box_set_fill_color (GL_LABEL_BOX(object), fill_color);
448 gl_debug (DEBUG_XML, "END");
450 return GL_LABEL_OBJECT(object);
453 /*--------------------------------------------------------------------------*/
454 /* PRIVATE. Parse XML Label->Line Node Properties */
455 /*--------------------------------------------------------------------------*/
456 static glLabelObject *
457 xml_parse_line_props (xmlNodePtr node,
465 gl_debug (DEBUG_XML, "START");
467 object = gl_label_line_new (label);
469 w = g_strtod (xmlGetProp (node, "dx"), NULL);
470 h = g_strtod (xmlGetProp (node, "dy"), NULL);
472 line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
474 sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
476 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
477 gl_label_line_set_line_width (GL_LABEL_LINE(object), line_width);
478 gl_label_line_set_line_color (GL_LABEL_LINE(object), line_color);
480 gl_debug (DEBUG_XML, "END");
482 return GL_LABEL_OBJECT(object);
485 /*--------------------------------------------------------------------------*/
486 /* PRIVATE. Parse XML Label->Ellipse Node Properties */
487 /*--------------------------------------------------------------------------*/
488 static glLabelObject *
489 xml_parse_ellipse_props (xmlNodePtr node,
494 guint line_color, fill_color;
497 gl_debug (DEBUG_XML, "START");
499 object = gl_label_ellipse_new (label);
501 w = g_strtod (xmlGetProp (node, "w"), NULL);
502 h = g_strtod (xmlGetProp (node, "h"), NULL);
504 line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
506 sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
507 sscanf (xmlGetProp (node, "fill_color"), "%x", &fill_color);
509 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
510 gl_label_ellipse_set_line_width (GL_LABEL_ELLIPSE(object), line_width);
511 gl_label_ellipse_set_line_color (GL_LABEL_ELLIPSE(object), line_color);
512 gl_label_ellipse_set_fill_color (GL_LABEL_ELLIPSE(object), fill_color);
514 gl_debug (DEBUG_XML, "END");
516 return GL_LABEL_OBJECT(object);
519 /*--------------------------------------------------------------------------*/
520 /* PRIVATE. Parse XML Label->Image Node Properties */
521 /*--------------------------------------------------------------------------*/
522 static glLabelObject *
523 xml_parse_image_props (xmlNodePtr node,
530 gl_debug (DEBUG_XML, "START");
532 object = gl_label_image_new (label);
534 w = g_strtod (xmlGetProp (node, "w"), NULL);
535 h = g_strtod (xmlGetProp (node, "h"), NULL);
537 filename = xmlNodeGetContent (node);
539 gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
540 gl_label_image_set_filename (GL_LABEL_IMAGE(object), filename);
544 gl_debug (DEBUG_XML, "END");
546 return GL_LABEL_OBJECT(object);
549 /*--------------------------------------------------------------------------*/
550 /* PRIVATE. Parse XML Label->Barcode Node Properties */
551 /*--------------------------------------------------------------------------*/
552 static glLabelObject *
553 xml_parse_barcode_props (xmlNodePtr node,
558 glTextNode *text_node;
559 glBarcodeStyle style;
564 gl_debug (DEBUG_XML, "START");
566 object = gl_label_barcode_new (label);
568 sscanf (xmlGetProp (node, "color"), "%x", &color);
570 style = gl_barcode_text_to_style (xmlGetProp (node, "style"));
571 text_flag = !(g_strcasecmp (xmlGetProp (node, "text"), "false") == 0);
572 scale = g_strtod (xmlGetProp (node, "scale"), NULL);
574 child = node->xmlChildrenNode;
575 text_node = g_new0 (glTextNode, 1);
576 if (g_strcasecmp (child->name, "Field") == 0) {
577 text_node->field_flag = TRUE;
578 text_node->data = xmlGetProp (child, "name");
579 } else if (xmlNodeIsText (child)) {
580 text_node->field_flag = FALSE;
581 text_node->data = xmlNodeGetContent (child);
583 g_warning ("Unexpected Barcode child: \"%s\"", child->name);
586 gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
587 gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
588 style, text_flag, color, scale);
590 gl_text_node_free (&text_node);
592 gl_debug (DEBUG_XML, "END");
594 return GL_LABEL_OBJECT(object);
597 /*--------------------------------------------------------------------------*/
598 /* PRIVATE. Parse XML merge fields tag. */
599 /*--------------------------------------------------------------------------*/
601 xml_parse_merge_fields (xmlNodePtr node,
606 glMergeFieldDefinition *field_def;
608 gl_debug (DEBUG_XML, "START");
610 merge = gl_merge_new ();
612 merge->type = gl_merge_text_to_type (xmlGetProp (node, "type"));
613 merge->src = xmlGetProp (node, "src");
615 for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
617 if (g_strcasecmp (child->name, "Field") == 0) {
618 field_def = g_new0 (glMergeFieldDefinition, 1);
619 field_def->key = xmlGetProp (child, "key");
620 field_def->loc = xmlGetProp (child, "loc");
622 g_list_append (merge->field_defs,
624 } else if (!xmlNodeIsText (child)) {
625 g_warning ("Unexpected Merge_Fields child: \"%s\"",
631 gl_label_set_merge (label, merge);
633 gl_merge_free (&merge);
635 gl_debug (DEBUG_XML, "END");
638 /****************************************************************************/
639 /* Save label to xml label file. */
640 /****************************************************************************/
642 gl_xml_label_save (glLabel *label,
643 const gchar *filename,
644 glXMLLabelStatus *status)
649 gl_debug (DEBUG_XML, "START");
651 doc = xml_label_to_doc (label, status);
653 xml_ret = xmlSaveFormatFile (filename, doc, TRUE);
656 g_warning (_("Problem saving xml file."));
657 *status = XML_LABEL_ERROR_SAVE_FILE;
660 gl_label_set_filename (label, filename);
661 gl_label_clear_modified (label);
663 gl_debug (DEBUG_XML, "END");
666 /****************************************************************************/
667 /* Save label to xml buffer. */
668 /****************************************************************************/
670 gl_xml_label_save_buffer (glLabel *label,
671 glXMLLabelStatus *status)
677 gl_debug (DEBUG_XML, "START");
679 doc = xml_label_to_doc (label, status);
681 xmlDocDumpMemory (doc, (xmlChar **)&buffer, &size);
684 gl_label_clear_modified (label);
686 gl_debug (DEBUG_XML, "END");
691 /*--------------------------------------------------------------------------*/
692 /* PRIVATE. Convert label to xml doc structure. */
693 /*--------------------------------------------------------------------------*/
695 xml_label_to_doc (glLabel * label,
696 glXMLLabelStatus *status)
700 glTemplate *template;
703 gl_debug (DEBUG_XML, "START");
707 doc = xmlNewDoc ("1.0");
708 doc->xmlRootNode = xmlNewDocNode (doc, NULL, "Document", NULL);
710 ns = xmlNewNs (doc->xmlRootNode, NAME_SPACE, "glabels");
711 xmlSetNs (doc->xmlRootNode, ns);
713 template = gl_label_get_template (label);
714 gl_template_xml_add_sheet (template, doc->xmlRootNode, ns);
716 xml_create_objects (doc->xmlRootNode, ns, label);
718 merge = gl_label_get_merge (label);
719 gl_debug (DEBUG_XML, "merge=%p", merge);
720 if (merge->type != GL_MERGE_NONE) {
721 xml_create_merge_fields (doc->xmlRootNode, ns, label);
723 gl_merge_free (&merge);
725 gl_debug (DEBUG_XML, "END");
727 *status = XML_LABEL_OK;
731 /*--------------------------------------------------------------------------*/
732 /* PRIVATE. Add XML Label->Objects Node */
733 /*--------------------------------------------------------------------------*/
735 xml_create_objects (xmlNodePtr root,
740 gboolean rotate_flag;
743 gl_debug (DEBUG_XML, "START");
745 rotate_flag = gl_label_get_rotate_flag (label);
747 node = xmlNewChild (root, ns, "Objects", NULL);
748 xmlSetProp (node, "id", "0");
749 xmlSetProp (node, "rotate", rotate_flag ? "True" : "False");
751 for (p = label->objects; p != NULL; p = p->next) {
752 xml_create_object (node, ns, GL_LABEL_OBJECT(p->data));
755 gl_debug (DEBUG_XML, "END");
758 /*--------------------------------------------------------------------------*/
759 /* PRIVATE. Add XML label object Node */
760 /*--------------------------------------------------------------------------*/
762 xml_create_object (xmlNodePtr root,
764 glLabelObject * object)
766 xmlNodePtr object_node;
770 gl_debug (DEBUG_XML, "START");
772 object_node = xmlNewChild (root, ns, "Object", NULL);
774 gl_label_object_get_position (object, &x, &y);
775 string = g_strdup_printf ("%g", x);
776 xmlSetProp (object_node, "x", string);
778 string = g_strdup_printf ("%g", y);
779 xmlSetProp (object_node, "y", string);
782 if ( GL_IS_LABEL_TEXT(object) ) {
783 xml_create_text_props (object_node, ns, object);
784 } else if ( GL_IS_LABEL_BOX(object) ) {
785 xml_create_box_props (object_node, ns, object);
786 } else if ( GL_IS_LABEL_LINE(object) ) {
787 xml_create_line_props (object_node, ns, object);
788 } else if ( GL_IS_LABEL_ELLIPSE(object) ) {
789 xml_create_ellipse_props (object_node, ns, object);
790 } else if ( GL_IS_LABEL_IMAGE(object) ) {
791 xml_create_image_props (object_node, ns, object);
792 } else if ( GL_IS_LABEL_BARCODE(object) ) {
793 xml_create_barcode_props (object_node, ns, object);
795 g_warning ("Unknown label object");
798 gl_debug (DEBUG_XML, "END");
801 /*--------------------------------------------------------------------------*/
802 /* PRIVATE. Add XML Label->Text Node Properties */
803 /*--------------------------------------------------------------------------*/
805 xml_create_text_props (xmlNodePtr object_node,
807 glLabelObject * object)
809 xmlNodePtr line_node, field_node;
813 GnomeFontWeight font_weight;
814 gboolean font_italic_flag;
816 GtkJustification just;
818 GList *p_line, *p_node;
819 glTextNode *node_text;
821 gl_debug (DEBUG_XML, "START");
823 xmlSetProp (object_node, "type", "Text");
825 lines = gl_label_text_get_lines (GL_LABEL_TEXT(object));
826 gl_label_text_get_props (GL_LABEL_TEXT(object),
827 &font_family, &font_size, &font_weight,
831 xmlSetProp (object_node, "font_family", font_family);
832 string = g_strdup_printf ("%g", font_size);
833 xmlSetProp (object_node, "font_size", string);
835 xmlSetProp (object_node, "font_weight",
836 gl_util_weight_to_string (font_weight));
837 xmlSetProp (object_node, "font_italic",
838 font_italic_flag?"True":"False");
840 xmlSetProp (object_node, "justify", gl_util_just_to_string (just));
842 string = g_strdup_printf ("0x%08x", color);
843 xmlSetProp (object_node, "color", string);
846 for (p_line = lines; p_line != NULL; p_line = p_line->next) {
847 line_node = xmlNewChild (object_node, ns, "Line", NULL);
849 for (p_node = (GList *) p_line->data; p_node != NULL;
850 p_node = p_node->next) {
851 node_text = (glTextNode *) p_node->data;
853 if (node_text->field_flag) {
855 xmlNewChild (line_node, ns, "Field", NULL);
856 xmlSetProp (field_node, "name",
859 xmlNodeAddContent (line_node, node_text->data);
866 gl_text_node_lines_free (&lines);
867 g_free (font_family);
869 gl_debug (DEBUG_XML, "END");
872 /*--------------------------------------------------------------------------*/
873 /* PRIVATE. Add XML Label->Box Node Properties */
874 /*--------------------------------------------------------------------------*/
876 xml_create_box_props (xmlNodePtr object_node,
878 glLabelObject * object)
882 guint line_color, fill_color;
885 gl_debug (DEBUG_XML, "START");
887 xmlSetProp (object_node, "type", "Box");
889 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
890 line_width = gl_label_box_get_line_width (GL_LABEL_BOX(object));
891 line_color = gl_label_box_get_line_color (GL_LABEL_BOX(object));
892 fill_color = gl_label_box_get_fill_color (GL_LABEL_BOX(object));
894 string = g_strdup_printf ("%g", w);
895 xmlSetProp (object_node, "w", string);
897 string = g_strdup_printf ("%g", h);
898 xmlSetProp (object_node, "h", string);
901 string = g_strdup_printf ("%g", line_width);
902 xmlSetProp (object_node, "line_width", string);
905 string = g_strdup_printf ("0x%08x", line_color);
906 xmlSetProp (object_node, "line_color", string);
909 string = g_strdup_printf ("0x%08x", fill_color);
910 xmlSetProp (object_node, "fill_color", string);
913 gl_debug (DEBUG_XML, "END");
916 /*--------------------------------------------------------------------------*/
917 /* PRIVATE. Add XML Label->Line Node Properties */
918 /*--------------------------------------------------------------------------*/
920 xml_create_line_props (xmlNodePtr object_node,
922 glLabelObject * object)
929 gl_debug (DEBUG_XML, "START");
931 xmlSetProp (object_node, "type", "Line");
933 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
934 line_width = gl_label_line_get_line_width (GL_LABEL_LINE(object));
935 line_color = gl_label_line_get_line_color (GL_LABEL_LINE(object));
937 string = g_strdup_printf ("%g", w);
938 xmlSetProp (object_node, "dx", string);
940 string = g_strdup_printf ("%g", h);
941 xmlSetProp (object_node, "dy", string);
944 string = g_strdup_printf ("%g", line_width);
945 xmlSetProp (object_node, "line_width", string);
948 string = g_strdup_printf ("0x%08x", line_color);
949 xmlSetProp (object_node, "line_color", string);
952 gl_debug (DEBUG_XML, "END");
955 /*--------------------------------------------------------------------------*/
956 /* PRIVATE. Add XML Label->Ellipse Node Properties */
957 /*--------------------------------------------------------------------------*/
959 xml_create_ellipse_props (xmlNodePtr object_node,
961 glLabelObject * object)
965 guint line_color, fill_color;
968 gl_debug (DEBUG_XML, "START");
970 xmlSetProp (object_node, "type", "Ellipse");
972 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
973 line_width = gl_label_ellipse_get_line_width (GL_LABEL_ELLIPSE(object));
974 line_color = gl_label_ellipse_get_line_color (GL_LABEL_ELLIPSE(object));
975 fill_color = gl_label_ellipse_get_fill_color (GL_LABEL_ELLIPSE(object));
977 string = g_strdup_printf ("%g", w);
978 xmlSetProp (object_node, "w", string);
980 string = g_strdup_printf ("%g", h);
981 xmlSetProp (object_node, "h", string);
984 string = g_strdup_printf ("%g", line_width);
985 xmlSetProp (object_node, "line_width", string);
988 string = g_strdup_printf ("0x%08x", line_color);
989 xmlSetProp (object_node, "line_color", string);
992 string = g_strdup_printf ("0x%08x", fill_color);
993 xmlSetProp (object_node, "fill_color", string);
996 gl_debug (DEBUG_XML, "END");
999 /*--------------------------------------------------------------------------*/
1000 /* PRIVATE. Add XML Label->Image Node Properties */
1001 /*--------------------------------------------------------------------------*/
1003 xml_create_image_props (xmlNodePtr object_node,
1005 glLabelObject * object)
1011 gl_debug (DEBUG_XML, "START");
1013 xmlSetProp (object_node, "type", "Image");
1015 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
1016 filename = gl_label_image_get_filename (GL_LABEL_IMAGE(object));
1018 string = g_strdup_printf ("%g", w);
1019 xmlSetProp (object_node, "w", string);
1021 string = g_strdup_printf ("%g", h);
1022 xmlSetProp (object_node, "h", string);
1025 xmlNodeSetContent (object_node, filename);
1029 gl_debug (DEBUG_XML, "END");
1032 /*--------------------------------------------------------------------------*/
1033 /* PRIVATE. Add XML Label->Barcode Node Properties */
1034 /*--------------------------------------------------------------------------*/
1036 xml_create_barcode_props (xmlNodePtr object_node,
1038 glLabelObject * object)
1040 glTextNode *text_node;
1041 glBarcodeStyle style;
1048 gl_debug (DEBUG_XML, "START");
1050 xmlSetProp (object_node, "type", "Barcode");
1052 text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE(object));
1053 gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
1054 &style, &text_flag, &color, &scale);
1056 string = g_strdup_printf ("0x%08x", color);
1057 xmlSetProp (object_node, "color", string);
1060 xmlSetProp (object_node, "style", gl_barcode_style_to_text (style));
1061 xmlSetProp (object_node, "text", text_flag?"True":"False");
1062 string = g_strdup_printf ("%g", scale);
1063 xmlSetProp (object_node, "scale", string);
1066 if (text_node->field_flag) {
1067 child = xmlNewChild (object_node, ns, "Field", NULL);
1068 xmlSetProp (child, "name", text_node->data);
1070 xmlNodeSetContent (object_node, text_node->data);
1073 gl_text_node_free (&text_node);
1075 gl_debug (DEBUG_XML, "END");
1078 /*--------------------------------------------------------------------------*/
1079 /* PRIVATE. Add XML Label Merge Fields Node */
1080 /*--------------------------------------------------------------------------*/
1082 xml_create_merge_fields (xmlNodePtr root,
1086 xmlNodePtr node, child;
1090 glMergeFieldDefinition *field_def;
1092 gl_debug (DEBUG_XML, "START");
1094 merge = gl_label_get_merge (label);
1096 node = xmlNewChild (root, ns, "Merge_Fields", NULL);
1098 string = gl_merge_type_to_text (merge->type);
1099 xmlSetProp (node, "type", string);
1102 xmlSetProp (node, "src", merge->src);
1104 for (p = merge->field_defs; p != NULL; p = p->next) {
1105 field_def = (glMergeFieldDefinition *) p->data;
1107 child = xmlNewChild (node, ns, "Field", NULL);
1108 xmlSetProp (child, "key", field_def->key);
1109 xmlSetProp (child, "loc", field_def->loc);
1112 gl_merge_free (&merge);
1114 gl_debug (DEBUG_XML, "END");