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,
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);
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);
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);
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);
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);
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");
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;
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);
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);
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);
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) {
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);
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]);
&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);
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);
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);
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);
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);
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));
}
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);
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:
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) {
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,
} 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,
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);
}
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;
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");
}
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");
}
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");
}
/* 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. */
/*========================================================*/
string = xmlGetProp (node, property);
if ( string != NULL ) {
- sscanf (string, "%d", &val);
+ val = strtol (string, NULL, 0);
g_free (string);
return val;
}
/* 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;
}
}
+/****************************************************************************/
+/* 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. */
/****************************************************************************/
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);
+}
+
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,
const gchar *property,
guint val);
+void gl_xml_set_prop_length (xmlNodePtr node,
+ const gchar *property,
+ gdouble val);
+
G_END_DECLS