[goffice] Take ppu into account for distance calculation.



commit f95fe6eac52416be3bdc498ee3320cb5f467b8ed
Author: Valek Filippov <frob gnome org>
Date:   Wed Mar 17 21:05:16 2010 -0400

    Take ppu into account for distance calculation.

 goffice/canvas/goc-arc.c       |    8 +++++---
 goffice/canvas/goc-ellipse.c   |    8 +++++---
 goffice/canvas/goc-polygon.c   |   12 ++++++++----
 goffice/canvas/goc-polyline.c  |   11 +++++++----
 goffice/canvas/goc-rectangle.c |    9 +++++----
 5 files changed, 30 insertions(+), 18 deletions(-)
---
diff --git a/goffice/canvas/goc-arc.c b/goffice/canvas/goc-arc.c
index dc3800c..1ef15dd 100644
--- a/goffice/canvas/goc-arc.c
+++ b/goffice/canvas/goc-arc.c
@@ -326,6 +326,7 @@ goc_arc_distance (GocItem *item, double x, double y, GocItem **near_item)
 	GOStyle *style = go_styled_object_get_style (GO_STYLED_OBJECT (item));
 	double tmp_width = 0;
 	double res = 20;
+	double ppu = goc_canvas_get_pixels_per_unit (item->canvas);
 	cairo_surface_t *surface;
 	cairo_t *cr;
 
@@ -334,9 +335,10 @@ goc_arc_distance (GocItem *item, double x, double y, GocItem **near_item)
 
 	*near_item = item;
 	tmp_width = style->line.width;
-	if (style->line.width < 5) {
-		style->line.width = 5;
-	}
+	if (style->line.width * ppu < 5)
+		style->line.width = 5. / (ppu * ppu);
+	else
+		style->line.width /= ppu;
 	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
 	cr = cairo_create (surface);
 
diff --git a/goffice/canvas/goc-ellipse.c b/goffice/canvas/goc-ellipse.c
index 58a8247..b887e40 100644
--- a/goffice/canvas/goc-ellipse.c
+++ b/goffice/canvas/goc-ellipse.c
@@ -160,6 +160,7 @@ goc_ellipse_distance (GocItem *item, double x, double y, GocItem **near_item)
 	GOStyle *style = go_styled_object_get_style (GO_STYLED_OBJECT (item));
 	double tmp_width = 0;
 	double res = 20;
+	double ppu = goc_canvas_get_pixels_per_unit (item->canvas);
 	cairo_surface_t *surface;
 	cairo_t *cr;
 
@@ -168,9 +169,10 @@ goc_ellipse_distance (GocItem *item, double x, double y, GocItem **near_item)
 
 	*near_item = item;
 	tmp_width = style->line.width;
-	if (style->line.width < 5){
-		style->line.width = 5;
-	}
+	if (style->line.width * ppu < 5)
+		style->line.width = 5. / (ppu * ppu);
+	else
+		style->line.width /= ppu;
 	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
 	cr = cairo_create (surface);
 
diff --git a/goffice/canvas/goc-polygon.c b/goffice/canvas/goc-polygon.c
index e963a23..6384738 100644
--- a/goffice/canvas/goc-polygon.c
+++ b/goffice/canvas/goc-polygon.c
@@ -178,6 +178,8 @@ goc_polygon_distance (GocItem *item, double x, double y, GocItem **near_item)
 	GocPolygon *polygon = GOC_POLYGON (item);
 	GOStyle *style = go_style_dup (go_styled_object_get_style (GO_STYLED_OBJECT (item)));
 	double res = G_MAXDOUBLE;
+	double ppu = goc_canvas_get_pixels_per_unit (item->canvas);
+	double tmp_width = 0;
 	cairo_surface_t *surface;
 	cairo_t *cr;
 
@@ -185,6 +187,11 @@ goc_polygon_distance (GocItem *item, double x, double y, GocItem **near_item)
 		return res;
 
 	*near_item = item;
+	tmp_width = style->line.width;
+	if (style->line.width * ppu < 5)
+		style->line.width = 5. / (ppu * ppu);
+	else
+		style->line.width /= ppu;
 	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
 	cr = cairo_create (surface);
 	goc_polygon_prepare_path (item, cr, 0);
