summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Amelang <dan@ereba.localdomain>2006-11-02 22:24:34 -0800
committerCarl Worth <cworth@cworth.org>2006-11-22 16:25:53 -0800
commit57fba8d9b6915fe4b0f506ecb2ef18a9002de370 (patch)
tree4dca7e7e9e567677a568e53c871b89cf75acefbe
parentefb483c3a36f8168d52086c2f61162f5a0306c15 (diff)
Replace existing rounding code with _cairo_lround
-rw-r--r--src/cairo-directfb-surface.c12
-rw-r--r--src/cairo-ft-font.c4
-rw-r--r--src/cairo-glitz-surface.c4
-rwxr-xr-xsrc/cairo-scaled-font.c14
-rw-r--r--src/cairo-win32-font.c14
-rw-r--r--src/cairo-win32-surface.c7
-rw-r--r--src/cairo-xcb-surface.c28
-rw-r--r--src/cairo-xlib-surface.c16
8 files changed, 50 insertions, 49 deletions
diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
index e724ed67..fc6cbefd 100644
--- a/src/cairo-directfb-surface.c
+++ b/src/cairo-directfb-surface.c
@@ -889,10 +889,10 @@ _cairo_directfb_surface_composite (cairo_operator_t op,
TRANSFORM_POINT (m, sr.x, sr.y, x1, y1);
TRANSFORM_POINT (m, sr.x+sr.w, sr.y+sr.h, x2, y2);
- dr.x = floor (x1+.5);
- dr.y = floor (y1+.5);
- dr.w = floor (x2-x1+.5);
- dr.h = floor (y2-y1+.5);
+ dr.x = _cairo_lround (x1);
+ dr.y = _cairo_lround (y1);
+ dr.w = _cairo_lround (x2-x1);
+ dr.h = _cairo_lround (y2-y1);
D_DEBUG_AT (Cairo_DirectFB, "Running StretchBlit().\n");
@@ -1283,8 +1283,8 @@ _directfb_acquire_font_cache (cairo_directfb_surface_t *surface,
return CAIRO_INT_STATUS_UNSUPPORTED;
}
- points[n].x = floor (glyphs[i].x + img->base.device_transform.x0 + .5);
- points[n].y = floor (glyphs[i].y + img->base.device_transform.y0 + .5);
+ points[n].x = _cairo_lround (glyphs[i].x + img->base.device_transform.x0);
+ points[n].y = _cairo_lround (glyphs[i].y + img->base.device_transform.y0);
if (points[n].x >= surface->width ||
points[n].y >= surface->height ||
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 25fabc99..59a5acba 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -1178,8 +1178,8 @@ _transform_glyph_bitmap (cairo_matrix_t * shape,
cairo_surface_destroy (&old_image->base);
cairo_surface_set_device_offset (&(*surface)->base,
- - floor (origin_x + 0.5),
- - floor (origin_y + 0.5));
+ - _cairo_lround (origin_x),
+ - _cairo_lround (origin_y));
return status;
}
diff --git a/src/cairo-glitz-surface.c b/src/cairo-glitz-surface.c
index febaa4a9..a5795119 100644
--- a/src/cairo-glitz-surface.c
+++ b/src/cairo-glitz-surface.c
@@ -2015,8 +2015,8 @@ _cairo_glitz_surface_old_show_glyphs (cairo_scaled_font_t *scaled_font,
x_offset = scaled_glyphs[i]->surface->base.device_transform.x0;
y_offset = scaled_glyphs[i]->surface->base.device_transform.y0;
- x1 = floor (glyphs[i].x + 0.5) + x_offset;
- y1 = floor (glyphs[i].y + 0.5) + y_offset;
+ x1 = _cairo_lround (glyphs[i].x) + x_offset;
+ y1 = _cairo_lround (glyphs[i].y) + y_offset;
x2 = x1 + glyph_private->area->width;
y2 = y1 + glyph_private->area->height;
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 0a96b9db..0b060fdf 100755
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -855,8 +855,8 @@ _cairo_scaled_font_glyph_device_extents (cairo_scaled_font_t *scaled_font,
}
/* glyph images are snapped to pixel locations */
- x = (int) floor (glyphs[i].x + 0.5);
- y = (int) floor (glyphs[i].y + 0.5);
+ x = _cairo_lround (glyphs[i].x);
+ y = _cairo_lround (glyphs[i].y);
left = x + _cairo_fixed_integer_floor(scaled_glyph->bbox.p1.x);
top = y + _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.y);
@@ -964,12 +964,10 @@ _cairo_scaled_font_show_glyphs (cairo_scaled_font_t *scaled_font,
/* round glyph locations to the nearest pixel */
/* XXX: FRAGILE: We're ignoring device_transform scaling here. A bug? */
- x = (int) floor (glyphs[i].x +
- glyph_surface->base.device_transform.x0 +
- 0.5);
- y = (int) floor (glyphs[i].y +
- glyph_surface->base.device_transform.y0 +
- 0.5);
+ x = _cairo_lround (glyphs[i].x +
+ glyph_surface->base.device_transform.x0);
+ y = _cairo_lround (glyphs[i].y +
+ glyph_surface->base.device_transform.y0);
_cairo_pattern_init_for_surface (&glyph_pattern, &glyph_surface->base);
diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index ee8cd3e7..58b4dd1b 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -151,7 +151,8 @@ _compute_transform (cairo_win32_scaled_font_t *scaled_font,
scaled_font->y_scale = - scaled_font->y_scale;
scaled_font->logical_scale = WIN32_FONT_LOGICAL_SCALE * scaled_font->y_scale;
- scaled_font->logical_size = WIN32_FONT_LOGICAL_SCALE * floor (scaled_font->y_scale + 0.5);
+ scaled_font->logical_size = WIN32_FONT_LOGICAL_SCALE *
+ _cairo_lround (scaled_font->y_scale);
}
/* The font matrix has x and y "scale" components which we extract and
@@ -165,7 +166,8 @@ _compute_transform (cairo_win32_scaled_font_t *scaled_font,
&scaled_font->x_scale, &scaled_font->y_scale,
TRUE); /* XXX: Handle vertical text */
- scaled_font->logical_size = floor (WIN32_FONT_LOGICAL_SCALE * scaled_font->y_scale + 0.5);
+ scaled_font->logical_size = _cairo_lround (WIN32_FONT_LOGICAL_SCALE *
+ scaled_font->y_scale);
scaled_font->logical_scale = WIN32_FONT_LOGICAL_SCALE * scaled_font->y_scale;
}
@@ -864,8 +866,8 @@ _cairo_win32_scaled_font_glyph_bbox (void *abstract_font,
glyph_index_option = 0;
for (i = 0; i < num_glyphs; i++) {
- int x = floor (0.5 + glyphs[i].x);
- int y = floor (0.5 + glyphs[i].y);
+ int x = _cairo_lround (glyphs[i].x);
+ int y = _cairo_lround (glyphs[i].y);
GetGlyphOutlineW (hdc, glyphs[i].index, GGO_METRICS | glyph_index_option,
&metrics, 0, NULL, &matrix);
@@ -966,8 +968,8 @@ _add_glyph (cairo_glyph_state_t *state,
cairo_matrix_transform_point (&state->scaled_font->device_to_logical, &user_x, &user_y);
- logical_x = floor (user_x + 0.5);
- logical_y = floor (user_y + 0.5);
+ logical_x = _cairo_lround (user_x);
+ logical_y = _cairo_lround (user_y);
if (state->glyphs.num_elements > 0) {
int dx;
diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
index f11895aa..a90f867a 100644
--- a/src/cairo-win32-surface.c
+++ b/src/cairo-win32-surface.c
@@ -1541,7 +1541,8 @@ _cairo_win32_surface_show_glyphs (void *surface,
if (i == num_glyphs - 1)
dx_buf[i] = 0;
else
- dx_buf[i] = (int) floor(((glyphs[i+1].x - glyphs[i].x) * WIN32_FONT_LOGICAL_SCALE) + 0.5);
+ dx_buf[i] = _cairo_lround ((glyphs[i+1].x - glyphs[i].x) *
+ WIN32_FONT_LOGICAL_SCALE);
if (i == num_glyphs - 1 || glyphs[i].y != glyphs[i+1].y) {
const int offset = (i - output_count) + 1;
@@ -1552,8 +1553,8 @@ _cairo_win32_surface_show_glyphs (void *surface,
cairo_matrix_transform_point(&device_to_logical,
&user_x, &user_y);
- logical_x = (int) floor(user_x + 0.5);
- logical_y = (int) floor(user_y + 0.5);
+ logical_x = _cairo_lround (user_x);
+ logical_y = _cairo_lround (user_y);
win_result = ExtTextOutW(dst->dc,
logical_x,
diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c
index 046c6205..9c34879f 100644
--- a/src/cairo-xcb-surface.c
+++ b/src/cairo-xcb-surface.c
@@ -2039,8 +2039,8 @@ _cairo_xcb_surface_add_glyph (xcb_connection_t *dpy,
*/
/* XXX: FRAGILE: We're ignore device_transform scaling here. A bug? */
- glyph_info.x = - (int) floor(glyph_surface->base.device_transform.x0 + 0.5);
- glyph_info.y = - (int) floor(glyph_surface->base.device_transform.y0 + 0.5);
+ glyph_info.x = - _cairo_lround (glyph_surface->base.device_transform.x0);
+ glyph_info.y = - _cairo_lround (glyph_surface->base.device_transform.y0);
glyph_info.width = glyph_surface->width;
glyph_info.height = glyph_surface->height;
glyph_info.x_off = 0;
@@ -2148,8 +2148,8 @@ _cairo_xcb_surface_show_glyphs_8 (cairo_xcb_surface_t *dst,
stream = xcb_render_util_composite_text_stream (font_private->glyphset, num_glyphs, 0);
for (i = 0; i < num_glyphs; ++i) {
- thisX = (int) floor (glyphs[i].x + 0.5);
- thisY = (int) floor (glyphs[i].y + 0.5);
+ thisX = _cairo_lround (glyphs[i].x);
+ thisY = _cairo_lround (glyphs[i].y);
glyph = glyphs[i].index;
xcb_render_util_glyphs_8 (stream, thisX - lastX, thisY - lastY, 1, &glyph);
lastX = thisX;
@@ -2161,8 +2161,8 @@ _cairo_xcb_surface_show_glyphs_8 (cairo_xcb_surface_t *dst,
src->src_picture,
dst->dst_picture,
font_private->xrender_format->id,
- src_x_offset + (int) floor (glyphs[0].x + 0.5),
- src_y_offset + (int) floor (glyphs[0].y + 0.5),
+ src_x_offset + _cairo_lround (glyphs[0].x),
+ src_y_offset + _cairo_lround (glyphs[0].y),
stream);
xcb_render_util_composite_text_free (stream);
@@ -2189,8 +2189,8 @@ _cairo_xcb_surface_show_glyphs_16 (cairo_xcb_surface_t *dst,
stream = xcb_render_util_composite_text_stream (font_private->glyphset, num_glyphs, 0);
for (i = 0; i < num_glyphs; ++i) {
- thisX = (int) floor (glyphs[i].x + 0.5);
- thisY = (int) floor (glyphs[i].y + 0.5);
+ thisX = _cairo_lround (glyphs[i].x);
+ thisY = _cairo_lround (glyphs[i].y);
glyph = glyphs[i].index;
xcb_render_util_glyphs_16 (stream, thisX - lastX, thisY - lastY, 1, &glyph);
lastX = thisX;
@@ -2202,8 +2202,8 @@ _cairo_xcb_surface_show_glyphs_16 (cairo_xcb_surface_t *dst,
src->src_picture,
dst->dst_picture,
font_private->xrender_format->id,
- src_x_offset + (int) floor (glyphs[0].x + 0.5),
- src_y_offset + (int) floor (glyphs[0].y + 0.5),
+ src_x_offset + _cairo_lround (glyphs[0].x),
+ src_y_offset + _cairo_lround (glyphs[0].y),
stream);
xcb_render_util_composite_text_free (stream);
@@ -2230,8 +2230,8 @@ _cairo_xcb_surface_show_glyphs_32 (cairo_xcb_surface_t *dst,
stream = xcb_render_util_composite_text_stream (font_private->glyphset, num_glyphs, 0);
for (i = 0; i < num_glyphs; ++i) {
- thisX = (int) floor (glyphs[i].x + 0.5);
- thisY = (int) floor (glyphs[i].y + 0.5);
+ thisX = _cairo_lround (glyphs[i].x);
+ thisY = _cairo_lround (glyphs[i].y);
glyph = glyphs[i].index;
xcb_render_util_glyphs_32 (stream, thisX - lastX, thisY - lastY, 1, &glyph);
lastX = thisX;
@@ -2243,8 +2243,8 @@ _cairo_xcb_surface_show_glyphs_32 (cairo_xcb_surface_t *dst,
src->src_picture,
dst->dst_picture,
font_private->xrender_format->id,
- src_x_offset + (int) floor (glyphs[0].x + 0.5),
- src_y_offset + (int) floor (glyphs[0].y + 0.5),
+ src_x_offset + _cairo_lround (glyphs[0].x),
+ src_y_offset + _cairo_lround (glyphs[0].y),
stream);
xcb_render_util_composite_text_free (stream);
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index aaf43e47..4e7f6404 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -2408,8 +2408,8 @@ _cairo_xlib_surface_add_glyph (Display *dpy,
*/
/* XXX: FRAGILE: We're ignore device_transform scaling here. A bug? */
- glyph_info.x = - (int) floor(glyph_surface->base.device_transform.x0 + 0.5);
- glyph_info.y = - (int) floor(glyph_surface->base.device_transform.y0 + 0.5);
+ glyph_info.x = - _cairo_lround (glyph_surface->base.device_transform.x0);
+ glyph_info.y = - _cairo_lround (glyph_surface->base.device_transform.y0);
glyph_info.width = glyph_surface->width;
glyph_info.height = glyph_surface->height;
glyph_info.xOff = 0;
@@ -2536,8 +2536,8 @@ _cairo_xlib_surface_show_glyphs8 (cairo_xlib_surface_t *dst,
elts[i].chars = &(chars[i]);
elts[i].nchars = 1;
elts[i].glyphset = font_private->glyphset;
- thisX = (int) floor (glyphs[i].x + 0.5);
- thisY = (int) floor (glyphs[i].y + 0.5);
+ thisX = _cairo_lround (glyphs[i].x);
+ thisY = _cairo_lround (glyphs[i].y);
elts[i].xOff = thisX - lastX;
elts[i].yOff = thisY - lastY;
lastX = thisX;
@@ -2597,8 +2597,8 @@ _cairo_xlib_surface_show_glyphs16 (cairo_xlib_surface_t *dst,
elts[i].chars = &(chars[i]);
elts[i].nchars = 1;
elts[i].glyphset = font_private->glyphset;
- thisX = (int) floor (glyphs[i].x + 0.5);
- thisY = (int) floor (glyphs[i].y + 0.5);
+ thisX = _cairo_lround (glyphs[i].x);
+ thisY = _cairo_lround (glyphs[i].y);
elts[i].xOff = thisX - lastX;
elts[i].yOff = thisY - lastY;
lastX = thisX;
@@ -2658,8 +2658,8 @@ _cairo_xlib_surface_show_glyphs32 (cairo_xlib_surface_t *dst,
elts[i].chars = &(chars[i]);
elts[i].nchars = 1;
elts[i].glyphset = font_private->glyphset;
- thisX = (int) floor (glyphs[i].x + 0.5);
- thisY = (int) floor (glyphs[i].y + 0.5);
+ thisX = _cairo_lround (glyphs[i].x);
+ thisY = _cairo_lround (glyphs[i].y);
elts[i].xOff = thisX - lastX;
elts[i].yOff = thisY - lastY;
lastX = thisX;