From ec932804d8b229fff5fea65452a4f6d0982e7cb1 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 23 Oct 2005 20:26:18 +0000 Subject: [PATCH] 2005-10-23 Jim Evins * libglabels/xml.h: * libglabels/xml.c: (gl_xml_get_prop_string), (gl_xml_get_prop_i18n_string), (gl_xml_set_prop_string), (gl_xml_is_node), (gl_xml_get_node_content): Added new XML utility functions. * libglabels/xml-paper.c: * libglabels/xml-template.c: * src/xml-label.c: Cleanup by using new xml utilities created above. * libglabels/paper.c: (gl_paper_free): * src/file.c: (new_response): * src/object-editor-image-page.c: (add_image_filters_to_chooser): * src/pixbuf-cache.c: (gl_pixbuf_cache_add_pixbuf), (gl_pixbuf_cache_get_pixbuf): * src/ui-property-bar.c: (gl_ui_property_bar_construct_color_combo): * src/view-highlight.c: (gl_view_highlight_finalize): * src/view-image.c: (update_object_from_editor_cb): * src/view.c: (gl_view_finalize), (draw_bg_fg_layers), (draw_bg_fg_rounded_rect), (draw_bg_fg_round), (draw_bg_fg_cd), (draw_bg_fg_cd_bc), (draw_markup_layer), (draw_markup_margin), (draw_markup_margin_rect), (draw_markup_margin_rounded_rect), (draw_markup_margin_round), (draw_markup_margin_cd), (draw_markup_margin_cd_bc): * src/wdgt-mini-preview.c: (mini_outline_list_new): * src/wdgt-rotate-label.c: (gl_wdgt_rotate_label_finalize): Plugged various memory leaks located with valgrind. * src/view-image.c: (update_canvas_item_from_object_cb): Don't allow a width or height of zero when drawing pixbuf. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@554 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/ChangeLog | 34 ++++ glabels2/libglabels/paper.c | 2 +- glabels2/libglabels/xml-paper.c | 30 ++-- glabels2/libglabels/xml-template.c | 159 +++++++++---------- glabels2/libglabels/xml.c | 150 ++++++++++++++++++ glabels2/libglabels/xml.h | 29 ++++ glabels2/src/file.c | 2 + glabels2/src/object-editor-image-page.c | 11 +- glabels2/src/pixbuf-cache.c | 9 +- glabels2/src/ui-property-bar.c | 2 + glabels2/src/view-highlight.c | 4 + glabels2/src/view-image.c | 5 +- glabels2/src/view.c | 27 ++++ glabels2/src/wdgt-mini-preview.c | 2 + glabels2/src/wdgt-rotate-label.c | 5 + glabels2/src/xml-label.c | 199 +++++++++++------------- 16 files changed, 449 insertions(+), 221 deletions(-) diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 8f9ccd7b..a03b3a64 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,37 @@ +2005-10-23 Jim Evins + + reviewed by: + + * libglabels/xml.h: + * libglabels/xml.c: (gl_xml_get_prop_string), + (gl_xml_get_prop_i18n_string), (gl_xml_set_prop_string), + (gl_xml_is_node), (gl_xml_get_node_content): + Added new XML utility functions. + * libglabels/xml-paper.c: + * libglabels/xml-template.c: + * src/xml-label.c: + Cleanup by using new xml utilities created above. + * libglabels/paper.c: (gl_paper_free): + * src/file.c: (new_response): + * src/object-editor-image-page.c: (add_image_filters_to_chooser): + * src/pixbuf-cache.c: (gl_pixbuf_cache_add_pixbuf), + (gl_pixbuf_cache_get_pixbuf): + * src/ui-property-bar.c: + (gl_ui_property_bar_construct_color_combo): + * src/view-highlight.c: (gl_view_highlight_finalize): + * src/view-image.c: (update_object_from_editor_cb): + * src/view.c: (gl_view_finalize), (draw_bg_fg_layers), + (draw_bg_fg_rounded_rect), (draw_bg_fg_round), (draw_bg_fg_cd), + (draw_bg_fg_cd_bc), (draw_markup_layer), (draw_markup_margin), + (draw_markup_margin_rect), (draw_markup_margin_rounded_rect), + (draw_markup_margin_round), (draw_markup_margin_cd), + (draw_markup_margin_cd_bc): + * src/wdgt-mini-preview.c: (mini_outline_list_new): + * src/wdgt-rotate-label.c: (gl_wdgt_rotate_label_finalize): + Plugged various memory leaks located with valgrind. + * src/view-image.c: (update_canvas_item_from_object_cb): + Don't allow a width or height of zero when drawing pixbuf. + 2005-10-22 Jim Evins * libglabels/xml-paper.c: diff --git a/glabels2/libglabels/paper.c b/glabels2/libglabels/paper.c index f4a54bf9..26063a64 100644 --- a/glabels2/libglabels/paper.c +++ b/glabels2/libglabels/paper.c @@ -148,7 +148,7 @@ void gl_paper_free (glPaper *paper) if ( paper != NULL ) { g_free (paper->id); - paper->name = NULL; + paper->id = NULL; g_free (paper->name); paper->name = NULL; diff --git a/glabels2/libglabels/xml-paper.c b/glabels2/libglabels/xml-paper.c index 894349a6..c30cb4df 100644 --- a/glabels2/libglabels/xml-paper.c +++ b/glabels2/libglabels/xml-paper.c @@ -113,7 +113,7 @@ gl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc) xmlFreeDoc (papers_doc); return papers; } - if (!xmlStrEqual (root->name, (xmlChar *)"Glabels-paper-sizes")) { + if (!gl_xml_is_node (root, "Glabels-paper-sizes")) { g_warning ("\"%s\" is not a glabels paper file (wrong root node)", papers_doc->name); xmlFreeDoc (papers_doc); @@ -122,12 +122,12 @@ gl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc) for (node = root->xmlChildrenNode; node != NULL; node = node->next) { - if (xmlStrEqual (node->name, (xmlChar *)"Paper-size")) { + if (gl_xml_is_node (node, "Paper-size")) { paper = gl_xml_paper_parse_paper_node (node); papers = g_list_append (papers, paper); } else { if ( !xmlNodeIsText(node) ) { - if (!xmlStrEqual (node->name,(xmlChar *)"comment")) { + if (!gl_xml_is_node (node, "comment")) { g_warning ("bad node = \"%s\"",node->name); } } @@ -151,34 +151,22 @@ glPaper * gl_xml_paper_parse_paper_node (xmlNodePtr paper_node) { glPaper *paper; - xmlChar *id, *name; + gchar *id, *name; gdouble width, height; LIBXML_TEST_VERSION; - id = xmlGetProp (paper_node, (xmlChar *)"id"); + id = gl_xml_get_prop_string (paper_node, "id", NULL); - name = xmlGetProp (paper_node, (xmlChar *)"_name"); - if (name != NULL) { - - xmlChar *tmp = (xmlChar *)gettext ((char *)name); - - if (tmp != name) { - xmlFree (name); - name = xmlStrdup (tmp); - } - - } else { - name = xmlGetProp (paper_node, (xmlChar *)"name"); - } + name = gl_xml_get_prop_i18n_string (paper_node, "name", NULL); width = gl_xml_get_prop_length (paper_node, "width", 0); height = gl_xml_get_prop_length (paper_node, "height", 0); - paper = gl_paper_new ((gchar *)id, (gchar *)name, width, height); + paper = gl_paper_new (id, name, width, height); - xmlFree (id); - xmlFree (name); + g_free (id); + g_free (name); return paper; } diff --git a/glabels2/libglabels/xml-template.c b/glabels2/libglabels/xml-template.c index 8994c19c..339a61b0 100644 --- a/glabels2/libglabels/xml-template.c +++ b/glabels2/libglabels/xml-template.c @@ -149,7 +149,7 @@ gl_xml_template_parse_templates_doc (const xmlDocPtr templates_doc) templates_doc->URL); return templates; } - if (!xmlStrEqual (root->name, (xmlChar *)"Glabels-templates")) { + if (!gl_xml_is_node (root, "Glabels-templates")) { g_warning ("\"%s\" is not a glabels template file (wrong root node)", templates_doc->URL); return templates; @@ -157,12 +157,12 @@ gl_xml_template_parse_templates_doc (const xmlDocPtr templates_doc) for (node = root->xmlChildrenNode; node != NULL; node = node->next) { - if (xmlStrEqual (node->name, (xmlChar *)"Template")) { + if (gl_xml_is_node (node, "Template")) { template = gl_xml_template_parse_template_node (node); templates = g_list_append (templates, template); } else { if ( !xmlNodeIsText(node) ) { - if (!xmlStrEqual (node->name,(xmlChar *)"comment")) { + if (!gl_xml_is_node (node,"comment")) { g_warning ("bad node = \"%s\"",node->name); } } @@ -185,46 +185,33 @@ gl_xml_template_parse_templates_doc (const xmlDocPtr templates_doc) glTemplate * gl_xml_template_parse_template_node (const xmlNodePtr template_node) { - xmlChar *name; - xmlChar *description; - xmlChar *page_size; + gchar *name; + gchar *description; + gchar *page_size; gdouble page_width, page_height; glPaper *paper = NULL; glTemplate *template; xmlNodePtr node; - name = xmlGetProp (template_node, (xmlChar *)"name"); + name = gl_xml_get_prop_string (template_node, "name", NULL); + description = gl_xml_get_prop_i18n_string (template_node, "description", NULL); + page_size = gl_xml_get_prop_string (template_node, "size", NULL); - description = xmlGetProp (template_node, (xmlChar *)"_description"); - if (description != NULL) { - - xmlChar *tmp = (xmlChar *)gettext ((char *)description); - - if (tmp != description) { - xmlFree (description); - description = xmlStrdup (tmp); - } - - } else { - description = xmlGetProp (template_node, (xmlChar *)"description"); - } - - page_size = xmlGetProp (template_node, (xmlChar *)"size"); - if (gl_paper_is_id_other ((gchar *)page_size)) { + if (gl_paper_is_id_other (page_size)) { page_width = gl_xml_get_prop_length (template_node, "width", 0); page_height = gl_xml_get_prop_length (template_node, "height", 0); } else { - paper = gl_paper_from_id ((gchar *)page_size); + paper = gl_paper_from_id (page_size); if (paper == NULL) { /* This should always be an id, but just in case a name slips by! */ g_warning (_("Unknown page size id \"%s\", trying as name"), page_size); - paper = gl_paper_from_name ((gchar *)page_size); - xmlFree (page_size); - page_size = xmlStrdup ((xmlChar *)paper->id); + paper = gl_paper_from_name (page_size); + g_free (page_size); + page_size = g_strdup (paper->id); } if (paper != NULL) { page_width = paper->width; @@ -237,33 +224,33 @@ gl_xml_template_parse_template_node (const xmlNodePtr template_node) paper = NULL; } - template = gl_template_new ((gchar *)name, - (gchar *)description, - (gchar *)page_size, + template = gl_template_new (name, + description, + page_size, page_width, page_height); for (node = template_node->xmlChildrenNode; node != NULL; node = node->next) { - if (xmlStrEqual (node->name, (xmlChar *)"Label-rectangle")) { + if (gl_xml_is_node (node, "Label-rectangle")) { xml_parse_label_rectangle_node (node, template); - } else if (xmlStrEqual (node->name, (xmlChar *)"Label-round")) { + } else if (gl_xml_is_node (node, "Label-round")) { xml_parse_label_round_node (node, template); - } else if (xmlStrEqual (node->name, (xmlChar *)"Label-cd")) { + } else if (gl_xml_is_node (node, "Label-cd")) { xml_parse_label_cd_node (node, template); - } else if (xmlStrEqual (node->name, (xmlChar *)"Alias")) { + } else if (gl_xml_is_node (node, "Alias")) { xml_parse_alias_node (node, template); } else { if (!xmlNodeIsText (node)) { - if (!xmlStrEqual (node->name,(xmlChar *)"comment")) { + if (!gl_xml_is_node (node,"comment")) { g_warning ("bad node = \"%s\"",node->name); } } } } - xmlFree (name); - xmlFree (description); - xmlFree (page_size); + g_free (name); + g_free (description); + g_free (page_size); return template; } @@ -275,19 +262,19 @@ static void xml_parse_label_rectangle_node (xmlNodePtr label_node, glTemplate *template) { - xmlChar *id; - xmlChar *tmp; + gchar *id; + gchar *tmp; gdouble x_waste, y_waste; gdouble w, h, r; glTemplateLabelType *label_type; xmlNodePtr node; - id = xmlGetProp (label_node, (xmlChar *)"id"); + id = gl_xml_get_prop_string (label_node, "id", NULL); - if (tmp = xmlGetProp (label_node, (xmlChar *)"waste")) { + if (tmp = gl_xml_get_prop_string (label_node, "waste", NULL)) { /* Handle single "waste" property. */ x_waste = y_waste = gl_xml_get_prop_length (label_node, "waste", 0); - xmlFree (tmp); + g_free (tmp); } else { x_waste = gl_xml_get_prop_length (label_node, "x_waste", 0); y_waste = gl_xml_get_prop_length (label_node, "y_waste", 0); @@ -302,22 +289,22 @@ xml_parse_label_rectangle_node (xmlNodePtr label_node, for (node = label_node->xmlChildrenNode; node != NULL; node = node->next) { - if (xmlStrEqual (node->name, (xmlChar *)"Layout")) { + if (gl_xml_is_node (node, "Layout")) { xml_parse_layout_node (node, label_type); - } else if (xmlStrEqual (node->name, (xmlChar *)"Markup-margin")) { + } else if (gl_xml_is_node (node, "Markup-margin")) { xml_parse_markup_margin_node (node, label_type); - } else if (xmlStrEqual (node->name, (xmlChar *)"Markup-line")) { + } else if (gl_xml_is_node (node, "Markup-line")) { xml_parse_markup_line_node (node, label_type); - } else if (xmlStrEqual (node->name, (xmlChar *)"Markup-circle")) { + } else if (gl_xml_is_node (node, "Markup-circle")) { xml_parse_markup_circle_node (node, label_type); } else if (!xmlNodeIsText (node)) { - if (!xmlStrEqual (node->name, (xmlChar *)"comment")) { + if (!gl_xml_is_node (node, "comment")) { g_warning ("bad node = \"%s\"",node->name); } } } - xmlFree (id); + g_free (id); } /*--------------------------------------------------------------------------*/ @@ -327,13 +314,13 @@ static void xml_parse_label_round_node (xmlNodePtr label_node, glTemplate *template) { - xmlChar *id; + gchar *id; gdouble waste; gdouble r; glTemplateLabelType *label_type; xmlNodePtr node; - id = xmlGetProp (label_node, (xmlChar *)"id"); + id = gl_xml_get_prop_string (label_node, "id", NULL); waste = gl_xml_get_prop_length (label_node, "waste", 0); r = gl_xml_get_prop_length (label_node, "radius", 0); @@ -342,22 +329,22 @@ xml_parse_label_round_node (xmlNodePtr label_node, for (node = label_node->xmlChildrenNode; node != NULL; node = node->next) { - if (xmlStrEqual (node->name, (xmlChar *)"Layout")) { + if (gl_xml_is_node (node, "Layout")) { xml_parse_layout_node (node, label_type); - } else if (xmlStrEqual (node->name, (xmlChar *)"Markup-margin")) { + } else if (gl_xml_is_node (node, "Markup-margin")) { xml_parse_markup_margin_node (node, label_type); - } else if (xmlStrEqual (node->name, (xmlChar *)"Markup-line")) { + } else if (gl_xml_is_node (node, "Markup-line")) { xml_parse_markup_line_node (node, label_type); - } else if (xmlStrEqual (node->name, (xmlChar *)"Markup-circle")) { + } else if (gl_xml_is_node (node, "Markup-circle")) { xml_parse_markup_circle_node (node, label_type); } else if (!xmlNodeIsText (node)) { - if (!xmlStrEqual (node->name, (xmlChar *)"comment")) { + if (!gl_xml_is_node (node, "comment")) { g_warning ("bad node = \"%s\"",node->name); } } } - xmlFree (id); + g_free (id); } /*--------------------------------------------------------------------------*/ @@ -367,13 +354,13 @@ static void xml_parse_label_cd_node (xmlNodePtr label_node, glTemplate *template) { - xmlChar *id; + gchar *id; gdouble waste; gdouble r1, r2, w, h; glTemplateLabelType *label_type; xmlNodePtr node; - id = xmlGetProp (label_node, (xmlChar *)"id"); + id = gl_xml_get_prop_string (label_node, "id", NULL); waste = gl_xml_get_prop_length (label_node, "waste", 0); r1 = gl_xml_get_prop_length (label_node, "radius", 0); r2 = gl_xml_get_prop_length (label_node, "hole", 0); @@ -385,22 +372,22 @@ xml_parse_label_cd_node (xmlNodePtr label_node, for (node = label_node->xmlChildrenNode; node != NULL; node = node->next) { - if (xmlStrEqual (node->name, (xmlChar *)"Layout")) { + if (gl_xml_is_node (node, "Layout")) { xml_parse_layout_node (node, label_type); - } else if (xmlStrEqual (node->name, (xmlChar *)"Markup-margin")) { + } else if (gl_xml_is_node (node, "Markup-margin")) { xml_parse_markup_margin_node (node, label_type); - } else if (xmlStrEqual (node->name, (xmlChar *)"Markup-line")) { + } else if (gl_xml_is_node (node, "Markup-line")) { xml_parse_markup_line_node (node, label_type); - } else if (xmlStrEqual (node->name, (xmlChar *)"Markup-circle")) { + } else if (gl_xml_is_node (node, "Markup-circle")) { xml_parse_markup_circle_node (node, label_type); } else if (!xmlNodeIsText (node)) { - if (!xmlStrEqual (node->name, (xmlChar *)"comment")) { + if (!gl_xml_is_node (node, "comment")) { g_warning ("bad node = \"%s\"",node->name); } } } - xmlFree (id); + g_free (id); } /*--------------------------------------------------------------------------*/ @@ -429,7 +416,7 @@ xml_parse_layout_node (xmlNodePtr layout_node, for (node = layout_node->xmlChildrenNode; node != NULL; node = node->next) { if (!xmlNodeIsText (node)) { - if (!xmlStrEqual (node->name, (xmlChar *)"comment")) { + if (!gl_xml_is_node (node, "comment")) { g_warning ("bad node = \"%s\"",node->name); } } @@ -455,7 +442,7 @@ xml_parse_markup_margin_node (xmlNodePtr markup_node, for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next) { if (!xmlNodeIsText (node)) { - if (!xmlStrEqual (node->name, (xmlChar *)"comment")) { + if (!gl_xml_is_node (node, "comment")) { g_warning ("bad node = \"%s\"",node->name); } } @@ -484,7 +471,7 @@ xml_parse_markup_line_node (xmlNodePtr markup_node, for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next) { if (!xmlNodeIsText (node)) { - if (!xmlStrEqual (node->name, (xmlChar *)"comment")) { + if (!gl_xml_is_node (node, "comment")) { g_warning ("bad node = \"%s\"",node->name); } } @@ -512,7 +499,7 @@ xml_parse_markup_circle_node (xmlNodePtr markup_node, for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next) { if (!xmlNodeIsText (node)) { - if (!xmlStrEqual (node->name, (xmlChar *)"comment")) { + if (!gl_xml_is_node (node, "comment")) { g_warning ("bad node = \"%s\"",node->name); } } @@ -527,13 +514,13 @@ static void xml_parse_alias_node (xmlNodePtr alias_node, glTemplate *template) { - xmlChar *name; + gchar *name; - name = xmlGetProp (alias_node, (xmlChar *)"name"); + name = gl_xml_get_prop_string (alias_node, "name", NULL); gl_template_add_alias (template, (gchar *)name); - xmlFree (name); + g_free (name); } /** @@ -626,9 +613,9 @@ gl_xml_template_create_template_node (const glTemplate *template, node = xmlNewChild (root, ns, (xmlChar *)"Template", NULL); - xmlSetProp (node, (xmlChar *)"name", (xmlChar *)template->name); + gl_xml_set_prop_string (node, "name", template->name); - xmlSetProp (node, (xmlChar *)"size", (xmlChar *)template->page_size); + gl_xml_set_prop_string (node, "size", template->page_size); if (xmlStrEqual ((xmlChar *)template->page_size, (xmlChar *)"Other")) { gl_xml_set_prop_length (node, "width", template->page_width); @@ -636,7 +623,7 @@ gl_xml_template_create_template_node (const glTemplate *template, } - xmlSetProp (node, (xmlChar *)"description", (xmlChar *)template->description); + gl_xml_set_prop_string (node, "description", template->description); for ( p=template->label_types; p != NULL; p=p->next ) { label_type = (glTemplateLabelType *)p->data; @@ -668,26 +655,26 @@ xml_create_label_node (const glTemplateLabelType *label_type, case GL_TEMPLATE_SHAPE_RECT: node = xmlNewChild(root, ns, (xmlChar *)"Label-rectangle", NULL); - xmlSetProp (node, (xmlChar *)"id", (xmlChar *)label_type->id); - gl_xml_set_prop_length (node, "width", label_type->size.rect.w); - gl_xml_set_prop_length (node, "height", label_type->size.rect.h); - gl_xml_set_prop_length (node, "round", label_type->size.rect.r); - gl_xml_set_prop_length (node, "x_waste", label_type->size.rect.x_waste); - gl_xml_set_prop_length (node, "y_waste", label_type->size.rect.y_waste); + gl_xml_set_prop_string (node, "id", label_type->id); + gl_xml_set_prop_length (node, "width", label_type->size.rect.w); + gl_xml_set_prop_length (node, "height", label_type->size.rect.h); + gl_xml_set_prop_length (node, "round", label_type->size.rect.r); + gl_xml_set_prop_length (node, "x_waste", label_type->size.rect.x_waste); + gl_xml_set_prop_length (node, "y_waste", label_type->size.rect.y_waste); break; case GL_TEMPLATE_SHAPE_ROUND: node = xmlNewChild(root, ns, (xmlChar *)"Label-round", NULL); - xmlSetProp (node, (xmlChar *)"id", (xmlChar *)label_type->id); + gl_xml_set_prop_string (node, "id", label_type->id); gl_xml_set_prop_length (node, "radius", label_type->size.round.r); gl_xml_set_prop_length (node, "waste", label_type->size.round.waste); break; case GL_TEMPLATE_SHAPE_CD: node = xmlNewChild(root, ns, (xmlChar *)"Label-cd", NULL); - xmlSetProp (node, (xmlChar *)"id", (xmlChar *)label_type->id); - gl_xml_set_prop_length (node, "radius", label_type->size.cd.r1); - gl_xml_set_prop_length (node, "hole", label_type->size.cd.r2); + gl_xml_set_prop_string (node, "id", label_type->id); + gl_xml_set_prop_length (node, "radius", label_type->size.cd.r1); + gl_xml_set_prop_length (node, "hole", label_type->size.cd.r2); if (label_type->size.cd.w != 0.0) { gl_xml_set_prop_length (node, "width", label_type->size.cd.w); } @@ -813,7 +800,7 @@ xml_create_alias_node (const gchar *name, xmlNodePtr node; node = xmlNewChild (root, ns, (xmlChar *)"Alias", NULL); - xmlSetProp (node, (xmlChar *)"name", (xmlChar *)name); + gl_xml_set_prop_string (node, "name", name); } diff --git a/glabels2/libglabels/xml.c b/glabels2/libglabels/xml.c index d7a876a3..eccd26bc 100644 --- a/glabels2/libglabels/xml.c +++ b/glabels2/libglabels/xml.c @@ -77,6 +77,89 @@ static glUnitsType default_units = GL_UNITS_POINT; /****************************************************************************/ +/** + * gl_xml_get_prop_string: + * @node: the libxml2 #xmlNodePtr of the node + * @property: the property name + * @default_val: a default value to return if property not found + * + * Return value of property as a string. + * + * Returns: the property as a pointer to a gchar string. This string should + * be freed with g_free(). + * + */ +gchar * +gl_xml_get_prop_string (xmlNodePtr node, + const gchar *property, + const gchar *default_val) +{ + gchar *val; + xmlChar *string; + + string = xmlGetProp (node, (xmlChar *)property); + if ( string != NULL ) { + val = g_strdup ((gchar *)string); + xmlFree (string); + return val; + } + + if (default_val) { + return g_strdup (default_val); + } + + return NULL; +} + + +/** + * gl_xml_get_prop_i18n_string: + * @node: the libxml2 #xmlNodePtr of the node + * @property: the property name + * @default_val: a default value to return if property not found + * + * Return value of a translatable property as a string. + * + * Returns: the property as a pointer to a gchar string. This string should + * be freed with g_free(). + * + */ +gchar * +gl_xml_get_prop_i18n_string (xmlNodePtr node, + const gchar *property, + const gchar *default_val) +{ + gchar *_property; + gchar *val; + xmlChar *string; + + _property = g_strdup_printf ("_%s", property); + string = xmlGetProp (node, (xmlChar *)_property); + g_free (_property); + + if ( string != NULL ) { + + val = g_strdup (gettext ((char *)string)); + xmlFree (string); + return val; + + } + + string = xmlGetProp (node, (xmlChar *)property); + if ( string != NULL ) { + val = g_strdup ((gchar *)string); + xmlFree (string); + return val; + } + + if (default_val) { + return g_strdup (default_val); + } + + return NULL; +} + + /** * gl_xml_get_prop_double: * @node: the libxml2 #xmlNodePtr of the node @@ -257,6 +340,26 @@ gl_xml_get_prop_length (xmlNodePtr node, } +/** + * gl_xml_set_prop_string: + * @node: the libxml2 #xmlNodePtr of the node + * @property: the property name + * @val: the value to set + * + * Set a property from a string. + * + */ +void +gl_xml_set_prop_string (xmlNodePtr node, + const gchar *property, + const gchar *val) +{ + if (val != NULL) { + xmlSetProp (node, (xmlChar *)property, (xmlChar *)val); + } +} + + /** * gl_xml_set_prop_double: * @node: the libxml2 #xmlNodePtr of the node @@ -370,6 +473,53 @@ gl_xml_set_prop_length (xmlNodePtr node, g_free (string_unit); } +/** + * gl_xml_is_node + * @node: the libxml2 #xmlNodePtr of the node + * @property: the node name + * + * Test if a node name matches given name. + * + * Returns: TRUE if the name of the node matches. Otherwise FALSE. + * + */ +gboolean +gl_xml_is_node (xmlNodePtr node, + const gchar *name) +{ + return xmlStrEqual (node->name, (xmlChar *)name); +} + + +/** + * gl_xml_get_node_content + * @node: the libxml2 #xmlNodePtr of the node + * + * Get the content of a node. + * + * Returns: the property as a pointer to a gchar string. This string should + * be freed with g_free(). + */ +gchar * +gl_xml_get_node_content (xmlNodePtr node) +{ + xmlChar *xml_content; + gchar *g_content; + + xml_content = xmlNodeGetContent (node); + + if (xml_content != NULL) { + + g_content = g_strdup ((gchar *)xml_content); + xmlFree (xml_content); + return g_content; + + } + + return NULL; +} + + /** * gl_xml_set_default_units: * @units: default units selection (#glUnitsType) diff --git a/glabels2/libglabels/xml.h b/glabels2/libglabels/xml.h index 6924ec8c..4b3bb056 100644 --- a/glabels2/libglabels/xml.h +++ b/glabels2/libglabels/xml.h @@ -35,6 +35,17 @@ G_BEGIN_DECLS +/* + * Get property functions + */ +gchar * gl_xml_get_prop_string (xmlNodePtr node, + const gchar *property, + const gchar *default_val); + +gchar * gl_xml_get_prop_i18n_string (xmlNodePtr node, + const gchar *property, + const gchar *default_val); + gdouble gl_xml_get_prop_double (xmlNodePtr node, const gchar *property, gdouble default_val); @@ -56,6 +67,13 @@ gdouble gl_xml_get_prop_length (xmlNodePtr node, gdouble default_val); +/* + * Set property functions + */ +void gl_xml_set_prop_string (xmlNodePtr node, + const gchar *property, + const gchar *val); + void gl_xml_set_prop_double (xmlNodePtr node, const gchar *property, gdouble val); @@ -76,6 +94,17 @@ void gl_xml_set_prop_length (xmlNodePtr node, const gchar *property, gdouble val); +/* + * Other node functions + */ +gboolean gl_xml_is_node (xmlNodePtr node, + const gchar *name); + +gchar * gl_xml_get_node_content (xmlNodePtr node); + +/* + * Misc functions + */ void gl_xml_set_default_units (glUnitsType units); G_END_DECLS diff --git a/glabels2/src/file.c b/glabels2/src/file.c index 5359dfba..a8c71fbf 100644 --- a/glabels2/src/file.c +++ b/glabels2/src/file.c @@ -231,6 +231,8 @@ new_response (GtkDialog *dlg, gl_label_set_template (label, template); gl_label_set_rotate_flag (label, rotate_flag); + gl_template_free (template); + window = GL_WINDOW (g_object_get_data (G_OBJECT (dlg), "parent_window")); diff --git a/glabels2/src/object-editor-image-page.c b/glabels2/src/object-editor-image-page.c index d810604e..b8d13ed0 100644 --- a/glabels2/src/object-editor-image-page.c +++ b/glabels2/src/object-editor-image-page.c @@ -283,16 +283,19 @@ add_image_filters_to_chooser (GtkFileChooser *chooser) /* Individual image filters */ formats = gdk_pixbuf_get_formats (); for (it = formats; it != NULL; it = it->next) { - char *filter_name; + gchar *filter_name; GdkPixbufFormat *format; filter = gtk_file_filter_new (); + gchar *description, *name; format = (GdkPixbufFormat*) it->data; /* Filter name: First description then file extension, eg. "The PNG-Format (*.png)".*/ - filter_name = g_strdup_printf (_("%s (*.%s)"), - gdk_pixbuf_format_get_description (format), - gdk_pixbuf_format_get_name (format)); + description = gdk_pixbuf_format_get_description (format); + name = gdk_pixbuf_format_get_name (format); + filter_name = g_strdup_printf (_("%s (*.%s)"), description, name); + g_free (description); + g_free (name); gtk_file_filter_set_name (filter, filter_name); g_free (filter_name); diff --git a/glabels2/src/pixbuf-cache.c b/glabels2/src/pixbuf-cache.c index e1ec24ba..4fc01ad1 100644 --- a/glabels2/src/pixbuf-cache.c +++ b/glabels2/src/pixbuf-cache.c @@ -99,7 +99,7 @@ gl_pixbuf_cache_free (GHashTable *pixbuf_cache) } /*****************************************************************************/ -/* Add pixbuf to cache explicitly. */ +/* Add pixbuf to cache explicitly (not a reference). */ /*****************************************************************************/ void gl_pixbuf_cache_add_pixbuf (GHashTable *pixbuf_cache, @@ -120,8 +120,8 @@ gl_pixbuf_cache_add_pixbuf (GHashTable *pixbuf_cache, record = g_new0 (CacheRecord, 1); record->key = g_strdup (name); - record->references = 0; - record->pixbuf = pixbuf; + record->references = 0; /* Nobody has referenced it yet. */ + record->pixbuf = g_object_ref (G_OBJECT (pixbuf)); g_hash_table_insert (pixbuf_cache, record->key, record); @@ -143,8 +143,9 @@ gl_pixbuf_cache_get_pixbuf (GHashTable *pixbuf_cache, record = g_hash_table_lookup (pixbuf_cache, name); if (record != NULL) { - gl_debug (DEBUG_PIXBUF_CACHE, "END cached"); record->references++; + gl_debug (DEBUG_PIXBUF_CACHE, "references=%d", record->references); + gl_debug (DEBUG_PIXBUF_CACHE, "END cached"); return record->pixbuf; } diff --git a/glabels2/src/ui-property-bar.c b/glabels2/src/ui-property-bar.c index 15825ff7..8d9de525 100644 --- a/glabels2/src/ui-property-bar.c +++ b/glabels2/src/ui-property-bar.c @@ -1267,6 +1267,8 @@ gl_ui_property_bar_construct_color_combo (gchar *name, color_combo_box_set_preview_relief (COLOR_COMBO(color_combo), GTK_RELIEF_NORMAL); + g_object_unref (G_OBJECT (pixbuf)); + return color_combo; } diff --git a/glabels2/src/view-highlight.c b/glabels2/src/view-highlight.c index 9103033b..0149f208 100644 --- a/glabels2/src/view-highlight.c +++ b/glabels2/src/view-highlight.c @@ -219,6 +219,10 @@ gl_view_highlight_finalize (GObject *object) gtk_object_destroy (GTK_OBJECT(view_highlight->private->position_group)); + if (view_highlight->private) { + g_free (view_highlight->private); + } + G_OBJECT_CLASS (parent_class)->finalize (object); gl_debug (DEBUG_VIEW, "END"); diff --git a/glabels2/src/view-image.c b/glabels2/src/view-image.c index 1bfe44e2..96ce6e9d 100644 --- a/glabels2/src/view-image.c +++ b/glabels2/src/view-image.c @@ -40,7 +40,7 @@ /* Private macros and constants. */ /*========================================================*/ -#define DELTA 0.01 +#define MIN_IMAGE_SIZE 0.01 /*========================================================*/ /* Private types. */ @@ -262,6 +262,8 @@ update_canvas_item_from_object_cb (glLabelObject *object, /* Query properties of object. */ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); + w = MAX (w, MIN_IMAGE_SIZE); + h = MAX (h, MIN_IMAGE_SIZE); pixbuf = gl_label_image_get_pixbuf (GL_LABEL_IMAGE(object), NULL); /* Adjust appearance of analogous canvas item. */ @@ -306,6 +308,7 @@ update_object_from_editor_cb (glObjectEditor *editor, filename = gl_object_editor_get_image (editor); gl_label_image_set_filename (GL_LABEL_IMAGE(object), filename); + gl_text_node_free (&filename); /* Setting filename may have modified the size. */ gl_label_object_get_size (object, &w, &h); diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 49c1702f..29f7fc0d 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -341,6 +341,10 @@ gl_view_finalize (GObject *object) view = GL_VIEW (object); + if (view->default_font_family) { + g_free (view->default_font_family); + } + G_OBJECT_CLASS (parent_class)->finalize (object); gl_debug (DEBUG_VIEW, "END"); @@ -735,6 +739,8 @@ draw_bg_fg_layers (glView *view) g_warning ("Unknown template label style"); break; } + + gl_template_free (template); } /*---------------------------------------------------------------------------*/ @@ -853,6 +859,7 @@ draw_bg_fg_rounded_rect (glView *view) NULL); gnome_canvas_points_free (points); + gl_template_free (template); gl_debug (DEBUG_VIEW, "END"); } @@ -901,6 +908,8 @@ draw_bg_fg_round (glView *view) "outline_color_rgba", OUTLINE_COLOR, NULL); + gl_template_free (template); + gl_debug (DEBUG_VIEW, "END"); } @@ -971,6 +980,8 @@ draw_bg_fg_cd (glView *view) "outline_color_rgba", OUTLINE_COLOR, NULL); + gl_template_free (template); + gl_debug (DEBUG_VIEW, "END"); } @@ -1107,6 +1118,7 @@ draw_bg_fg_cd_bc (glView *view) NULL); gnome_canvas_points_free (points); + gl_template_free (template); gl_debug (DEBUG_VIEW, "END"); } @@ -1229,6 +1241,9 @@ draw_markup_layer (glView *view) break; } } + + gl_template_free (template); + } /*---------------------------------------------------------------------------*/ @@ -1282,6 +1297,8 @@ draw_markup_margin (glView *view, g_warning ("Unknown template label style"); break; } + + gl_template_free (template); } /*---------------------------------------------------------------------------*/ @@ -1320,6 +1337,8 @@ draw_markup_margin_rect (glView *view, "outline_color_rgba", MARKUP_COLOR, NULL); + gl_template_free (template); + gl_debug (DEBUG_VIEW, "END"); } @@ -1390,6 +1409,7 @@ draw_markup_margin_rounded_rect (glView *view, "outline_color_rgba", MARKUP_COLOR, NULL); gnome_canvas_points_free (points); + gl_template_free (template); gl_debug (DEBUG_VIEW, "END"); } @@ -1430,6 +1450,8 @@ draw_markup_margin_round (glView *view, "outline_color_rgba", MARKUP_COLOR, NULL); + gl_template_free (template); + gl_debug (DEBUG_VIEW, "END"); } @@ -1480,6 +1502,8 @@ draw_markup_margin_cd (glView *view, "outline_color_rgba", MARKUP_COLOR, NULL); + gl_template_free (template); + gl_debug (DEBUG_VIEW, "END"); } @@ -1602,6 +1626,9 @@ draw_markup_margin_cd_bc (glView *view, "outline_color_rgba", MARKUP_COLOR, NULL); + + gl_template_free (template); + gl_debug (DEBUG_VIEW, "END"); } diff --git a/glabels2/src/wdgt-mini-preview.c b/glabels2/src/wdgt-mini-preview.c index 255954a5..c05d6d3f 100644 --- a/glabels2/src/wdgt-mini-preview.c +++ b/glabels2/src/wdgt-mini-preview.c @@ -435,6 +435,8 @@ mini_outline_list_new (GnomeCanvas *canvas, list = g_list_append (list, item); } + g_free (origins); + gl_debug (DEBUG_MINI_PREVIEW, "END"); return list; } diff --git a/glabels2/src/wdgt-rotate-label.c b/glabels2/src/wdgt-rotate-label.c index 9d60bf7c..71e1bb3b 100644 --- a/glabels2/src/wdgt-rotate-label.c +++ b/glabels2/src/wdgt-rotate-label.c @@ -168,6 +168,11 @@ gl_wdgt_rotate_label_finalize (GObject *object) rotate_select = GL_WDGT_ROTATE_LABEL (object); + if (rotate_select->template) { + gl_template_free (rotate_select->template); + rotate_select->template = NULL; + } + G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/glabels2/src/xml-label.c b/glabels2/src/xml-label.c index 6f551911..380120a2 100644 --- a/glabels2/src/xml-label.c +++ b/glabels2/src/xml-label.c @@ -307,7 +307,7 @@ xml_parse_label (xmlNodePtr root, *status = XML_LABEL_OK; - if (!xmlStrEqual (root->name, (xmlChar *)"Glabels-document")) { + if (!gl_xml_is_node (root, "Glabels-document")) { g_warning (_("Bad root node = \"%s\""), root->name); *status = XML_LABEL_ERROR_OPEN_PARSE; return NULL; @@ -317,7 +317,7 @@ xml_parse_label (xmlNodePtr root, /* Pass 1, extract data nodes to pre-load cache. */ for (child_node = root->xmlChildrenNode; child_node != NULL; child_node = child_node->next) { - if (xmlStrEqual (child_node->name, (xmlChar *)"Data")) { + if (gl_xml_is_node (child_node, "Data")) { xml_parse_data (child_node, label); } } @@ -327,7 +327,7 @@ xml_parse_label (xmlNodePtr root, child_node != NULL; child_node = child_node->next) { - if (xmlStrEqual (child_node->name, (xmlChar *)"Template")) { + if (gl_xml_is_node (child_node, "Template")) { template = gl_xml_template_parse_template_node (child_node); if (!template) { g_object_unref (label); @@ -337,11 +337,11 @@ xml_parse_label (xmlNodePtr root, gl_template_register (template); gl_label_set_template (label, template); gl_template_free (template); - } else if (xmlStrEqual (child_node->name, (xmlChar *)"Objects")) { + } else if (gl_xml_is_node (child_node, "Objects")) { xml_parse_objects (child_node, label); - } else if (xmlStrEqual (child_node->name, (xmlChar *)"Merge")) { + } else if (gl_xml_is_node (child_node, "Merge")) { xml_parse_merge_fields (child_node, label); - } else if (xmlStrEqual (child_node->name, (xmlChar *)"Data")) { + } else if (gl_xml_is_node (child_node, "Data")) { /* Handled in pass 1. */ } else { if (!xmlNodeIsText (child_node)) { @@ -376,17 +376,17 @@ xml_parse_objects (xmlNodePtr node, for (child = node->xmlChildrenNode; child != NULL; child = child->next) { - if (xmlStrEqual (child->name, (xmlChar *)"Object-text")) { + if (gl_xml_is_node (child, "Object-text")) { xml_parse_object_text (child, label); - } else if (xmlStrEqual (child->name, (xmlChar *)"Object-box")) { + } else if (gl_xml_is_node (child, "Object-box")) { xml_parse_object_box (child, label); - } else if (xmlStrEqual (child->name, (xmlChar *)"Object-ellipse")) { + } else if (gl_xml_is_node (child, "Object-ellipse")) { xml_parse_object_ellipse (child, label); - } else if (xmlStrEqual (child->name, (xmlChar *)"Object-line")) { + } else if (gl_xml_is_node (child, "Object-line")) { xml_parse_object_line (child, label); - } else if (xmlStrEqual (child->name, (xmlChar *)"Object-image")) { + } else if (gl_xml_is_node (child, "Object-image")) { xml_parse_object_image (child, label); - } else if (xmlStrEqual (child->name, (xmlChar *)"Object-barcode")) { + } else if (gl_xml_is_node (child, "Object-barcode")) { xml_parse_object_barcode (child, label); } else { if (!xmlNodeIsText (child)) { @@ -409,7 +409,7 @@ xml_parse_object_text (xmlNodePtr node, GObject *object; gdouble x, y; gdouble w, h; - xmlChar *string; + gchar *string; GtkJustification just; gboolean auto_shrink; gdouble affine[6]; @@ -430,9 +430,9 @@ xml_parse_object_text (xmlNodePtr node, gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); /* justify attr */ - string = xmlGetProp (node, (xmlChar *)"justify"); - just = gl_util_string_to_just ((gchar *)string); - xmlFree (string); + string = gl_xml_get_prop_string (node, "justify", NULL); + just = gl_util_string_to_just (string); + g_free (string); gl_label_object_set_text_alignment (GL_LABEL_OBJECT(object), just); /* auto_shrink attr */ @@ -450,7 +450,7 @@ xml_parse_object_text (xmlNodePtr node, /* Process children */ for (child = node->xmlChildrenNode; child != NULL; child = child->next) { - if (xmlStrEqual (child->name,(xmlChar *) "Span")) { + if (gl_xml_is_node (child, "Span")) { xml_parse_toplevel_span (child, GL_LABEL_OBJECT(object)); break; } else { @@ -477,7 +477,7 @@ xml_parse_object_box (xmlNodePtr node, gdouble line_width; glColorNode *line_color_node; gdouble affine[6]; - xmlChar *string; + gchar *string; glColorNode *fill_color_node; gl_debug (DEBUG_XML, "START"); @@ -499,11 +499,10 @@ xml_parse_object_box (xmlNodePtr node, gl_label_object_set_line_width (GL_LABEL_OBJECT(object), line_width); line_color_node = gl_color_node_new_default (); - string = xmlGetProp (node, (xmlChar *)"line_color_field"); + string = gl_xml_get_prop_string (node, "line_color_field", NULL); if ( string ) { line_color_node->field_flag = TRUE; - line_color_node->key = g_strdup ((gchar *)string); - xmlFree (string); + line_color_node->key = string; } else { line_color_node->color = gl_xml_get_prop_uint (node, "line_color", 0); } @@ -513,10 +512,10 @@ xml_parse_object_box (xmlNodePtr node, /* fill attrs */ fill_color_node = gl_color_node_new_default (); - string = xmlGetProp (node, (xmlChar *)"fill_color_field"); + string = gl_xml_get_prop_string (node, "fill_color_field", NULL); if ( string ) { fill_color_node->field_flag = TRUE; - fill_color_node->key = g_strdup ((gchar *)string); + fill_color_node->key = string; } else { fill_color_node->color = gl_xml_get_prop_uint (node, "fill_color", 0); } @@ -548,7 +547,7 @@ xml_parse_object_ellipse (xmlNodePtr node, gdouble line_width; glColorNode *line_color_node; gdouble affine[6]; - xmlChar *string; + gchar *string; glColorNode *fill_color_node; gl_debug (DEBUG_XML, "START"); @@ -570,11 +569,10 @@ xml_parse_object_ellipse (xmlNodePtr node, gl_label_object_set_line_width (GL_LABEL_OBJECT(object), line_width); line_color_node = gl_color_node_new_default (); - string = xmlGetProp (node, (xmlChar *)"line_color_field"); + string = gl_xml_get_prop_string (node, "line_color_field", NULL); if ( string ) { line_color_node->field_flag = TRUE; - line_color_node->key = g_strdup ((gchar *)string); - xmlFree (string); + line_color_node->key = string; } else { line_color_node->color = gl_xml_get_prop_uint (node, "line_color", 0); } @@ -584,11 +582,10 @@ xml_parse_object_ellipse (xmlNodePtr node, /* fill attrs */ fill_color_node = gl_color_node_new_default (); - string = xmlGetProp (node, (xmlChar *)"fill_color_field"); + string = gl_xml_get_prop_string (node, "fill_color_field", NULL); if ( string ) { fill_color_node->field_flag = TRUE; - fill_color_node->key = g_strdup ((gchar *)string); - xmlFree (string); + fill_color_node->key = string; } else { fill_color_node->color = gl_xml_get_prop_uint (node, "fill_color", 0); } @@ -620,7 +617,7 @@ xml_parse_object_line (xmlNodePtr node, gdouble line_width; glColorNode *line_color_node; gdouble affine[6]; - xmlChar *string; + gchar *string; gl_debug (DEBUG_XML, "START"); @@ -641,11 +638,10 @@ xml_parse_object_line (xmlNodePtr node, gl_label_object_set_line_width (GL_LABEL_OBJECT(object), line_width); line_color_node = gl_color_node_new_default (); - string = xmlGetProp (node, (xmlChar *)"line_color_field"); + string = gl_xml_get_prop_string (node, "line_color_field", NULL); if ( string ) { line_color_node->field_flag = TRUE; - line_color_node->key = g_strdup ((gchar *)string); - xmlFree (string); + line_color_node->key = string; } else { line_color_node->color = gl_xml_get_prop_uint (node, "line_color", 0); } @@ -674,7 +670,7 @@ xml_parse_object_image (xmlNodePtr node, GObject *object; gdouble x, y; gdouble w, h; - xmlChar *string; + gchar *string; glTextNode *filename; gdouble affine[6]; @@ -688,7 +684,7 @@ xml_parse_object_image (xmlNodePtr node, gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y); /* src or field attr */ - string = xmlGetProp (node, (xmlChar *)"src"); + string = gl_xml_get_prop_string (node, "src", NULL); if ( string ) { filename = g_new0 (glTextNode, 1); filename->field_flag = FALSE; @@ -697,7 +693,7 @@ xml_parse_object_image (xmlNodePtr node, gl_text_node_free (&filename); xmlFree (string); } else { - string = xmlGetProp (node, (xmlChar *)"field"); + string = gl_xml_get_prop_string (node, "field", NULL); if ( string ) { filename = g_new0 (glTextNode, 1); filename->field_flag = TRUE; @@ -737,9 +733,9 @@ xml_parse_object_barcode (xmlNodePtr node, GObject *object; gdouble x, y; gdouble w, h; - xmlChar *string; + gchar *string; glTextNode *text_node; - xmlChar *id; + gchar *id; gboolean text_flag; gboolean checksum_flag; glColorNode *color_node; @@ -761,20 +757,19 @@ xml_parse_object_barcode (xmlNodePtr node, gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h); /* prop attrs */ - id = xmlGetProp (node, (xmlChar *)"style"); + id = gl_xml_get_prop_string (node, "style", NULL); text_flag = gl_xml_get_prop_boolean (node, "text", FALSE); checksum_flag = gl_xml_get_prop_boolean (node, "checksum", TRUE); format_digits = gl_xml_get_prop_uint (node, "format", 10); gl_label_barcode_set_props (GL_LABEL_BARCODE(object), (gchar *)id, text_flag, checksum_flag, format_digits); - xmlFree (id); + g_free (id); color_node = gl_color_node_new_default (); - string = xmlGetProp (node, (xmlChar *)"color_field"); + string = gl_xml_get_prop_string (node, "color_field", NULL); if ( string ) { color_node->field_flag = TRUE; - color_node->key = g_strdup ((gchar *)string); - xmlFree (string); + color_node->key = string; } else { color_node->color = gl_xml_get_prop_uint (node, "color", 0); } @@ -782,23 +777,21 @@ xml_parse_object_barcode (xmlNodePtr node, gl_color_node_free (&color_node); /* data or field attr */ - string = xmlGetProp (node, (xmlChar *)"data"); + string = gl_xml_get_prop_string (node, "data", NULL); if ( string ) { text_node = g_new0 (glTextNode, 1); text_node->field_flag = FALSE; - text_node->data = g_strdup ((gchar *)string); + text_node->data = string; gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node); gl_text_node_free (&text_node); - xmlFree (string); } else { - string = xmlGetProp (node, (xmlChar *)"field"); + string = gl_xml_get_prop_string (node, "field", NULL); if ( string ) { text_node = g_new0 (glTextNode, 1); text_node->field_flag = TRUE; - text_node->data = g_strdup ((gchar *)string); + text_node->data = string; gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node); gl_text_node_free (&text_node); - xmlFree (string); } else { g_warning ("Missing Object-barcode data or field attr"); } @@ -824,18 +817,18 @@ xml_parse_merge_fields (xmlNodePtr node, glLabel *label) { xmlNodePtr child; - xmlChar *string; + gchar *string; glMerge *merge; gl_debug (DEBUG_XML, "START"); - string = xmlGetProp (node, (xmlChar *)"type"); - merge = gl_merge_new ((gchar *)string); - xmlFree (string); + string = gl_xml_get_prop_string (node, "type", NULL); + merge = gl_merge_new (string); + g_free (string); - string = xmlGetProp (node, (xmlChar *)"src"); - gl_merge_set_src (merge, (gchar *)string); - xmlFree (string); + string = gl_xml_get_prop_string (node, "src", NULL); + gl_merge_set_src (merge, string); + g_free (string); gl_label_set_merge (label, merge); @@ -857,7 +850,7 @@ xml_parse_data (xmlNodePtr node, for (child = node->xmlChildrenNode; child != NULL; child = child->next) { - if (xmlStrEqual (child->name, (xmlChar *)"Pixdata")) { + if (gl_xml_is_node (child, "Pixdata")) { xml_parse_pixdata (child, label); } else { if (!xmlNodeIsText (child)) { @@ -877,7 +870,7 @@ static void xml_parse_pixdata (xmlNodePtr node, glLabel *label) { - xmlChar *name, *base64; + gchar *name, *base64; guchar *stream; guint stream_length; gboolean ret; @@ -887,8 +880,8 @@ xml_parse_pixdata (xmlNodePtr node, gl_debug (DEBUG_XML, "START"); - name = xmlGetProp (node, (xmlChar *)"name"); - base64 = xmlNodeGetContent (node); + name = gl_xml_get_prop_string (node, "name", NULL); + base64 = gl_xml_get_node_content (node); stream = gl_base64_decode ((gchar *)base64, &stream_length); pixdata = g_new0 (GdkPixdata, 1); @@ -901,8 +894,8 @@ xml_parse_pixdata (xmlNodePtr node, gl_pixbuf_cache_add_pixbuf (pixbuf_cache, (gchar *)name, pixbuf); } - xmlFree (name); - xmlFree (base64); + g_free (name); + g_free (base64); g_free (stream); g_free (pixdata); @@ -917,13 +910,13 @@ static void xml_parse_toplevel_span (xmlNodePtr node, glLabelObject *object) { - xmlChar *font_family; + gchar *font_family; gdouble font_size; GnomeFontWeight font_weight; gboolean font_italic_flag; glColorNode *color_node; gdouble text_line_spacing; - xmlChar *string; + gchar *string; GList *lines, *text_nodes; xmlNodePtr child; glTextNode *text_node; @@ -931,18 +924,18 @@ xml_parse_toplevel_span (xmlNodePtr node, gl_debug (DEBUG_XML, "START"); /* Font family attr */ - font_family = xmlGetProp (node, (xmlChar *)"font_family"); - gl_label_object_set_font_family (object, (gchar *)font_family); - xmlFree (font_family); + font_family = gl_xml_get_prop_string (node, "font_family", "Sans"); + gl_label_object_set_font_family (object, font_family); + g_free (font_family); /* Font size attr */ font_size = gl_xml_get_prop_double (node, "font_size", 0.0); gl_label_object_set_font_size (object, font_size); /* Font weight attr */ - string = xmlGetProp (node, (xmlChar *)"font_weight"); - font_weight = gl_util_string_to_weight ((gchar *)string); - xmlFree (string); + string = gl_xml_get_prop_string (node, "font_weight", NULL); + font_weight = gl_util_string_to_weight (string); + g_free (string); gl_label_object_set_font_weight (object, font_weight); /* Font italic flag attr */ @@ -951,11 +944,10 @@ xml_parse_toplevel_span (xmlNodePtr node, /* Text color attr */ color_node = gl_color_node_new_default (); - string = xmlGetProp (node, (xmlChar *)"color_field"); + string = gl_xml_get_prop_string (node, "color_field", NULL); if ( string ) { color_node->field_flag = TRUE; - color_node->key = g_strdup ((gchar *)string); - xmlFree (string); + color_node->key = string; } else { color_node->color = gl_xml_get_prop_uint (node, "color", 0); } @@ -973,9 +965,9 @@ xml_parse_toplevel_span (xmlNodePtr node, for (child = node->xmlChildrenNode; child != NULL; child = child->next) { if (xmlNodeIsText (child)) { - xmlChar *data = xmlNodeGetContent (child); + gchar *data = gl_xml_get_node_content (child); - /* Hack: if the first char is LF, it's a xml formatting string */ + /* Hack: if the first char is LF, it's an xml formatting string */ if (data[0] != '\n') { /* Literal text */ text_node = g_new0 (glTextNode, 1); @@ -983,23 +975,22 @@ xml_parse_toplevel_span (xmlNodePtr node, text_node->data = g_strdup ((gchar *)data); text_nodes = g_list_append (text_nodes, text_node); } - xmlFree (data); + g_free (data); - } else if (xmlStrEqual (child->name, (xmlChar *)"Span")) { + } else if (gl_xml_is_node (child, "Span")) { g_warning ("Unexpected rich text (not supported, yet!)"); - } else if (xmlStrEqual (child->name, (xmlChar *)"Field")) { + } else if (gl_xml_is_node (child, "Field")) { /* Field node */ - string = xmlGetProp (child, (xmlChar *)"name"); + string = gl_xml_get_prop_string (child, "name", NULL); text_node = g_new0 (glTextNode, 1); text_node->field_flag = TRUE; - text_node->data = g_strdup ((gchar *)string); + text_node->data = string; text_nodes = g_list_append (text_nodes, text_node); - xmlFree (string); - } else if (xmlStrEqual (child->name, (xmlChar *)"NL")) { + } else if (gl_xml_is_node (child, "NL")) { /* Store line. */ lines = g_list_append (lines, text_nodes); @@ -1146,7 +1137,7 @@ xml_create_objects (xmlNodePtr root, rotate_flag = gl_label_get_rotate_flag (label); node = xmlNewChild (root, ns, (xmlChar *)"Objects", NULL); - xmlSetProp (node, (xmlChar *)"id", (xmlChar *)"0"); + gl_xml_set_prop_string (node, "id", "0"); gl_xml_set_prop_boolean (node, "rotate", rotate_flag); for (p = label->objects; p != NULL; p = p->next) { @@ -1205,7 +1196,7 @@ xml_create_object_text (xmlNodePtr root, /* justify attr */ just = gl_label_object_get_text_alignment (object); - xmlSetProp (node, (xmlChar *)"justify", (xmlChar *)gl_util_just_to_string (just)); + gl_xml_set_prop_string (node, "justify", gl_util_just_to_string (just)); /* auto_shrink attr */ auto_shrink = gl_label_text_get_auto_shrink (GL_LABEL_TEXT (object)); @@ -1263,7 +1254,7 @@ xml_create_object_box (xmlNodePtr root, line_color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object)); if (line_color_node->field_flag) { - xmlSetProp (node, (xmlChar *)"line_color_field", (xmlChar *)line_color_node->key); + gl_xml_set_prop_string (node, "line_color_field", line_color_node->key); } else { @@ -1275,7 +1266,7 @@ xml_create_object_box (xmlNodePtr root, fill_color_node = gl_label_object_get_fill_color (GL_LABEL_OBJECT(object)); if (fill_color_node->field_flag) { - xmlSetProp (node, (xmlChar *)"fill_color_field", (xmlChar *)fill_color_node->key); + gl_xml_set_prop_string (node, "fill_color_field", fill_color_node->key); } else { @@ -1332,7 +1323,7 @@ xml_create_object_ellipse (xmlNodePtr root, line_color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object)); if (line_color_node->field_flag) { - xmlSetProp (node, (xmlChar *)"line_color_field", (xmlChar *)line_color_node->key); + gl_xml_set_prop_string (node, "line_color_field", line_color_node->key); } else { @@ -1345,7 +1336,7 @@ xml_create_object_ellipse (xmlNodePtr root, fill_color_node = gl_label_object_get_fill_color (GL_LABEL_OBJECT(object)); if (fill_color_node->field_flag) { - xmlSetProp (node, (xmlChar *)"fill_color_field", (xmlChar *)fill_color_node->key); + gl_xml_set_prop_string (node, "fill_color_field", fill_color_node->key); } else { @@ -1401,7 +1392,7 @@ xml_create_object_line (xmlNodePtr root, line_color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object)); if (line_color_node->field_flag) { - xmlSetProp (node, (xmlChar *)"line_color_field", (xmlChar *)line_color_node->key); + gl_xml_set_prop_string (node, "line_color_field", line_color_node->key); } else { @@ -1453,9 +1444,9 @@ xml_create_object_image (xmlNodePtr root, /* src OR field attr */ filename = gl_label_image_get_filename (GL_LABEL_IMAGE(object)); if (filename->field_flag) { - xmlSetProp (node, (xmlChar *)"field", (xmlChar *)filename->data); + gl_xml_set_prop_string (node, "field", filename->data); } else { - xmlSetProp (node, (xmlChar *)"src", (xmlChar *)filename->data); + gl_xml_set_prop_string (node, "src", filename->data); } gl_text_node_free (&filename); @@ -1507,7 +1498,7 @@ xml_create_object_barcode (xmlNodePtr root, /* Barcode properties attrs */ gl_label_barcode_get_props (GL_LABEL_BARCODE(object), &id, &text_flag, &checksum_flag, &format_digits); - xmlSetProp (node, (xmlChar *)"style", (xmlChar *)id); + gl_xml_set_prop_string (node, "style", id); gl_xml_set_prop_boolean (node, "text", text_flag); gl_xml_set_prop_boolean (node, "checksum", checksum_flag); @@ -1516,7 +1507,7 @@ xml_create_object_barcode (xmlNodePtr root, color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object)); if (color_node->field_flag) { - xmlSetProp (node, (xmlChar *)"color_field", (xmlChar *)color_node->key); + gl_xml_set_prop_string (node, "color_field", color_node->key); } else { @@ -1528,10 +1519,10 @@ xml_create_object_barcode (xmlNodePtr root, /* data OR field attr */ text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE(object)); if (text_node->field_flag) { - xmlSetProp (node, (xmlChar *)"field", (xmlChar *)text_node->data); + gl_xml_set_prop_string (node, "field", text_node->data); gl_xml_set_prop_int (node, "format", format_digits); } else { - xmlSetProp (node, (xmlChar *)"data", (xmlChar *)text_node->data); + gl_xml_set_prop_string (node, "data", text_node->data); } gl_text_node_free (&text_node); @@ -1567,11 +1558,11 @@ xml_create_merge_fields (xmlNodePtr root, node = xmlNewChild (root, ns, (xmlChar *)"Merge", NULL); string = gl_merge_get_name (merge); - xmlSetProp (node, (xmlChar *)"type", (xmlChar *)string); + gl_xml_set_prop_string (node, "type", string); g_free (string); string = gl_merge_get_src (merge); - xmlSetProp (node, (xmlChar *)"src", (xmlChar *)string); + gl_xml_set_prop_string (node, "src", string); g_free (string); g_object_unref (G_OBJECT(merge)); @@ -1638,8 +1629,8 @@ xml_create_pixdata (xmlNodePtr root, base64 = gl_base64_encode (stream, stream_length); node = xmlNewChild (root, ns, (xmlChar *)"Pixdata", (xmlChar *)base64); - xmlSetProp (node, (xmlChar *)"name", (xmlChar *)name); - xmlSetProp (node, (xmlChar *)"encoding", (xmlChar *)"Base64"); + gl_xml_set_prop_string (node, "name", name); + gl_xml_set_prop_string (node, "encoding", "Base64"); gl_pixbuf_cache_remove_pixbuf (pixbuf_cache, name); @@ -1684,7 +1675,7 @@ xml_create_toplevel_span (xmlNodePtr root, color_node = gl_label_object_get_text_color (GL_LABEL_OBJECT(object_text)); if (color_node->field_flag) { - xmlSetProp (node, (xmlChar *)"color_field", (xmlChar *)color_node->key); + gl_xml_set_prop_string (node, "color_field", color_node->key); } else { @@ -1693,9 +1684,9 @@ xml_create_toplevel_span (xmlNodePtr root, gl_color_node_free (&color_node); just = gl_label_object_get_text_alignment (GL_LABEL_OBJECT(object_text)); - xmlSetProp (node, (xmlChar *)"font_family", (xmlChar *)font_family); + gl_xml_set_prop_string (node, "font_family", font_family); gl_xml_set_prop_double (node, "font_size", font_size); - xmlSetProp (node, (xmlChar *)"font_weight", (xmlChar *)gl_util_weight_to_string (font_weight)); + gl_xml_set_prop_string (node, "font_weight", gl_util_weight_to_string (font_weight)); gl_xml_set_prop_boolean (node, "font_italic", font_italic_flag); gl_xml_set_prop_double (node, "line_spacing", text_line_spacing); @@ -1710,7 +1701,7 @@ xml_create_toplevel_span (xmlNodePtr root, if (text_node->field_flag) { child = xmlNewChild (node, ns, (xmlChar *)"Field", NULL); - xmlSetProp (child, (xmlChar *)"name", (xmlChar *)text_node->data); + gl_xml_set_prop_string (child, "name", text_node->data); } else { xmlNodeAddContent (node, (xmlChar *)text_node->data); } -- 2.39.5