From 2eab1f387f9288550bac8c615b707eaa58235084 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Mon, 26 May 2003 05:08:21 +0000 Subject: [PATCH] In xml.[ch]: - Added functions to get and set length properties: gl_xml_get_prop_length() gl_xml_set_prop_length() - Changed gl_xml_get_prop_uint_hex() to gl_xml_get_prop_uint(). It should automatically determine base according to "C" rules, i.e. "0x" => hex, "0" => octal, and anything else is decimal. - gl_xml_get_prop_int() has also been modified to use the "C" rules. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@256 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/xml-label-04.c | 14 +++--- glabels2/src/xml-label.c | 82 +++++++++++++++--------------- glabels2/src/xml-template.c | 76 ++++++++++++++-------------- glabels2/src/xml.c | 99 +++++++++++++++++++++++++++++++++++-- glabels2/src/xml.h | 10 +++- 5 files changed, 189 insertions(+), 92 deletions(-) diff --git a/glabels2/src/xml-label-04.c b/glabels2/src/xml-label-04.c index a1e05a59..7d05b782 100644 --- a/glabels2/src/xml-label-04.c +++ b/glabels2/src/xml-label-04.c @@ -216,7 +216,7 @@ xml04_parse_text_props (xmlNodePtr object_node, just = gl_util_string_to_just (string); g_free (string); - color = gl_xml_get_prop_uint_hex (object_node, "color", 0); + color = gl_xml_get_prop_uint (object_node, "color", 0); gl_label_text_set_props (object, font_family, @@ -311,8 +311,8 @@ xml04_parse_box_props (xmlNodePtr node, line_width = gl_xml_get_prop_double (node, "line_width", 0); - line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0); - fill_color = gl_xml_get_prop_uint_hex (node, "fill_color", 0); + line_color = gl_xml_get_prop_uint (node, "line_color", 0); + fill_color = gl_xml_get_prop_uint (node, "fill_color", 0); gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); gl_label_box_set_line_width (object, line_width); @@ -339,7 +339,7 @@ xml04_parse_line_props (xmlNodePtr node, line_width = gl_xml_get_prop_double (node, "line_width", 0); - line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0); + line_color = gl_xml_get_prop_uint (node, "line_color", 0); gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); gl_label_line_set_line_width (object, line_width); @@ -365,8 +365,8 @@ xml04_parse_ellipse_props (xmlNodePtr node, line_width = gl_xml_get_prop_double (node, "line_width", 0); - line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0); - fill_color = gl_xml_get_prop_uint_hex (node, "fill_color", 0); + line_color = gl_xml_get_prop_uint (node, "line_color", 0); + fill_color = gl_xml_get_prop_uint (node, "fill_color", 0); gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); gl_label_ellipse_set_line_width (object, line_width); @@ -418,7 +418,7 @@ xml04_parse_barcode_props (xmlNodePtr node, gl_debug (DEBUG_XML, "START"); - color = gl_xml_get_prop_uint_hex (node, "color", 0); + color = gl_xml_get_prop_uint (node, "color", 0); string = xmlGetProp (node, "style"); style = gl_barcode_text_to_style (string); diff --git a/glabels2/src/xml-label.c b/glabels2/src/xml-label.c index de039044..1b0eed8a 100644 --- a/glabels2/src/xml-label.c +++ b/glabels2/src/xml-label.c @@ -398,8 +398,8 @@ xml_parse_object (xmlNodePtr object_node, g_free (string); - x = gl_xml_get_prop_double (object_node, "x", 0.0); - y = gl_xml_get_prop_double (object_node, "y", 0.0); + x = gl_xml_get_prop_length (object_node, "x", 0.0); + y = gl_xml_get_prop_length (object_node, "y", 0.0); gl_label_object_set_position (object, x, y); @@ -442,8 +442,8 @@ xml_parse_text_props (xmlNodePtr object_node, object = gl_label_text_new (label); - w = gl_xml_get_prop_double (object_node, "w", 0); - h = gl_xml_get_prop_double (object_node, "h", 0); + w = gl_xml_get_prop_length (object_node, "w", 0); + h = gl_xml_get_prop_length (object_node, "h", 0); font_family = xmlGetProp (object_node, "font_family"); @@ -459,7 +459,7 @@ xml_parse_text_props (xmlNodePtr object_node, just = gl_util_string_to_just (string); g_free (string); - color = gl_xml_get_prop_uint_hex (object_node, "color", 0); + color = gl_xml_get_prop_uint (object_node, "color", 0); lines = NULL; for (line_node = object_node->xmlChildrenNode; @@ -530,13 +530,13 @@ xml_parse_box_props (xmlNodePtr node, object = gl_label_box_new (label); - w = gl_xml_get_prop_double (node, "w", 0); - h = gl_xml_get_prop_double (node, "h", 0); + w = gl_xml_get_prop_length (node, "w", 0); + h = gl_xml_get_prop_length (node, "h", 0); - line_width = gl_xml_get_prop_double (node, "line_width", 1.0); + line_width = gl_xml_get_prop_length (node, "line_width", 1.0); - line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0); - fill_color = gl_xml_get_prop_uint_hex (node, "fill_color", 0); + line_color = gl_xml_get_prop_uint (node, "line_color", 0); + fill_color = gl_xml_get_prop_uint (node, "fill_color", 0); gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); gl_label_box_set_line_width (GL_LABEL_BOX(object), line_width); @@ -564,12 +564,12 @@ xml_parse_line_props (xmlNodePtr node, object = gl_label_line_new (label); - w = gl_xml_get_prop_double (node, "dx", 0); - h = gl_xml_get_prop_double (node, "dy", 0); + w = gl_xml_get_prop_length (node, "dx", 0); + h = gl_xml_get_prop_length (node, "dy", 0); - line_width = gl_xml_get_prop_double (node, "line_width", 1.0); + line_width = gl_xml_get_prop_length (node, "line_width", 1.0); - line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0); + line_color = gl_xml_get_prop_uint (node, "line_color", 0); gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); gl_label_line_set_line_width (GL_LABEL_LINE(object), line_width); @@ -596,13 +596,13 @@ xml_parse_ellipse_props (xmlNodePtr node, object = gl_label_ellipse_new (label); - w = gl_xml_get_prop_double (node, "w", 0); - h = gl_xml_get_prop_double (node, "h", 0); + w = gl_xml_get_prop_length (node, "w", 0); + h = gl_xml_get_prop_length (node, "h", 0); - line_width = gl_xml_get_prop_double (node, "line_width", 1.0); + line_width = gl_xml_get_prop_length (node, "line_width", 1.0); - line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0); - fill_color = gl_xml_get_prop_uint_hex (node, "fill_color", 0); + line_color = gl_xml_get_prop_uint (node, "line_color", 0); + fill_color = gl_xml_get_prop_uint (node, "fill_color", 0); gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); gl_label_ellipse_set_line_width (GL_LABEL_ELLIPSE(object), line_width); @@ -630,8 +630,8 @@ xml_parse_image_props (xmlNodePtr node, object = gl_label_image_new (label); - w = gl_xml_get_prop_double (node, "w", 0); - h = gl_xml_get_prop_double (node, "h", 0); + w = gl_xml_get_prop_length (node, "w", 0); + h = gl_xml_get_prop_length (node, "h", 0); filename = g_new0 (glTextNode, 1); for (child = node->xmlChildrenNode; child != NULL; child = child->next) { @@ -677,10 +677,10 @@ xml_parse_barcode_props (xmlNodePtr node, object = gl_label_barcode_new (label); - w = gl_xml_get_prop_double (node, "w", 0); - h = gl_xml_get_prop_double (node, "h", 0); + w = gl_xml_get_prop_length (node, "w", 0); + h = gl_xml_get_prop_length (node, "h", 0); - color = gl_xml_get_prop_uint_hex (node, "color", 0); + color = gl_xml_get_prop_uint (node, "color", 0); string = xmlGetProp (node, "style"); style = gl_barcode_text_to_style (string); @@ -952,8 +952,8 @@ xml_create_object (xmlNodePtr root, object_node = xmlNewChild (root, ns, "Object", NULL); gl_label_object_get_position (object, &x, &y); - gl_xml_set_prop_double (object_node, "x", x); - gl_xml_set_prop_double (object_node, "y", y); + gl_xml_set_prop_length (object_node, "x", x); + gl_xml_set_prop_length (object_node, "y", y); gl_label_object_get_affine (object, affine); gl_xml_set_prop_double (object_node, "a0", affine[0]); @@ -1013,8 +1013,8 @@ xml_create_text_props (xmlNodePtr object_node, &font_italic_flag, &color, &just); - gl_xml_set_prop_double (object_node, "w", w); - gl_xml_set_prop_double (object_node, "h", h); + gl_xml_set_prop_length (object_node, "w", w); + gl_xml_set_prop_length (object_node, "h", h); xmlSetProp (object_node, "font_family", font_family); gl_xml_set_prop_double (object_node, "font_size", font_size); @@ -1075,10 +1075,10 @@ 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)); - gl_xml_set_prop_double (object_node, "w", w); - gl_xml_set_prop_double (object_node, "h", h); + gl_xml_set_prop_length (object_node, "w", w); + gl_xml_set_prop_length (object_node, "h", h); - gl_xml_set_prop_double (object_node, "line_width", line_width); + gl_xml_set_prop_length (object_node, "line_width", line_width); gl_xml_set_prop_uint_hex (object_node, "line_color", line_color); gl_xml_set_prop_uint_hex (object_node, "fill_color", fill_color); @@ -1106,10 +1106,10 @@ 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)); - gl_xml_set_prop_double (object_node, "dx", w); - gl_xml_set_prop_double (object_node, "dy", h); + gl_xml_set_prop_length (object_node, "dx", w); + gl_xml_set_prop_length (object_node, "dy", h); - gl_xml_set_prop_double (object_node, "line_width", line_width); + gl_xml_set_prop_length (object_node, "line_width", line_width); gl_xml_set_prop_uint_hex (object_node, "line_color", line_color); @@ -1137,10 +1137,10 @@ 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)); - gl_xml_set_prop_double (object_node, "w", w); - gl_xml_set_prop_double (object_node, "h", h); + gl_xml_set_prop_length (object_node, "w", w); + gl_xml_set_prop_length (object_node, "h", h); - gl_xml_set_prop_double (object_node, "line_width", line_width); + gl_xml_set_prop_length (object_node, "line_width", line_width); gl_xml_set_prop_uint_hex (object_node, "line_color", line_color); gl_xml_set_prop_uint_hex (object_node, "fill_color", fill_color); @@ -1167,8 +1167,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)); - gl_xml_set_prop_double (object_node, "w", w); - gl_xml_set_prop_double (object_node, "h", h); + gl_xml_set_prop_length (object_node, "w", w); + gl_xml_set_prop_length (object_node, "h", h); if (filename->field_flag) { child = xmlNewChild (object_node, ns, "Field", NULL); @@ -1205,8 +1205,8 @@ xml_create_barcode_props (xmlNodePtr object_node, gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); - gl_xml_set_prop_double (object_node, "w", w); - gl_xml_set_prop_double (object_node, "h", h); + gl_xml_set_prop_length (object_node, "w", w); + gl_xml_set_prop_length (object_node, "h", h); text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE(object)); diff --git a/glabels2/src/xml-template.c b/glabels2/src/xml-template.c index 5bacd5e9..340ba60e 100644 --- a/glabels2/src/xml-template.c +++ b/glabels2/src/xml-template.c @@ -146,8 +146,8 @@ gl_xml_template_parse_sheet (xmlNodePtr sheet_node) } if (xmlStrEqual (template->page_size, "Other")) { - template->page_width = gl_xml_get_prop_double (sheet_node, "width", 0); - template->page_height = gl_xml_get_prop_double (sheet_node, "height", 0); + template->page_width = gl_xml_get_prop_length (sheet_node, "width", 0); + template->page_height = gl_xml_get_prop_length (sheet_node, "height", 0); } else { paper = gnome_print_paper_get_by_name (template->page_size); @@ -207,20 +207,20 @@ xml_parse_label (xmlNodePtr label_node, switch (template->label.style) { case GL_TEMPLATE_STYLE_RECT: - template->label.rect.w = gl_xml_get_prop_double (label_node, "width", 0); - template->label.rect.h = gl_xml_get_prop_double (label_node, "height", 0); - template->label.rect.r = gl_xml_get_prop_double (label_node, "round", 0); + template->label.rect.w = gl_xml_get_prop_length (label_node, "width", 0); + template->label.rect.h = gl_xml_get_prop_length (label_node, "height", 0); + template->label.rect.r = gl_xml_get_prop_length (label_node, "round", 0); break; case GL_TEMPLATE_STYLE_ROUND: - template->label.round.r = gl_xml_get_prop_double (label_node, "radius", 0); + template->label.round.r = gl_xml_get_prop_length (label_node, "radius", 0); break; case GL_TEMPLATE_STYLE_CD: - template->label.cd.r1 = gl_xml_get_prop_double (label_node, "radius", 0); - template->label.cd.r2 = gl_xml_get_prop_double (label_node, "hole", 0); - template->label.cd.w = gl_xml_get_prop_double (label_node, "width", 0); - template->label.cd.h = gl_xml_get_prop_double (label_node, "height", 0); + template->label.cd.r1 = gl_xml_get_prop_length (label_node, "radius", 0); + template->label.cd.r2 = gl_xml_get_prop_length (label_node, "hole", 0); + template->label.cd.w = gl_xml_get_prop_length (label_node, "width", 0); + template->label.cd.h = gl_xml_get_prop_length (label_node, "height", 0); break; default: @@ -258,11 +258,11 @@ xml_parse_layout (xmlNodePtr layout_node, nx = gl_xml_get_prop_int (layout_node, "nx", 1); ny = gl_xml_get_prop_int (layout_node, "ny", 1); - x0 = gl_xml_get_prop_double (layout_node, "x0", 0); - y0 = gl_xml_get_prop_double (layout_node, "y0", 0); + x0 = gl_xml_get_prop_length (layout_node, "x0", 0); + y0 = gl_xml_get_prop_length (layout_node, "y0", 0); - dx = gl_xml_get_prop_double (layout_node, "dx", 0); - dy = gl_xml_get_prop_double (layout_node, "dy", 0); + dx = gl_xml_get_prop_length (layout_node, "dx", 0); + dy = gl_xml_get_prop_length (layout_node, "dy", 0); for (node = layout_node->xmlChildrenNode; node != NULL; node = node->next) { @@ -295,7 +295,7 @@ xml_parse_markup (xmlNodePtr markup_node, type = xmlGetProp (markup_node, "type"); if (xmlStrEqual (type, "margin")) { - size = gl_xml_get_prop_double (markup_node, "size", 0); + size = gl_xml_get_prop_length (markup_node, "size", 0); template->label.any.markups = g_list_append (template->label.any.markups, @@ -303,10 +303,10 @@ xml_parse_markup (xmlNodePtr markup_node, } else if (xmlStrEqual (type, "line")) { - x1 = gl_xml_get_prop_double (markup_node, "x1", 0); - y1 = gl_xml_get_prop_double (markup_node, "y1", 0); - x2 = gl_xml_get_prop_double (markup_node, "x2", 0); - y2 = gl_xml_get_prop_double (markup_node, "y2", 0); + x1 = gl_xml_get_prop_length (markup_node, "x1", 0); + y1 = gl_xml_get_prop_length (markup_node, "y1", 0); + x2 = gl_xml_get_prop_length (markup_node, "x2", 0); + y2 = gl_xml_get_prop_length (markup_node, "y2", 0); template->label.any.markups = g_list_append (template->label.any.markups, @@ -359,8 +359,8 @@ gl_xml_template_add_sheet (const glTemplate *template, xmlSetProp (node, "size", template->page_size); if (xmlStrEqual (template->page_size, "Other")) { - gl_xml_set_prop_double (node, "width", template->page_width); - gl_xml_set_prop_double (node, "height", template->page_height); + gl_xml_set_prop_length (node, "width", template->page_width); + gl_xml_set_prop_length (node, "height", template->page_height); } @@ -398,25 +398,25 @@ xml_add_label (const glTemplate *template, case GL_TEMPLATE_STYLE_RECT: xmlSetProp (node, "style", "rectangle"); - 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); + gl_xml_set_prop_length (node, "width", template->label.rect.w); + gl_xml_set_prop_length (node, "height", template->label.rect.h); + gl_xml_set_prop_length (node, "round", template->label.rect.r); break; case GL_TEMPLATE_STYLE_ROUND: xmlSetProp (node, "style", "round"); - gl_xml_set_prop_double (node, "radius", template->label.round.r); + gl_xml_set_prop_length (node, "radius", template->label.round.r); break; case GL_TEMPLATE_STYLE_CD: xmlSetProp (node, "style", "cd"); - gl_xml_set_prop_double (node, "radius", template->label.cd.r1); - gl_xml_set_prop_double (node, "hole", template->label.cd.r2); + gl_xml_set_prop_length (node, "radius", template->label.cd.r1); + gl_xml_set_prop_length (node, "hole", template->label.cd.r2); if (template->label.cd.w != 0.0) { - gl_xml_set_prop_double (node, "width", template->label.cd.w); + gl_xml_set_prop_length (node, "width", template->label.cd.w); } if (template->label.cd.h != 0.0) { - gl_xml_set_prop_double (node, "height", template->label.cd.h); + gl_xml_set_prop_length (node, "height", template->label.cd.h); } break; @@ -466,10 +466,10 @@ xml_add_layout (glTemplateLayout *layout, node = xmlNewChild(root, ns, "Layout", NULL); 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_xml_set_prop_length (node, "x0", layout->x0); + gl_xml_set_prop_length (node, "y0", layout->y0); + gl_xml_set_prop_length (node, "dx", layout->dx); + gl_xml_set_prop_length (node, "dy", layout->dy); gl_debug (DEBUG_TEMPLATE, "END"); } @@ -489,7 +489,7 @@ xml_add_markup_margin (glTemplateMarkupMargin *margin, node = xmlNewChild(root, ns, "Markup", NULL); xmlSetProp (node, "type", "margin"); - gl_xml_set_prop_double (node, "size", margin->size); + gl_xml_set_prop_length (node, "size", margin->size); gl_debug (DEBUG_TEMPLATE, "END"); } @@ -509,10 +509,10 @@ xml_add_markup_line (glTemplateMarkupLine *line, node = xmlNewChild(root, ns, "Markup", NULL); xmlSetProp (node, "type", "line"); - 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_xml_set_prop_length (node, "x1", line->x1); + gl_xml_set_prop_length (node, "y1", line->y1); + gl_xml_set_prop_length (node, "x2", line->x2); + gl_xml_set_prop_length (node, "y2", line->y2); gl_debug (DEBUG_TEMPLATE, "END"); } diff --git a/glabels2/src/xml.c b/glabels2/src/xml.c index a42e6024..f0a210ec 100644 --- a/glabels2/src/xml.c +++ b/glabels2/src/xml.c @@ -27,14 +27,45 @@ /* Private macros and constants. */ /*========================================================*/ +#define POINTS_PER_POINT 1.0 +#define POINTS_PER_INCH 72.0 +#define POINTS_PER_MM 2.83464566929 +#define POINTS_PER_CM (10.0*POINTS_PER_MM) +#define POINTS_PER_M (1000.0*POINTS_PER_MM) + /*========================================================*/ /* Private types. */ /*========================================================*/ +typedef struct { + gchar *name; + gdouble points_per_unit; +} UnitTableEntry; + /*========================================================*/ /* Private globals. */ /*========================================================*/ +UnitTableEntry unit_table[] = { + {"point", POINTS_PER_POINT}, + {"points", POINTS_PER_POINT}, + {"pt", POINTS_PER_POINT}, + {"pts", POINTS_PER_POINT}, + {"in", POINTS_PER_INCH}, + {"inch", POINTS_PER_INCH}, + {"inches", POINTS_PER_INCH}, + {"mm", POINTS_PER_MM}, + {"millimeter", POINTS_PER_MM}, + {"millimeters", POINTS_PER_MM}, + {"cm", POINTS_PER_CM}, + {"centimeter", POINTS_PER_CM}, + {"centimeters", POINTS_PER_CM}, + {"m", POINTS_PER_M}, + {"meter", POINTS_PER_M}, + {"meters", POINTS_PER_M}, + {NULL, 0} +}; + /*========================================================*/ /* Private function prototypes. */ /*========================================================*/ @@ -97,7 +128,7 @@ gl_xml_get_prop_int (xmlNodePtr node, string = xmlGetProp (node, property); if ( string != NULL ) { - sscanf (string, "%d", &val); + val = strtol (string, NULL, 0); g_free (string); return val; } @@ -110,16 +141,16 @@ gl_xml_get_prop_int (xmlNodePtr node, /* Return value of hex property as an unsigned int. */ /****************************************************************************/ guint -gl_xml_get_prop_uint_hex (xmlNodePtr node, - const gchar *property, - guint default_val) +gl_xml_get_prop_uint (xmlNodePtr node, + const gchar *property, + guint default_val) { guint val; gchar *string; string = xmlGetProp (node, property); if ( string != NULL ) { - sscanf (string, "%x", &val); + val = strtoul (string, NULL, 0); g_free (string); return val; } @@ -128,6 +159,49 @@ gl_xml_get_prop_uint_hex (xmlNodePtr node, } +/****************************************************************************/ +/* Return value of length property as a double, converting to internal units*/ +/****************************************************************************/ +gdouble +gl_xml_get_prop_length (xmlNodePtr node, + const gchar *property, + gdouble default_val) +{ + gdouble val; + gchar *string, units[65]; + gint n, i; + + string = xmlGetProp (node, property); + if ( string != NULL ) { + n = sscanf (string, "%lf%64s", &val, units); + g_free (string); + + switch (n) { + case 1: + break; + case 2: + for (i=0; unit_table[i].name != NULL; i++) { + if (xmlStrcasecmp (units, unit_table[i].name) != 0) { + val *= unit_table[i].points_per_unit; + break; + } + } + if (unit_table[i].name == NULL) { + g_warning ("Line %d, Node \"%s\", Property \"%s\": Unknown units \"%s\", assuming points", + xmlGetLineNo (node), node->name, property, + units); + } + break; + default: + val = 0.0; + break; + } + return val; + } + + return default_val; +} + /****************************************************************************/ /* Set property from double. */ /****************************************************************************/ @@ -184,3 +258,18 @@ gl_xml_set_prop_uint_hex (xmlNodePtr node, g_free (string); } +/****************************************************************************/ +/* Set property from length. */ +/****************************************************************************/ +void +gl_xml_set_prop_length (xmlNodePtr node, + const gchar *property, + gdouble val) +{ + gchar *string; + + string = g_strdup_printf ("%gpts", val); + xmlSetProp (node, property, string); + g_free (string); +} + diff --git a/glabels2/src/xml.h b/glabels2/src/xml.h index ce69f796..a0057cdc 100644 --- a/glabels2/src/xml.h +++ b/glabels2/src/xml.h @@ -39,10 +39,14 @@ gint gl_xml_get_prop_int (xmlNodePtr node, const gchar *property, gint default_val); -guint gl_xml_get_prop_uint_hex (xmlNodePtr node, +guint gl_xml_get_prop_uint (xmlNodePtr node, const gchar *property, guint default_val); +gdouble gl_xml_get_prop_length (xmlNodePtr node, + const gchar *property, + gdouble default_val); + void gl_xml_set_prop_double (xmlNodePtr node, const gchar *property, @@ -60,6 +64,10 @@ void gl_xml_set_prop_uint_hex (xmlNodePtr node, const gchar *property, guint val); +void gl_xml_set_prop_length (xmlNodePtr node, + const gchar *property, + gdouble val); + G_END_DECLS -- 2.39.5