/* * Create a basic gimp-print XML document tree root */ stp_mxml_node_t * stp_xmldoc_create_generic(void) { stp_mxml_node_t *doc; stp_mxml_node_t *rootnode; /* Create the XML tree */ doc = stp_mxmlNewElement(NULL, "?xml"); stp_mxmlElementSetAttr(doc, "version", "1.0"); rootnode = stp_mxmlNewElement(doc, "gimp-print"); stp_mxmlElementSetAttr (rootnode, "xmlns", "http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0"); stp_mxmlElementSetAttr (rootnode, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); stp_mxmlElementSetAttr (rootnode, "xsi:schemaLocation", "http://gimp-print.sourceforge.net/xsd/gp.xsd-1.0 gimpprint.xsd"); return doc; }
stp_mxml_node_t * stp_xmltree_create_from_array(const stp_array_t *array) /* The array */ { int x_size, y_size; char *xs, *ys; stp_mxml_node_t *arraynode = NULL; stp_mxml_node_t *child = NULL; stp_xml_init(); /* Get array details */ stp_array_get_size(array, &x_size, &y_size); /* Construct the allocated strings required */ stp_asprintf(&xs, "%d", x_size); stp_asprintf(&ys, "%d", y_size); arraynode = stp_mxmlNewElement(NULL, "array"); stp_mxmlElementSetAttr(arraynode, "x-size", xs); stp_mxmlElementSetAttr(arraynode, "y-size", ys); stp_free(xs); stp_free(ys); child = stp_xmltree_create_from_sequence(stp_array_get_sequence(array)); if (child) stp_mxmlAdd(arraynode, STP_MXML_ADD_AFTER, NULL, child); else { stp_mxmlDelete(arraynode); arraynode = NULL; } stp_xml_exit(); return arraynode; }
stp_mxml_node_t * stp_xmltree_create_from_curve(const stp_curve_t *curve) /* The curve */ { stp_curve_wrap_mode_t wrapmode; stp_curve_type_t interptype; double gammaval, low, high; stp_sequence_t *seq; char *cgamma; stp_mxml_node_t *curvenode = NULL; stp_mxml_node_t *child = NULL; stp_xml_init(); /* Get curve details */ wrapmode = stp_curve_get_wrap(curve); interptype = stp_curve_get_interpolation_type(curve); gammaval = stp_curve_get_gamma(curve); if (gammaval && wrapmode != STP_CURVE_WRAP_NONE) { stp_deprintf(STP_DBG_CURVE_ERRORS, "stp_xmltree_create_from_curve: " "curve sets gamma and wrap_mode is not STP_CURVE_WRAP_NONE\n"); goto error; } /* Construct the allocated strings required */ stp_asprintf(&cgamma, "%g", gammaval); curvenode = stp_mxmlNewElement(NULL, "curve"); stp_mxmlElementSetAttr(curvenode, "wrap", stpi_wrap_mode_names[wrapmode]); stp_mxmlElementSetAttr(curvenode, "type", stpi_curve_type_names[interptype]); stp_mxmlElementSetAttr(curvenode, "gamma", cgamma); if (curve->piecewise) stp_mxmlElementSetAttr(curvenode, "piecewise", "true"); else stp_mxmlElementSetAttr(curvenode, "piecewise", "false"); stp_free(cgamma); seq = stp_sequence_create(); stp_curve_get_bounds(curve, &low, &high); stp_sequence_set_bounds(seq, low, high); if (gammaval != 0) /* A gamma curve does not require sequence data */ { stp_sequence_set_size(seq, 0); } else { const double *data; size_t count; data = stpi_curve_get_data_internal(curve, &count); stp_sequence_set_data(seq, count, data); } child = stp_xmltree_create_from_sequence(seq); if (seq) { stp_sequence_destroy(seq); seq = NULL; } if (child == NULL) { stp_deprintf(STP_DBG_CURVE_ERRORS, "stp_xmltree_create_from_curve: sequence node is NULL\n"); goto error; } stp_mxmlAdd(curvenode, STP_MXML_ADD_AFTER, NULL, child); stp_xml_exit(); return curvenode; error: stp_deprintf(STP_DBG_CURVE_ERRORS, "stp_xmltree_create_from_curve: error during xmltree creation\n"); if (curvenode) stp_mxmlDelete(curvenode); if (child) stp_mxmlDelete(child); stp_xml_exit(); return NULL; }