3 * Copyright (C) 2001-2010 Jim Evins <evins@snaught.com>.
5 * This file is part of libglabels.
7 * libglabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * libglabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with libglabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "lgl-xml-template.h"
25 #include <glib/gi18n.h>
30 #include "libglabels-private.h"
35 /*===========================================*/
37 /*===========================================*/
39 /*===========================================*/
41 /*===========================================*/
43 /*===========================================*/
44 /* Local function prototypes */
45 /*===========================================*/
46 static void xml_parse_meta_node (xmlNodePtr label_node,
47 lglTemplate *template);
48 static void xml_parse_label_rectangle_node (xmlNodePtr label_node,
49 lglTemplate *template);
50 static void xml_parse_label_ellipse_node (xmlNodePtr label_node,
51 lglTemplate *template);
52 static void xml_parse_label_round_node (xmlNodePtr label_node,
53 lglTemplate *template);
54 static void xml_parse_label_cd_node (xmlNodePtr label_node,
55 lglTemplate *template);
56 static void xml_parse_layout_node (xmlNodePtr layout_node,
57 lglTemplateFrame *frame);
58 static void xml_parse_markup_margin_node (xmlNodePtr markup_node,
59 lglTemplateFrame *frame);
60 static void xml_parse_markup_line_node (xmlNodePtr markup_node,
61 lglTemplateFrame *frame);
62 static void xml_parse_markup_circle_node (xmlNodePtr markup_node,
63 lglTemplateFrame *frame);
64 static void xml_parse_markup_rect_node (xmlNodePtr markup_node,
65 lglTemplateFrame *frame);
66 static void xml_parse_markup_ellipse_node (xmlNodePtr markup_node,
67 lglTemplateFrame *frame);
68 static void xml_parse_alias_node (xmlNodePtr alias_node,
69 lglTemplate *template);
71 static void xml_create_meta_node (const gchar *attr,
75 static void xml_create_label_node (const lglTemplateFrame *frame,
78 static void xml_create_layout_node (const lglTemplateLayout *layout,
81 static void xml_create_markup_margin_node (const lglTemplateMarkup *margin,
84 static void xml_create_markup_line_node (const lglTemplateMarkup *line,
87 static void xml_create_markup_circle_node (const lglTemplateMarkup *circle,
90 static void xml_create_markup_rect_node (const lglTemplateMarkup *circle,
93 static void xml_create_markup_ellipse_node (const lglTemplateMarkup *circle,
99 * lgl_xml_template_read_templates_from_file:
100 * @utf8_filename: Filename of papers file (name encoded as UTF-8)
102 * Read glabels templates from template file.
106 lgl_xml_template_read_templates_from_file (const gchar *utf8_filename)
109 xmlDocPtr templates_doc;
113 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
116 g_message ("Utf8 filename conversion error");
120 templates_doc = xmlParseFile (filename);
123 g_message ("\"%s\" is not a glabels template file (not XML)",
128 lgl_xml_template_parse_templates_doc (templates_doc);
131 xmlFreeDoc (templates_doc);
136 * lgl_xml_template_parse_templates_doc:
137 * @templates_doc: libxml #xmlDocPtr tree, representing template file.
139 * Read glabels templates from a libxml #xmlDocPtr tree.
143 lgl_xml_template_parse_templates_doc (const xmlDocPtr templates_doc)
146 xmlNodePtr root, node;
147 lglTemplate *template;
151 root = xmlDocGetRootElement (templates_doc);
152 if (!root || !root->name)
154 g_message ("\"%s\" is not a glabels template file (no root node)",
158 if (!lgl_xml_is_node (root, "Glabels-templates"))
160 g_message ("\"%s\" is not a glabels template file (wrong root node)",
165 for (node = root->xmlChildrenNode; node != NULL; node = node->next)
168 if (lgl_xml_is_node (node, "Template"))
170 template = lgl_xml_template_parse_template_node (node);
173 _lgl_db_register_template_internal (template);
174 lgl_template_free (template);
179 if ( !xmlNodeIsText(node) )
181 if (!lgl_xml_is_node (node,"comment"))
183 g_message ("bad node = \"%s\"",node->name);
192 * lgl_xml_template_parse_template_node:
193 * @template_node: libxml #xmlNodePtr template node from a #xmlDocPtr tree.
195 * Read a single glabels template from a libxml #xmlNodePtr node.
197 * Returns: a pointer to a newly created #lglTemplate structure.
201 lgl_xml_template_parse_template_node (const xmlNodePtr template_node)
209 gdouble page_width, page_height;
210 lglPaper *paper = NULL;
211 lglTemplate *template;
214 lglTemplateFrame *frame;
217 brand = lgl_xml_get_prop_string (template_node, "brand", NULL);
218 part = lgl_xml_get_prop_string (template_node, "part", NULL);
221 name = lgl_xml_get_prop_string (template_node, "name", NULL);
224 v = g_strsplit (name, " ", 2);
225 brand = g_strdup (v[0]);
226 part = g_strchug (g_strdup (v[1]));
233 g_message ("Missing name or brand/part attributes.");
238 equiv_part = lgl_xml_get_prop_string (template_node, "equiv", NULL);
241 description = lgl_xml_get_prop_i18n_string (template_node, "description", NULL);
242 paper_id = lgl_xml_get_prop_string (template_node, "size", NULL);
244 if (lgl_db_is_paper_id_other (paper_id))
247 page_width = lgl_xml_get_prop_length (template_node, "width", 0);
248 page_height = lgl_xml_get_prop_length (template_node, "height", 0);
253 paper = lgl_db_lookup_paper_from_id (paper_id);
256 /* This should always be an id, but just in case a name
258 g_message ("Unknown page size id \"%s\", trying as name",
260 paper = lgl_db_lookup_paper_from_name (paper_id);
262 paper_id = g_strdup (paper->id);
266 page_width = paper->width;
267 page_height = paper->height;
273 g_message ("Unknown page size id or name \"%s\"",
276 lgl_paper_free (paper);
283 template = lgl_template_new (brand, part, description,
284 paper_id, page_width, page_height);
288 template = lgl_template_new_from_equiv (brand, part, equiv_part);
292 g_message ("Forward references not supported.");
298 for (node = template_node->xmlChildrenNode; node != NULL; node = node->next)
300 if (lgl_xml_is_node (node, "Meta"))
302 xml_parse_meta_node (node, template);
304 else if (lgl_xml_is_node (node, "Label-rectangle"))
306 xml_parse_label_rectangle_node (node, template);
308 else if (lgl_xml_is_node (node, "Label-ellipse"))
310 xml_parse_label_ellipse_node (node, template);
312 else if (lgl_xml_is_node (node, "Label-round"))
314 xml_parse_label_round_node (node, template);
316 else if (lgl_xml_is_node (node, "Label-cd"))
318 xml_parse_label_cd_node (node, template);
320 else if (lgl_xml_is_node (node, "Alias"))
322 xml_parse_alias_node (node, template);
326 if (!xmlNodeIsText (node))
328 if (!lgl_xml_is_node (node,"comment"))
330 g_message ("bad node = \"%s\"",node->name);
339 g_free (description);
343 * Create a default full-page frame, if a known frame type was not found.
345 if ( template->frames == NULL )
347 g_message ("%s %s: missing valid frame node", template->brand, template->part);
348 frame = lgl_template_frame_rect_new ("0", page_width, page_height, 0, 0, 0);
349 lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0, 0, 0, 0));
350 lgl_template_add_frame (template, frame);
354 * Create a default 1x1 layout, if layout is missing.
356 frame = (lglTemplateFrame *)template->frames->data;
357 if ( frame->all.layouts == NULL )
359 g_message ("%s %s: missing layout node", template->brand, template->part);
360 lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0, 0, 0, 0));
366 /*--------------------------------------------------------------------------*/
367 /* PRIVATE. Parse XML Template->Meta Node. */
368 /*--------------------------------------------------------------------------*/
370 xml_parse_meta_node (xmlNodePtr meta_node,
371 lglTemplate *template)
376 product_url = lgl_xml_get_prop_string (meta_node, "product_url", NULL);
377 if ( product_url != NULL )
379 g_free (template->product_url);
380 template->product_url = product_url;
383 category = lgl_xml_get_prop_string (meta_node, "category", NULL);
384 if ( category != NULL )
386 lgl_template_add_category (template, category);
392 /*--------------------------------------------------------------------------*/
393 /* PRIVATE. Parse XML Template->Label-rectangle Node. */
394 /*--------------------------------------------------------------------------*/
396 xml_parse_label_rectangle_node (xmlNodePtr label_node,
397 lglTemplate *template)
401 gdouble x_waste, y_waste;
403 lglTemplateFrame *frame;
406 id = lgl_xml_get_prop_string (label_node, "id", NULL);
408 if ((tmp = lgl_xml_get_prop_string (label_node, "waste", NULL)))
410 /* Handle single "waste" property. */
411 x_waste = y_waste = lgl_xml_get_prop_length (label_node, "waste", 0);
416 x_waste = lgl_xml_get_prop_length (label_node, "x_waste", 0);
417 y_waste = lgl_xml_get_prop_length (label_node, "y_waste", 0);
420 w = lgl_xml_get_prop_length (label_node, "width", 0);
421 h = lgl_xml_get_prop_length (label_node, "height", 0);
422 r = lgl_xml_get_prop_length (label_node, "round", 0);
424 frame = lgl_template_frame_rect_new ((gchar *)id, w, h, r, x_waste, y_waste);
425 lgl_template_add_frame (template, frame);
427 for (node = label_node->xmlChildrenNode; node != NULL; node = node->next)
429 if (lgl_xml_is_node (node, "Layout"))
431 xml_parse_layout_node (node, frame);
433 else if (lgl_xml_is_node (node, "Markup-margin"))
435 xml_parse_markup_margin_node (node, frame);
437 else if (lgl_xml_is_node (node, "Markup-line"))
439 xml_parse_markup_line_node (node, frame);
441 else if (lgl_xml_is_node (node, "Markup-circle"))
443 xml_parse_markup_circle_node (node, frame);
445 else if (lgl_xml_is_node (node, "Markup-rect"))
447 xml_parse_markup_rect_node (node, frame);
449 else if (lgl_xml_is_node (node, "Markup-ellipse"))
451 xml_parse_markup_ellipse_node (node, frame);
453 else if (!xmlNodeIsText (node))
455 if (!lgl_xml_is_node (node, "comment"))
457 g_message ("bad node = \"%s\"",node->name);
466 /*--------------------------------------------------------------------------*/
467 /* PRIVATE. Parse XML Template->Label-ellipse Node. */
468 /*--------------------------------------------------------------------------*/
470 xml_parse_label_ellipse_node (xmlNodePtr label_node,
471 lglTemplate *template)
476 lglTemplateFrame *frame;
479 id = lgl_xml_get_prop_string (label_node, "id", NULL);
481 w = lgl_xml_get_prop_length (label_node, "width", 0);
482 h = lgl_xml_get_prop_length (label_node, "height", 0);
483 waste = lgl_xml_get_prop_length (label_node, "waste", 0);
485 frame = lgl_template_frame_ellipse_new ((gchar *)id, w, h, waste);
486 lgl_template_add_frame (template, frame);
488 for (node = label_node->xmlChildrenNode; node != NULL; node = node->next)
490 if (lgl_xml_is_node (node, "Layout"))
492 xml_parse_layout_node (node, frame);
494 else if (lgl_xml_is_node (node, "Markup-margin"))
496 xml_parse_markup_margin_node (node, frame);
498 else if (lgl_xml_is_node (node, "Markup-line"))
500 xml_parse_markup_line_node (node, frame);
502 else if (lgl_xml_is_node (node, "Markup-circle"))
504 xml_parse_markup_circle_node (node, frame);
506 else if (lgl_xml_is_node (node, "Markup-rect"))
508 xml_parse_markup_rect_node (node, frame);
510 else if (lgl_xml_is_node (node, "Markup-ellipse"))
512 xml_parse_markup_ellipse_node (node, frame);
514 else if (!xmlNodeIsText (node))
516 if (!lgl_xml_is_node (node, "comment"))
518 g_message ("bad node = \"%s\"",node->name);
527 /*--------------------------------------------------------------------------*/
528 /* PRIVATE. Parse XML Template->Label-round Node. */
529 /*--------------------------------------------------------------------------*/
531 xml_parse_label_round_node (xmlNodePtr label_node,
532 lglTemplate *template)
537 lglTemplateFrame *frame;
540 id = lgl_xml_get_prop_string (label_node, "id", NULL);
541 waste = lgl_xml_get_prop_length (label_node, "waste", 0);
542 r = lgl_xml_get_prop_length (label_node, "radius", 0);
544 frame = lgl_template_frame_round_new ((gchar *)id, r, waste);
545 lgl_template_add_frame (template, frame);
547 for (node = label_node->xmlChildrenNode; node != NULL; node = node->next)
549 if (lgl_xml_is_node (node, "Layout"))
551 xml_parse_layout_node (node, frame);
553 else if (lgl_xml_is_node (node, "Markup-margin"))
555 xml_parse_markup_margin_node (node, frame);
557 else if (lgl_xml_is_node (node, "Markup-line"))
559 xml_parse_markup_line_node (node, frame);
561 else if (lgl_xml_is_node (node, "Markup-circle"))
563 xml_parse_markup_circle_node (node, frame);
565 else if (lgl_xml_is_node (node, "Markup-rect"))
567 xml_parse_markup_rect_node (node, frame);
569 else if (lgl_xml_is_node (node, "Markup-ellipse"))
571 xml_parse_markup_ellipse_node (node, frame);
573 else if (!xmlNodeIsText (node))
575 if (!lgl_xml_is_node (node, "comment"))
577 g_message ("bad node = \"%s\"",node->name);
585 /*--------------------------------------------------------------------------*/
586 /* PRIVATE. Parse XML Template->Label-cd Node. */
587 /*--------------------------------------------------------------------------*/
589 xml_parse_label_cd_node (xmlNodePtr label_node,
590 lglTemplate *template)
594 gdouble r1, r2, w, h;
595 lglTemplateFrame *frame;
598 id = lgl_xml_get_prop_string (label_node, "id", NULL);
599 waste = lgl_xml_get_prop_length (label_node, "waste", 0);
600 r1 = lgl_xml_get_prop_length (label_node, "radius", 0);
601 r2 = lgl_xml_get_prop_length (label_node, "hole", 0);
602 w = lgl_xml_get_prop_length (label_node, "width", 0);
603 h = lgl_xml_get_prop_length (label_node, "height", 0);
605 frame = lgl_template_frame_cd_new ((gchar *)id, r1, r2, w, h, waste);
606 lgl_template_add_frame (template, frame);
608 for (node = label_node->xmlChildrenNode; node != NULL; node = node->next)
610 if (lgl_xml_is_node (node, "Layout"))
612 xml_parse_layout_node (node, frame);
614 else if (lgl_xml_is_node (node, "Markup-margin"))
616 xml_parse_markup_margin_node (node, frame);
618 else if (lgl_xml_is_node (node, "Markup-line"))
620 xml_parse_markup_line_node (node, frame);
622 else if (lgl_xml_is_node (node, "Markup-circle"))
624 xml_parse_markup_circle_node (node, frame);
626 else if (lgl_xml_is_node (node, "Markup-rect"))
628 xml_parse_markup_rect_node (node, frame);
630 else if (lgl_xml_is_node (node, "Markup-ellipse"))
632 xml_parse_markup_ellipse_node (node, frame);
634 else if (!xmlNodeIsText (node))
636 if (!lgl_xml_is_node (node, "comment"))
638 g_message ("bad node = \"%s\"",node->name);
646 /*--------------------------------------------------------------------------*/
647 /* PRIVATE. Parse XML Template->Label->Layout Node. */
648 /*--------------------------------------------------------------------------*/
650 xml_parse_layout_node (xmlNodePtr layout_node,
651 lglTemplateFrame *frame)
654 gdouble x0, y0, dx, dy;
657 nx = lgl_xml_get_prop_int (layout_node, "nx", 1);
658 ny = lgl_xml_get_prop_int (layout_node, "ny", 1);
660 x0 = lgl_xml_get_prop_length (layout_node, "x0", 0);
661 y0 = lgl_xml_get_prop_length (layout_node, "y0", 0);
663 dx = lgl_xml_get_prop_length (layout_node, "dx", 0);
664 dy = lgl_xml_get_prop_length (layout_node, "dy", 0);
666 lgl_template_frame_add_layout (frame, lgl_template_layout_new (nx, ny, x0, y0, dx, dy));
668 for (node = layout_node->xmlChildrenNode; node != NULL; node = node->next)
670 if (!xmlNodeIsText (node))
672 if (!lgl_xml_is_node (node, "comment"))
674 g_message ("bad node = \"%s\"",node->name);
681 /*--------------------------------------------------------------------------*/
682 /* PRIVATE. Parse XML Template->Label->Markup-margin Node. */
683 /*--------------------------------------------------------------------------*/
685 xml_parse_markup_margin_node (xmlNodePtr markup_node,
686 lglTemplateFrame *frame)
691 size = lgl_xml_get_prop_length (markup_node, "size", 0);
693 lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (size));
695 for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next)
697 if (!xmlNodeIsText (node))
699 if (!lgl_xml_is_node (node, "comment"))
701 g_message ("bad node = \"%s\"",node->name);
708 /*--------------------------------------------------------------------------*/
709 /* PRIVATE. Parse XML Template->Label->Markup-line Node. */
710 /*--------------------------------------------------------------------------*/
712 xml_parse_markup_line_node (xmlNodePtr markup_node,
713 lglTemplateFrame *frame)
715 gdouble x1, y1, x2, y2;
718 x1 = lgl_xml_get_prop_length (markup_node, "x1", 0);
719 y1 = lgl_xml_get_prop_length (markup_node, "y1", 0);
720 x2 = lgl_xml_get_prop_length (markup_node, "x2", 0);
721 y2 = lgl_xml_get_prop_length (markup_node, "y2", 0);
723 lgl_template_frame_add_markup (frame, lgl_template_markup_line_new (x1, y1, x2, y2));
725 for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next)
727 if (!xmlNodeIsText (node))
729 if (!lgl_xml_is_node (node, "comment"))
731 g_message ("bad node = \"%s\"",node->name);
738 /*--------------------------------------------------------------------------*/
739 /* PRIVATE. Parse XML Template->Label->Markup-circle Node. */
740 /*--------------------------------------------------------------------------*/
742 xml_parse_markup_circle_node (xmlNodePtr markup_node,
743 lglTemplateFrame *frame)
748 x0 = lgl_xml_get_prop_length (markup_node, "x0", 0);
749 y0 = lgl_xml_get_prop_length (markup_node, "y0", 0);
750 r = lgl_xml_get_prop_length (markup_node, "radius", 0);
752 lgl_template_frame_add_markup (frame, lgl_template_markup_circle_new (x0, y0, r));
754 for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next)
756 if (!xmlNodeIsText (node))
758 if (!lgl_xml_is_node (node, "comment"))
760 g_message ("bad node = \"%s\"",node->name);
768 /*--------------------------------------------------------------------------*/
769 /* PRIVATE. Parse XML Template->Label->Markup-rect Node. */
770 /*--------------------------------------------------------------------------*/
772 xml_parse_markup_rect_node (xmlNodePtr markup_node,
773 lglTemplateFrame *frame)
775 gdouble x1, y1, w, h, r;
778 x1 = lgl_xml_get_prop_length (markup_node, "x1", 0);
779 y1 = lgl_xml_get_prop_length (markup_node, "y1", 0);
780 w = lgl_xml_get_prop_length (markup_node, "w", 0);
781 h = lgl_xml_get_prop_length (markup_node, "h", 0);
782 r = lgl_xml_get_prop_length (markup_node, "r", 0);
784 lgl_template_frame_add_markup (frame, lgl_template_markup_rect_new (x1, y1, w, h, r));
786 for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next)
788 if (!xmlNodeIsText (node))
790 if (!lgl_xml_is_node (node, "comment"))
792 g_message ("bad node = \"%s\"",node->name);
800 /*--------------------------------------------------------------------------*/
801 /* PRIVATE. Parse XML Template->Label->Markup-ellipse Node. */
802 /*--------------------------------------------------------------------------*/
804 xml_parse_markup_ellipse_node (xmlNodePtr markup_node,
805 lglTemplateFrame *frame)
807 gdouble x1, y1, w, h;
810 x1 = lgl_xml_get_prop_length (markup_node, "x1", 0);
811 y1 = lgl_xml_get_prop_length (markup_node, "y1", 0);
812 w = lgl_xml_get_prop_length (markup_node, "w", 0);
813 h = lgl_xml_get_prop_length (markup_node, "h", 0);
815 lgl_template_frame_add_markup (frame, lgl_template_markup_ellipse_new (x1, y1, w, h));
817 for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next)
819 if (!xmlNodeIsText (node))
821 if (!lgl_xml_is_node (node, "comment"))
823 g_message ("bad node = \"%s\"",node->name);
831 /*--------------------------------------------------------------------------*/
832 /* PRIVATE. Parse deprecated XML Template->Alias Node. */
833 /*--------------------------------------------------------------------------*/
835 xml_parse_alias_node (xmlNodePtr alias_node,
836 lglTemplate *template)
838 g_message ("Skipping deprecated \"Alias\" node.");
843 * lgl_xml_template_write_templates_to_file:
844 * @templates: List of #lglTemplate structures
845 * @utf8_filename: Filename of templates file (name encoded as UTF-8)
847 * Write a list of #lglTemplate structures to a glabels XML template file.
849 * Returns: the number of bytes written or -1 in case of failure
853 lgl_xml_template_write_templates_to_file (GList *templates,
854 const gchar *utf8_filename)
860 lglTemplate *template;
863 doc = xmlNewDoc ((xmlChar *)"1.0");
864 doc->xmlRootNode = xmlNewDocNode (doc, NULL, (xmlChar *)"Glabels-templates", NULL);
866 ns = xmlNewNs (doc->xmlRootNode, (xmlChar *)LGL_XML_NAME_SPACE, NULL);
867 xmlSetNs (doc->xmlRootNode, ns);
869 for (p=templates; p!=NULL; p=p->next)
871 template = (lglTemplate *)p->data;
872 lgl_xml_template_create_template_node (template, doc->xmlRootNode, ns);
875 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
878 g_message ("Utf8 conversion error.");
883 xmlSetDocCompressMode (doc, 0);
884 bytes_written = xmlSaveFormatFile (filename, doc, TRUE);
887 return bytes_written;
894 * lgl_xml_template_write_template_to_file:
895 * @template: #lglTemplate structure to be written
896 * @utf8_filename: Filename of templates file (name encoded as UTF-8)
898 * Write a single #lglTemplate structures to a glabels XML template file.
900 * Returns: the number of bytes written or -1 in case of failure
904 lgl_xml_template_write_template_to_file (const lglTemplate *template,
905 const gchar *utf8_filename)
907 GList *templates = NULL;
910 templates = g_list_append (templates, (gpointer)template);
912 bytes_written = lgl_xml_template_write_templates_to_file (templates, utf8_filename);
914 g_list_free (templates);
916 return bytes_written;
921 * lgl_xml_template_create_template_node:
922 * @template: #lglTemplate structure to be written
923 * @root: parent node to receive new child node
924 * @ns: a libxml #xmlNsPtr
926 * Add a single #lglTemplate child node to given #xmlNodePtr.
930 lgl_xml_template_create_template_node (const lglTemplate *template,
936 lglTemplateFrame *frame;
938 node = xmlNewChild (root, ns, (xmlChar *)"Template", NULL);
940 lgl_xml_set_prop_string (node, "brand", template->brand);
941 lgl_xml_set_prop_string (node, "part", template->part);
943 lgl_xml_set_prop_string (node, "size", template->paper_id);
944 if (xmlStrEqual ((xmlChar *)template->paper_id, (xmlChar *)"Other"))
947 lgl_xml_set_prop_length (node, "width", template->page_width);
948 lgl_xml_set_prop_length (node, "height", template->page_height);
952 lgl_xml_set_prop_string (node, "description", template->description);
954 xml_create_meta_node ("product_url", template->product_url, node, ns );
955 for ( p=template->category_ids; p != NULL; p=p->next )
957 xml_create_meta_node ( "category", p->data, node, ns );
959 for ( p=template->frames; p != NULL; p=p->next )
961 frame = (lglTemplateFrame *)p->data;
962 xml_create_label_node (frame, node, ns);
967 /*--------------------------------------------------------------------------*/
968 /* PRIVATE. Add XML Template->Meta Node with category. */
969 /*--------------------------------------------------------------------------*/
971 xml_create_meta_node (const gchar *attr,
980 node = xmlNewChild (root, ns, (xmlChar *)"Meta", NULL);
981 lgl_xml_set_prop_string (node, attr, value);
986 /*--------------------------------------------------------------------------*/
987 /* PRIVATE. Add XML Template->Label Node. */
988 /*--------------------------------------------------------------------------*/
990 xml_create_label_node (const lglTemplateFrame *frame,
996 lglTemplateMarkup *markup;
997 lglTemplateLayout *layout;
999 switch (frame->shape)
1002 case LGL_TEMPLATE_FRAME_SHAPE_RECT:
1003 node = xmlNewChild(root, ns, (xmlChar *)"Label-rectangle", NULL);
1004 lgl_xml_set_prop_string (node, "id", frame->all.id);
1005 lgl_xml_set_prop_length (node, "width", frame->rect.w);
1006 lgl_xml_set_prop_length (node, "height", frame->rect.h);
1007 lgl_xml_set_prop_length (node, "round", frame->rect.r);
1008 lgl_xml_set_prop_length (node, "x_waste", frame->rect.x_waste);
1009 lgl_xml_set_prop_length (node, "y_waste", frame->rect.y_waste);
1012 case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
1013 node = xmlNewChild(root, ns, (xmlChar *)"Label-ellipse", NULL);
1014 lgl_xml_set_prop_string (node, "id", frame->all.id);
1015 lgl_xml_set_prop_length (node, "width", frame->ellipse.w);
1016 lgl_xml_set_prop_length (node, "height", frame->ellipse.h);
1017 lgl_xml_set_prop_length (node, "waste", frame->ellipse.waste);
1020 case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
1021 node = xmlNewChild(root, ns, (xmlChar *)"Label-round", NULL);
1022 lgl_xml_set_prop_string (node, "id", frame->all.id);
1023 lgl_xml_set_prop_length (node, "radius", frame->round.r);
1024 lgl_xml_set_prop_length (node, "waste", frame->round.waste);
1027 case LGL_TEMPLATE_FRAME_SHAPE_CD:
1028 node = xmlNewChild(root, ns, (xmlChar *)"Label-cd", NULL);
1029 lgl_xml_set_prop_string (node, "id", frame->all.id);
1030 lgl_xml_set_prop_length (node, "radius", frame->cd.r1);
1031 lgl_xml_set_prop_length (node, "hole", frame->cd.r2);
1032 if (frame->cd.w != 0.0)
1034 lgl_xml_set_prop_length (node, "width", frame->cd.w);
1036 if (frame->cd.h != 0.0)
1038 lgl_xml_set_prop_length (node, "height", frame->cd.h);
1040 lgl_xml_set_prop_length (node, "waste", frame->cd.waste);
1044 g_message ("Unknown label style");
1050 for ( p=frame->all.markups; p != NULL; p=p->next )
1052 markup = (lglTemplateMarkup *)p->data;
1053 switch (markup->type)
1055 case LGL_TEMPLATE_MARKUP_MARGIN:
1056 xml_create_markup_margin_node (markup, node, ns);
1058 case LGL_TEMPLATE_MARKUP_LINE:
1059 xml_create_markup_line_node (markup, node, ns);
1061 case LGL_TEMPLATE_MARKUP_CIRCLE:
1062 xml_create_markup_circle_node (markup, node, ns);
1064 case LGL_TEMPLATE_MARKUP_RECT:
1065 xml_create_markup_rect_node (markup, node, ns);
1067 case LGL_TEMPLATE_MARKUP_ELLIPSE:
1068 xml_create_markup_ellipse_node (markup, node, ns);
1071 g_message ("Unknown markup type");
1076 for ( p=frame->all.layouts; p != NULL; p=p->next )
1078 layout = (lglTemplateLayout *)p->data;
1079 xml_create_layout_node (layout, node, ns);
1084 /*--------------------------------------------------------------------------*/
1085 /* PRIVATE. Add XML Template->Label->Layout Node. */
1086 /*--------------------------------------------------------------------------*/
1088 xml_create_layout_node (const lglTemplateLayout *layout,
1094 node = xmlNewChild(root, ns, (xmlChar *)"Layout", NULL);
1095 lgl_xml_set_prop_int (node, "nx", layout->nx);
1096 lgl_xml_set_prop_int (node, "ny", layout->ny);
1097 lgl_xml_set_prop_length (node, "x0", layout->x0);
1098 lgl_xml_set_prop_length (node, "y0", layout->y0);
1099 lgl_xml_set_prop_length (node, "dx", layout->dx);
1100 lgl_xml_set_prop_length (node, "dy", layout->dy);
1104 /*--------------------------------------------------------------------------*/
1105 /* PRIVATE. Add XML Template->Label->Markup-margin Node. */
1106 /*--------------------------------------------------------------------------*/
1108 xml_create_markup_margin_node (const lglTemplateMarkup *markup,
1114 node = xmlNewChild(root, ns, (xmlChar *)"Markup-margin", NULL);
1116 lgl_xml_set_prop_length (node, "size", markup->margin.size);
1120 /*--------------------------------------------------------------------------*/
1121 /* PRIVATE. Add XML Template->Label->Markup-line Node. */
1122 /*--------------------------------------------------------------------------*/
1124 xml_create_markup_line_node (const lglTemplateMarkup *markup,
1130 node = xmlNewChild(root, ns, (xmlChar *)"Markup-line", NULL);
1132 lgl_xml_set_prop_length (node, "x1", markup->line.x1);
1133 lgl_xml_set_prop_length (node, "y1", markup->line.y1);
1134 lgl_xml_set_prop_length (node, "x2", markup->line.x2);
1135 lgl_xml_set_prop_length (node, "y2", markup->line.y2);
1139 /*--------------------------------------------------------------------------*/
1140 /* PRIVATE. Add XML Template->Label->Markup-circle Node. */
1141 /*--------------------------------------------------------------------------*/
1143 xml_create_markup_circle_node (const lglTemplateMarkup *markup,
1149 node = xmlNewChild(root, ns, (xmlChar *)"Markup-circle", NULL);
1151 lgl_xml_set_prop_length (node, "x0", markup->circle.x0);
1152 lgl_xml_set_prop_length (node, "y0", markup->circle.y0);
1153 lgl_xml_set_prop_length (node, "radius", markup->circle.r);
1158 /*--------------------------------------------------------------------------*/
1159 /* PRIVATE. Add XML Template->Label->Markup-rect Node. */
1160 /*--------------------------------------------------------------------------*/
1162 xml_create_markup_rect_node (const lglTemplateMarkup *markup,
1168 node = xmlNewChild(root, ns, (xmlChar *)"Markup-rect", NULL);
1170 lgl_xml_set_prop_length (node, "x1", markup->rect.x1);
1171 lgl_xml_set_prop_length (node, "y1", markup->rect.y1);
1172 lgl_xml_set_prop_length (node, "w", markup->rect.w);
1173 lgl_xml_set_prop_length (node, "h", markup->rect.h);
1174 lgl_xml_set_prop_length (node, "r", markup->rect.r);
1179 /*--------------------------------------------------------------------------*/
1180 /* PRIVATE. Add XML Template->Label->Markup-ellipse Node. */
1181 /*--------------------------------------------------------------------------*/
1183 xml_create_markup_ellipse_node (const lglTemplateMarkup *markup,
1189 node = xmlNewChild(root, ns, (xmlChar *)"Markup-ellipse", NULL);
1191 lgl_xml_set_prop_length (node, "x1", markup->ellipse.x1);
1192 lgl_xml_set_prop_length (node, "y1", markup->ellipse.y1);
1193 lgl_xml_set_prop_length (node, "w", markup->ellipse.w);
1194 lgl_xml_set_prop_length (node, "h", markup->ellipse.h);
1201 * Local Variables: -- emacs
1203 * c-basic-offset: 8 -- emacs
1204 * tab-width: 8 -- emacs
1205 * indent-tabs-mode: nil -- emacs