[cairo] Re: [cairo-commit] test/operator-clear.c test/operator-source.c test/unbounded-operator.c

Daniel Amelang daniel.amelang at gmail.com
Wed Nov 29 18:35:02 PST 2006


On 11/23/06, Behdad Esfahbod <behdad at behdad.org> wrote:
> On Wed, 2006-11-22 at 19:44 -0500, Carl Worth wrote:
> >     test: Use round to pass only integers to cairo_show_glyphs (in 3
> > more tests)
>
> Didn't we intentionally avoid round and lround because of their C99
> introduction?  I think the same floor(...+.5) trick should be used here
> too.

I agree, VC++ doesn't have round(), for example. What do you think of
this patch?

Dan
-------------- next part --------------
From nobody Mon Sep 17 00:00:00 2001
From: Dan Amelang <dan at amelang.net>
Date: Wed Nov 29 18:32:35 2006 -0800
Subject: [PATCH] Purge cairo-test of all calls to round()

Although round() is in the C99 standard, it isn't available in all
toolchains on which cairo is compiled (VC++, for example).

---

 test/clip-operator.c      |    4 ++--
 test/operator-clear.c     |    4 ++--
 test/operator-source.c    |    4 ++--
 test/unbounded-operator.c |    4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

72f820727804c500eb0ab41a605db730c6fe2dea
diff --git a/test/clip-operator.c b/test/clip-operator.c
index 22bdab0..2e014a9 100644
--- a/test/clip-operator.c
+++ b/test/clip-operator.c
@@ -76,8 +76,8 @@ draw_glyphs (cairo_t *cr, int x, int y)
 
     cairo_text_extents (cr, "FG", &extents);
     cairo_move_to (cr,
-		   x + round ((WIDTH - extents.width) / 2) - extents.x_bearing,
-		   y + round ((HEIGHT - extents.height) / 2) - extents.y_bearing);
+		   x + floor ((WIDTH - extents.width) / 2 + 0.5) - extents.x_bearing,
+		   y + floor ((HEIGHT - extents.height) / 2 + 0.5) - extents.y_bearing);
     cairo_show_text (cr, "FG");
 }
 
diff --git a/test/operator-clear.c b/test/operator-clear.c
index 5590e0f..84123fb 100644
--- a/test/operator-clear.c
+++ b/test/operator-clear.c
@@ -89,8 +89,8 @@ draw_glyphs (cairo_t *cr, int x, int y)
 
     cairo_text_extents (cr, "FG", &extents);
     cairo_move_to (cr,
-		   x + round ((WIDTH - extents.width) / 2) - extents.x_bearing,
-		   y + round ((HEIGHT - extents.height) / 2) - extents.y_bearing);
+		   x + floor ((WIDTH - extents.width) / 2 + 0.5) - extents.x_bearing,
+		   y + floor ((HEIGHT - extents.height) / 2 + 0.5) - extents.y_bearing);
     cairo_show_text (cr, "FG");
 }
 
diff --git a/test/operator-source.c b/test/operator-source.c
index 555eb25..9984ca2 100644
--- a/test/operator-source.c
+++ b/test/operator-source.c
@@ -126,8 +126,8 @@ draw_glyphs (cairo_t *cr, int x, int y)
 
     cairo_text_extents (cr, "FG", &extents);
     cairo_move_to (cr,
-		   x + round ((WIDTH - extents.width) / 2) - extents.x_bearing,
-		   y + round ((HEIGHT - extents.height) / 2) - extents.y_bearing);
+		   x + floor ((WIDTH - extents.width) / 2 + 0.5) - extents.x_bearing,
+		   y + floor ((HEIGHT - extents.height) / 2 + 0.5) - extents.y_bearing);
     cairo_show_text (cr, "FG");
 }
 
diff --git a/test/unbounded-operator.c b/test/unbounded-operator.c
index 6a9f617..7986c7c 100644
--- a/test/unbounded-operator.c
+++ b/test/unbounded-operator.c
@@ -75,8 +75,8 @@ draw_glyphs (cairo_t *cr, int x, int y)
 
     cairo_text_extents (cr, "FG", &extents);
     cairo_move_to (cr,
-		   x + round ((WIDTH - extents.width) / 2) - extents.x_bearing,
-		   y + round ((HEIGHT - extents.height) / 2) - extents.y_bearing);
+		   x + floor ((WIDTH - extents.width) / 2 + 0.5) - extents.x_bearing,
+		   y + floor ((HEIGHT - extents.height) / 2 + 0.5) - extents.y_bearing);
     cairo_show_text (cr, "FG");
 }
 
-- 
1.2.6


More information about the cairo mailing list