]> git.sur5r.net Git - glabels/commitdiff
Added xml_set_prop_*() utilities to xml.c.
authorJim Evins <evins@snaught.com>
Wed, 8 Jan 2003 00:13:45 +0000 (00:13 +0000)
committerJim Evins <evins@snaught.com>
Wed, 8 Jan 2003 00:13:45 +0000 (00:13 +0000)
git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@243 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/src/template.c
glabels2/src/xml-label.c
glabels2/src/xml.c
glabels2/src/xml.h

index 6b323b99b2223fd43423a54f8c2e9e1630352db7..374d6fd0f027a2c8dbf974abb5ba31d3dc38e6d8 100644 (file)
@@ -776,7 +776,6 @@ gl_template_xml_add_sheet (const glTemplate *template,
 {
        xmlNodePtr  node;
        GList      *p;
-       gchar      *string;
 
        gl_debug (DEBUG_TEMPLATE, "START");
 
@@ -787,13 +786,9 @@ gl_template_xml_add_sheet (const glTemplate *template,
        xmlSetProp (node, "size", template->page_size);
        if (g_strcasecmp (template->page_size, "Other") == 0) {
 
-               string = g_strdup_printf ("%g", template->page_width);
-               xmlSetProp (node, "width", string);
-               g_free (string);
+               gl_xml_set_prop_double (node, "width", template->page_width);
+               gl_xml_set_prop_double (node, "height", template->page_height);
 
-               string = g_strdup_printf ("%g", template->page_height);
-               xmlSetProp (node, "height", string);
-               g_free (string);
        }
 
        xmlSetProp (node, "description", template->description);
@@ -816,7 +811,6 @@ xml_add_label (const glTemplate *template,
               xmlNsPtr          ns)
 {
        xmlNodePtr        node;
-       gchar            *string;
        GList            *p;
        glTemplateMarkup *markup;
        glTemplateLayout *layout;
@@ -828,46 +822,35 @@ xml_add_label (const glTemplate *template,
        xmlSetProp (node, "id", "0");
 
        switch (template->label.style) {
+
        case GL_TEMPLATE_STYLE_RECT:
                xmlSetProp (node, "style", "rectangle");
-               string = g_strdup_printf ("%g", template->label.rect.w);
-               xmlSetProp (node, "width", string);
-               g_free (string);
-               string = g_strdup_printf ("%g", template->label.rect.h);
-               xmlSetProp (node, "height", string);
-               g_free (string);
-               string = g_strdup_printf ("%g", template->label.rect.r);
-               xmlSetProp (node, "round", string);
-               g_free (string);
+               gl_xml_set_prop_double (node, "width",  template->label.rect.w);
+               gl_xml_set_prop_double (node, "height", template->label.rect.h);
+               gl_xml_set_prop_double (node, "round",  template->label.rect.r);
                break;
+
        case GL_TEMPLATE_STYLE_ROUND:
                xmlSetProp (node, "style", "round");
-               string = g_strdup_printf ("%g", template->label.round.r);
-               xmlSetProp (node, "radius", string);
-               g_free (string);
+               gl_xml_set_prop_double (node, "radius",  template->label.round.r);
                break;
+
        case GL_TEMPLATE_STYLE_CD:
                xmlSetProp (node, "style", "cd");
-               string = g_strdup_printf ("%g", template->label.cd.r1);
-               xmlSetProp (node, "radius", string);
-               g_free (string);
-               string = g_strdup_printf ("%g", template->label.cd.r2);
-               xmlSetProp (node, "hole", string);
-               g_free (string);
-               if (template->label.cd.h != 0.0) {
-                       string = g_strdup_printf ("%g", template->label.cd.h);
-                       xmlSetProp (node, "width", string);
-                       g_free (string);
-               }
+               gl_xml_set_prop_double (node, "radius",  template->label.cd.r1);
+               gl_xml_set_prop_double (node, "hole",    template->label.cd.r2);
                if (template->label.cd.w != 0.0) {
-                       string = g_strdup_printf ("%g", template->label.cd.w);
-                       xmlSetProp (node, "height", string);
-                       g_free (string);
+                       gl_xml_set_prop_double (node, "width",  template->label.cd.w);
+               }
+               if (template->label.cd.h != 0.0) {
+                       gl_xml_set_prop_double (node, "height", template->label.cd.h);
                }
                break;
+
        default:
                g_warning ("Unknown label style");
                break;
+
        }
 
        for ( p=template->label.any.markups; p != NULL; p=p->next ) {
@@ -904,29 +887,16 @@ xml_add_layout (glTemplateLayout *layout,
                xmlNsPtr          ns)
 {
        xmlNodePtr  node;
-       gchar      *string;
 
        gl_debug (DEBUG_TEMPLATE, "START");
 
        node = xmlNewChild(root, ns, "Layout", NULL);
-       string = g_strdup_printf ("%d", layout->nx);
-       xmlSetProp (node, "nx", string);
-       g_free (string);
-       string = g_strdup_printf ("%d", layout->ny);
-       xmlSetProp (node, "ny", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", layout->x0);
-       xmlSetProp (node, "x0", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", layout->y0);
-       xmlSetProp (node, "y0", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", layout->dx);
-       xmlSetProp (node, "dx", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", layout->dy);
-       xmlSetProp (node, "dy", string);
-       g_free (string);
+       gl_xml_set_prop_int (node, "nx", layout->nx);
+       gl_xml_set_prop_int (node, "ny", layout->ny);
+       gl_xml_set_prop_double (node, "x0", layout->x0);
+       gl_xml_set_prop_double (node, "y0", layout->y0);
+       gl_xml_set_prop_double (node, "dx", layout->dx);
+       gl_xml_set_prop_double (node, "dy", layout->dy);
 
        gl_debug (DEBUG_TEMPLATE, "END");
 }
@@ -940,16 +910,13 @@ xml_add_markup_margin (glTemplateMarkupMargin *margin,
                       xmlNsPtr                ns)
 {
        xmlNodePtr  node;
-       gchar      *string;
 
        gl_debug (DEBUG_TEMPLATE, "START");
 
        node = xmlNewChild(root, ns, "Markup", NULL);
        xmlSetProp (node, "type", "margin");
 
-       string = g_strdup_printf ("%g", margin->size);
-       xmlSetProp (node, "size", string);
-       g_free (string);
+       gl_xml_set_prop_double (node, "size", margin->size);
 
        gl_debug (DEBUG_TEMPLATE, "END");
 }
@@ -963,25 +930,16 @@ xml_add_markup_line (glTemplateMarkupLine *line,
                     xmlNsPtr              ns)
 {
        xmlNodePtr  node;
-       gchar      *string;
 
        gl_debug (DEBUG_TEMPLATE, "START");
 
        node = xmlNewChild(root, ns, "Markup", NULL);
        xmlSetProp (node, "type", "line");
 
-       string = g_strdup_printf ("%g", line->x1);
-       xmlSetProp (node, "x1", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", line->y1);
-       xmlSetProp (node, "y1", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", line->x2);
-       xmlSetProp (node, "x2", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", line->y2);
-       xmlSetProp (node, "y2", string);
-       g_free (string);
+       gl_xml_set_prop_double (node, "x1", line->x1);
+       gl_xml_set_prop_double (node, "y1", line->y1);
+       gl_xml_set_prop_double (node, "x2", line->x2);
+       gl_xml_set_prop_double (node, "y2", line->y2);
 
        gl_debug (DEBUG_TEMPLATE, "END");
 }
index 5f1edce719a3d893851b782893253a5104b184d8..c1f05a7e9262f4f2696d1b797a8ad6db0b44ae99 100644 (file)
@@ -916,7 +916,7 @@ xml_create_objects (xmlNodePtr  root,
 
        node = xmlNewChild (root, ns, "Objects", NULL);
        xmlSetProp (node, "id", "0");
-       xmlSetProp (node, "rotate", rotate_flag ? "True" : "False");
+       gl_xml_set_prop_boolean (node, "rotate", rotate_flag);
 
        for (p = label->objects; p != NULL; p = p->next) {
                xml_create_object (node, ns, GL_LABEL_OBJECT(p->data));
@@ -935,7 +935,6 @@ xml_create_object (xmlNodePtr     root,
 {
        xmlNodePtr  object_node;
        gdouble     x, y;
-       gchar      *string;
        gdouble     affine[6];
 
        gl_debug (DEBUG_XML, "START");
@@ -943,32 +942,16 @@ xml_create_object (xmlNodePtr     root,
        object_node = xmlNewChild (root, ns, "Object", NULL);
 
        gl_label_object_get_position (object, &x, &y);
-       string = g_strdup_printf ("%g", x);
-       xmlSetProp (object_node, "x", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", y);
-       xmlSetProp (object_node, "y", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "x", x);
+       gl_xml_set_prop_double (object_node, "y", y);
 
        gl_label_object_get_affine (object, affine);
-       string = g_strdup_printf ("%g", affine[0]);
-       xmlSetProp (object_node, "a0", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", affine[1]);
-       xmlSetProp (object_node, "a1", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", affine[2]);
-       xmlSetProp (object_node, "a2", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", affine[3]);
-       xmlSetProp (object_node, "a3", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", affine[4]);
-       xmlSetProp (object_node, "a4", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", affine[5]);
-       xmlSetProp (object_node, "a5", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "a0", affine[0]);
+       gl_xml_set_prop_double (object_node, "a1", affine[1]);
+       gl_xml_set_prop_double (object_node, "a2", affine[2]);
+       gl_xml_set_prop_double (object_node, "a3", affine[3]);
+       gl_xml_set_prop_double (object_node, "a4", affine[4]);
+       gl_xml_set_prop_double (object_node, "a5", affine[5]);
 
        if ( GL_IS_LABEL_TEXT(object) ) {
                xml_create_text_props (object_node, ns, object);
@@ -1006,7 +989,6 @@ xml_create_text_props (xmlNodePtr     object_node,
        gboolean          font_italic_flag;
        guint             color;
        GtkJustification  just;
-       gchar            *string;
        GList            *p_line, *p_node;
        glTextNode       *node_text;
 
@@ -1021,27 +1003,18 @@ xml_create_text_props (xmlNodePtr     object_node,
                                 &font_italic_flag,
                                 &color, &just);
 
-       string = g_strdup_printf ("%g", w);
-       xmlSetProp (object_node, "w", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", h);
-       xmlSetProp (object_node, "h", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "w", w);
+       gl_xml_set_prop_double (object_node, "h", h);
 
        xmlSetProp (object_node, "font_family", font_family);
-       string = g_strdup_printf ("%g", font_size);
-       xmlSetProp (object_node, "font_size", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "font_size", font_size);
        xmlSetProp (object_node, "font_weight",
                    gl_util_weight_to_string (font_weight));
-       xmlSetProp (object_node, "font_italic",
-                   font_italic_flag?"True":"False");
+       gl_xml_set_prop_boolean (object_node, "font_italic", font_italic_flag);
 
        xmlSetProp (object_node, "justify", gl_util_just_to_string (just));
 
-       string = g_strdup_printf ("0x%08x", color);
-       xmlSetProp (object_node, "color", string);
-       g_free (string);
+       gl_xml_set_prop_uint_hex (object_node, "color", color);
 
        for (p_line = lines; p_line != NULL; p_line = p_line->next) {
                line_node = xmlNewChild (object_node, ns, "Line", NULL);
@@ -1079,7 +1052,6 @@ xml_create_box_props (xmlNodePtr     object_node,
                      xmlNsPtr       ns,
                      glLabelObject *object)
 {
-       gchar   *string;
        gdouble  line_width;
        guint    line_color, fill_color;
        gdouble  w, h;
@@ -1093,24 +1065,13 @@ xml_create_box_props (xmlNodePtr     object_node,
        line_color = gl_label_box_get_line_color (GL_LABEL_BOX(object));
        fill_color = gl_label_box_get_fill_color (GL_LABEL_BOX(object));
 
-       string = g_strdup_printf ("%g", w);
-       xmlSetProp (object_node, "w", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", h);
-       xmlSetProp (object_node, "h", string);
-       g_free (string);
-
-       string = g_strdup_printf ("%g", line_width);
-       xmlSetProp (object_node, "line_width", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "w", w);
+       gl_xml_set_prop_double (object_node, "h", h);
 
-       string = g_strdup_printf ("0x%08x", line_color);
-       xmlSetProp (object_node, "line_color", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "line_width", line_width);
 
-       string = g_strdup_printf ("0x%08x", fill_color);
-       xmlSetProp (object_node, "fill_color", string);
-       g_free (string);
+       gl_xml_set_prop_uint_hex (object_node, "line_color", line_color);
+       gl_xml_set_prop_uint_hex (object_node, "fill_color", fill_color);
 
        gl_debug (DEBUG_XML, "END");
 }
@@ -1123,7 +1084,6 @@ xml_create_line_props (xmlNodePtr     object_node,
                       xmlNsPtr       ns,
                       glLabelObject *object)
 {
-       gchar   *string;
        gdouble  line_width;
        guint    line_color;
        gdouble  w, h;
@@ -1136,20 +1096,12 @@ xml_create_line_props (xmlNodePtr     object_node,
        line_width = gl_label_line_get_line_width (GL_LABEL_LINE(object));
        line_color = gl_label_line_get_line_color (GL_LABEL_LINE(object));
 
-       string = g_strdup_printf ("%g", w);
-       xmlSetProp (object_node, "dx", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", h);
-       xmlSetProp (object_node, "dy", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "dx", w);
+       gl_xml_set_prop_double (object_node, "dy", h);
 
-       string = g_strdup_printf ("%g", line_width);
-       xmlSetProp (object_node, "line_width", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "line_width", line_width);
 
-       string = g_strdup_printf ("0x%08x", line_color);
-       xmlSetProp (object_node, "line_color", string);
-       g_free (string);
+       gl_xml_set_prop_uint_hex (object_node, "line_color", line_color);
 
        gl_debug (DEBUG_XML, "END");
 }
@@ -1162,7 +1114,6 @@ xml_create_ellipse_props (xmlNodePtr     object_node,
                          xmlNsPtr       ns,
                          glLabelObject *object)
 {
-       gchar   *string;
        gdouble  line_width;
        guint    line_color, fill_color;
        gdouble  w, h;
@@ -1176,24 +1127,13 @@ xml_create_ellipse_props (xmlNodePtr     object_node,
        line_color = gl_label_ellipse_get_line_color (GL_LABEL_ELLIPSE(object));
        fill_color = gl_label_ellipse_get_fill_color (GL_LABEL_ELLIPSE(object));
 
-       string = g_strdup_printf ("%g", w);
-       xmlSetProp (object_node, "w", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", h);
-       xmlSetProp (object_node, "h", string);
-       g_free (string);
-
-       string = g_strdup_printf ("%g", line_width);
-       xmlSetProp (object_node, "line_width", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "w", w);
+       gl_xml_set_prop_double (object_node, "h", h);
 
-       string = g_strdup_printf ("0x%08x", line_color);
-       xmlSetProp (object_node, "line_color", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "line_width", line_width);
 
-       string = g_strdup_printf ("0x%08x", fill_color);
-       xmlSetProp (object_node, "fill_color", string);
-       g_free (string);
+       gl_xml_set_prop_uint_hex (object_node, "line_color", line_color);
+       gl_xml_set_prop_uint_hex (object_node, "fill_color", fill_color);
 
        gl_debug (DEBUG_XML, "END");
 }
@@ -1206,7 +1146,6 @@ xml_create_image_props (xmlNodePtr     object_node,
                        xmlNsPtr       ns,
                        glLabelObject *object)
 {
-       gchar      *string;
        gdouble     w, h;
        glTextNode *filename;
        xmlNodePtr  child;
@@ -1218,12 +1157,8 @@ xml_create_image_props (xmlNodePtr     object_node,
        gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
        filename = gl_label_image_get_filename (GL_LABEL_IMAGE(object));
 
-       string = g_strdup_printf ("%g", w);
-       xmlSetProp (object_node, "w", string);
-       g_free (string);
-       string = g_strdup_printf ("%g", h);
-       xmlSetProp (object_node, "h", string);
-       g_free (string);
+       gl_xml_set_prop_double (object_node, "w", w);
+       gl_xml_set_prop_double (object_node, "h", h);
 
        if (filename->field_flag) {
                child = xmlNewChild (object_node, ns, "Field", NULL);
@@ -1252,7 +1187,6 @@ xml_create_barcode_props (xmlNodePtr     object_node,
        guint               color;
        gdouble             scale;
        xmlNodePtr          child;
-       gchar              *string;
 
        gl_debug (DEBUG_XML, "START");
 
@@ -1262,15 +1196,11 @@ xml_create_barcode_props (xmlNodePtr     object_node,
        gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
                                    &style, &text_flag, &color, &scale);
 
-       string = g_strdup_printf ("0x%08x", color);
-       xmlSetProp (object_node, "color", string);
-       g_free (string);
+       gl_xml_set_prop_uint_hex (object_node, "color", color);
 
        xmlSetProp (object_node, "style", gl_barcode_style_to_text (style));
-       xmlSetProp (object_node, "text", text_flag?"True":"False");
-       string = g_strdup_printf ("%g", scale);
-       xmlSetProp (object_node, "scale", string);
-       g_free (string);
+       gl_xml_set_prop_boolean (object_node, "text", text_flag);
+       gl_xml_set_prop_double (object_node, "scale", scale);
 
        if (text_node->field_flag) {
                child = xmlNewChild (object_node, ns, "Field", NULL);
index e6b7d53da77629c0d172c48764bb89f8f7a25939..3dd99748345ef7fb2250ae3af417eba6b0c4e25d 100644 (file)
@@ -127,3 +127,55 @@ gl_xml_get_prop_uint_hex (xmlNodePtr   node,
 }
 
 
+/****************************************************************************/
+/* Set property from double.                                                */
+/****************************************************************************/
+void     gl_xml_set_prop_double   (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gdouble       val)
+{
+       gchar  *string;
+
+       string = g_strdup_printf ("%g", val);
+       xmlSetProp (node, property, string);
+       g_free (string);
+}
+
+/****************************************************************************/
+/* Set property from boolean.                                               */
+/****************************************************************************/
+void     gl_xml_set_prop_boolean  (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gboolean      val)
+{
+       xmlSetProp (node, property, (val ? "True" : "False"));
+}
+
+/****************************************************************************/
+/* Set property from int.                                                   */
+/****************************************************************************/
+void     gl_xml_set_prop_int      (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gint          val)
+{
+       gchar  *string;
+
+       string = g_strdup_printf ("%d", val);
+       xmlSetProp (node, property, string);
+       g_free (string);
+}
+
+/****************************************************************************/
+/* Set property from uint in hex.                                           */
+/****************************************************************************/
+void     gl_xml_set_prop_uint_hex (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  guint         val)
+{
+       gchar  *string;
+
+       string = g_strdup_printf ("0x%08x", val);
+       xmlSetProp (node, property, string);
+       g_free (string);
+}
+
index c20581b668563b2f6a81bb8136589fcbb84b6421..ce69f796752d79785938155f5b1956dda658ce69 100644 (file)
@@ -43,6 +43,23 @@ guint    gl_xml_get_prop_uint_hex (xmlNodePtr    node,
                                   const gchar  *property,
                                   guint         default_val);
 
+
+void     gl_xml_set_prop_double   (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gdouble       val);
+
+void     gl_xml_set_prop_boolean  (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gboolean      val);
+
+void     gl_xml_set_prop_int      (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  gint          val);
+
+void     gl_xml_set_prop_uint_hex (xmlNodePtr    node,
+                                  const gchar  *property,
+                                  guint         val);
+
 G_END_DECLS