From: Andrea Zagli Date: Sat, 22 Aug 2009 10:57:28 +0000 (+0200) Subject: Some adjustments and bugfixes before 0.0.3 X-Git-Tag: GTKGIS_0_0_3^0 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=HEAD;p=libgtkgis Some adjustments and bugfixes before 0.0.3 --- diff --git a/configure.ac b/configure.ac index 93c481a..29e8703 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) -AC_INIT([libgtkgis], [0.0.2], [azagli@libero.it]) +AC_INIT([libgtkgis], [0.0.3], [azagli@libero.it]) AC_CONFIG_SRCDIR([src/gtkgis.c]) AC_CONFIG_HEADER([config.h]) @@ -48,10 +48,12 @@ AC_ARG_VAR(GDAL_LIBS, [linker flags for Gdal - on Windows there isn't gdal-confi # Checks for header files. AC_FUNC_ALLOCA AC_HEADER_STDC +AC_CHECK_HEADERS([locale.h string.h]) # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. +AC_CHECK_FUNCS([setlocale strtol strtoul]) AC_CONFIG_FILES([ libgtkgis.pc diff --git a/data/gtkgis.dtd b/data/gtkgis.dtd index f104b00..bbc9898 100644 --- a/data/gtkgis.dtd +++ b/data/gtkgis.dtd @@ -39,4 +39,11 @@ - + + + + + + + + diff --git a/docs/reference/libgtkgis-decl.txt b/docs/reference/libgtkgis-decl.txt index 7600ce7..607ece2 100644 --- a/docs/reference/libgtkgis-decl.txt +++ b/docs/reference/libgtkgis-decl.txt @@ -688,7 +688,8 @@ struct _GtkGisGeometryClass GooCanvasItem *(*draw) (GtkGisGeometry *geometry, GtkGisScale *scale, - GtkGisLayerStyle *style); + GtkGisLayerStyle *style, + GtkGisLayerLabel *label); }; @@ -724,7 +725,7 @@ GtkGisGeometry *geometry gtk_gis_geometry_draw GooCanvasItem * -GtkGisGeometry *geometry,GtkGisScale *scale,GtkGisLayerStyle *style +GtkGisGeometry *geometry,GtkGisScale *scale,GtkGisLayerStyle *style,GtkGisLayerLabel *label TYPE_GTK_GIS_LAYER_SOURCE_POSTGIS diff --git a/docs/reference/libgtkgis-undocumented.txt b/docs/reference/libgtkgis-undocumented.txt index 5bdfc50..1089258 100644 --- a/docs/reference/libgtkgis-undocumented.txt +++ b/docs/reference/libgtkgis-undocumented.txt @@ -1,7 +1,7 @@ -11% symbol docs coverage. -23 symbols documented. +14% symbol docs coverage. +28 symbols documented. 7 symbols incomplete. -181 not documented. +177 not documented. GTK_GIS @@ -92,8 +92,8 @@ TYPE_GTK_GIS_LAYER_SOURCE_SHP gtk_gis_add_group gtk_gis_add_layer gtk_gis_color_parse +gtk_gis_color_string_is_valid gtk_gis_color_to_string -gtk_gis_draw gtk_gis_geometry_draw gtk_gis_geometry_get_editable gtk_gis_geometry_get_extent @@ -157,14 +157,10 @@ gtk_gis_layers_group_new (source, name, geometrytype, name) gtk_gis_layers_group_remove_layer gtk_gis_layers_group_set_name gtk_gis_move_to -gtk_gis_new_from_file -gtk_gis_new_from_xml gtk_gis_remove_group -gtk_gis_remove_layer gtk_gis_save_to_xml gtk_gis_set_scale gtk_gis_zoom_to_extent -gtk_gis_zoom_to_layer commons:Long_Description diff --git a/docs/reference/tmpl/geometry.sgml b/docs/reference/tmpl/geometry.sgml index 073d518..789bf5e 100644 --- a/docs/reference/tmpl/geometry.sgml +++ b/docs/reference/tmpl/geometry.sgml @@ -104,6 +104,7 @@ GtkGisGeometry @geometry: @scale: @style: +@label: @Returns: diff --git a/src/commons.c b/src/commons.c index 0c63fff..e2badda 100644 --- a/src/commons.c +++ b/src/commons.c @@ -33,11 +33,17 @@ guint32 gtk_gis_color_parse (const gchar *color) { - guint32 ret_color = 0; + guint32 ret_color; gchar *c; + g_return_val_if_fail (color != NULL, 0); + c = g_strstrip (g_strdup (color)); + g_return_val_if_fail (strcmp (c, "") != 0, 0); + + ret_color = 0; + if (c[0] == '#') { gint val; @@ -120,3 +126,18 @@ gchar return ret; } + +/** + * gtk_gis_color_string_is_valid: + * @color: a string representing a color: + * + * Returns: TRUE if the string in @color is a valid color for GtkGis; FALSE + * otherwise. + */ +gboolean +gtk_gis_color_string_is_valid (const gchar *color) +{ + /* to test if the string color is valid, it simply tries to convert the + * color to a 32bit integer */ + return (gtk_gis_color_parse (color) != 0 ? TRUE : FALSE); +} diff --git a/src/commons.h b/src/commons.h index f7b3d29..988da9c 100644 --- a/src/commons.h +++ b/src/commons.h @@ -54,12 +54,21 @@ typedef struct gchar *fill_color; } GtkGisLayerStyle; +typedef struct + { + gchar *name; + guint size; + gboolean bold; + gboolean italic; + gboolean underline; + } GtkGisFont; + typedef struct { gchar *field; gchar *color; gchar *background_color; - gchar *font; + GtkGisFont *font; } GtkGisLayerLabel; typedef enum diff --git a/src/geometry.c b/src/geometry.c index be1058f..500d2f4 100644 --- a/src/geometry.c +++ b/src/geometry.c @@ -186,13 +186,14 @@ GtkGisExtent GooCanvasItem *gtk_gis_geometry_draw (GtkGisGeometry *geometry, GtkGisScale *scale, - GtkGisLayerStyle *style) + GtkGisLayerStyle *style, + GtkGisLayerLabel *label) { GooCanvasItem *item = NULL; if (IS_GTK_GIS_GEOMETRY (geometry) && GTK_GIS_GEOMETRY_GET_CLASS (geometry)->draw != NULL) { - item = GTK_GIS_GEOMETRY_GET_CLASS (geometry)->draw (geometry, scale, style); + item = GTK_GIS_GEOMETRY_GET_CLASS (geometry)->draw (geometry, scale, style, label); } return item; diff --git a/src/geometry.h b/src/geometry.h index 50a7ad5..7921b3b 100644 --- a/src/geometry.h +++ b/src/geometry.h @@ -54,7 +54,8 @@ struct _GtkGisGeometryClass GooCanvasItem *(*draw) (GtkGisGeometry *geometry, GtkGisScale *scale, - GtkGisLayerStyle *style); + GtkGisLayerStyle *style, + GtkGisLayerLabel *label); }; GType gtk_gis_geometry_get_type (void) G_GNUC_CONST; @@ -70,7 +71,8 @@ GtkGisExtent *gtk_gis_geometry_get_extent (GtkGisGeometry *geometry); GooCanvasItem *gtk_gis_geometry_draw (GtkGisGeometry *geometry, GtkGisScale *scale, - GtkGisLayerStyle *style); + GtkGisLayerStyle *style, + GtkGisLayerLabel *label); G_END_DECLS diff --git a/src/geometryline.c b/src/geometryline.c index 23ab56b..1d1e3fc 100644 --- a/src/geometryline.c +++ b/src/geometryline.c @@ -35,7 +35,8 @@ static gchar *convert_comma_to_dot (gchar *str); static GtkGisExtent *gtk_gis_geometry_line_get_extent (GtkGisGeometry *line); static GooCanvasItem *gtk_gis_geometry_line_draw (GtkGisGeometry *line, GtkGisScale *scale, - GtkGisLayerStyle *style); + GtkGisLayerStyle *style, + GtkGisLayerLabel *label); static void gtk_gis_geometry_line_set_property (GObject *object, guint property_id, @@ -287,7 +288,8 @@ static GtkGisExtent static GooCanvasItem *gtk_gis_geometry_line_draw (GtkGisGeometry *line, GtkGisScale *scale, - GtkGisLayerStyle *style) + GtkGisLayerStyle *style, + GtkGisLayerLabel *label) { GtkGisGeometryLinePrivate *priv; GooCanvasItem *item = NULL; @@ -334,7 +336,7 @@ static GooCanvasItem str_label, x, y, -1, GTK_ANCHOR_CENTER, - "font", g_strdup_printf ("Sans %fpx", 12 / scale->xy), + "font", g_strdup_printf ("%s %fpx", label->font->name, label->font->size / scale->xy), NULL); item = group; diff --git a/src/geometrypoint.c b/src/geometrypoint.c index 3110af0..a847d1f 100644 --- a/src/geometrypoint.c +++ b/src/geometrypoint.c @@ -33,7 +33,8 @@ static void gtk_gis_geometry_point_init (GtkGisGeometryPoint *gtk_gis_geometry_p static GtkGisExtent *gtk_gis_geometry_point_get_extent (GtkGisGeometry *point); static GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, GtkGisScale *scale, - GtkGisLayerStyle *style); + GtkGisLayerStyle *style, + GtkGisLayerLabel *label); static void gtk_gis_geometry_point_set_property (GObject *object, guint property_id, @@ -173,7 +174,8 @@ static GtkGisExtent static GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, GtkGisScale *scale, - GtkGisLayerStyle *style) + GtkGisLayerStyle *style, + GtkGisLayerLabel *label) { GooCanvasItem *item = NULL; @@ -205,7 +207,7 @@ GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, str_label, priv->point->x, priv->point->y, -1, GTK_ANCHOR_CENTER, - "font", g_strdup_printf ("Sans %fpx", 12 / scale->xy), + "font", g_strdup_printf ("%s %fpx", label->font->name, label->font->size / scale->xy), NULL); item = group; diff --git a/src/geometrypolygon.c b/src/geometrypolygon.c index 3d57369..a4a5d34 100644 --- a/src/geometrypolygon.c +++ b/src/geometrypolygon.c @@ -33,7 +33,8 @@ static void gtk_gis_geometry_polygon_init (GtkGisGeometryPolygon *gtk_gis_geomet static GtkGisExtent *gtk_gis_geometry_polygon_get_extent (GtkGisGeometry *polygon); static GooCanvasItem *gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon, GtkGisScale *scale, - GtkGisLayerStyle *style); + GtkGisLayerStyle *style, + GtkGisLayerLabel *label); static void gtk_gis_geometry_polygon_set_property (GObject *object, guint property_id, @@ -255,7 +256,8 @@ static GtkGisExtent static GooCanvasItem *gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon, GtkGisScale *scale, - GtkGisLayerStyle *style) + GtkGisLayerStyle *style, + GtkGisLayerLabel *label) { GtkGisGeometryPolygonPrivate *priv; GooCanvasItem *item = NULL; @@ -318,7 +320,7 @@ static GooCanvasItem str_label, x, y, -1, GTK_ANCHOR_CENTER, - "font", g_strdup_printf ("Sans %fpx", 12 / scale->xy), + "font", g_strdup_printf ("%s %fpx", label->font->name, label->font->size / scale->xy), NULL); item = group; diff --git a/src/geometryraster.c b/src/geometryraster.c index fae7722..35ba452 100644 --- a/src/geometryraster.c +++ b/src/geometryraster.c @@ -33,7 +33,8 @@ static void gtk_gis_geometry_raster_init (GtkGisGeometryRaster *gtk_gis_geometry static GooCanvasItem *gtk_gis_geometry_raster_draw (GtkGisGeometry *raster, GtkGisScale *scale, - GtkGisLayerStyle *style); + GtkGisLayerStyle *style, + GtkGisLayerLabel *label); static void gtk_gis_geometry_raster_set_property (GObject *object, guint property_id, @@ -118,7 +119,8 @@ GtkGisGeometry static GooCanvasItem *gtk_gis_geometry_raster_draw (GtkGisGeometry *raster, GtkGisScale *scale, - GtkGisLayerStyle *style) + GtkGisLayerStyle *style, + GtkGisLayerLabel *label) { GooCanvasItem *item = NULL; diff --git a/src/gtkgis.c b/src/gtkgis.c index b0cae17..49b8fcf 100644 --- a/src/gtkgis.c +++ b/src/gtkgis.c @@ -193,6 +193,8 @@ GtkWidget * gtk_gis_new_from_xml: * @xdoc: an #xmlDoc that contains the GtkGis definition. * + * Creates a new #GtkGis object from the xml definition. + * * Returns: the newly created #GtkGis object. */ GtkWidget @@ -306,8 +308,6 @@ GtkWidget xml_style = cur; style = g_malloc0 (sizeof (GtkGisLayerStyle)); - style->stroke_color = NULL; - style->fill_color = NULL; cur = cur->children; while (cur != NULL) @@ -343,10 +343,6 @@ GtkWidget xml_label = cur; label = g_malloc0 (sizeof (GtkGisLayerLabel)); - label->field = NULL; - label->color = NULL; - label->background_color = NULL; - label->font = NULL; cur = cur->children; while (cur != NULL) @@ -369,7 +365,47 @@ GtkWidget else if (cur->type == XML_ELEMENT_NODE && (xmlStrcmp (cur->name, "font") == 0)) { - label->font = g_strdup ((gchar *)xmlNodeGetContent (cur)); + xmlNode *xml_font; + GtkGisFont *font; + + xml_font = cur; + + font = g_malloc0 (sizeof (GtkGisLayerLabel)); + + label->font = font; + + cur = cur->children; + while (cur != NULL) + { + if (cur->type == XML_ELEMENT_NODE + && (xmlStrcmp (cur->name, "name") == 0)) + { + font->name = g_strdup ((gchar *)xmlNodeGetContent (cur)); + } + else if (cur->type == XML_ELEMENT_NODE + && (xmlStrcmp (cur->name, "size") == 0)) + { + font->size = atol (xmlNodeGetContent (cur)); + } + else if (cur->type == XML_ELEMENT_NODE + && (xmlStrcmp (cur->name, "bold") == 0)) + { + font->bold = (xmlStrcmp (xmlNodeGetContent (cur), "y") == 0 ? TRUE : FALSE); + } + else if (cur->type == XML_ELEMENT_NODE + && (xmlStrcmp (cur->name, "italic") == 0)) + { + font->italic = (xmlStrcmp (xmlNodeGetContent (cur), "y") == 0 ? TRUE : FALSE); + } + else if (cur->type == XML_ELEMENT_NODE + && (xmlStrcmp (cur->name, "underline") == 0)) + { + font->underline = (xmlStrcmp (xmlNodeGetContent (cur), "y") == 0 ? TRUE : FALSE); + } + cur = cur->next; + } + + cur = xml_font; } cur = cur->next; } @@ -405,6 +441,8 @@ GtkWidget * gtk_gis_new_from_file: * @file_name: the xml file's name that contains the GtkGis definition. * + * Creates a new #GtkGis object from the xml file definition. + * * Returns: the newly created #GtkGis object. */ GtkWidget @@ -487,7 +525,7 @@ xmlDoc /** * gtk_gis_save_to_xml: * @gtkgis: a #GtkGis object. - * @file_name: + * @file_name: the file name to save the #GtkGis object definition. */ void gtk_gis_save_to_xml (GtkGis *gtkgis, const gchar *file_name) @@ -567,6 +605,8 @@ g_fprintf(stderr,"max extent %f %f %f %f\n",priv->extent->min_x,priv->extent->mi * gtk_gis_remove_layer: * @gtkgis: a #GtkGis object. * @layer: a #GtkGisLayer object to remove from the #GtkGis widget. + * + * Removes the layer from the #GtkGis object. */ void gtk_gis_remove_layer (GtkGis *gtkgis, GtkGisLayer *layer) @@ -583,8 +623,9 @@ gtk_gis_remove_layer (GtkGis *gtkgis, GtkGisLayer *layer) /** * gtk_gis_get_layer_by_name: * @gtkgis: a #GtkGis object. - * @layer_name: + * @layer_name: the layer's name. * + * Returns: the #GtkGisLayer object with the name passed by @layer_name. */ GtkGisLayer *gtk_gis_get_layer_by_name (GtkGis *gtkgis, @@ -620,6 +661,7 @@ GtkGisLayer * gtk_gis_draw: * @gtkgis: a #GtkGis object. * + * Tells to the #GtkGis object to draw the layers. */ void gtk_gis_draw (GtkGis *gtkgis) @@ -799,7 +841,7 @@ gtk_gis_zoom_to_extent (GtkGis *gtkgis, GtkGisExtent extent) * gtk_gis_zoom_to_max: * @gtkgis: a #GtkGis object. * - * Zoom to the possible max extent. + * Zoom to the max possible extent. */ void gtk_gis_zoom_to_max (GtkGis *gtkgis) @@ -877,6 +919,7 @@ gtk_gis_zoom_to_max (GtkGis *gtkgis) * @gtkgis: a #GtkGis object. * @layer: a #GtkGisLayer object at which to zoom. * + * Zoom to the @layer's extent. */ void gtk_gis_zoom_to_layer (GtkGis *gtkgis, GtkGisLayer *layer) @@ -892,9 +935,9 @@ gtk_gis_zoom_to_layer (GtkGis *gtkgis, GtkGisLayer *layer) /** * gtk_gis_move_to: - * @gtkgis: - * @x: - * @y: + * @gtkgis: a #GtkGis object. + * @x: the x coordinate of the left-top corner. + * @y: the y coordinate of the left-top corner. * */ void diff --git a/src/layer.c b/src/layer.c index a920e84..fe45e66 100644 --- a/src/layer.c +++ b/src/layer.c @@ -39,6 +39,9 @@ static void gtk_gis_layer_get_property (GObject *object, GValue *value, GParamSpec *pspec); +static void gtk_gis_layer_style_set_defaults (GtkGisLayer *layer); +static void gtk_gis_layer_label_set_defaults (GtkGisLayer *layer); + #define GTK_GIS_LAYER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_GIS_LAYER, GtkGisLayerPrivate)) @@ -83,16 +86,11 @@ gtk_gis_layer_init (GtkGisLayer *gtk_gis_layer) priv->visible = TRUE; priv->editable = FALSE; - priv->style = g_malloc (sizeof (GtkGisLayerStyle)); - priv->style->width = 0.5; - priv->style->stroke_color = g_strdup ("#000000"); - priv->style->fill_color = g_strdup ("#FFFFFF"); + priv->style = g_malloc0 (sizeof (GtkGisLayerStyle)); + gtk_gis_layer_style_set_defaults (gtk_gis_layer); - priv->label = g_malloc (sizeof (GtkGisLayerLabel)); - priv->label->field = NULL; - priv->label->color = g_strdup ("#000000"); - priv->label->background_color = g_strdup ("#FFFFFF"); - priv->label->font = g_strdup ("Sans 12"); + priv->label = g_malloc0 (sizeof (GtkGisLayerLabel)); + gtk_gis_layer_label_set_defaults (gtk_gis_layer); } /** @@ -174,14 +172,7 @@ xmlNode xmlSetProp (xnode, "name", priv->name); } - if (priv->visible) - { - xmlSetProp (xnode, "visible", "y"); - } - else - { - xmlSetProp (xnode, "visible", "n"); - } + xmlSetProp (xnode, "visible", (priv->visible ? "y" : "n")); if (priv->source != NULL) { @@ -216,6 +207,8 @@ xmlNode { xmlNode *xnode_label; xmlNode *xnode_label_prop; + xmlNode *xnode_font; + xmlNode *xnode_font_prop; xnode_label = xmlNewNode (NULL, "label"); xmlAddChild (xnode, xnode_label); @@ -232,9 +225,28 @@ xmlNode xmlNodeSetContent (xnode_label_prop, g_strdup (priv->label->background_color)); xmlAddChild (xnode_label, xnode_label_prop); - xnode_label_prop = xmlNewNode (NULL, "font"); - xmlNodeSetContent (xnode_label_prop, g_strdup (priv->label->font)); - xmlAddChild (xnode_label, xnode_label_prop); + xnode_font = xmlNewNode (NULL, "font"); + xmlAddChild (xnode_label, xnode_font); + + xnode_font_prop = xmlNewNode (NULL, "name"); + xmlNodeSetContent (xnode_font_prop, g_strdup (priv->label->font->name)); + xmlAddChild (xnode_font, xnode_font_prop); + + xnode_font_prop = xmlNewNode (NULL, "size"); + xmlNodeSetContent (xnode_font_prop, g_strdup_printf ("%d", priv->label->font->size)); + xmlAddChild (xnode_font, xnode_font_prop); + + xnode_font_prop = xmlNewNode (NULL, "bold"); + xmlNodeSetContent (xnode_font_prop, (priv->label->font->bold ? "y" : "n")); + xmlAddChild (xnode_font, xnode_font_prop); + + xnode_font_prop = xmlNewNode (NULL, "underline"); + xmlNodeSetContent (xnode_font_prop, (priv->label->font->underline ? "y" : "n")); + xmlAddChild (xnode_font, xnode_font_prop); + + xnode_font_prop = xmlNewNode (NULL, "italic"); + xmlNodeSetContent (xnode_font_prop, (priv->label->font->italic ? "y" : "n")); + xmlAddChild (xnode_font, xnode_font_prop); } return xnode; @@ -458,7 +470,6 @@ GtkGisLayerStyle priv = GTK_GIS_LAYER_GET_PRIVATE (layer); - style = g_malloc (sizeof (GtkGisLayerStyle)); style = g_memdup (priv->style, sizeof (GtkGisLayerStyle)); return style; @@ -475,50 +486,21 @@ void gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle *style) { GtkGisLayerPrivate *priv; - GtkGisLayerStyle *new_style; - gchar *prop; g_return_if_fail (IS_GTK_GIS_LAYER (layer)); - if (style == NULL) return; - priv = GTK_GIS_LAYER_GET_PRIVATE (layer); - new_style = g_malloc0 (sizeof (GtkGisLayerStyle)); - - if (style->width != 0) + if (style == NULL) { - new_style->width = style->width; + priv->style = g_malloc0 (sizeof (GtkGisLayerStyle)); } else { - new_style->width = priv->style->width; + priv->style = g_memdup (style, sizeof (GtkGisLayerStyle)); } - prop = g_strdup (style->stroke_color); - if (style->stroke_color != NULL && - g_strcmp0 (g_strstrip (prop), "") != 0) - { - new_style->stroke_color = g_strdup (prop); - } - else - { - new_style->stroke_color = g_strdup (priv->style->stroke_color); - } - - prop = g_strdup (style->fill_color); - if (style->fill_color != NULL && - g_strcmp0 (g_strstrip (prop), "") != 0) - { - new_style->fill_color = g_strdup (prop); - } - else - { - new_style->fill_color = g_strdup (priv->style->fill_color); - } - - g_free (priv->style); - priv->style = new_style; + gtk_gis_layer_style_set_defaults (layer); } /** @@ -534,7 +516,7 @@ GtkGisLayerLabel g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), NULL); - return label; + return g_memdup (label, sizeof (GtkGisLayerLabel)); } /** @@ -547,63 +529,19 @@ void gtk_gis_layer_set_label (GtkGisLayer *layer, GtkGisLayerLabel *label) { GtkGisLayerPrivate *priv; - GtkGisLayerLabel *new_label; - gchar *prop; g_return_if_fail (IS_GTK_GIS_LAYER (layer)); - if (label == NULL) return; - - priv = GTK_GIS_LAYER_GET_PRIVATE (layer); - - new_label = g_malloc0 (sizeof (GtkGisLayerLabel)); - - prop = g_strdup (label->field); - if (label->field != NULL && - g_strcmp0 (g_strstrip (prop), "") != 0) + if (label == NULL) { - new_label->field = g_strdup (prop); + priv->label = g_malloc0 (sizeof (GtkGisLayerLabel)); } else { - new_label->field = g_strdup (priv->label->field); + priv->label = g_memdup (label, sizeof (GtkGisLayerLabel)); } - prop = g_strdup (label->color); - if (label->color != NULL && - g_strcmp0 (g_strstrip (prop), "") != 0) - { - new_label->color = g_strdup (prop); - } - else - { - new_label->color = g_strdup (priv->label->color); - } - - prop = g_strdup (label->background_color); - if (label->background_color != NULL && - g_strcmp0 (g_strstrip (prop), "") != 0) - { - new_label->background_color = g_strdup (prop); - } - else - { - new_label->background_color = g_strdup (priv->label->background_color); - } - - prop = g_strdup (label->font); - if (label->font != NULL && - g_strcmp0 (g_strstrip (prop), "") != 0) - { - new_label->font = g_strdup (prop); - } - else - { - new_label->font = g_strdup (priv->label->font); - } - - g_free (priv->label); - priv->label = new_label; + gtk_gis_layer_label_set_defaults (layer); } /** @@ -641,7 +579,8 @@ GooCanvasItem cur = priv->geometries; while (cur != NULL) { - item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data, scale, priv->style); + item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data, scale, + priv->style, priv->label); if (item != NULL) { goo_canvas_item_add_child (priv->layer_item, item, -1); @@ -682,3 +621,57 @@ gtk_gis_layer_get_property (GObject *object, guint property_id, GValue *value, G break; } } + +static void +gtk_gis_layer_style_set_defaults (GtkGisLayer *layer) +{ + GtkGisLayerPrivate *priv; + + g_return_if_fail (IS_GTK_GIS_LAYER (layer)); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + if (!gtk_gis_color_string_is_valid (priv->style->stroke_color)) + { + priv->style->stroke_color = g_strdup ("#000000"); + } + if (!gtk_gis_color_string_is_valid (priv->style->fill_color)) + { + priv->style->fill_color = g_strdup ("#FFFFFF"); + } +} + +static void +gtk_gis_layer_label_set_defaults (GtkGisLayer *layer) +{ + GtkGisLayerPrivate *priv; + + g_return_if_fail (IS_GTK_GIS_LAYER (layer)); + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + if (priv->label->field == NULL) + { + priv->label->field = g_strdup (""); + } + if (!gtk_gis_color_string_is_valid (priv->label->color)) + { + priv->label->color = g_strdup ("#000000"); + } + if (!gtk_gis_color_string_is_valid (priv->label->background_color)) + { + priv->label->background_color = g_strdup ("#FFFFFF"); + } + if (priv->label->font == NULL) + { + priv->label->font = g_malloc0 (sizeof (GtkGisFont)); + priv->label->font->name = g_strdup (""); + } + else + { + if (priv->label->font->name == NULL) + { + priv->label->font->name = g_strdup (""); + } + } +} diff --git a/tests/test1.gtkgis b/tests/test1.gtkgis index d3b0e72..7614b1f 100644 --- a/tests/test1.gtkgis +++ b/tests/test1.gtkgis @@ -5,6 +5,7 @@ @@ -14,6 +15,7 @@