# 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])
# 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
<!ELEMENT field (#PCDATA) />
<!ELEMENT color (#PCDATA) />
<!ELEMENT background-color (#PCDATA) />
-<!ELEMENT font (#PCDATA) />
+
+<!ELEMENT font (name, size, bold?, italic?, underline?) />
+
+<!ELEMENT name (#PCDATA) />
+<!ELEMENT size (#PCDATA) />
+<!ELEMENT bold (y | n) "n" />
+<!ELEMENT italic (y | n) "n" />
+<!ELEMENT underline (y | n) "n" />
GooCanvasItem *(*draw) (GtkGisGeometry *geometry,
GtkGisScale *scale,
- GtkGisLayerStyle *style);
+ GtkGisLayerStyle *style,
+ GtkGisLayerLabel *label);
};
</STRUCT>
<FUNCTION>
<FUNCTION>
<NAME>gtk_gis_geometry_draw</NAME>
<RETURNS>GooCanvasItem *</RETURNS>
-GtkGisGeometry *geometry,GtkGisScale *scale,GtkGisLayerStyle *style
+GtkGisGeometry *geometry,GtkGisScale *scale,GtkGisLayerStyle *style,GtkGisLayerLabel *label
</FUNCTION>
<MACRO>
<NAME>TYPE_GTK_GIS_LAYER_SOURCE_POSTGIS</NAME>
-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
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
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
@geometry:
@scale:
@style:
+@label:
@Returns:
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;
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);
+}
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
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;
GooCanvasItem *(*draw) (GtkGisGeometry *geometry,
GtkGisScale *scale,
- GtkGisLayerStyle *style);
+ GtkGisLayerStyle *style,
+ GtkGisLayerLabel *label);
};
GType gtk_gis_geometry_get_type (void) G_GNUC_CONST;
GooCanvasItem *gtk_gis_geometry_draw (GtkGisGeometry *geometry,
GtkGisScale *scale,
- GtkGisLayerStyle *style);
+ GtkGisLayerStyle *style,
+ GtkGisLayerLabel *label);
G_END_DECLS
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,
static GooCanvasItem
*gtk_gis_geometry_line_draw (GtkGisGeometry *line,
GtkGisScale *scale,
- GtkGisLayerStyle *style)
+ GtkGisLayerStyle *style,
+ GtkGisLayerLabel *label)
{
GtkGisGeometryLinePrivate *priv;
GooCanvasItem *item = NULL;
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;
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,
static
GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point,
GtkGisScale *scale,
- GtkGisLayerStyle *style)
+ GtkGisLayerStyle *style,
+ GtkGisLayerLabel *label)
{
GooCanvasItem *item = NULL;
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;
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,
static GooCanvasItem
*gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon,
GtkGisScale *scale,
- GtkGisLayerStyle *style)
+ GtkGisLayerStyle *style,
+ GtkGisLayerLabel *label)
{
GtkGisGeometryPolygonPrivate *priv;
GooCanvasItem *item = NULL;
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;
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,
static GooCanvasItem
*gtk_gis_geometry_raster_draw (GtkGisGeometry *raster,
GtkGisScale *scale,
- GtkGisLayerStyle *style)
+ GtkGisLayerStyle *style,
+ GtkGisLayerLabel *label)
{
GooCanvasItem *item = NULL;
* 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
xml_style = cur;
style = g_malloc0 (sizeof (GtkGisLayerStyle));
- style->stroke_color = NULL;
- style->fill_color = NULL;
cur = cur->children;
while (cur != NULL)
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)
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;
}
* 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
/**
* 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)
* 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)
/**
* 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,
* gtk_gis_draw:
* @gtkgis: a #GtkGis object.
*
+ * Tells to the #GtkGis object to draw the layers.
*/
void
gtk_gis_draw (GtkGis *gtkgis)
* 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)
* @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)
/**
* 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
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))
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);
}
/**
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)
{
{
xmlNode *xnode_label;
xmlNode *xnode_label_prop;
+ xmlNode *xnode_font;
+ xmlNode *xnode_font_prop;
xnode_label = xmlNewNode (NULL, "label");
xmlAddChild (xnode, xnode_label);
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;
priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
- style = g_malloc (sizeof (GtkGisLayerStyle));
style = g_memdup (priv->style, sizeof (GtkGisLayerStyle));
return style;
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);
}
/**
g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), NULL);
- return label;
+ return g_memdup (label, sizeof (GtkGisLayerLabel));
}
/**
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);
}
/**
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);
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 ("");
+ }
+ }
+}
<shape filename="tests/samples/alaska.shp" />
</source>
<style>
+ <width>0.5</width>
<fill-color>#C5DFBF</fill-color>
</style>
</layer>
<shape filename="tests/samples/airports.shp" />
</source>
<style>
+ <width>0.5</width>
<stroke-color>#FF0000</stroke-color>
</style>
<!--<label>
<shape filename="tests/samples/railroads.shp" />
</source>
<style>
+ <width>0.5</width>
<stroke-color>#00FF00</stroke-color>
</style>
</layer>
<shape filename="tests/samples/rivers.shp" />
</source>
<style>
+ <width>0.5</width>
<stroke-color>#0000FF</stroke-color>
</style>
<!--<label>