@@ -195,13 +202,9 @@ goc_polygon_distance (GocItem *item, double x, double y, GocItem **near_item)
 		else if ((item->x1 - item->x0 < 5 || item->y1 - item->y0 < 5) && style->line.dash_type == GO_LINE_NONE) {
 			style->line.dash_type = GO_LINE_SOLID;
 			style->line.auto_dash = FALSE;
-			style->line.width = 5;
 		}
 	}
 	if (res > 0 && style->line.dash_type != GO_LINE_NONE) {
-		if (style->line.width < 5) {
-			style->line.width = 5;
-		}
 		go_styled_object_set_cairo_line (GO_STYLED_OBJECT (item), cr);
 		if (cairo_in_stroke (cr, x, y))
 			res = 0;
@@ -210,6 +213,7 @@ goc_polygon_distance (GocItem *item, double x, double y, GocItem **near_item)
 	g_object_unref (style);
 	cairo_destroy (cr);
 	cairo_surface_destroy (surface);
+	style->line.width = tmp_width;
 	return res;
 }
 
diff --git a/goffice/canvas/goc-polyline.c b/goffice/canvas/goc-polyline.c
index ec187ff..44a04d2 100644
--- a/goffice/canvas/goc-polyline.c
+++ b/goffice/canvas/goc-polyline.c
@@ -164,9 +164,10 @@ static double
 goc_polyline_distance (GocItem *item, double x, double y, GocItem **near_item)
 {
 	GocPolyline *polyline = GOC_POLYLINE (item);
-	GOStyle *style = go_styled_object_get_style (GO_STYLED_OBJECT (item));
+	GOStyle *style = go_style_dup (go_styled_object_get_style (GO_STYLED_OBJECT (item)));
 	double tmp_width = 0;
 	double res = 20;
+	double ppu = goc_canvas_get_pixels_per_unit (item->canvas);
 	cairo_surface_t *surface;
 	cairo_t *cr;
 
@@ -175,9 +176,10 @@ goc_polyline_distance (GocItem *item, double x, double y, GocItem **near_item)
 
 	*near_item = item;
 	tmp_width = style->line.width;
-	if (style->line.width < 5) {
-		style->line.width = 5;
-	}
+	if (style->line.width * ppu < 5)
+		style->line.width = 5. / (ppu * ppu);
+	else
+		style->line.width /= ppu;
 	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
 	cr = cairo_create (surface);
 
@@ -186,6 +188,7 @@ goc_polyline_distance (GocItem *item, double x, double y, GocItem **near_item)
 			res = 0;
 	}
 
+	g_object_unref (style);
 	cairo_destroy (cr);
 	cairo_surface_destroy (surface);
 	style->line.width = tmp_width;
diff --git a/goffice/canvas/goc-rectangle.c b/goffice/canvas/goc-rectangle.c
index 2f2ec2f..607f0ec 100644
--- a/goffice/canvas/goc-rectangle.c
+++ b/goffice/canvas/goc-rectangle.c
@@ -249,9 +249,9 @@ goc_rectangle_distance (GocItem *item, double x, double y, GocItem **near_item)
 {
 	GocRectangle *rect = GOC_RECTANGLE (item);
 	GOStyle *style = go_styled_object_get_style (GO_STYLED_OBJECT (item));
-
 	double tmp_width = 0;
 	double res = 20;
+	double ppu = goc_canvas_get_pixels_per_unit (item->canvas);
 	cairo_surface_t *surface;
 	cairo_t *cr;
 
@@ -260,9 +260,10 @@ goc_rectangle_distance (GocItem *item, double x, double y, GocItem **near_item)
 
 	*near_item = item;
 	tmp_width = style->line.width;
-	if (style->line.width < 5){
-		style->line.width = 5;
-	}
+	if (style->line.width * ppu < 5)
+		style->line.width = 5. / (ppu * ppu);
+	else
+		style->line.width /= ppu;
 	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
 	cr = cairo_create (surface);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]