[cairo-commit] 9 commits - boilerplate/cairo-boilerplate.c boilerplate/cairo-boilerplate.h boilerplate/cairo-boilerplate-pdf.c boilerplate/cairo-boilerplate-pdf-private.h boilerplate/cairo-boilerplate-ps.c boilerplate/cairo-boilerplate-ps-private.h boilerplate/cairo-boilerplate-svg.c boilerplate/cairo-boilerplate-svg-private.h boilerplate/cairo-boilerplate-test-surfaces.c boilerplate/cairo-boilerplate-test-surfaces-private.h boilerplate/cairo-boilerplate-win32-printing.c boilerplate/cairo-boilerplate-win32-private.h src/cairo-compiler-private.h src/cairo-svg-surface.c src/cairo-win32-font.c src/Makefile.am test/buffer-diff.c test/buffer-diff.h test/cairo-test.c test/cairo-test.h test/imagediff.c test/leaky-dashed-rectangle.c test/make-html.pl test/toy-font-face.c test/user-font.c test/xlib-expose-event.c
Chris Wilson
ickle at kemper.freedesktop.org
Mon Aug 18 08:44:40 PDT 2008
boilerplate/cairo-boilerplate-pdf-private.h | 5
boilerplate/cairo-boilerplate-pdf.c | 26 +
boilerplate/cairo-boilerplate-ps-private.h | 5
boilerplate/cairo-boilerplate-ps.c | 29 +
boilerplate/cairo-boilerplate-svg-private.h | 5
boilerplate/cairo-boilerplate-svg.c | 26 +
boilerplate/cairo-boilerplate-test-surfaces-private.h | 5
boilerplate/cairo-boilerplate-test-surfaces.c | 58 ++-
boilerplate/cairo-boilerplate-win32-printing.c | 26 +
boilerplate/cairo-boilerplate-win32-private.h | 5
boilerplate/cairo-boilerplate.c | 135 +++++++
boilerplate/cairo-boilerplate.h | 62 ++-
src/Makefile.am | 6
src/cairo-compiler-private.h | 1
src/cairo-svg-surface.c | 31 -
src/cairo-win32-font.c | 244 +++++++------
test/buffer-diff.c | 327 +++++++++++-------
test/buffer-diff.h | 38 --
test/cairo-test.c | 160 +++++++-
test/cairo-test.h | 4
test/imagediff.c | 2
test/leaky-dashed-rectangle.c | 2
test/make-html.pl | 2
test/toy-font-face.c | 17
test/user-font.c | 91 ++---
test/xlib-expose-event.c | 10
26 files changed, 932 insertions(+), 390 deletions(-)
New commits:
commit c56385eacc076a149ffe0fb6690b7b128fdc9e50
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon Aug 18 16:08:16 2008 +0100
[test/make-html.pl] Don't include links to non-existent images.
Some tests do not generate output images, so do not insert a link if we
don't have an image.
diff --git a/test/make-html.pl b/test/make-html.pl
index 8bc961e..e9c84a1 100755
--- a/test/make-html.pl
+++ b/test/make-html.pl
@@ -199,6 +199,8 @@ printl '</tr>';
sub img_for {
my ($fn, $withlink) = @_;
+ return "" unless defined $fn;
+
if ($config_show_inline) {
$fn = file_to_data("image/png", $fn);
# never return links, people can just right-click view image,
commit 17fbb652b1c74ba0ccced48c14c63a4d24bb3891
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon Aug 18 12:53:43 2008 +0100
[test] Avoid redundant writes/reads of test surfaces via png.
As Behdad suggested, we can dramatically speed up the test suite by
short-circuiting the write to a png file, only to then immediately read it
back in. So for the raster based surfaces, we avoid the round-trip through
libpng by implementing a new boilerplate method to directly extract the image
buffer from the test result. A secondary speedup is achieved by caching the
most recent reference image.
diff --git a/boilerplate/cairo-boilerplate-pdf-private.h b/boilerplate/cairo-boilerplate-pdf-private.h
index a792cc4..69f8da3 100644
--- a/boilerplate/cairo-boilerplate-pdf-private.h
+++ b/boilerplate/cairo-boilerplate-pdf-private.h
@@ -44,4 +44,9 @@ _cairo_boilerplate_pdf_cleanup (void *closure);
cairo_status_t
_cairo_boilerplate_pdf_surface_write_to_png (cairo_surface_t *surface, const char *filename);
+cairo_surface_t *
+_cairo_boilerplate_pdf_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height);
+
#endif
diff --git a/boilerplate/cairo-boilerplate-pdf.c b/boilerplate/cairo-boilerplate-pdf.c
index 84e9f3e..dc76435 100644
--- a/boilerplate/cairo-boilerplate-pdf.c
+++ b/boilerplate/cairo-boilerplate-pdf.c
@@ -152,6 +152,32 @@ _cairo_boilerplate_pdf_surface_write_to_png (cairo_surface_t *surface, const cha
return CAIRO_STATUS_SUCCESS;
}
+cairo_surface_t *
+_cairo_boilerplate_pdf_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height)
+{
+ pdf_target_closure_t *ptc = cairo_surface_get_user_data (surface,
+ &pdf_closure_key);
+ char *filename;
+ cairo_status_t status;
+
+ xasprintf (&filename, "%s.png", ptc->filename);
+ status = _cairo_boilerplate_pdf_surface_write_to_png (surface, filename);
+ if (status)
+ return cairo_boilerplate_surface_create_in_error (status);
+
+ surface = cairo_boilerplate_get_image_surface_from_png (filename,
+ width,
+ height,
+ ptc->target == NULL);
+
+ remove (filename);
+ free (filename);
+
+ return surface;
+}
+
void
_cairo_boilerplate_pdf_cleanup (void *closure)
{
diff --git a/boilerplate/cairo-boilerplate-ps-private.h b/boilerplate/cairo-boilerplate-ps-private.h
index 07b15f6..7cd15bf 100644
--- a/boilerplate/cairo-boilerplate-ps-private.h
+++ b/boilerplate/cairo-boilerplate-ps-private.h
@@ -44,4 +44,9 @@ _cairo_boilerplate_ps_cleanup (void *closure);
cairo_status_t
_cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char *filename);
+cairo_surface_t *
+_cairo_boilerplate_ps_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height);
+
#endif
diff --git a/boilerplate/cairo-boilerplate-ps.c b/boilerplate/cairo-boilerplate-ps.c
index f5bd28c..f21d172 100644
--- a/boilerplate/cairo-boilerplate-ps.c
+++ b/boilerplate/cairo-boilerplate-ps.c
@@ -103,7 +103,8 @@ _cairo_boilerplate_ps_create_surface (const char *name,
cairo_status_t
_cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char *filename)
{
- ps_target_closure_t *ptc = cairo_surface_get_user_data (surface, &ps_closure_key);
+ ps_target_closure_t *ptc = cairo_surface_get_user_data (surface,
+ &ps_closure_key);
char command[4096];
cairo_status_t status;
@@ -149,6 +150,32 @@ _cairo_boilerplate_ps_surface_write_to_png (cairo_surface_t *surface, const char
return CAIRO_STATUS_WRITE_ERROR;
}
+cairo_surface_t *
+_cairo_boilerplate_ps_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height)
+{
+ ps_target_closure_t *ptc = cairo_surface_get_user_data (surface,
+ &ps_closure_key);
+ char *filename;
+ cairo_status_t status;
+
+ xasprintf (&filename, "%s.png", ptc->filename);
+ status = _cairo_boilerplate_ps_surface_write_to_png (surface, filename);
+ if (status)
+ return cairo_boilerplate_surface_create_in_error (status);
+
+ surface = cairo_boilerplate_get_image_surface_from_png (filename,
+ width,
+ height,
+ ptc->target == NULL);
+
+ remove (filename);
+ free (filename);
+
+ return surface;
+}
+
void
_cairo_boilerplate_ps_cleanup (void *closure)
{
diff --git a/boilerplate/cairo-boilerplate-svg-private.h b/boilerplate/cairo-boilerplate-svg-private.h
index 4cf5f63..3f2856d 100644
--- a/boilerplate/cairo-boilerplate-svg-private.h
+++ b/boilerplate/cairo-boilerplate-svg-private.h
@@ -44,4 +44,9 @@ _cairo_boilerplate_svg_cleanup (void *closure);
cairo_status_t
_cairo_boilerplate_svg_surface_write_to_png (cairo_surface_t *surface, const char *filename);
+cairo_surface_t *
+_cairo_boilerplate_svg_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height);
+
#endif
diff --git a/boilerplate/cairo-boilerplate-svg.c b/boilerplate/cairo-boilerplate-svg.c
index 1772988..d931847 100644
--- a/boilerplate/cairo-boilerplate-svg.c
+++ b/boilerplate/cairo-boilerplate-svg.c
@@ -145,6 +145,32 @@ _cairo_boilerplate_svg_surface_write_to_png (cairo_surface_t *surface, const cha
return CAIRO_STATUS_SUCCESS;
}
+cairo_surface_t *
+_cairo_boilerplate_svg_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height)
+{
+ svg_target_closure_t *ptc = cairo_surface_get_user_data (surface,
+ &svg_closure_key);
+ char *filename;
+ cairo_status_t status;
+
+ xasprintf (&filename, "%s.png", ptc->filename);
+ status = _cairo_boilerplate_svg_surface_write_to_png (surface, filename);
+ if (status)
+ return cairo_boilerplate_surface_create_in_error (status);
+
+ surface = cairo_boilerplate_get_image_surface_from_png (filename,
+ width,
+ height,
+ FALSE);
+
+ remove (filename);
+ free (filename);
+
+ return surface;
+}
+
void
_cairo_boilerplate_svg_cleanup (void *closure)
{
diff --git a/boilerplate/cairo-boilerplate-test-surfaces-private.h b/boilerplate/cairo-boilerplate-test-surfaces-private.h
index 0b2bebc..ed6cb5b 100644
--- a/boilerplate/cairo-boilerplate-test-surfaces-private.h
+++ b/boilerplate/cairo-boilerplate-test-surfaces-private.h
@@ -66,6 +66,11 @@ cairo_status_t
_cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface,
const char *filename);
+cairo_surface_t *
+_cairo_boilerplate_test_paginated_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height);
+
void
_cairo_boilerplate_test_paginated_cleanup (void *closure);
diff --git a/boilerplate/cairo-boilerplate-test-surfaces.c b/boilerplate/cairo-boilerplate-test-surfaces.c
index f38dda9..297faff 100644
--- a/boilerplate/cairo-boilerplate-test-surfaces.c
+++ b/boilerplate/cairo-boilerplate-test-surfaces.c
@@ -85,23 +85,25 @@ _cairo_boilerplate_test_paginated_create_surface (const char *name,
void **closure)
{
test_paginated_closure_t *tpc;
+ cairo_format_t format;
cairo_surface_t *surface;
cairo_status_t status;
*closure = tpc = xmalloc (sizeof (test_paginated_closure_t));
+ format = cairo_boilerplate_format_from_content (content);
+
tpc->content = content;
tpc->width = width;
tpc->height = height;
- tpc->stride = width * 4;
-
- tpc->data = xcalloc (tpc->stride * height, 1);
+ tpc->stride = cairo_format_stride_for_width (format, width);
+ tpc->data = xcalloc (tpc->stride, height);
surface = _cairo_test_paginated_surface_create_for_data (tpc->data,
- tpc->content,
- tpc->width,
- tpc->height,
- tpc->stride);
+ tpc->content,
+ tpc->width,
+ tpc->height,
+ tpc->stride);
if (cairo_surface_status (surface))
goto CLEANUP;
@@ -162,6 +164,48 @@ _cairo_boilerplate_test_paginated_surface_write_to_png (cairo_surface_t *surface
return status;
}
+cairo_surface_t *
+_cairo_boilerplate_test_paginated_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height)
+{
+ cairo_format_t format;
+ test_paginated_closure_t *tpc;
+ cairo_status_t status;
+
+ /* show page first. the automatic show_page is too late for us */
+ cairo_surface_show_page (surface);
+ status = cairo_surface_status (surface);
+ if (status)
+ return cairo_boilerplate_surface_create_in_error (status);
+
+ tpc = cairo_surface_get_user_data (surface, &test_paginated_closure_key);
+
+ format = cairo_boilerplate_format_from_content (tpc->content);
+
+ if (0) {
+ return cairo_image_surface_create_for_data (tpc->data + tpc->stride * (tpc->height - height) + 4 * (tpc->width - width), /* hide the device offset */
+ format,
+ width,
+ height,
+ tpc->stride);
+ } else {
+ cairo_surface_t *image, *surface;
+
+ image = cairo_image_surface_create_for_data (tpc->data,
+ format,
+ tpc->width,
+ tpc->height,
+ tpc->stride);
+ cairo_surface_set_device_offset (image,
+ tpc->width - width,
+ tpc->height - height);
+ surface = _cairo_boilerplate_get_image_surface (image, width, height);
+ cairo_surface_destroy (image);
+ return surface;
+ }
+}
+
void
_cairo_boilerplate_test_paginated_cleanup (void *closure)
{
diff --git a/boilerplate/cairo-boilerplate-win32-printing.c b/boilerplate/cairo-boilerplate-win32-printing.c
index 617b087..691552d 100644
--- a/boilerplate/cairo-boilerplate-win32-printing.c
+++ b/boilerplate/cairo-boilerplate-win32-printing.c
@@ -298,6 +298,32 @@ _cairo_boilerplate_win32_printing_surface_write_to_png (cairo_surface_t *surface
return CAIRO_STATUS_SUCCESS;
}
+cairo_surface_t *
+_cairo_boilerplate_win32_printing_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height)
+{
+ win32_target_closure_t *ptc = cairo_surface_get_user_data (surface,
+ &win32_closure_key);
+ char *filename;
+ cairo_status_t status;
+
+ xasprintf (&filename, "%s.png", ptc->filename);
+ status = _cairo_boilerplate_win32_printing_surface_write_to_png (surface, filename);
+ if (status)
+ return cairo_boilerplate_surface_create_in_error (status);
+
+ surface = cairo_boilerplate_get_image_surface_from_png (filename,
+ width,
+ height,
+ ptc->target == NULL);
+
+ remove (filename);
+ free (filename);
+
+ return surface;
+}
+
void
_cairo_boilerplate_win32_printing_cleanup (void *closure)
{
diff --git a/boilerplate/cairo-boilerplate-win32-private.h b/boilerplate/cairo-boilerplate-win32-private.h
index b982b2a..093ca9b 100644
--- a/boilerplate/cairo-boilerplate-win32-private.h
+++ b/boilerplate/cairo-boilerplate-win32-private.h
@@ -56,4 +56,9 @@ cairo_status_t
_cairo_boilerplate_win32_printing_surface_write_to_png (cairo_surface_t *surface,
const char *filename);
+cairo_surface_t *
+_cairo_boilerplate_win32_printing_get_image_surface (cairo_surface_t *surface,
+ int width,
+ int height);
+
#endif
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index c0af5bd..0ddcde5 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -140,6 +140,106 @@ _cairo_boilerplate_image_create_surface (const char *name,
return cairo_image_surface_create (format, width, height);
}
+cairo_surface_t *
+_cairo_boilerplate_get_image_surface (cairo_surface_t *src,
+ int width,
+ int height)
+{
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+#if 0
+ if (cairo_surface_get_type (src) == CAIRO_SURFACE_TYPE_IMAGE) {
+ int ww = cairo_image_surface_get_width (src);
+ int hh = cairo_image_surface_get_height (src);
+ if (width == ww && hh == height) {
+ return cairo_surface_reference (src);
+ } else {
+ cairo_format_t format = cairo_image_surface_get_format (src);
+ unsigned char *data = cairo_image_surface_get_data (src);
+ int stride = cairo_image_surface_get_stride (src);
+
+ data += stride * (hh - height) + 4 * (ww - width);
+ return cairo_image_surface_create_for_data (data,
+ format,
+ width,
+ height,
+ stride);
+ }
+ }
+#endif
+
+ /* extract sub-surface */
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+ cr = cairo_create (surface);
+ cairo_surface_destroy (surface);
+
+ cairo_set_source_surface (cr, src, 0, 0);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_paint (cr);
+
+ surface = cairo_surface_reference (cairo_get_target (cr));
+ cairo_destroy (cr);
+
+ return surface;
+}
+
+cairo_surface_t *
+cairo_boilerplate_get_image_surface_from_png (const char *filename,
+ int width,
+ int height,
+ cairo_bool_t flatten)
+{
+ cairo_surface_t *surface;
+
+ surface = cairo_image_surface_create_from_png (filename);
+
+ if (flatten) {
+ cairo_t *cr;
+ cairo_surface_t *flattened;
+
+ flattened = cairo_image_surface_create (cairo_image_surface_get_format (surface),
+ width,
+ height);
+ cr = cairo_create (flattened);
+ cairo_surface_destroy (flattened);
+
+ cairo_set_source_rgb (cr, 1, 1, 1);
+ cairo_paint (cr);
+
+ cairo_set_source_surface (cr, surface,
+ width - cairo_image_surface_get_width (surface),
+ height - cairo_image_surface_get_height (surface));
+ cairo_paint (cr);
+
+ cairo_surface_destroy (surface);
+ surface = cairo_surface_reference (cairo_get_target (cr));
+ cairo_destroy (cr);
+ } else if (cairo_image_surface_get_width (surface) != width ||
+ cairo_image_surface_get_height (surface) != height)
+ {
+ cairo_t *cr;
+ cairo_surface_t *sub;
+
+ sub = cairo_image_surface_create (cairo_image_surface_get_format (surface),
+ width,
+ height);
+ cr = cairo_create (sub);
+ cairo_surface_destroy (sub);
+
+ cairo_set_source_surface (cr, surface,
+ width - cairo_image_surface_get_width (surface),
+ height - cairo_image_surface_get_height (surface));
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_paint (cr);
+
+ cairo_surface_destroy (surface);
+ surface = cairo_surface_reference (cairo_get_target (cr));
+ cairo_destroy (cr);
+ }
+
+ return surface;
+}
static cairo_boilerplate_target_t targets[] =
{
@@ -148,35 +248,43 @@ static cairo_boilerplate_target_t targets[] =
* our control here. */
{ "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR_ALPHA, 0,
_cairo_boilerplate_image_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png },
{ "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_image_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png },
#ifdef CAIRO_HAS_TEST_SURFACES
{ "test-fallback", CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
CAIRO_CONTENT_COLOR_ALPHA, 0,
_cairo_boilerplate_test_fallback_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png },
{ "test-fallback", CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_test_fallback_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png },
{ "test-meta", CAIRO_INTERNAL_SURFACE_TYPE_TEST_META,
CAIRO_CONTENT_COLOR_ALPHA, 0,
_cairo_boilerplate_test_meta_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png },
{ "test-meta", CAIRO_INTERNAL_SURFACE_TYPE_TEST_META,
CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_test_meta_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png },
{ "test-paginated", CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED,
CAIRO_CONTENT_COLOR_ALPHA, 0,
_cairo_boilerplate_test_paginated_create_surface,
+ _cairo_boilerplate_test_paginated_get_image_surface,
_cairo_boilerplate_test_paginated_surface_write_to_png,
_cairo_boilerplate_test_paginated_cleanup },
{ "test-paginated", CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED,
CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_test_paginated_create_surface,
+ _cairo_boilerplate_test_paginated_get_image_surface,
_cairo_boilerplate_test_paginated_surface_write_to_png,
_cairo_boilerplate_test_paginated_cleanup },
#endif
@@ -184,30 +292,36 @@ static cairo_boilerplate_target_t targets[] =
#if CAIRO_CAN_TEST_GLITZ_GLX_SURFACE
{ "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ,CAIRO_CONTENT_COLOR_ALPHA, 0,
_cairo_boilerplate_glitz_glx_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_glitz_glx_cleanup },
{ "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_glitz_glx_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_glitz_glx_cleanup },
#endif
#if CAIRO_CAN_TEST_GLITZ_AGL_SURFACE
{ "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA, 0,
_cairo_boilerplate_glitz_agl_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_glitz_agl_cleanup },
{ "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_glitz_agl_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_glitz_agl_cleanup },
#endif
#if CAIRO_CAN_TEST_GLITZ_WGL_SURFACE
{ "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA, 0,
_cairo_boilerplate_glitz_wgl_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_glitz_wgl_cleanup },
{ "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_glitz_wgl_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_glitz_wgl_cleanup },
#endif
@@ -215,32 +329,38 @@ static cairo_boilerplate_target_t targets[] =
#if CAIRO_HAS_QUARTZ_SURFACE
{ "quartz", CAIRO_SURFACE_TYPE_QUARTZ, CAIRO_CONTENT_COLOR_ALPHA, 0,
_cairo_boilerplate_quartz_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_quartz_cleanup },
{ "quartz", CAIRO_SURFACE_TYPE_QUARTZ, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_quartz_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_quartz_cleanup },
#endif
#if CAIRO_HAS_WIN32_SURFACE
{ "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_win32_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png },
/* Testing the win32 surface isn't interesting, since for
* ARGB images it just chains to the image backend
*/
{ "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR_ALPHA, 0,
_cairo_boilerplate_win32_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png },
#if CAIRO_CAN_TEST_WIN32_PRINTING_SURFACE
{ "win32-printing", CAIRO_SURFACE_TYPE_WIN32_PRINTING,
CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, 0,
_cairo_boilerplate_win32_printing_create_surface,
+ _cairo_boilerplate_win32_printing_get_image_surface,
_cairo_boilerplate_win32_printing_surface_write_to_png,
_cairo_boilerplate_win32_printing_cleanup,
NULL, TRUE },
{ "win32-printing", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_win32_printing_create_surface,
+ _cairo_boilerplate_win32_printing_get_image_surface,
_cairo_boilerplate_win32_printing_surface_write_to_png,
_cairo_boilerplate_win32_printing_cleanup,
NULL, TRUE },
@@ -251,6 +371,7 @@ static cairo_boilerplate_target_t targets[] =
* bit, so we set the error tolerance to 1. */
{ "xcb", CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA, 1,
_cairo_boilerplate_xcb_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_xcb_cleanup,
_cairo_boilerplate_xcb_synchronize},
@@ -260,11 +381,13 @@ static cairo_boilerplate_target_t targets[] =
* bit, so we set the error tolerance to 1. */
{ "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR_ALPHA, 1,
_cairo_boilerplate_xlib_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_xlib_cleanup,
_cairo_boilerplate_xlib_synchronize},
{ "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR, 1,
_cairo_boilerplate_xlib_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_xlib_cleanup,
_cairo_boilerplate_xlib_synchronize},
@@ -274,6 +397,7 @@ static cairo_boilerplate_target_t targets[] =
* the Render extension. */
{ "xlib-fallback", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR, 1,
_cairo_boilerplate_xlib_fallback_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_xlib_cleanup,
_cairo_boilerplate_xlib_synchronize},
@@ -282,11 +406,13 @@ static cairo_boilerplate_target_t targets[] =
{ "ps", CAIRO_SURFACE_TYPE_PS,
CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, 0,
_cairo_boilerplate_ps_create_surface,
+ _cairo_boilerplate_ps_get_image_surface,
_cairo_boilerplate_ps_surface_write_to_png,
_cairo_boilerplate_ps_cleanup,
NULL, TRUE },
{ "ps", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_ps_create_surface,
+ _cairo_boilerplate_ps_get_image_surface,
_cairo_boilerplate_ps_surface_write_to_png,
_cairo_boilerplate_ps_cleanup,
NULL, TRUE },
@@ -295,11 +421,13 @@ static cairo_boilerplate_target_t targets[] =
{ "pdf", CAIRO_SURFACE_TYPE_PDF,
CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, 0,
_cairo_boilerplate_pdf_create_surface,
+ _cairo_boilerplate_pdf_get_image_surface,
_cairo_boilerplate_pdf_surface_write_to_png,
_cairo_boilerplate_pdf_cleanup,
NULL, TRUE },
{ "pdf", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_pdf_create_surface,
+ _cairo_boilerplate_pdf_get_image_surface,
_cairo_boilerplate_pdf_surface_write_to_png,
_cairo_boilerplate_pdf_cleanup,
NULL, TRUE },
@@ -312,11 +440,13 @@ static cairo_boilerplate_target_t targets[] =
* For now just set the svg error tolerance to 1. */
{ "svg", CAIRO_SURFACE_TYPE_SVG, CAIRO_CONTENT_COLOR_ALPHA, 1,
_cairo_boilerplate_svg_create_surface,
+ _cairo_boilerplate_svg_get_image_surface,
_cairo_boilerplate_svg_surface_write_to_png,
_cairo_boilerplate_svg_cleanup,
NULL, TRUE },
{ "svg", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR, 1,
_cairo_boilerplate_svg_create_surface,
+ _cairo_boilerplate_svg_get_image_surface,
_cairo_boilerplate_svg_surface_write_to_png,
_cairo_boilerplate_svg_cleanup,
NULL, TRUE },
@@ -327,14 +457,17 @@ static cairo_boilerplate_target_t targets[] =
* Just ignore the small difference. */
{ "beos", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR, 1,
_cairo_boilerplate_beos_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_beos_cleanup},
{ "beos-bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR, 1,
_cairo_boilerplate_beos_create_surface_for_bitmap,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_beos_cleanup_bitmap},
{ "beos-bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR_ALPHA, 1,
_cairo_boilerplate_beos_create_surface_for_bitmap,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_beos_cleanup_bitmap},
#endif
@@ -343,10 +476,12 @@ static cairo_boilerplate_target_t targets[] =
#if CAIRO_HAS_DIRECTFB_SURFACE
{ "directfb", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR, 0,
_cairo_boilerplate_directfb_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_directfb_cleanup},
{ "directfb-bitmap", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR_ALPHA, 0,
_cairo_boilerplate_directfb_create_surface,
+ _cairo_boilerplate_get_image_surface,
cairo_surface_write_to_png,
_cairo_boilerplate_directfb_cleanup},
#endif
diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h
index 8031df8..ccd30ff 100644
--- a/boilerplate/cairo-boilerplate.h
+++ b/boilerplate/cairo-boilerplate.h
@@ -51,22 +51,23 @@
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
-# ifndef HAVE_UINT64_T
-# define HAVE_UINT64_T 1
-# endif
-# ifndef INT16_MIN
-# define INT16_MIN (-32767-1)
-# endif
-# ifndef INT16_MAX
-# define INT16_MAX (32767)
-# endif
-# ifndef UINT16_MAX
-# define UINT16_MAX (65535)
-# endif
#else
#error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.)
#endif
+#ifndef HAVE_UINT64_T
+# define HAVE_UINT64_T 1
+#endif
+#ifndef INT16_MIN
+# define INT16_MIN (-32767-1)
+#endif
+#ifndef INT16_MAX
+# define INT16_MAX (32767)
+#endif
+#ifndef UINT16_MAX
+# define UINT16_MAX (65535)
+#endif
+
#ifndef CAIRO_BOILERPLATE_LOG
#define CAIRO_BOILERPLATE_LOG(...) fprintf(stderr, __VA_ARGS__)
#endif
@@ -120,8 +121,14 @@ typedef cairo_surface_t *
int id,
void **closure);
+typedef cairo_surface_t *
+(*cairo_boilerplate_get_image_surface_t) (cairo_surface_t *surface,
+ int width,
+ int height);
+
typedef cairo_status_t
-(*cairo_boilerplate_write_to_png_t) (cairo_surface_t *surface, const char *filename);
+(*cairo_boilerplate_write_to_png_t) (cairo_surface_t *surface,
+ const char *filename);
typedef void
(*cairo_boilerplate_cleanup_t) (void *closure);
@@ -131,15 +138,16 @@ typedef void
typedef struct _cairo_boilerplate_target
{
- const char *name;
- cairo_surface_type_t expected_type;
- cairo_content_t content;
- unsigned int error_tolerance;
- cairo_boilerplate_create_surface_t create_surface;
- cairo_boilerplate_write_to_png_t write_to_png;
- cairo_boilerplate_cleanup_t cleanup;
- cairo_boilerplate_wait_t synchronize;
- cairo_bool_t is_vector;
+ const char *name;
+ cairo_surface_type_t expected_type;
+ cairo_content_t content;
+ unsigned int error_tolerance;
+ cairo_boilerplate_create_surface_t create_surface;
+ cairo_boilerplate_get_image_surface_t get_image_surface;
+ cairo_boilerplate_write_to_png_t write_to_png;
+ cairo_boilerplate_cleanup_t cleanup;
+ cairo_boilerplate_wait_t synchronize;
+ cairo_bool_t is_vector;
} cairo_boilerplate_target_t;
cairo_boilerplate_target_t **
@@ -149,6 +157,16 @@ void
cairo_boilerplate_free_targets (cairo_boilerplate_target_t **targets);
cairo_surface_t *
+_cairo_boilerplate_get_image_surface (cairo_surface_t *src,
+ int width,
+ int height);
+cairo_surface_t *
+cairo_boilerplate_get_image_surface_from_png (const char *filename,
+ int width,
+ int height,
+ cairo_bool_t flatten);
+
+cairo_surface_t *
cairo_boilerplate_surface_create_in_error (cairo_status_t status);
#include "xmalloc.h"
diff --git a/test/buffer-diff.c b/test/buffer-diff.c
index ef70876..b656b11 100644
--- a/test/buffer-diff.c
+++ b/test/buffer-diff.c
@@ -64,28 +64,28 @@ xunlink (const cairo_test_context_t *ctx, const char *pathname)
* cairo_format_t instead of taking a mask as a parameter.
*/
static void
-buffer_diff_core (unsigned char *_buf_a,
- unsigned char *_buf_b,
- unsigned char *_buf_diff,
+buffer_diff_core (const unsigned char *_buf_a, int stride_a,
+ const unsigned char *_buf_b, int stride_b,
+ unsigned char *_buf_diff, int stride_diff,
int width,
int height,
- int stride,
uint32_t mask,
buffer_diff_result_t *result_ret)
{
+ const uint32_t *buf_a = (const uint32_t*) _buf_a;
+ const uint32_t *buf_b = (const uint32_t*) _buf_b;
+ uint32_t *buf_diff = (uint32_t*) _buf_diff;
int x, y;
- uint32_t *row_a, *row_b, *row;
buffer_diff_result_t result = {0, 0};
- uint32_t *buf_a = (uint32_t*)_buf_a;
- uint32_t *buf_b = (uint32_t*)_buf_b;
- uint32_t *buf_diff = (uint32_t*)_buf_diff;
- stride /= sizeof(uint32_t);
+ stride_a /= sizeof (uint32_t);
+ stride_b /= sizeof (uint32_t);
+ stride_diff /= sizeof (uint32_t);
for (y = 0; y < height; y++)
{
- row_a = buf_a + y * stride;
- row_b = buf_b + y * stride;
- row = buf_diff + y * stride;
+ const uint32_t *row_a = buf_a + y * stride_a;
+ const uint32_t *row_b = buf_b + y * stride_b;
+ uint32_t *row = buf_diff + y * stride_diff;
for (x = 0; x < width; x++)
{
/* check if the pixels are the same */
@@ -121,7 +121,15 @@ buffer_diff_core (unsigned char *_buf_a,
*result_ret = result;
}
-void
+/* Compares two image surfaces
+ *
+ * Provides number of pixels changed and maximum single-channel
+ * difference in result.
+ *
+ * Also fills in a "diff" surface intended to visually show where the
+ * images differ.
+ */
+static void
compare_surfaces (const cairo_test_context_t *ctx,
cairo_surface_t *surface_a,
cairo_surface_t *surface_b,
@@ -141,12 +149,14 @@ compare_surfaces (const cairo_test_context_t *ctx,
* runs about 3x slower if we run pdiff_compare first).
*/
buffer_diff_core (cairo_image_surface_get_data (surface_a),
+ cairo_image_surface_get_stride (surface_a),
cairo_image_surface_get_data (surface_b),
+ cairo_image_surface_get_stride (surface_b),
cairo_image_surface_get_data (surface_diff),
+ cairo_image_surface_get_stride (surface_diff),
cairo_image_surface_get_width (surface_a),
cairo_image_surface_get_height (surface_a),
- cairo_image_surface_get_stride (surface_a),
- 0xffffffff,
+ cairo_surface_get_content (surface_a) & CAIRO_CONTENT_ALPHA ? 0xffffffff : 0x00ffffff,
result);
if (result->pixels_changed == 0)
return;
@@ -176,16 +186,19 @@ compare_surfaces (const cairo_test_context_t *ctx,
}
void
-buffer_diff_noalpha (unsigned char *buf_a,
- unsigned char *buf_b,
+buffer_diff_noalpha (const unsigned char *buf_a,
+ const unsigned char *buf_b,
unsigned char *buf_diff,
int width,
int height,
int stride,
buffer_diff_result_t *result)
{
- buffer_diff_core(buf_a, buf_b, buf_diff,
- width, height, stride, 0x00ffffff,
+ buffer_diff_core(buf_a, stride,
+ buf_b, stride,
+ buf_diff, stride,
+ width, height,
+ 0x00ffffff,
result);
}
@@ -271,6 +284,21 @@ extract_sub_surface (const cairo_test_context_t *ctx,
cairo_destroy (cr);
}
+static cairo_bool_t
+same_size (cairo_surface_t *a, cairo_surface_t *b)
+{
+ unsigned int width_a, height_a;
+ unsigned int width_b, height_b;
+
+ width_a = cairo_image_surface_get_width (a);
+ height_a = cairo_image_surface_get_height (a);
+
+ width_b = cairo_image_surface_get_width (b);
+ height_b = cairo_image_surface_get_height (b);
+
+ return width_a == width_b && height_a == height_b;
+}
+
/* Image comparison code courtesy of Richard Worth <richard at theworths.org>
* Returns number of pixels changed, (or -1 on error).
* Also saves a "diff" image intended to visually show where the
@@ -286,22 +314,80 @@ extract_sub_surface (const cairo_test_context_t *ctx,
* CAIRO_STATUS_SURFACE_TYPE_MISMATCH (which is a bit of an abuse, but
* oh well).
*/
+cairo_status_t
+image_diff (const cairo_test_context_t *ctx,
+ cairo_surface_t *surface_a,
+ cairo_surface_t *surface_b,
+ cairo_surface_t *surface_diff,
+ buffer_diff_result_t *result)
+{
+ if (cairo_surface_status (surface_a))
+ return cairo_surface_status (surface_a);
+
+ if (cairo_surface_status (surface_b))
+ return cairo_surface_status (surface_b);
+
+ if (cairo_surface_status (surface_diff))
+ return cairo_surface_status (surface_diff);
+
+ if (! same_size (surface_a, surface_b) ||
+ ! same_size (surface_a, surface_diff))
+ {
+ cairo_test_log (ctx, "Error: Image size mismatch\n");
+ return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
+ }
+
+ compare_surfaces (ctx, surface_a, surface_b, surface_diff, result);
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
static cairo_status_t
-image_diff_core (const cairo_test_context_t *ctx,
- const char *filename_a,
- const char *filename_b,
- const char *filename_diff,
- int ax,
- int ay,
- int bx,
- int by,
- buffer_diff_result_t *result,
- cairo_bool_t flatten)
+write_png (cairo_surface_t *surface, const char *filename)
{
cairo_status_t status;
- unsigned int width_a, height_a, stride_a;
- unsigned int width_b, height_b, stride_b;
- cairo_surface_t *surface_a, *surface_b, *surface_diff;
+ FILE *png_file;
+
+ if (filename != NULL) {
+ png_file = fopen (filename, "wb");
+ if (png_file == NULL) {
+ switch (errno) {
+ case ENOMEM:
+ return CAIRO_STATUS_NO_MEMORY;
+ default:
+ return CAIRO_STATUS_WRITE_ERROR;
+ }
+ }
+ } else
+ png_file = stdout;
+
+ status = cairo_surface_write_to_png_stream (surface,
+ stdio_write_func,
+ png_file);
+
+ if (png_file != stdout)
+ fclose (png_file);
+
+ return status;
+}
+
+
+
+cairo_status_t
+png_diff (const cairo_test_context_t *ctx,
+ const char *filename_a,
+ const char *filename_b,
+ const char *filename_diff,
+ int ax,
+ int ay,
+ int bx,
+ int by,
+ buffer_diff_result_t *result)
+{
+ cairo_surface_t *surface_a;
+ cairo_surface_t *surface_b;
+ cairo_surface_t *surface_diff;
+ cairo_status_t status;
surface_a = cairo_image_surface_create_from_png (filename_a);
status = cairo_surface_status (surface_a);
@@ -320,12 +406,6 @@ image_diff_core (const cairo_test_context_t *ctx,
return status;
}
- if (flatten) {
- flatten_surface (ctx, &surface_a, ax, ay);
- flatten_surface (ctx, &surface_b, bx, by);
- ax = ay = bx = by = 0;
- }
-
if (ax || ay) {
extract_sub_surface (ctx, &surface_a, ax, ay);
ax = ay = 0;
@@ -353,29 +433,92 @@ image_diff_core (const cairo_test_context_t *ctx,
return status;
}
- width_a = cairo_image_surface_get_width (surface_a);
- height_a = cairo_image_surface_get_height (surface_a);
- stride_a = cairo_image_surface_get_stride (surface_a);
- width_b = cairo_image_surface_get_width (surface_b);
- height_b = cairo_image_surface_get_height (surface_b);
- stride_b = cairo_image_surface_get_stride (surface_b);
+ surface_diff = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ cairo_image_surface_get_width (surface_a),
+ cairo_image_surface_get_height (surface_a));
+ status = cairo_surface_status (surface_diff);
+ if (status) {
+ cairo_test_log (ctx, "Error: Failed to allocate surface to hold differences\n");
+ cairo_surface_destroy (surface_a);
+ cairo_surface_destroy (surface_b);
+ return CAIRO_STATUS_NO_MEMORY;
+ }
+
+ status = image_diff (ctx,
+ surface_a, surface_b, surface_diff,
+ result);
- if (width_a != width_b ||
- height_a != height_b ||
- stride_a != stride_b)
+ cairo_surface_destroy (surface_a);
+ cairo_surface_destroy (surface_b);
+ cairo_surface_destroy (surface_diff);
+
+ xunlink (ctx, filename_diff);
+ if (status == CAIRO_STATUS_SUCCESS &&
+ result->pixels_changed)
{
- cairo_test_log (ctx, "Error: Image size mismatch: (%dx%d) vs. (%dx%d)\n"
- " for %s vs. %s\n",
- width_a, height_a,
- width_b, height_b,
- filename_a, filename_b);
+ status = write_png (surface_diff, filename_diff);
+ }
+
+
+ return status;
+}
+
+cairo_status_t
+png_diff_flattened (const cairo_test_context_t *ctx,
+ const char *filename_a,
+ const char *filename_b,
+ const char *filename_diff,
+ int ax,
+ int ay,
+ int bx,
+ int by,
+ buffer_diff_result_t *result)
+{
+ cairo_surface_t *surface_a;
+ cairo_surface_t *surface_b;
+ cairo_surface_t *surface_diff;
+ cairo_status_t status;
+
+ surface_a = cairo_image_surface_create_from_png (filename_a);
+ status = cairo_surface_status (surface_a);
+ if (status) {
+ cairo_test_log (ctx, "Error: Failed to create surface from %s: %s\n",
+ filename_a, cairo_status_to_string (status));
+ return status;
+ }
+
+ surface_b = cairo_image_surface_create_from_png (filename_b);
+ status = cairo_surface_status (surface_b);
+ if (status) {
+ cairo_test_log (ctx, "Error: Failed to create surface from %s: %s\n",
+ filename_b, cairo_status_to_string (status));
+ cairo_surface_destroy (surface_a);
+ return status;
+ }
+
+ flatten_surface (ctx, &surface_a, ax, ay);
+ flatten_surface (ctx, &surface_b, bx, by);
+
+ status = cairo_surface_status (surface_a);
+ if (status) {
+ cairo_test_log (ctx, "Error: Failed to extract surface from %s: %s\n",
+ filename_a, cairo_status_to_string (status));
cairo_surface_destroy (surface_a);
cairo_surface_destroy (surface_b);
- return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
+ return status;
+ }
+ status = cairo_surface_status (surface_b);
+ if (status) {
+ cairo_test_log (ctx, "Error: Failed to extract surface from %s: %s\n",
+ filename_b, cairo_status_to_string (status));
+ cairo_surface_destroy (surface_a);
+ cairo_surface_destroy (surface_b);
+ return status;
}
surface_diff = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- width_a, height_a);
+ cairo_image_surface_get_width (surface_a),
+ cairo_image_surface_get_height (surface_a));
status = cairo_surface_status (surface_diff);
if (status) {
cairo_test_log (ctx, "Error: Failed to allocate surface to hold differences\n");
@@ -384,41 +527,15 @@ image_diff_core (const cairo_test_context_t *ctx,
return CAIRO_STATUS_NO_MEMORY;
}
+ status = image_diff (ctx,
+ surface_a, surface_b, surface_diff,
+ result);
- compare_surfaces (ctx, surface_a, surface_b, surface_diff, result);
-
- status = CAIRO_STATUS_SUCCESS;
- if (result->pixels_changed) {
- FILE *png_file;
-
- if (filename_diff) {
- png_file = fopen (filename_diff, "wb");
- if (png_file == NULL) {
- int err = errno;
-
- cairo_surface_destroy (surface_a);
- cairo_surface_destroy (surface_b);
- cairo_surface_destroy (surface_diff);
-
- switch (err) {
- case ENOMEM:
- return CAIRO_STATUS_NO_MEMORY;
- default:
- return CAIRO_STATUS_WRITE_ERROR;
- }
- }
- } else
- png_file = stdout;
-
- status = cairo_surface_write_to_png_stream (surface_diff,
- stdio_write_func,
- png_file);
-
- if (png_file != stdout)
- fclose (png_file);
- } else {
- if (filename_diff)
- xunlink (ctx, filename_diff);
+ xunlink (ctx, filename_diff);
+ if (status == CAIRO_STATUS_SUCCESS &&
+ result->pixels_changed)
+ {
+ status = write_png (surface_diff, filename_diff);
}
cairo_surface_destroy (surface_a);
@@ -427,37 +544,3 @@ image_diff_core (const cairo_test_context_t *ctx,
return status;
}
-
-cairo_status_t
-image_diff (const cairo_test_context_t *ctx,
- const char *filename_a,
- const char *filename_b,
- const char *filename_diff,
- int ax,
- int ay,
- int bx,
- int by,
- buffer_diff_result_t *result)
-{
- return image_diff_core (ctx,
- filename_a, filename_b, filename_diff,
- ax, ay, bx, by,
- result, FALSE);
-}
-
-cairo_status_t
-image_diff_flattened (const cairo_test_context_t *ctx,
- const char *filename_a,
- const char *filename_b,
- const char *filename_diff,
- int ax,
- int ay,
- int bx,
- int by,
- buffer_diff_result_t *result)
-{
- return image_diff_core (ctx,
- filename_a, filename_b, filename_diff,
- ax, ay, bx, by,
- result, TRUE);
-}
diff --git a/test/buffer-diff.h b/test/buffer-diff.h
index 61daa89..64bce92 100644
--- a/test/buffer-diff.h
+++ b/test/buffer-diff.h
@@ -36,21 +36,6 @@ typedef struct _buffer_diff_result {
unsigned int max_diff;
} buffer_diff_result_t;
-/* Compares two image surfaces
- *
- * Provides number of pixels changed and maximum single-channel
- * difference in result.
- *
- * Also fills in a "diff" surface intended to visually show where the
- * images differ.
- */
-void
-compare_surfaces (const cairo_test_context_t *ctx,
- cairo_surface_t *surface_a,
- cairo_surface_t *surface_b,
- cairo_surface_t *surface_diff,
- buffer_diff_result_t *result);
-
/* Compares two image buffers ignoring the alpha channel.
*
* Provides number of pixels changed and maximum single-channel
@@ -60,8 +45,8 @@ compare_surfaces (const cairo_test_context_t *ctx,
* images differ.
*/
void
-buffer_diff_noalpha (unsigned char *buf_a,
- unsigned char *buf_b,
+buffer_diff_noalpha (const unsigned char *buf_a,
+ const unsigned char *buf_b,
unsigned char *buf_diff,
int width,
int height,
@@ -82,7 +67,7 @@ buffer_diff_noalpha (unsigned char *buf_a,
* images differ.
*/
cairo_status_t
-image_diff (const cairo_test_context_t *ctx,
+png_diff (const cairo_test_context_t *ctx,
const char *filename_a,
const char *filename_b,
const char *filename_diff,
@@ -92,9 +77,9 @@ image_diff (const cairo_test_context_t *ctx,
int by,
buffer_diff_result_t *result);
-/* Like image_diff, but blending the contents of b over white first. */
+/* Like png_diff, but blending the contents of b over white first. */
cairo_status_t
-image_diff_flattened (const cairo_test_context_t *ctx,
+png_diff_flattened (const cairo_test_context_t *ctx,
const char *filename_a,
const char *filename_b,
const char *filename_diff,
@@ -104,4 +89,17 @@ image_diff_flattened (const cairo_test_context_t *ctx,
int by,
buffer_diff_result_t *result);
+/* The central algorithm to compare two images, and return the differences
+ * in the surface_diff.
+ *
+ * Provides number of pixels changed and maximum single-channel
+ * difference in result.
+ */
+cairo_status_t
+image_diff (const cairo_test_context_t *ctx,
+ cairo_surface_t *surface_a,
+ cairo_surface_t *surface_b,
+ cairo_surface_t *surface_diff,
+ buffer_diff_result_t *result);
+
#endif
diff --git a/test/cairo-test.c b/test/cairo-test.c
index 739a027..79d6c2b 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -134,6 +134,10 @@ _cairo_test_init (cairo_test_context_t *ctx,
ctx->refdir = getenv ("CAIRO_REF_DIR");
+ ctx->ref_name = NULL;
+ ctx->ref_image = NULL;
+ ctx->ref_image_flattened = NULL;
+
ctx->thread = 0;
{
@@ -174,6 +178,11 @@ cairo_test_fini (cairo_test_context_t *ctx)
fclose (ctx->log_file);
ctx->log_file = NULL;
+ if (ctx->ref_name != NULL)
+ free (ctx->ref_name);
+ cairo_surface_destroy (ctx->ref_image);
+ cairo_surface_destroy (ctx->ref_image_flattened);
+
cairo_boilerplate_free_targets (ctx->targets_to_test);
cairo_debug_reset_static_data ();
@@ -351,8 +360,75 @@ cairo_test_target_has_similar (const cairo_test_context_t *ctx,
return has_similar;
}
+static cairo_surface_t *
+_cairo_test_flatten_reference_image (cairo_test_context_t *ctx,
+ cairo_bool_t flatten)
+{
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+ if (! flatten)
+ return ctx->ref_image;
+
+ if (ctx->ref_image_flattened != NULL)
+ return ctx->ref_image_flattened;
+
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ cairo_image_surface_get_width (ctx->ref_image),
+ cairo_image_surface_get_height (ctx->ref_image));
+ cr = cairo_create (surface);
+ cairo_surface_destroy (surface);
+
+ cairo_set_source_rgb (cr, 1, 1, 1);
+ cairo_paint (cr);
+
+ cairo_set_source_surface (cr, ctx->ref_image, 0, 0);
+ cairo_paint (cr);
+
+ surface = cairo_surface_reference (cairo_get_target (cr));
+ cairo_destroy (cr);
+
+ if (cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS)
+ ctx->ref_image_flattened = surface;
+ return surface;
+}
+
+static cairo_surface_t *
+cairo_test_get_reference_image (cairo_test_context_t *ctx,
+ const char *filename,
+ cairo_bool_t flatten)
+{
+ cairo_surface_t *surface;
+ int len;
+
+ if (ctx->ref_name != NULL) {
+ if (strcmp (ctx->ref_name, filename) == 0)
+ return _cairo_test_flatten_reference_image (ctx, flatten);
+
+ cairo_surface_destroy (ctx->ref_image);
+ ctx->ref_image = NULL;
+
+ cairo_surface_destroy (ctx->ref_image_flattened);
+ ctx->ref_image_flattened = NULL;
+
+ free (ctx->ref_name);
+ ctx->ref_name = NULL;
+ }
+
+ surface = cairo_image_surface_create_from_png (filename);
+ if (cairo_surface_status (surface))
+ return surface;
+
+ len = strlen (filename);
+ ctx->ref_name = xmalloc (len + 1);
+ memcpy (ctx->ref_name, filename, len + 1);
+
+ ctx->ref_image = surface;
+ return _cairo_test_flatten_reference_image (ctx, flatten);
+}
+
static cairo_test_status_t
-cairo_test_for_target (const cairo_test_context_t *ctx,
+cairo_test_for_target (cairo_test_context_t *ctx,
const cairo_boilerplate_target_t *target,
int dev_offset,
cairo_bool_t similar)
@@ -378,7 +454,6 @@ cairo_test_for_target (const cairo_test_context_t *ctx,
ctx->test->name,
target->name,
format);
-
if (dev_offset)
xasprintf (&offset_str, "-%d", dev_offset);
else
@@ -520,23 +595,15 @@ cairo_test_for_target (const cairo_test_context_t *ctx,
/* Skip image check for tests with no image (width,height == 0,0) */
if (ctx->test->width != 0 && ctx->test->height != 0) {
+ cairo_surface_t *ref_image;
+ cairo_surface_t *test_image;
+ cairo_surface_t *diff_image;
buffer_diff_result_t result;
cairo_status_t diff_status;
- xunlink (ctx, png_name);
-
- diff_status = (target->write_to_png) (surface, png_name);
- if (diff_status) {
- cairo_test_log (ctx, "Error: Failed to compare images: %s\n",
- cairo_status_to_string (diff_status));
- ret = CAIRO_TEST_FAILURE;
- goto UNWIND_CAIRO;
- }
- have_output = TRUE;
-
- if (!ref_name) {
+ if (ref_name == NULL) {
cairo_test_log (ctx, "Error: Cannot find reference image for %s/%s-%s-%s%s\n",
- ctx->srcdir,
+ ctx->srcdir,
ctx->test->name,
target->name,
format,
@@ -545,27 +612,64 @@ cairo_test_for_target (const cairo_test_context_t *ctx,
goto UNWIND_CAIRO;
}
- if (target->content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED) {
- diff_status = image_diff_flattened (ctx,
- png_name, ref_name, diff_name,
- dev_offset, dev_offset, 0, 0, &result);
- } else {
- diff_status = image_diff (ctx,
- png_name, ref_name, diff_name,
- dev_offset, dev_offset, 0, 0, &result);
+ ref_image = cairo_test_get_reference_image (ctx, ref_name,
+ target->content == CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED);
+ if (cairo_surface_status (ref_image)) {
+ cairo_test_log (ctx, "Error: Cannot open reference image for %s: %s\n",
+ ref_name,
+ cairo_status_to_string (cairo_surface_status (ref_image)));
+ ret = CAIRO_TEST_FAILURE;
+ goto UNWIND_CAIRO;
}
+
+ xunlink (ctx, png_name);
+ xunlink (ctx, diff_name);
+
+ test_image = target->get_image_surface (surface,
+ ctx->test->width,
+ ctx->test->height);
+ if (cairo_surface_status (test_image)) {
+ cairo_test_log (ctx, "Error: Failed to extract image: %s\n",
+ cairo_status_to_string (cairo_surface_status (test_image)));
+ ret = CAIRO_TEST_FAILURE;
+ goto UNWIND_CAIRO;
+ }
+
+ diff_image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ ctx->test->width,
+ ctx->test->height);
+
+ diff_status = image_diff (ctx,
+ test_image, ref_image,
+ diff_image,
+ &result);
if (diff_status) {
cairo_test_log (ctx, "Error: Failed to compare images: %s\n",
cairo_status_to_string (diff_status));
ret = CAIRO_TEST_FAILURE;
- goto UNWIND_CAIRO;
}
-
- have_result = TRUE;
- if (result.pixels_changed && result.max_diff > target->error_tolerance) {
+ else if (result.pixels_changed &&
+ result.max_diff > target->error_tolerance)
+ {
ret = CAIRO_TEST_FAILURE;
- goto UNWIND_CAIRO;
+
+ diff_status = cairo_surface_write_to_png (test_image, png_name);
+ if (diff_status) {
+ cairo_test_log (ctx, "Error: Failed to write output image: %s\n",
+ cairo_status_to_string (diff_status));
+ } else
+ have_output = TRUE;
+
+ diff_status = cairo_surface_write_to_png (diff_image, diff_name);
+ if (diff_status) {
+ cairo_test_log (ctx, "Error: Failed to write differences image: %s\n",
+ cairo_status_to_string (diff_status));
+ } else
+ have_result = TRUE;
}
+
+ cairo_surface_destroy (test_image);
+ cairo_surface_destroy (diff_image);
}
UNWIND_CAIRO:
diff --git a/test/cairo-test.h b/test/cairo-test.h
index aff8079..5dd61f8 100644
--- a/test/cairo-test.h
+++ b/test/cairo-test.h
@@ -120,6 +120,10 @@ struct _cairo_test_context {
const char *srcdir; /* directory containing sources and input data */
const char *refdir; /* directory containing reference images */
+ char *ref_name; /* cache of the current reference image */
+ cairo_surface_t *ref_image;
+ cairo_surface_t *ref_image_flattened;
+
size_t num_targets;
cairo_bool_t limited_targets;
cairo_boilerplate_target_t **targets_to_test;
diff --git a/test/imagediff.c b/test/imagediff.c
index c170c8e..6404242 100644
--- a/test/imagediff.c
+++ b/test/imagediff.c
@@ -54,7 +54,7 @@ main (int argc, char *argv[])
ax = ay = bx = by = 0;
}
- status = image_diff (NULL, argv[1], argv[2], NULL, ax, ay, bx, by, &result);
+ status = png_diff (NULL, argv[1], argv[2], NULL, ax, ay, bx, by, &result);
if (status) {
fprintf (stderr, "Error comparing images: %s\n",
diff --git a/test/xlib-expose-event.c b/test/xlib-expose-event.c
index bf320da..189b8f1 100644
--- a/test/xlib-expose-event.c
+++ b/test/xlib-expose-event.c
@@ -175,6 +175,7 @@ compare (const cairo_test_context_t *ctx, cairo_surface_t *surface)
{
cairo_t *cr;
cairo_surface_t *image, *reference, *diff;
+ cairo_status_t status;
buffer_diff_result_t result;
diff = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE, SIZE);
@@ -187,17 +188,14 @@ compare (const cairo_test_context_t *ctx, cairo_surface_t *surface)
cairo_destroy (cr);
reference = cairo_test_create_surface_from_png (ctx, "xlib-expose-event-ref.png");
- if (cairo_image_surface_get_width (image) != cairo_image_surface_get_width (reference) ||
- cairo_image_surface_get_height (image) != cairo_image_surface_get_height (reference))
- return CAIRO_TEST_FAILURE;
-
- compare_surfaces (ctx, reference, image, diff, &result);
+ status = image_diff (ctx, reference, image, diff, &result);
cairo_surface_destroy (reference);
cairo_surface_destroy (image);
cairo_surface_destroy (diff);
- return result.pixels_changed ? CAIRO_TEST_FAILURE : CAIRO_TEST_SUCCESS;
+ return status == CAIRO_STATUS_SUCCESS && ! result.pixels_changed ?
+ CAIRO_TEST_SUCCESS : CAIRO_TEST_FAILURE;
}
int
commit 9b0b55cea724f91eb2835294f929c49224bd0bac
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon Aug 18 08:07:25 2008 +0100
[test/leaky-dashed-rectangle] Add ref to bug report.
Yevgen Muntyan has filed a bug report with the same symptoms as
leaky-dashed-rectangle, so add a reminder for when it is finally fixed.
diff --git a/test/leaky-dashed-rectangle.c b/test/leaky-dashed-rectangle.c
index 5a867a4..b593991 100644
--- a/test/leaky-dashed-rectangle.c
+++ b/test/leaky-dashed-rectangle.c
@@ -26,6 +26,8 @@
/* Test case for bug reported by Franz Schmid <Franz.Schmid at altmuehlnet.de>
* http://lists.cairographics.org/archives/cairo/2008-April/013912.html
+ *
+ * See also: http://bugs.freedesktop.org/show_bug.cgi?id=17177
*/
#include "cairo-test.h"
commit 212cbd3f1b089c1b1948072db515dbf81cc32580
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sun Aug 17 21:48:06 2008 +0100
[test/user-font] Correct the lifetime of the user font face.
By keeping a static reference to the user font face, it is erroneously kept
alive during a call to cairo_debug_reset_static_data(). (A violation of
the caller's contract to ensure that no active reference to a cairo object
is held by the caller.)
diff --git a/test/user-font.c b/test/user-font.c
index 57a174a..1f702df 100644
--- a/test/user-font.c
+++ b/test/user-font.c
@@ -146,51 +146,48 @@ test_scaled_font_render_glyph (cairo_scaled_font_t *scaled_font,
}
static cairo_font_face_t *
-get_user_font_face (void)
+_user_font_face_create (void)
{
- static cairo_font_face_t *user_font_face = NULL;
-
- if (!user_font_face) {
-
- /* Simple glyph definition: 1 - 15 means lineto (or moveto for first
- * point) for one of the points on this grid:
- *
- * 1 2 3
- * 4 5 6
- * 7 8 9
- * ----10 11 12----(baseline)
- * 13 14 15
- */
- static const test_scaled_font_glyph_t glyphs [] = {
- { '\0', 1, { END_GLYPH } }, /* Poppler has a bug assuming glyph 0 is .notdef */
- { ' ', 1, { END_GLYPH } },
- { '-', 2, { 7, 8, STROKE, END_GLYPH } },
- { '.', 1, { 10, 10, STROKE, END_GLYPH } },
- { 'a', 3, { 4, 6, 12, 10, 7, 9, STROKE, END_GLYPH } },
- { 'c', 3, { 6, 4, 10, 12, STROKE, END_GLYPH } },
- { 'e', 3, { 12, 10, 4, 6, 9, 7, STROKE, END_GLYPH } },
- { 'f', 3, { 3, 2, 11, STROKE, 4, 6, STROKE, END_GLYPH } },
- { 'g', 3, { 12, 10, 4, 6, 15, 13, STROKE, END_GLYPH } },
- { 'h', 3, { 1, 10, STROKE, 7, 5, 6, 12, STROKE, END_GLYPH } },
- { 'i', 1, { 1, 1, STROKE, 4, 10, STROKE, END_GLYPH } },
- { 'l', 1, { 1, 10, STROKE, END_GLYPH } },
- { 'n', 3, { 10, 4, STROKE, 7, 5, 6, 12, STROKE, END_GLYPH } },
- { 'o', 3, { 4, 10, 12, 6, CLOSE, END_GLYPH } },
- { 'r', 3, { 4, 10, STROKE, 7, 5, 6, STROKE, END_GLYPH } },
- { 's', 3, { 6, 4, 7, 9, 12, 10, STROKE, END_GLYPH } },
- { 't', 3, { 2, 11, 12, STROKE, 4, 6, STROKE, END_GLYPH } },
- { 'u', 3, { 4, 10, 12, 6, STROKE, END_GLYPH } },
- { 'z', 3, { 4, 6, 10, 12, STROKE, END_GLYPH } },
- { -1, 0, { END_GLYPH } },
- };
-
- user_font_face = cairo_user_font_face_create ();
- cairo_user_font_face_set_init_func (user_font_face, test_scaled_font_init);
- cairo_user_font_face_set_render_glyph_func (user_font_face, test_scaled_font_render_glyph);
- cairo_user_font_face_set_unicode_to_glyph_func (user_font_face, test_scaled_font_unicode_to_glyph);
-
- cairo_font_face_set_user_data (user_font_face, &test_font_face_glyphs_key, (void*) glyphs, NULL);
- }
+ /* Simple glyph definition: 1 - 15 means lineto (or moveto for first
+ * point) for one of the points on this grid:
+ *
+ * 1 2 3
+ * 4 5 6
+ * 7 8 9
+ * ----10 11 12----(baseline)
+ * 13 14 15
+ */
+ static const test_scaled_font_glyph_t glyphs [] = {
+ { '\0', 1, { END_GLYPH } }, /* Poppler has a bug assuming glyph 0 is .notdef */
+ { ' ', 1, { END_GLYPH } },
+ { '-', 2, { 7, 8, STROKE, END_GLYPH } },
+ { '.', 1, { 10, 10, STROKE, END_GLYPH } },
+ { 'a', 3, { 4, 6, 12, 10, 7, 9, STROKE, END_GLYPH } },
+ { 'c', 3, { 6, 4, 10, 12, STROKE, END_GLYPH } },
+ { 'e', 3, { 12, 10, 4, 6, 9, 7, STROKE, END_GLYPH } },
+ { 'f', 3, { 3, 2, 11, STROKE, 4, 6, STROKE, END_GLYPH } },
+ { 'g', 3, { 12, 10, 4, 6, 15, 13, STROKE, END_GLYPH } },
+ { 'h', 3, { 1, 10, STROKE, 7, 5, 6, 12, STROKE, END_GLYPH } },
+ { 'i', 1, { 1, 1, STROKE, 4, 10, STROKE, END_GLYPH } },
+ { 'l', 1, { 1, 10, STROKE, END_GLYPH } },
+ { 'n', 3, { 10, 4, STROKE, 7, 5, 6, 12, STROKE, END_GLYPH } },
+ { 'o', 3, { 4, 10, 12, 6, CLOSE, END_GLYPH } },
+ { 'r', 3, { 4, 10, STROKE, 7, 5, 6, STROKE, END_GLYPH } },
+ { 's', 3, { 6, 4, 7, 9, 12, 10, STROKE, END_GLYPH } },
+ { 't', 3, { 2, 11, 12, STROKE, 4, 6, STROKE, END_GLYPH } },
+ { 'u', 3, { 4, 10, 12, 6, STROKE, END_GLYPH } },
+ { 'z', 3, { 4, 6, 10, 12, STROKE, END_GLYPH } },
+ { -1, 0, { END_GLYPH } },
+ };
+
+ cairo_font_face_t *user_font_face;
+
+ user_font_face = cairo_user_font_face_create ();
+ cairo_user_font_face_set_init_func (user_font_face, test_scaled_font_init);
+ cairo_user_font_face_set_render_glyph_func (user_font_face, test_scaled_font_render_glyph);
+ cairo_user_font_face_set_unicode_to_glyph_func (user_font_face, test_scaled_font_unicode_to_glyph);
+
+ cairo_font_face_set_user_data (user_font_face, &test_font_face_glyphs_key, (void*) glyphs, NULL);
return user_font_face;
}
@@ -198,6 +195,7 @@ get_user_font_face (void)
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
+ cairo_font_face_t *font_face;
const char text[] = TEXT;
cairo_font_extents_t font_extents;
cairo_text_extents_t extents;
@@ -210,7 +208,10 @@ draw (cairo_t *cr, int width, int height)
cairo_rotate (cr, .6);
#endif
- cairo_set_font_face (cr, get_user_font_face ());
+ font_face = _user_font_face_create ();
+ cairo_set_font_face (cr, font_face);
+ cairo_font_face_destroy (font_face);
+
cairo_set_font_size (cr, TEXT_SIZE);
cairo_font_extents (cr, &font_extents);
commit 19d721d84c550b091927d22e00b34291cedd92aa
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sun Aug 17 21:43:14 2008 +0100
[cairo-compiler-private.h] Clear definition of __attribute__
Avoid a redefinition error when playing silly tricks with 'cpp -U__GNUC__'.
diff --git a/src/cairo-compiler-private.h b/src/cairo-compiler-private.h
index 3ce906c..6c14048 100644
--- a/src/cairo-compiler-private.h
+++ b/src/cairo-compiler-private.h
@@ -108,6 +108,7 @@ CAIRO_BEGIN_DECLS
#endif
#ifndef __GNUC__
+#undef __attribute__
#define __attribute__(x)
#endif
commit 12d3d32f2251c78189cf3eaca61bc690ad17e1bb
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sun Aug 17 21:41:36 2008 +0100
[Makefile.am] Support uno.
For the extreme masochist only. At the moment, it only generate syntax
errors, but the command line appears functional.
diff --git a/src/Makefile.am b/src/Makefile.am
index 7869877..939f0f3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -388,4 +388,10 @@ splint:
$(SPLINT) -I$(top_builddir) $(libcairo_la_CFLAGS) -DHAVE_CONFIG_H $$f || status=false; \
done; $$status
+UNO = uno
+uno:
+ @cpp_flags=`echo $(libcairo_la_CFLAGS) | sed 's/\(-I.*\) /\1 /g'`; \
+ files=`echo $(cairo_sources) | sed 's/[^ ]*\.h//g'`; \
+ $(UNO) -I$(top_builddir) $$cpp_flags -DHAVE_CONFIG_H -U__GNUC__ $$files
+
EXTRA_DIST += Makefile.win32
commit 6808174e72c923ebabe61846617496e25df92363
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sun Aug 17 20:28:34 2008 +0100
[win32-font] Review error handling.
The test-suite for win32 shows less than ideal error detection whilst
running on mingw32. Looking at the code, I spotted a few places where the
error propagation could be improved, and lo...
diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index 4c1c929..6d7485b 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -130,6 +130,28 @@ _cairo_win32_scaled_font_init_glyph_path (cairo_win32_scaled_font_t *scaled_font
#define NEARLY_ZERO(d) (fabs(d) < (1. / 65536.))
+static HDC
+_get_global_font_dc (void)
+{
+ static HDC hdc;
+
+ if (!hdc) {
+ hdc = CreateCompatibleDC (NULL);
+ if (!hdc) {
+ _cairo_win32_print_gdi_error ("_get_global_font_dc");
+ return NULL;
+ }
+
+ if (!SetGraphicsMode (hdc, GM_ADVANCED)) {
+ _cairo_win32_print_gdi_error ("_get_global_font_dc");
+ DeleteDC (hdc);
+ return NULL;
+ }
+ }
+
+ return hdc;
+}
+
static cairo_status_t
_compute_transform (cairo_win32_scaled_font_t *scaled_font,
cairo_matrix_t *sc)
@@ -259,10 +281,15 @@ _win32_scaled_font_create (LOGFONTW *logfont,
const cairo_font_options_t *options,
cairo_scaled_font_t **font_out)
{
+ HDC hdc;
cairo_win32_scaled_font_t *f;
cairo_matrix_t scale;
cairo_status_t status;
+ hdc = _get_global_font_dc ();
+ if (hdc == NULL)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+
f = malloc (sizeof(cairo_win32_scaled_font_t));
if (f == NULL)
return _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -363,30 +390,9 @@ _win32_scaled_font_set_identity_transform (HDC hdc)
return CAIRO_STATUS_SUCCESS;
}
-static HDC
-_get_global_font_dc (void)
-{
- static HDC hdc;
-
- if (!hdc) {
- hdc = CreateCompatibleDC (NULL);
- if (!hdc) {
- _cairo_win32_print_gdi_error ("_get_global_font_dc");
- return NULL;
- }
-
- if (!SetGraphicsMode (hdc, GM_ADVANCED)) {
- _cairo_win32_print_gdi_error ("_get_global_font_dc");
- DeleteDC (hdc);
- return NULL;
- }
- }
-
- return hdc;
-}
-
-static HFONT
-_win32_scaled_font_get_scaled_hfont (cairo_win32_scaled_font_t *scaled_font)
+static cairo_status_t
+_win32_scaled_font_get_scaled_hfont (cairo_win32_scaled_font_t *scaled_font,
+ HFONT *hfont_out)
{
if (!scaled_font->scaled_hfont) {
LOGFONTW logfont = scaled_font->logfont;
@@ -397,50 +403,46 @@ _win32_scaled_font_get_scaled_hfont (cairo_win32_scaled_font_t *scaled_font)
logfont.lfQuality = scaled_font->quality;
scaled_font->scaled_hfont = CreateFontIndirectW (&logfont);
- if (!scaled_font->scaled_hfont) {
- _cairo_win32_print_gdi_error ("_win32_scaled_font_get_scaled_hfont");
- return NULL;
- }
+ if (!scaled_font->scaled_hfont)
+ return _cairo_win32_print_gdi_error ("_win32_scaled_font_get_scaled_hfont");
}
- return scaled_font->scaled_hfont;
+ *hfont_out = scaled_font->scaled_hfont;
+ return CAIRO_STATUS_SUCCESS;
}
-static HFONT
+static cairo_status_t
_win32_scaled_font_get_unscaled_hfont (cairo_win32_scaled_font_t *scaled_font,
- HDC hdc)
+ HDC hdc,
+ HFONT *hfont_out)
{
- if (!scaled_font->unscaled_hfont) {
+ if (scaled_font->unscaled_hfont == NULL) {
OUTLINETEXTMETRIC *otm;
unsigned int otm_size;
HFONT scaled_hfont;
LOGFONTW logfont;
+ cairo_status_t status;
- scaled_hfont = _win32_scaled_font_get_scaled_hfont (scaled_font);
- if (!scaled_hfont)
- return NULL;
+ status = _win32_scaled_font_get_scaled_hfont (scaled_font,
+ &scaled_hfont);
+ if (status)
+ return status;
- if (!SelectObject (hdc, scaled_hfont)) {
- _cairo_win32_print_gdi_error ("_win32_scaled_font_get_unscaled_hfont:SelectObject");
- return NULL;
- }
+ if (! SelectObject (hdc, scaled_hfont))
+ return _cairo_win32_print_gdi_error ("_win32_scaled_font_get_unscaled_hfont:SelectObject");
otm_size = GetOutlineTextMetrics (hdc, 0, NULL);
- if (!otm_size) {
- _cairo_win32_print_gdi_error ("_win32_scaled_font_get_unscaled_hfont:GetOutlineTextMetrics");
- return NULL;
- }
+ if (! otm_size)
+ return _cairo_win32_print_gdi_error ("_win32_scaled_font_get_unscaled_hfont:GetOutlineTextMetrics");
otm = malloc (otm_size);
- if (!otm) {
- _cairo_error_throw (CAIRO_STATUS_NO_MEMORY);
- return NULL;
- }
+ if (otm == NULL)
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
- if (!GetOutlineTextMetrics (hdc, otm_size, otm)) {
- _cairo_win32_print_gdi_error ("_win32_scaled_font_get_unscaled_hfont:GetOutlineTextMetrics");
+ if (! GetOutlineTextMetrics (hdc, otm_size, otm)) {
+ status = _cairo_win32_print_gdi_error ("_win32_scaled_font_get_unscaled_hfont:GetOutlineTextMetrics");
free (otm);
- return NULL;
+ return status;
}
scaled_font->em_square = otm->otmEMSquare;
@@ -454,13 +456,12 @@ _win32_scaled_font_get_unscaled_hfont (cairo_win32_scaled_font_t *scaled_font,
logfont.lfQuality = scaled_font->quality;
scaled_font->unscaled_hfont = CreateFontIndirectW (&logfont);
- if (!scaled_font->unscaled_hfont) {
- _cairo_win32_print_gdi_error ("_win32_scaled_font_get_unscaled_hfont:CreateIndirect");
- return NULL;
- }
+ if (! scaled_font->unscaled_hfont)
+ return _cairo_win32_print_gdi_error ("_win32_scaled_font_get_unscaled_hfont:CreateIndirect");
}
- return scaled_font->unscaled_hfont;
+ *hfont_out = scaled_font->unscaled_hfont;
+ return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t
@@ -471,9 +472,9 @@ _cairo_win32_scaled_font_select_unscaled_font (cairo_scaled_font_t *scaled_font,
HFONT hfont;
HFONT old_hfont = NULL;
- hfont = _win32_scaled_font_get_unscaled_hfont ((cairo_win32_scaled_font_t *)scaled_font, hdc);
- if (!hfont)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ status = _win32_scaled_font_get_unscaled_hfont ((cairo_win32_scaled_font_t *)scaled_font, hdc, &hfont);
+ if (status)
+ return status;
old_hfont = SelectObject (hdc, hfont);
if (!old_hfont)
@@ -615,7 +616,7 @@ _cairo_win32_scaled_font_type1_text_to_glyphs (cairo_win32_scaled_font_t *scaled
int n16;
int i;
WORD *glyph_indices = NULL;
- cairo_status_t status = CAIRO_STATUS_SUCCESS;
+ cairo_status_t status;
double x_pos, y_pos;
HDC hdc = NULL;
cairo_matrix_t mat;
@@ -631,10 +632,7 @@ _cairo_win32_scaled_font_type1_text_to_glyphs (cairo_win32_scaled_font_t *scaled
}
hdc = _get_global_font_dc ();
- if (!hdc) {
- status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
- goto FAIL2;
- }
+ assert (hdc != NULL);
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
if (status)
@@ -655,7 +653,8 @@ _cairo_win32_scaled_font_type1_text_to_glyphs (cairo_win32_scaled_font_t *scaled
x_pos = x;
y_pos = y;
mat = scaled_font->base.ctm;
- cairo_matrix_invert (&mat);
+ status = cairo_matrix_invert (&mat);
+ assert (status == CAIRO_STATUS_SUCCESS);
for (i = 0; i < n16; i++) {
cairo_scaled_glyph_t *scaled_glyph;
@@ -704,7 +703,7 @@ _cairo_win32_scaled_font_text_to_glyphs (void *abstract_font,
unsigned int buffer_size, i;
WCHAR *glyph_indices = NULL;
int *dx = NULL;
- cairo_status_t status = CAIRO_STATUS_SUCCESS;
+ cairo_status_t status;
double x_pos, y_pos;
double x_incr, y_incr;
HDC hdc = NULL;
@@ -743,10 +742,7 @@ _cairo_win32_scaled_font_text_to_glyphs (void *abstract_font,
}
hdc = _get_global_font_dc ();
- if (!hdc) {
- status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
- goto FAIL1;
- }
+ assert (hdc != NULL);
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
if (status)
@@ -786,7 +782,7 @@ _cairo_win32_scaled_font_text_to_glyphs (void *abstract_font,
/* Too small a buffer, try again */
- buffer_size *= 1.5;
+ buffer_size += buffer_size / 2;
if (buffer_size > INT_MAX) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto FAIL2;
@@ -837,8 +833,7 @@ _cairo_win32_scaled_font_ucs4_to_index (void *abstract_font,
cairo_status_t status;
hdc = _get_global_font_dc ();
- if (!hdc)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ assert (hdc != NULL);
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
if (status)
@@ -866,8 +861,7 @@ _cairo_win32_scaled_font_set_metrics (cairo_win32_scaled_font_t *scaled_font)
HDC hdc;
hdc = _get_global_font_dc ();
- if (!hdc)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ assert (hdc != NULL);
if (scaled_font->preserve_axes || scaled_font->base.options.hint_metrics == CAIRO_HINT_METRICS_OFF) {
/* For 90-degree rotations (including 0), we get the metrics
@@ -942,8 +936,7 @@ _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_f
HDC hdc;
hdc = _get_global_font_dc ();
- if (!hdc)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ assert (hdc != NULL);
if (scaled_font->is_bitmap) {
/* GetGlyphOutline will not work. Assume that the glyph does not extend outside the font box. */
@@ -954,13 +947,16 @@ _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_f
cairo_scaled_font_extents (&scaled_font->base, &font_extents);
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
- if (!status) {
- if (!GetCharWidth32(hdc, charIndex, charIndex, &width)) {
- status = _cairo_win32_print_gdi_error ("_cairo_win32_scaled_font_init_glyph_metrics:GetCharWidth32");
- width = 0;
- }
+ if (status)
+ return status;
+
+ if (!GetCharWidth32(hdc, charIndex, charIndex, &width)) {
+ status = _cairo_win32_print_gdi_error ("_cairo_win32_scaled_font_init_glyph_metrics:GetCharWidth32");
+ width = 0;
}
cairo_win32_scaled_font_done_font (&scaled_font->base);
+ if (status)
+ return status;
extents.x_bearing = 0;
extents.y_bearing = scaled_font->base.ctm.yy * (-font_extents.ascent / scaled_font->y_scale);
@@ -975,6 +971,7 @@ _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_f
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
if (status)
return status;
+
if (GetGlyphOutlineW (hdc, _cairo_scaled_glyph_index (scaled_glyph),
GGO_METRICS | GGO_GLYPH_INDEX,
&metrics, 0, NULL, &matrix) == GDI_ERROR) {
@@ -982,6 +979,8 @@ _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_f
memset (&metrics, 0, sizeof (GLYPHMETRICS));
}
cairo_win32_scaled_font_done_font (&scaled_font->base);
+ if (status)
+ return status;
if (scaled_font->swap_axes) {
extents.x_bearing = - metrics.gmptGlyphOrigin.y / scaled_font->y_scale;
@@ -1014,6 +1013,9 @@ _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_f
* of the font.
*/
status = _cairo_win32_scaled_font_select_unscaled_font (&scaled_font->base, hdc);
+ if (status)
+ return status;
+
if (GetGlyphOutlineW (hdc, _cairo_scaled_glyph_index (scaled_glyph),
GGO_METRICS | GGO_GLYPH_INDEX,
&metrics, 0, NULL, &matrix) == GDI_ERROR) {
@@ -1021,6 +1023,8 @@ _cairo_win32_scaled_font_init_glyph_metrics (cairo_win32_scaled_font_t *scaled_f
memset (&metrics, 0, sizeof (GLYPHMETRICS));
}
_cairo_win32_scaled_font_done_unscaled_font (&scaled_font->base);
+ if (status)
+ return status;
extents.x_bearing = (double)metrics.gmptGlyphOrigin.x / scaled_font->em_square;
extents.y_bearing = - (double)metrics.gmptGlyphOrigin.y / scaled_font->em_square;
@@ -1054,13 +1058,13 @@ _cairo_win32_scaled_font_glyph_bbox (void *abstract_font,
int x1 = 0, x2 = 0, y1 = 0, y2 = 0;
if (num_glyphs > 0) {
- HDC hdc = _get_global_font_dc ();
+ HDC hdc;
GLYPHMETRICS metrics;
cairo_status_t status;
int i;
- if (!hdc)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ hdc = _get_global_font_dc ();
+ assert (hdc != NULL);
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
if (status)
@@ -1194,14 +1198,17 @@ _add_glyph (cairo_glyph_state_t *state,
return CAIRO_STATUS_SUCCESS;
}
-static void
+static cairo_status_t
_finish_glyphs (cairo_glyph_state_t *state)
{
- /* ignore errors as we only call _finish_glyphs on the error path */
- _flush_glyphs (state);
+ cairo_status_t status;
+
+ status = _flush_glyphs (state);
_cairo_array_fini (&state->glyphs);
_cairo_array_fini (&state->dx);
+
+ return status;
}
static cairo_status_t
@@ -1211,10 +1218,10 @@ _draw_glyphs_on_surface (cairo_win32_surface_t *surface,
int x_offset,
int y_offset,
const cairo_glyph_t *glyphs,
- int num_glyphs)
+ int num_glyphs)
{
cairo_glyph_state_t state;
- cairo_status_t status = CAIRO_STATUS_SUCCESS;
+ cairo_status_t status, status2;
int i;
if (!SaveDC (surface->dc))
@@ -1238,7 +1245,10 @@ _draw_glyphs_on_surface (cairo_win32_surface_t *surface,
}
FAIL2:
- _finish_glyphs (&state);
+ status2 = _finish_glyphs (&state);
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = status2;
+
cairo_win32_scaled_font_done_font (&scaled_font->base);
FAIL1:
RestoreDC (surface->dc, -1);
@@ -1290,10 +1300,13 @@ _compute_a8_mask (cairo_win32_surface_t *mask_surface)
cairo_image_surface_t *image8;
int i, j;
+ if (image24->base.status)
+ return cairo_surface_reference (&image24->base);
+
image8 = (cairo_image_surface_t *)cairo_image_surface_create (CAIRO_FORMAT_A8,
image24->width, image24->height);
if (image8->base.status)
- return NULL;
+ return &image8->base;
for (i = 0; i < image24->height; i++) {
uint32_t *p = (uint32_t *) (image24->data + i * image24->stride);
@@ -1432,8 +1445,9 @@ _cairo_win32_scaled_font_show_glyphs (void *abstract_font,
} else {
mask_surface = _compute_a8_mask (tmp_surface);
cairo_surface_destroy (&tmp_surface->base);
- if (!mask_surface)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ status = mask_surface->status;
+ if (status)
+ return status;
}
/* For op == OVER, no-cleartype, a possible optimization here is to
@@ -1465,13 +1479,12 @@ _cairo_win32_scaled_font_load_truetype_table (void *abstract_font,
unsigned char *buffer,
unsigned long *length)
{
+ cairo_win32_scaled_font_t *scaled_font = abstract_font;
HDC hdc;
cairo_status_t status;
- cairo_win32_scaled_font_t *scaled_font = abstract_font;
hdc = _get_global_font_dc ();
- if (!hdc)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ assert (hdc != NULL);
tag = (tag&0x000000ff)<<24 | (tag&0x0000ff00)<<8 | (tag&0x00ff0000)>>8 | (tag&0xff000000)>>24;
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
@@ -1487,8 +1500,8 @@ _cairo_win32_scaled_font_load_truetype_table (void *abstract_font,
return status;
}
-static cairo_status_t
-_cairo_win32_scaled_font_index_to_ucs4 (void *abstract_font,
+static cairo_int_status_t
+_cairo_win32_scaled_font_index_to_ucs4 (void *abstract_font,
unsigned long index,
uint32_t *ucs4)
{
@@ -1499,11 +1512,10 @@ _cairo_win32_scaled_font_index_to_ucs4 (void *abstract_font,
HDC hdc = NULL;
int res;
unsigned int i, j, num_glyphs;
- cairo_status_t status = CAIRO_STATUS_SUCCESS;
+ cairo_status_t status;
hdc = _get_global_font_dc ();
- if (!hdc)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ assert (hdc != NULL);
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
if (status)
@@ -1583,7 +1595,7 @@ static cairo_status_t
_cairo_win32_scaled_font_init_glyph_surface (cairo_win32_scaled_font_t *scaled_font,
cairo_scaled_glyph_t *scaled_glyph)
{
- cairo_status_t status = CAIRO_STATUS_SUCCESS;
+ cairo_status_t status;
cairo_glyph_t glyph;
cairo_win32_surface_t *surface;
cairo_t *cr;
@@ -1601,23 +1613,35 @@ _cairo_win32_scaled_font_init_glyph_surface (cairo_win32_scaled_font_t *scaled_f
surface = (cairo_win32_surface_t *)
cairo_win32_surface_create_with_dib (CAIRO_FORMAT_RGB24, width, height);
- cr = cairo_create((cairo_surface_t *)surface);
+ cr = cairo_create (&surface->base);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_paint (cr);
+ status = cairo_status (cr);
cairo_destroy(cr);
+ if (status)
+ goto FAIL;
glyph.index = _cairo_scaled_glyph_index (scaled_glyph);
glyph.x = -x1;
glyph.y = -y1;
status = _draw_glyphs_on_surface (surface, scaled_font, RGB(0,0,0),
0, 0, &glyph, 1);
+ if (status)
+ goto FAIL;
+
GdiFlush();
image = _compute_a8_mask (surface);
- cairo_surface_set_device_offset ((cairo_surface_t *)image, -x1, -y1);
+ status = image->status;
+ if (status)
+ goto FAIL;
+
+ cairo_surface_set_device_offset (image, -x1, -y1);
_cairo_scaled_glyph_set_surface (scaled_glyph,
&scaled_font->base,
- (cairo_image_surface_t*)image);
+ (cairo_image_surface_t *) image);
+
+ FAIL:
cairo_surface_destroy (&surface->base);
return status;
@@ -1653,8 +1677,7 @@ _cairo_win32_scaled_font_init_glyph_path (cairo_win32_scaled_font_t *scaled_font
return CAIRO_INT_STATUS_UNSUPPORTED;
hdc = _get_global_font_dc ();
- if (!hdc)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ assert (hdc != NULL);
path = _cairo_path_fixed_create ();
if (!path)
@@ -1681,7 +1704,6 @@ _cairo_win32_scaled_font_init_glyph_path (cairo_win32_scaled_font_t *scaled_font
}
ptr = buffer = malloc (bytesGlyph);
-
if (!buffer) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto CLEANUP_FONT;
@@ -2015,9 +2037,9 @@ cairo_win32_scaled_font_select_font (cairo_scaled_font_t *scaled_font,
if (scaled_font->status)
return scaled_font->status;
- hfont = _win32_scaled_font_get_scaled_hfont ((cairo_win32_scaled_font_t *)scaled_font);
- if (!hfont)
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ status = _win32_scaled_font_get_scaled_hfont ((cairo_win32_scaled_font_t *)scaled_font, &hfont);
+ if (status)
+ return status;
old_hfont = SelectObject (hdc, hfont);
if (!old_hfont)
commit 5ef52cd08f586d4ca0b30ff7d47575f0dfba9172
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sun Aug 17 18:01:15 2008 +0100
[svg] Tweak base64_write_func().
On a wild goose chase to eliminate a valgrind warning (caused by libpng,
alas) tweak the code for a bit of simplification.
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 0b0165e..8d17cad 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -870,12 +870,11 @@ _cairo_svg_surface_emit_alpha_filter (cairo_svg_document_t *document)
typedef struct {
cairo_output_stream_t *output;
unsigned int in_mem;
- unsigned char src[3];
- unsigned char dst[5];
unsigned int trailing;
+ unsigned char src[3];
} base64_write_closure_t;
-static char const *base64_table =
+static char const base64_table[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static cairo_status_t
@@ -885,26 +884,27 @@ base64_write_func (void *closure,
{
base64_write_closure_t *info = (base64_write_closure_t *) closure;
unsigned int i;
- unsigned char *src, *dst;
+ unsigned char *src;
- dst = info->dst;
src = info->src;
if (info->in_mem + length < 3) {
for (i = 0; i < length; i++) {
- src[i + info->in_mem] = *data;
- data++;
+ src[i + info->in_mem] = *data++;
}
info->in_mem += length;
return CAIRO_STATUS_SUCCESS;
}
- while (info->in_mem + length >= 3) {
- for (i = 0; i < 3 - info->in_mem; i++) {
- src[i + info->in_mem] = *data;
- data++;
+ do {
+ unsigned char dst[4];
+
+ for (i = info->in_mem; i < 3; i++) {
+ src[i] = *data++;
length--;
}
+ info->in_mem = 0;
+
dst[0] = base64_table[src[0] >> 2];
dst[1] = base64_table[(src[0] & 0x03) << 4 | src[1] >> 4];
dst[2] = base64_table[(src[1] & 0x0f) << 2 | src[2] >> 6];
@@ -919,16 +919,14 @@ base64_write_func (void *closure,
break;
}
_cairo_output_stream_write (info->output, dst, 4);
- info->in_mem = 0;
- }
+ } while (length >= 3);
for (i = 0; i < length; i++) {
- src[i] = *data;
- data++;
+ src[i] = *data++;
}
info->in_mem = length;
- return CAIRO_STATUS_SUCCESS;
+ return _cairo_output_stream_get_status (info->output);
}
static cairo_int_status_t
@@ -942,7 +940,6 @@ _cairo_surface_base64_encode (cairo_surface_t *surface,
info.output = output;
info.in_mem = 0;
info.trailing = 0;
- memset (info.dst, '\x0', 5);
_cairo_output_stream_printf (info.output, "data:image/png;base64,");
commit c745a622db7844ad0dc0da14446457eed1133eb5
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sun Aug 17 17:33:29 2008 +0100
[test/toy-font-face] Use cairo_test_init/fini().
Minor step to harmonise the test with the rest of the suite.
diff --git a/test/toy-font-face.c b/test/toy-font-face.c
index 262f7ce..7b984eb 100644
--- a/test/toy-font-face.c
+++ b/test/toy-font-face.c
@@ -28,22 +28,22 @@
#include "config.h"
#endif
+#include "cairo-test.h"
+
#include <cairo.h>
#include <assert.h>
-#include <stdlib.h>
#include <string.h>
-#if HAVE_FCFINI
-#include <fontconfig/fontconfig.h>
-#endif
-
int
main (void)
{
+ cairo_test_context_t ctx;
cairo_t *cr;
cairo_surface_t *surface;
cairo_font_face_t *font_face;
+ cairo_test_init (&ctx, "toy-font-face");
+
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 0, 0);
cr = cairo_create (surface);
cairo_surface_destroy (surface);
@@ -120,10 +120,7 @@ main (void)
cairo_destroy (cr);
- cairo_debug_reset_static_data ();
-#if HAVE_FCFINI
- FcFini ();
-#endif
+ cairo_test_fini (&ctx);
- return 0;
+ return CAIRO_TEST_SUCCESS;
}
More information about the cairo-commit
mailing list