Example #1
0
// Before placing a new label we need to see if the label overlaps over
// previously placed labels. This algorithm will be refactored a bit to try
// NE SE SW NW placements in the future.
void
try_and_insert_placement(simplet_lithograph_t *litho, PangoLayout *layout, double x, double y){
  int width, height;
  // Find the computed width and height of a layout in image pixels
  pango_layout_get_pixel_size(layout, &width, &height);
  simplet_bounds_t *bounds = simplet_bounds_new();
  if(!bounds) return;
  // Create a bounds to test for intersection
  simplet_bounds_extend(bounds, floor(x - width / 2), floor(y - height / 2));
  simplet_bounds_extend(bounds, floor(x + width / 2), floor(y + height / 2));

  // Iterate through the list of already placed labels and check for overlaps.
  simplet_listiter_t *iter = simplet_get_list_iter(litho->placements);
  placement_t *placement;
  while((placement = (placement_t *) simplet_list_next(iter))){
    if(simplet_bounds_intersects(placement->bounds, bounds)){
      simplet_bounds_free(bounds);
      g_object_unref(layout);
      simplet_list_iter_free(iter);
      return;
    }
  }

  // If we get here we can create and insert a new placement.
  placement_t *plc = placement_new(layout, bounds);
  if(!plc) {
    simplet_bounds_free(bounds);
    g_object_unref(layout);
    return;
  }

  simplet_list_push(litho->placements, (void *)plc);
}
Example #2
0
// Creat and append a filter to the layer's filters.
simplet_filter_t*
simplet_layer_add_filter(simplet_layer_t *layer, const char *ogrsql){
  simplet_filter_t* filter;
  if(!(filter = simplet_filter_new(ogrsql)))
    return NULL;

  if(!simplet_list_push(layer->filters, filter)){
    simplet_filter_free(filter);
    return NULL;
  }

  return filter;
}
Example #3
0
// Creat and append a query to the layer's queries.
simplet_query_t*
simplet_layer_add_query(simplet_layer_t *layer, const char *ogrsql){
  simplet_query_t* query;
  if(!(query = simplet_query_new(ogrsql)))
    return NULL;

  if(!simplet_list_push(layer->queries, query)){
    simplet_query_free(query);
    return NULL;
  }

  return query;
}
Example #4
0
// Add a previously initialized filter to the layer.
simplet_filter_t*
simplet_layer_add_filter_directly(simplet_layer_t *layer, simplet_filter_t *filter){
  if(!simplet_list_push(layer->filters, filter)) return NULL;
  return filter;
}
Example #5
0
// Add a previously initialized query to the layer.
simplet_query_t*
simplet_layer_add_query_directly(simplet_layer_t *layer, simplet_query_t *query){
  if(!simplet_list_push(layer->queries, query)) return NULL;
  return query;
}