From 9287d60d60f55ae3838a7cecfa9fa04a5f95e8de Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 24 Feb 2006 11:24:03 -0800 Subject: [PATCH 01/13] Add get_type functions: cairo_surface_get_type, cairo_pattern_get_type, cairo_font_face_get_type, and cairo_scaled_font_get_type. --- src/cairo-surface.c | 3 +- src/cairo.h | 134 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 3 deletions(-) diff --git a/src/cairo-surface.c b/src/cairo-surface.c index 29820173e..52aeafe46 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -186,7 +186,8 @@ _cairo_surface_create_similar_scratch (cairo_surface_t *other, * * Create a new surface that is as compatible as possible with an * existing surface. The new surface will use the same backend as - * @other unless that is not possible for some reason. + * @other unless that is not possible for some reason. The type of the + * returned surface may be examined with cairo_surface_get_type(). * * Return value: a pointer to the newly allocated surface. The caller * owns the surface and should call cairo_surface_destroy when done diff --git a/src/cairo.h b/src/cairo.h index fbb362088..76f9257e3 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -896,6 +896,46 @@ cairo_font_face_destroy (cairo_font_face_t *font_face); cairo_public cairo_status_t cairo_font_face_status (cairo_font_face_t *font_face); +/** + * cairo_font_type_t + * @CAIRO_SCALED_FONT_TYPE_FT: The font is of type ft + * @CAIRO_SCALED_FONT_TYPE_WIN32: The font is of type win32 + * @CAIRO_SCALED_FONT_TYPE_ATSUI: The font is of type atsui + * + * @cairo_font_type_t is used to describe the type of a given font + * face or scaled font. The font types are also known as "font + * backends" within cairo. + * + * The type of a font face is determined by the function used to + * create it, which will generally be of the form + * cairo__font_face_create. The font face type can be queried + * with cairo_font_face_get_type() + * + * The various cairo_font_face functions can be used with a font face + * of any type. + * + * The type of a scaled font is determined by the type of the font + * face passed to cairo_scaled_font_create. The scaled font type can + * be queried with cairo_scaled_font_get_type() + * + * The various cairo_scaled_font functions can be used with scaled + * fonts of any type, but some font backends also provide + * type-specific functions that must only be called with a scaled font + * of the appropriate type. These functions have names that begin with + * cairo__scaled_font such as cairo_ft_scaled_font_lock_face. + * + * The behavior of calling a type-specific function with a scaled font + * of the wrong type is undefined. + */ +typedef enum _cairo_font_type { + CAIRO_FONT_TYPE_FT, + CAIRO_FONT_TYPE_WIN32, + CAIRO_FONT_TYPE_ATSUI +} cairo_font_type_t; + +cairo_public cairo_font_type_t +cairo_font_face_get_type (cairo_scaled_font_t *font_face); + cairo_public void * cairo_font_face_get_user_data (cairo_font_face_t *font_face, const cairo_user_data_key_t *key); @@ -923,6 +963,9 @@ cairo_scaled_font_destroy (cairo_scaled_font_t *scaled_font); cairo_public cairo_status_t cairo_scaled_font_status (cairo_scaled_font_t *scaled_font); +cairo_public cairo_font_type_t +cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font); + cairo_public void cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font, cairo_font_extents_t *extents); @@ -1147,14 +1190,64 @@ cairo_surface_create_similar (cairo_surface_t *other, cairo_public cairo_surface_t * cairo_surface_reference (cairo_surface_t *surface); +cairo_public void +cairo_surface_finish (cairo_surface_t *surface); + cairo_public void cairo_surface_destroy (cairo_surface_t *surface); cairo_public cairo_status_t cairo_surface_status (cairo_surface_t *surface); -cairo_public void -cairo_surface_finish (cairo_surface_t *surface); +/** + * cairo_surface_type_t + * @CAIRO_SURFACE_TYPE_IMAGE: The surface is of type image + * @CAIRO_SURFACE_TYPE_PDF: The surface is of type pdf + * @CAIRO_SURFACE_TYPE_PS: The surface is of type ps + * @CAIRO_SURFACE_TYPE_XLIB: The surface is of typs xlib + * @CAIRO_SURFACE_TYPE_XCB: The surface is of type xcb + * @CAIRO_SURFACE_TYPE_GLITZ: The surface is of type glitz + * @CAIRO_SURFACE_TYPE_QUARTZ: The surface is of type quartz + * @CAIRO_SURFACE_TYPE_WIN32: The surface is of type win32 + * @CAIRO_SURFACE_TYPE_BEOS: The surface is of type beos + * @CAIRO_SURFACE_TYPE_DIRECTFB: The surface is of type directfb + * @CAIRO_SURFACE_TYPE_SVG: The surface is of type svg + * + * @cairo_surface_type_t is used to describe the type of a given + * surface. The surface types are also known as "backends" or "surface + * backends" within cairo. + * + * The type of a surface is determined by the function used to create + * it, which will generally be of the form cairo__surface_create, + * (though see cairo_surface_create_similar as well). + * + * The surface type can be queried with cairo_surface_get_type() + * + * The various cairo_surface functions can be used with surfaces of + * any type, but some backends also provide type-specific functions + * that must only be called with a surface of the appropriate + * type. These functions have names that begin with + * cairo__surface such as cairo_image_surface_get_width(). + * + * The behavior of calling a type-specific function with a surface of + * the wrong type is undefined. + */ +typedef enum _cairo_surface_type { + CAIRO_SURFACE_TYPE_IMAGE, + CAIRO_SURFACE_TYPE_PDF, + CAIRO_SURFACE_TYPE_PS, + CAIRO_SURFACE_TYPE_XLIB, + CAIRO_SURFACE_TYPE_XCB, + CAIRO_SURFACE_TYPE_GLITZ, + CAIRO_SURFACE_TYPE_QUARTZ, + CAIRO_SURFACE_TYPE_WIN32, + CAIRO_SURFACE_TYPE_BEOS, + CAIRO_SURFACE_TYPE_DIRECTFB, + CAIRO_SURFACE_TYPE_SVG +} cairo_surface_type_t; + +cairo_public cairo_surface_type_t +cairo_surface_get_type (cairo_surface_t *surface); #if CAIRO_HAS_PNG_FUNCTIONS @@ -1290,6 +1383,43 @@ cairo_pattern_destroy (cairo_pattern_t *pattern); cairo_public cairo_status_t cairo_pattern_status (cairo_pattern_t *pattern); +/** + * cairo_pattern_type_t + + * @CAIRO_PATTERN_TYPE_SOLID: The pattern is a solid (uniform) + * color. It may be opaque or translucent. + * @CAIRO_PATTERN_TYPE_SURFACE: The pattern is a based on a surface (an image). + * @CAIRO_PATTERN_TYPE_LINEAR_GRADIENT: The pattern is a linear gradient. + * @CAIRO_PATTERN_TYPE_RADIAL_GRADIENT: The pattern is a radial gradient. + * + * @cairo_pattern_type_t us used to describe the type of a given pattern. + * + * The type of a pattern is determined by the function used to create + * it. The cairo_pattern_create_rgb() and cairo_pattern_create_rgba() + * functions create SOLID patterns. The reamaining + * cairo_pattern_create functions map to pattern types in obvious + * ways. + * + * The pattern type can be queried with cairo_pattern_get_type() + * + * Most cairo_pattern functions can be called with a pattern of any + * type, (though trying to change the extend or filter for a solid + * pattern will have no effect). A notable exception is + * cairo_pattern_add_color_stop_rgb() and + * cairo_pattern_add_color_stop_rgba() which must only be called with + * gradient patterns. Otherwise the pattern will be shutdown and put + * into an error state. + */ +typedef enum _cairo_pattern_type { + CAIRO_PATTERN_TYPE_SOLID, + CAIRO_PATTERN_TYPE_SURFACE, + CAIRO_PATTERN_TYPE_LINEAR_GRADIENT, + CAIRO_PATTERN_TYPE_RADIAL_GRADIENT +} cairo_pattern_type_t; + +cairo_public cairo_pattern_type_t +cairo_pattern_get_type (cairo_pattern_t *pattern); + cairo_public void cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, double offset, From 2fc9fd79e794129b26cc8f9b62a5aa4604cb99d9 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 24 Feb 2006 11:37:50 -0800 Subject: [PATCH 02/13] cairo.h: Fix two typos in the documentation. --- src/cairo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cairo.h b/src/cairo.h index 76f9257e3..0dd361643 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -1204,7 +1204,7 @@ cairo_surface_status (cairo_surface_t *surface); * @CAIRO_SURFACE_TYPE_IMAGE: The surface is of type image * @CAIRO_SURFACE_TYPE_PDF: The surface is of type pdf * @CAIRO_SURFACE_TYPE_PS: The surface is of type ps - * @CAIRO_SURFACE_TYPE_XLIB: The surface is of typs xlib + * @CAIRO_SURFACE_TYPE_XLIB: The surface is of type xlib * @CAIRO_SURFACE_TYPE_XCB: The surface is of type xcb * @CAIRO_SURFACE_TYPE_GLITZ: The surface is of type glitz * @CAIRO_SURFACE_TYPE_QUARTZ: The surface is of type quartz @@ -1396,7 +1396,7 @@ cairo_pattern_status (cairo_pattern_t *pattern); * * The type of a pattern is determined by the function used to create * it. The cairo_pattern_create_rgb() and cairo_pattern_create_rgba() - * functions create SOLID patterns. The reamaining + * functions create SOLID patterns. The remaining * cairo_pattern_create functions map to pattern types in obvious * ways. * From f58f39d7afee8d8a663569f149651c789aa95da8 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 24 Feb 2006 15:06:50 -0800 Subject: [PATCH 03/13] cairo.h: Fix typo (thanks to Torsten Schoenfeld) --- src/cairo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cairo.h b/src/cairo.h index 0dd361643..cc87b7e2b 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -934,7 +934,7 @@ typedef enum _cairo_font_type { } cairo_font_type_t; cairo_public cairo_font_type_t -cairo_font_face_get_type (cairo_scaled_font_t *font_face); +cairo_font_face_get_type (cairo_font_face_t *font_face); cairo_public void * cairo_font_face_get_user_data (cairo_font_face_t *font_face, From 5928d03b496420b2d0a89cf8e2d294081a60cc67 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 24 Feb 2006 15:25:19 -0800 Subject: [PATCH 04/13] Remove private cairo_pattern_type in favor of new public one. Rename all values to now include TYPE. Drop _GRADIENT from LINEAR and RADIAL. --- src/cairo-meta-surface.c | 2 +- src/cairo-pattern.c | 68 ++++++++++++++++++------------------ src/cairo-pdf-surface.c | 10 +++--- src/cairo-ps-surface.c | 26 +++++++------- src/cairo-surface-fallback.c | 2 +- src/cairo-xlib-surface.c | 2 +- src/cairo.h | 12 +++---- src/cairoint.h | 7 ---- 8 files changed, 61 insertions(+), 68 deletions(-) diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c index a314150bc..6f824634c 100644 --- a/src/cairo-meta-surface.c +++ b/src/cairo-meta-surface.c @@ -201,7 +201,7 @@ _init_pattern_with_snapshot (cairo_pattern_t *pattern, { _cairo_pattern_init_copy (pattern, other); - if (pattern->type == CAIRO_PATTERN_SURFACE) { + if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) pattern; cairo_surface_t *surface = surface_pattern->surface; diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index d7b73693b..27ede9a64 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -30,7 +30,7 @@ #include "cairoint.h" const cairo_solid_pattern_t cairo_pattern_nil = { - { CAIRO_PATTERN_SOLID, /* type */ + { CAIRO_PATTERN_TYPE_SOLID, /* type */ (unsigned int)-1, /* ref_count */ CAIRO_STATUS_NO_MEMORY, /* status */ { 1., 0., 0., 1., 0., 0., }, /* matrix */ @@ -39,7 +39,7 @@ const cairo_solid_pattern_t cairo_pattern_nil = { }; static const cairo_solid_pattern_t cairo_pattern_nil_null_pointer = { - { CAIRO_PATTERN_SOLID, /* type */ + { CAIRO_PATTERN_TYPE_SOLID, /* type */ (unsigned int)-1, /* ref_count */ CAIRO_STATUS_NULL_POINTER,/* status */ { 1., 0., 0., 1., 0., 0., }, /* matrix */ @@ -48,7 +48,7 @@ static const cairo_solid_pattern_t cairo_pattern_nil_null_pointer = { }; static const cairo_solid_pattern_t cairo_pattern_nil_file_not_found = { - { CAIRO_PATTERN_SOLID, /* type */ + { CAIRO_PATTERN_TYPE_SOLID, /* type */ (unsigned int)-1, /* ref_count */ CAIRO_STATUS_FILE_NOT_FOUND, /* status */ { 1., 0., 0., 1., 0., 0., }, /* matrix */ @@ -57,7 +57,7 @@ static const cairo_solid_pattern_t cairo_pattern_nil_file_not_found = { }; static const cairo_solid_pattern_t cairo_pattern_nil_read_error = { - { CAIRO_PATTERN_SOLID, /* type */ + { CAIRO_PATTERN_TYPE_SOLID, /* type */ (unsigned int)-1, /* ref_count */ CAIRO_STATUS_READ_ERROR, /* status */ { 1., 0., 0., 1., 0., 0., }, /* matrix */ @@ -117,7 +117,7 @@ _cairo_pattern_init (cairo_pattern_t *pattern, cairo_pattern_type_t type) pattern->ref_count = 1; pattern->status = CAIRO_STATUS_SUCCESS; - if (type == CAIRO_PATTERN_SURFACE) + if (type == CAIRO_PATTERN_TYPE_SURFACE) pattern->extend = CAIRO_EXTEND_SURFACE_DEFAULT; else pattern->extend = CAIRO_EXTEND_GRADIENT_DEFAULT; @@ -131,7 +131,7 @@ static void _cairo_gradient_pattern_init_copy (cairo_gradient_pattern_t *pattern, const cairo_gradient_pattern_t *other) { - if (other->base.type == CAIRO_PATTERN_LINEAR) + if (other->base.type == CAIRO_PATTERN_TYPE_LINEAR) { cairo_linear_pattern_t *dst = (cairo_linear_pattern_t *) pattern; cairo_linear_pattern_t *src = (cairo_linear_pattern_t *) other; @@ -170,21 +170,21 @@ _cairo_pattern_init_copy (cairo_pattern_t *pattern, } switch (other->type) { - case CAIRO_PATTERN_SOLID: { + case CAIRO_PATTERN_TYPE_SOLID: { cairo_solid_pattern_t *dst = (cairo_solid_pattern_t *) pattern; cairo_solid_pattern_t *src = (cairo_solid_pattern_t *) other; *dst = *src; } break; - case CAIRO_PATTERN_SURFACE: { + case CAIRO_PATTERN_TYPE_SURFACE: { cairo_surface_pattern_t *dst = (cairo_surface_pattern_t *) pattern; cairo_surface_pattern_t *src = (cairo_surface_pattern_t *) other; *dst = *src; cairo_surface_reference (dst->surface); } break; - case CAIRO_PATTERN_LINEAR: - case CAIRO_PATTERN_RADIAL: { + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: { cairo_gradient_pattern_t *dst = (cairo_gradient_pattern_t *) pattern; cairo_gradient_pattern_t *src = (cairo_gradient_pattern_t *) other; @@ -199,16 +199,16 @@ void _cairo_pattern_fini (cairo_pattern_t *pattern) { switch (pattern->type) { - case CAIRO_PATTERN_SOLID: + case CAIRO_PATTERN_TYPE_SOLID: break; - case CAIRO_PATTERN_SURFACE: { + case CAIRO_PATTERN_TYPE_SURFACE: { cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *) pattern; cairo_surface_destroy (surface_pattern->surface); } break; - case CAIRO_PATTERN_LINEAR: - case CAIRO_PATTERN_RADIAL: { + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: { cairo_gradient_pattern_t *gradient = (cairo_gradient_pattern_t *) pattern; @@ -222,7 +222,7 @@ void _cairo_pattern_init_solid (cairo_solid_pattern_t *pattern, const cairo_color_t *color) { - _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_SOLID); + _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_SOLID); pattern->color = *color; } @@ -232,12 +232,12 @@ _cairo_pattern_init_for_surface (cairo_surface_pattern_t *pattern, { if (surface->status) { /* Force to solid to simplify the pattern_fini process. */ - pattern->base.type = CAIRO_PATTERN_SOLID; + pattern->base.type = CAIRO_PATTERN_TYPE_SOLID; _cairo_pattern_set_error (&pattern->base, surface->status); return; } - _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_SURFACE); + _cairo_pattern_init (&pattern->base, CAIRO_PATTERN_TYPE_SURFACE); pattern->surface = cairo_surface_reference (surface); } @@ -256,7 +256,7 @@ void _cairo_pattern_init_linear (cairo_linear_pattern_t *pattern, double x0, double y0, double x1, double y1) { - _cairo_pattern_init_gradient (&pattern->base, CAIRO_PATTERN_LINEAR); + _cairo_pattern_init_gradient (&pattern->base, CAIRO_PATTERN_TYPE_LINEAR); pattern->gradient.p1.x = _cairo_fixed_from_double (x0); pattern->gradient.p1.y = _cairo_fixed_from_double (y0); @@ -269,7 +269,7 @@ _cairo_pattern_init_radial (cairo_radial_pattern_t *pattern, double cx0, double cy0, double radius0, double cx1, double cy1, double radius1) { - _cairo_pattern_init_gradient (&pattern->base, CAIRO_PATTERN_RADIAL); + _cairo_pattern_init_gradient (&pattern->base, CAIRO_PATTERN_TYPE_RADIAL); pattern->gradient.inner.x = _cairo_fixed_from_double (cx0); pattern->gradient.inner.y = _cairo_fixed_from_double (cy0); @@ -641,8 +641,8 @@ cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, if (pattern->status) return; - if (pattern->type != CAIRO_PATTERN_LINEAR && - pattern->type != CAIRO_PATTERN_RADIAL) + if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR && + pattern->type != CAIRO_PATTERN_TYPE_RADIAL) { _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); return; @@ -689,8 +689,8 @@ cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern, if (pattern->status) return; - if (pattern->type != CAIRO_PATTERN_LINEAR && - pattern->type != CAIRO_PATTERN_RADIAL) + if (pattern->type != CAIRO_PATTERN_TYPE_LINEAR && + pattern->type != CAIRO_PATTERN_TYPE_RADIAL) { _cairo_pattern_set_error (pattern, CAIRO_STATUS_PATTERN_TYPE_MISMATCH); return; @@ -894,7 +894,7 @@ _cairo_pattern_acquire_surface_for_gradient (cairo_gradient_pattern_t *pattern, cairo_status_t status; cairo_bool_t repeat = FALSE; - if (pattern->base.type == CAIRO_PATTERN_LINEAR) + if (pattern->base.type == CAIRO_PATTERN_TYPE_LINEAR) { cairo_linear_pattern_t *linear = (cairo_linear_pattern_t *) pattern; @@ -936,7 +936,7 @@ _cairo_pattern_acquire_surface_for_gradient (cairo_gradient_pattern_t *pattern, return CAIRO_STATUS_SUCCESS; } - if (pattern->base.type == CAIRO_PATTERN_LINEAR) { + if (pattern->base.type == CAIRO_PATTERN_TYPE_LINEAR) { cairo_bool_t is_horizontal; cairo_bool_t is_vertical; @@ -1055,7 +1055,7 @@ _cairo_pattern_is_opaque_solid (cairo_pattern_t *pattern) { cairo_solid_pattern_t *solid; - if (pattern->type != CAIRO_PATTERN_SOLID) + if (pattern->type != CAIRO_PATTERN_TYPE_SOLID) return FALSE; solid = (cairo_solid_pattern_t *) pattern; @@ -1151,7 +1151,7 @@ _cairo_pattern_acquire_surface (cairo_pattern_t *pattern, } switch (pattern->type) { - case CAIRO_PATTERN_SOLID: { + case CAIRO_PATTERN_TYPE_SOLID: { cairo_solid_pattern_t *src = (cairo_solid_pattern_t *) pattern; status = _cairo_pattern_acquire_surface_for_solid (src, dst, @@ -1159,8 +1159,8 @@ _cairo_pattern_acquire_surface (cairo_pattern_t *pattern, surface_out, attributes); } break; - case CAIRO_PATTERN_LINEAR: - case CAIRO_PATTERN_RADIAL: { + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: { cairo_gradient_pattern_t *src = (cairo_gradient_pattern_t *) pattern; /* fast path for gradients with less than 2 color stops */ @@ -1203,7 +1203,7 @@ _cairo_pattern_acquire_surface (cairo_pattern_t *pattern, attributes); } } break; - case CAIRO_PATTERN_SURFACE: { + case CAIRO_PATTERN_TYPE_SURFACE: { cairo_surface_pattern_t *src = (cairo_surface_pattern_t *) pattern; status = _cairo_pattern_acquire_surface_for_surface (src, dst, @@ -1235,7 +1235,7 @@ _cairo_pattern_release_surface (cairo_pattern_t *pattern, { cairo_surface_pattern_t *surface_pattern; - assert (pattern->type == CAIRO_PATTERN_SURFACE); + assert (pattern->type == CAIRO_PATTERN_TYPE_SURFACE); surface_pattern = (cairo_surface_pattern_t *) pattern; _cairo_surface_release_source_image (surface_pattern->surface, @@ -1277,8 +1277,8 @@ _cairo_pattern_acquire_surfaces (cairo_pattern_t *src, /* XXX: This optimization assumes that there is no color * information in mask, so this will need to change when we * support RENDER-style 4-channel masks. */ - if (src->type == CAIRO_PATTERN_SOLID && - mask && mask->type == CAIRO_PATTERN_SOLID) + if (src->type == CAIRO_PATTERN_TYPE_SOLID && + mask && mask->type == CAIRO_PATTERN_TYPE_SOLID) { cairo_color_t combined; cairo_solid_pattern_t *src_solid = (cairo_solid_pattern_t *) src; @@ -1346,7 +1346,7 @@ _cairo_pattern_get_extents (cairo_pattern_t *pattern, cairo_rectangle_t *extents) { if (pattern->extend == CAIRO_EXTEND_NONE && - pattern->type == CAIRO_PATTERN_SURFACE) + pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { cairo_status_t status; cairo_rectangle_t surface_extents; diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index ee5c482cf..289eeb961 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -841,7 +841,7 @@ _cairo_pdf_surface_composite (cairo_operator_t op, if (mask_pattern) return CAIRO_STATUS_SUCCESS; - if (src_pattern->type != CAIRO_PATTERN_SURFACE) + if (src_pattern->type != CAIRO_PATTERN_TYPE_SURFACE) return CAIRO_STATUS_SUCCESS; if (src->surface->backend == &cairo_pdf_surface_backend) @@ -1237,16 +1237,16 @@ static cairo_status_t emit_pattern (cairo_pdf_surface_t *surface, cairo_pattern_t *pattern) { switch (pattern->type) { - case CAIRO_PATTERN_SOLID: + case CAIRO_PATTERN_TYPE_SOLID: return emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern); - case CAIRO_PATTERN_SURFACE: + case CAIRO_PATTERN_TYPE_SURFACE: return emit_surface_pattern (surface, (cairo_surface_pattern_t *) pattern); - case CAIRO_PATTERN_LINEAR: + case CAIRO_PATTERN_TYPE_LINEAR: return emit_linear_pattern (surface, (cairo_linear_pattern_t *) pattern); - case CAIRO_PATTERN_RADIAL: + case CAIRO_PATTERN_TYPE_RADIAL: return emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern); } diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index 6cf862170..371290cc2 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -546,12 +546,12 @@ pattern_is_translucent (const cairo_pattern_t *abstract_pattern) pattern = (cairo_pattern_union_t *) abstract_pattern; switch (pattern->base.type) { - case CAIRO_PATTERN_SOLID: + case CAIRO_PATTERN_TYPE_SOLID: return color_is_translucent (&pattern->solid.color); - case CAIRO_PATTERN_SURFACE: + case CAIRO_PATTERN_TYPE_SURFACE: return surface_is_translucent (pattern->surface.surface); - case CAIRO_PATTERN_LINEAR: - case CAIRO_PATTERN_RADIAL: + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: return gradient_is_translucent (&pattern->gradient.base); } @@ -637,7 +637,7 @@ color_operation_needs_fallback (cairo_operator_t op, static cairo_bool_t pattern_type_supported (const cairo_pattern_t *pattern) { - if (pattern->type == CAIRO_PATTERN_SOLID) + if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) return TRUE; return FALSE; } @@ -837,19 +837,19 @@ emit_pattern (cairo_ps_surface_t *surface, cairo_pattern_t *pattern) * different pattern. */ switch (pattern->type) { - case CAIRO_PATTERN_SOLID: + case CAIRO_PATTERN_TYPE_SOLID: emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern); break; - case CAIRO_PATTERN_SURFACE: + case CAIRO_PATTERN_TYPE_SURFACE: emit_surface_pattern (surface, (cairo_surface_pattern_t *) pattern); break; - case CAIRO_PATTERN_LINEAR: + case CAIRO_PATTERN_TYPE_LINEAR: emit_linear_pattern (surface, (cairo_linear_pattern_t *) pattern); break; - case CAIRO_PATTERN_RADIAL: + case CAIRO_PATTERN_TYPE_RADIAL: emit_radial_pattern (surface, (cairo_radial_pattern_t *) pattern); break; } @@ -890,12 +890,12 @@ _cairo_ps_surface_composite (cairo_operator_t op, status = CAIRO_STATUS_SUCCESS; switch (src_pattern->type) { - case CAIRO_PATTERN_SOLID: + case CAIRO_PATTERN_TYPE_SOLID: _cairo_output_stream_printf (stream, "%% _cairo_ps_surface_composite: solid\n"); goto bail; - case CAIRO_PATTERN_SURFACE: + case CAIRO_PATTERN_TYPE_SURFACE: surface_pattern = (cairo_surface_pattern_t *) src_pattern; if (src_pattern->extend != CAIRO_EXTEND_NONE) { @@ -920,8 +920,8 @@ _cairo_ps_surface_composite (cairo_operator_t op, image, image_extra); break; - case CAIRO_PATTERN_LINEAR: - case CAIRO_PATTERN_RADIAL: + case CAIRO_PATTERN_TYPE_LINEAR: + case CAIRO_PATTERN_TYPE_RADIAL: _cairo_output_stream_printf (stream, "%% _cairo_ps_surface_composite: gradient\n"); goto bail; diff --git a/src/cairo-surface-fallback.c b/src/cairo-surface-fallback.c index 8f18ca33b..9dde31f23 100644 --- a/src/cairo-surface-fallback.c +++ b/src/cairo-surface-fallback.c @@ -576,7 +576,7 @@ _clip_and_composite_trapezoids (cairo_pattern_t *src, { cairo_surface_t *clip_surface = clip ? clip->surface : NULL; - if ((src->type == CAIRO_PATTERN_SOLID || op == CAIRO_OPERATOR_CLEAR) && + if ((src->type == CAIRO_PATTERN_TYPE_SOLID || op == CAIRO_OPERATOR_CLEAR) && !clip_surface) { const cairo_color_t *color; diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index 38c7c76b6..1ce7e890b 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -1047,7 +1047,7 @@ _categorize_composite_operation (cairo_xlib_surface_t *dst, if (!dst->buggy_repeat) return DO_RENDER; - if (src_pattern->type == CAIRO_PATTERN_SURFACE) + if (src_pattern->type == CAIRO_PATTERN_TYPE_SURFACE) { cairo_surface_pattern_t *surface_pattern = (cairo_surface_pattern_t *)src_pattern; diff --git a/src/cairo.h b/src/cairo.h index cc87b7e2b..f6187210b 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -1389,8 +1389,8 @@ cairo_pattern_status (cairo_pattern_t *pattern); * @CAIRO_PATTERN_TYPE_SOLID: The pattern is a solid (uniform) * color. It may be opaque or translucent. * @CAIRO_PATTERN_TYPE_SURFACE: The pattern is a based on a surface (an image). - * @CAIRO_PATTERN_TYPE_LINEAR_GRADIENT: The pattern is a linear gradient. - * @CAIRO_PATTERN_TYPE_RADIAL_GRADIENT: The pattern is a radial gradient. + * @CAIRO_PATTERN_TYPE_LINEAR: The pattern is a linear gradient. + * @CAIRO_PATTERN_TYPE_RADIAL: The pattern is a radial gradient. * * @cairo_pattern_type_t us used to describe the type of a given pattern. * @@ -1407,14 +1407,14 @@ cairo_pattern_status (cairo_pattern_t *pattern); * pattern will have no effect). A notable exception is * cairo_pattern_add_color_stop_rgb() and * cairo_pattern_add_color_stop_rgba() which must only be called with - * gradient patterns. Otherwise the pattern will be shutdown and put - * into an error state. + * gradient patterns (either LINEAR or RADIAL). Otherwise the pattern + * will be shutdown and put into an error state. */ typedef enum _cairo_pattern_type { CAIRO_PATTERN_TYPE_SOLID, CAIRO_PATTERN_TYPE_SURFACE, - CAIRO_PATTERN_TYPE_LINEAR_GRADIENT, - CAIRO_PATTERN_TYPE_RADIAL_GRADIENT + CAIRO_PATTERN_TYPE_LINEAR, + CAIRO_PATTERN_TYPE_RADIAL } cairo_pattern_type_t; cairo_public cairo_pattern_type_t diff --git a/src/cairoint.h b/src/cairoint.h index 88fccae11..ebf2b31d0 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -909,13 +909,6 @@ typedef enum { #define CAIRO_EXTEND_GRADIENT_DEFAULT CAIRO_EXTEND_PAD #define CAIRO_FILTER_DEFAULT CAIRO_FILTER_BEST -typedef enum { - CAIRO_PATTERN_SOLID, - CAIRO_PATTERN_SURFACE, - CAIRO_PATTERN_LINEAR, - CAIRO_PATTERN_RADIAL -} cairo_pattern_type_t; - struct _cairo_pattern { cairo_pattern_type_t type; unsigned int ref_count; From 5a3c30eafe0b77f69434e139a2e247c8eb4230d7 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 24 Feb 2006 15:32:26 -0800 Subject: [PATCH 05/13] Implement cairo_font_face_get_type. Add font type to font_face_backend. Also export new CAIRO_FONT_TYPE_TOY. --- src/cairo-atsui-font.c | 1 + src/cairo-font.c | 7 +++++++ src/cairo-ft-font.c | 1 + src/cairo-win32-font.c | 1 + src/cairo.h | 1 + src/cairoint.h | 3 +++ 6 files changed, 14 insertions(+) diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c index 9f3b54da1..572359f8d 100644 --- a/src/cairo-atsui-font.c +++ b/src/cairo-atsui-font.c @@ -94,6 +94,7 @@ _cairo_atsui_font_face_scaled_font_create (void *abstract_face, } static const cairo_font_face_backend_t _cairo_atsui_font_face_backend = { + CAIRO_FONT_TYPE_ATSUI, _cairo_atsui_font_face_destroy, _cairo_atsui_font_face_scaled_font_create }; diff --git a/src/cairo-font.c b/src/cairo-font.c index b0fab1b4a..bb184c48d 100644 --- a/src/cairo-font.c +++ b/src/cairo-font.c @@ -130,6 +130,12 @@ cairo_font_face_destroy (cairo_font_face_t *font_face) free (font_face); } +cairo_font_type_t +cairo_font_face_get_type (cairo_font_face_t *font_face) +{ + return font_face->backend->type; +} + /** * cairo_font_face_status: * @font_face: a #cairo_font_face_t @@ -409,6 +415,7 @@ _cairo_toy_font_face_scaled_font_create (void *abstract_font_face } static const cairo_font_face_backend_t _cairo_toy_font_face_backend = { + CAIRO_FONT_TYPE_TOY, _cairo_toy_font_face_destroy, _cairo_toy_font_face_scaled_font_create }; diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c index 45997444d..e159826a0 100644 --- a/src/cairo-ft-font.c +++ b/src/cairo-ft-font.c @@ -2004,6 +2004,7 @@ _cairo_ft_font_face_scaled_font_create (void *abstract_face, } static const cairo_font_face_backend_t _cairo_ft_font_face_backend = { + CAIRO_FONT_TYPE_FT, _cairo_ft_font_face_destroy, _cairo_ft_font_face_scaled_font_create }; diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c index 3343abfd4..ca8e4a610 100644 --- a/src/cairo-win32-font.c +++ b/src/cairo-win32-font.c @@ -1398,6 +1398,7 @@ _cairo_win32_font_face_scaled_font_create (void *abstract_face, } static const cairo_font_face_backend_t _cairo_win32_font_face_backend = { + CAIRO_FONT_TYPE_WIN32, _cairo_win32_font_face_destroy, _cairo_win32_font_face_scaled_font_create }; diff --git a/src/cairo.h b/src/cairo.h index f6187210b..5b38d18e4 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -928,6 +928,7 @@ cairo_font_face_status (cairo_font_face_t *font_face); * of the wrong type is undefined. */ typedef enum _cairo_font_type { + CAIRO_FONT_TYPE_TOY, CAIRO_FONT_TYPE_FT, CAIRO_FONT_TYPE_WIN32, CAIRO_FONT_TYPE_ATSUI diff --git a/src/cairoint.h b/src/cairoint.h index ebf2b31d0..401114cb7 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -464,6 +464,7 @@ struct _cairo_scaled_font { }; struct _cairo_font_face { + /* hash_entry must be first */ cairo_hash_entry_t hash_entry; cairo_status_t status; int ref_count; @@ -555,6 +556,8 @@ struct _cairo_scaled_font_backend { }; struct _cairo_font_face_backend { + cairo_font_type_t type; + /* The destroy() function is allowed to resurrect the font face * by re-referencing. This is needed for the FreeType backend. */ From 1769830e6eea08744830c1c7ea9220d56808831a Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 27 Feb 2006 17:22:45 -0800 Subject: [PATCH 06/13] Implement cairo_scaled_font_get_type --- src/cairo-atsui-font.c | 1 + src/cairo-ft-font.c | 1 + src/cairo-scaled-font.c | 6 ++++++ src/cairo-win32-font.c | 1 + src/cairoint.h | 2 ++ 5 files changed, 11 insertions(+) diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c index 572359f8d..9c5585178 100644 --- a/src/cairo-atsui-font.c +++ b/src/cairo-atsui-font.c @@ -664,6 +664,7 @@ _cairo_atsui_font_old_show_glyphs (void *abstract_font, } const cairo_scaled_font_backend_t cairo_atsui_scaled_font_backend = { + CAIRO_FONT_TYPE_ATSUI, _cairo_atsui_font_create_toy, _cairo_atsui_font_fini, _cairo_atsui_font_scaled_glyph_init, diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c index e159826a0..092838ab4 100644 --- a/src/cairo-ft-font.c +++ b/src/cairo-ft-font.c @@ -1901,6 +1901,7 @@ _cairo_ft_show_glyphs (void *abstract_font, } const cairo_scaled_font_backend_t cairo_ft_scaled_font_backend = { + CAIRO_FONT_TYPE_FT, _cairo_ft_scaled_font_create_toy, _cairo_ft_scaled_font_fini, _cairo_ft_scaled_glyph_init, diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c index 8ebbf455f..46e1caccf 100644 --- a/src/cairo-scaled-font.c +++ b/src/cairo-scaled-font.c @@ -118,6 +118,12 @@ _cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font, _cairo_error (status); } +cairo_font_type_t +cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font) +{ + return scaled_font->backend->type; +} + /** * cairo_scaled_font_status: * @scaled_font: a #cairo_scaled_font_t diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c index ca8e4a610..a3289fced 100644 --- a/src/cairo-win32-font.c +++ b/src/cairo-win32-font.c @@ -1355,6 +1355,7 @@ CLEANUP_FONT: } const cairo_scaled_font_backend_t cairo_win32_scaled_font_backend = { + CAIRO_FONT_TYPE_WIN32, _cairo_win32_scaled_font_create_toy, _cairo_win32_scaled_font_fini, _cairo_win32_scaled_font_glyph_init, diff --git a/src/cairoint.h b/src/cairoint.h index 401114cb7..a1978a90d 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -509,6 +509,8 @@ typedef enum _cairo_scaled_glyph_info { } cairo_scaled_glyph_info_t; struct _cairo_scaled_font_backend { + cairo_font_type_t type; + cairo_status_t (*create_toy) (cairo_toy_font_face_t *toy_face, const cairo_matrix_t *font_matrix, From 5ae0b9f912b7f5fd1700cbf18763a05493f55b62 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 27 Feb 2006 23:11:32 -0800 Subject: [PATCH 07/13] Implement cairo_surface_get_type --- src/cairo-directfb-surface.c | 1 + src/cairo-glitz-surface.c | 1 + src/cairo-image-surface.c | 1 + src/cairo-meta-surface.c | 1 + src/cairo-paginated-surface.c | 5 +++++ src/cairo-pdf-surface.c | 1 + src/cairo-ps-surface.c | 1 + src/cairo-surface.c | 15 +++++++++++++++ src/cairo-svg-surface.c | 1 + src/cairo-win32-surface.c | 1 + src/cairo-xcb-surface.c | 1 + src/cairo-xlib-surface.c | 1 + src/cairoint.h | 12 ++++++++++++ 13 files changed, 42 insertions(+) diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c index be1791584..a02e56bf4 100644 --- a/src/cairo-directfb-surface.c +++ b/src/cairo-directfb-surface.c @@ -662,6 +662,7 @@ _cairo_directfb_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph, static const cairo_surface_backend_t cairo_directfb_surface_backend = { + CAIRO_SURFACE_TYPE_DIRECTFB, _cairo_directfb_surface_create_similar, _cairo_directfb_surface_finish, _cairo_directfb_surface_acquire_source_image, diff --git a/src/cairo-glitz-surface.c b/src/cairo-glitz-surface.c index b62547236..667e231d5 100644 --- a/src/cairo-glitz-surface.c +++ b/src/cairo-glitz-surface.c @@ -2121,6 +2121,7 @@ _cairo_glitz_surface_flush (void *abstract_surface) } static const cairo_surface_backend_t cairo_glitz_surface_backend = { + CAIRO_SURFACE_TYPE_GLITZ, _cairo_glitz_surface_create_similar, _cairo_glitz_surface_finish, _cairo_glitz_surface_acquire_source_image, diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index 108e89b5e..06219464c 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -903,6 +903,7 @@ _cairo_surface_is_image (const cairo_surface_t *surface) } const cairo_surface_backend_t cairo_image_surface_backend = { + CAIRO_SURFACE_TYPE_IMAGE, _cairo_image_surface_create_similar, _cairo_image_surface_finish, _cairo_image_surface_acquire_source_image, diff --git a/src/cairo-meta-surface.c b/src/cairo-meta-surface.c index 6f824634c..f7aeb719c 100644 --- a/src/cairo-meta-surface.c +++ b/src/cairo-meta-surface.c @@ -557,6 +557,7 @@ _cairo_surface_is_meta (const cairo_surface_t *surface) } static const cairo_surface_backend_t cairo_meta_surface_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_META, _cairo_meta_surface_create_similar, _cairo_meta_surface_finish, _cairo_meta_surface_acquire_source_image, diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c index 6317d7083..4bb857265 100644 --- a/src/cairo-paginated-surface.c +++ b/src/cairo-paginated-surface.c @@ -111,6 +111,10 @@ _cairo_paginated_surface_create (cairo_surface_t *target, _cairo_surface_init (&surface->base, &cairo_paginated_surface_backend); + /* Override surface->base.type with target's type so we don't leak + * evidence of the paginated wrapper out to the user. */ + surface->base.type = cairo_surface_get_type (target); + surface->content = content; surface->width = width; surface->height = height; @@ -381,6 +385,7 @@ _cairo_paginated_surface_snapshot (void *abstract_other) } const cairo_surface_backend_t cairo_paginated_surface_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED, NULL, /* create_similar */ _cairo_paginated_surface_finish, _cairo_paginated_surface_acquire_source_image, diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index 289eeb961..cb8287bcf 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -1657,6 +1657,7 @@ _cairo_pdf_surface_get_font_options (void *abstract_surface, } static const cairo_surface_backend_t cairo_pdf_surface_backend = { + CAIRO_SURFACE_TYPE_PDF, _cairo_pdf_surface_create_similar, _cairo_pdf_surface_finish, NULL, /* acquire_source_image */ diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index 371290cc2..6028b6d50 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -1322,6 +1322,7 @@ _cairo_ps_surface_fill (void *abstract_surface, } static const cairo_surface_backend_t cairo_ps_surface_backend = { + CAIRO_SURFACE_TYPE_PS, NULL, /* create_similar */ _cairo_ps_surface_finish, NULL, /* acquire_source_image */ diff --git a/src/cairo-surface.c b/src/cairo-surface.c index 52aeafe46..a317e5b64 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -43,6 +43,7 @@ const cairo_surface_t _cairo_surface_nil = { &cairo_image_surface_backend, /* backend */ + CAIRO_SURFACE_TYPE_IMAGE, -1, /* ref_count */ CAIRO_STATUS_NO_MEMORY, /* status */ FALSE, /* finished */ @@ -59,6 +60,7 @@ const cairo_surface_t _cairo_surface_nil = { const cairo_surface_t _cairo_surface_nil_file_not_found = { &cairo_image_surface_backend, /* backend */ + CAIRO_SURFACE_TYPE_IMAGE, -1, /* ref_count */ CAIRO_STATUS_FILE_NOT_FOUND, /* status */ FALSE, /* finished */ @@ -75,6 +77,7 @@ const cairo_surface_t _cairo_surface_nil_file_not_found = { const cairo_surface_t _cairo_surface_nil_read_error = { &cairo_image_surface_backend, /* backend */ + CAIRO_SURFACE_TYPE_IMAGE, -1, /* ref_count */ CAIRO_STATUS_READ_ERROR, /* status */ FALSE, /* finished */ @@ -118,6 +121,16 @@ _cairo_surface_set_error (cairo_surface_t *surface, _cairo_error (status); } +cairo_surface_type_t +cairo_surface_get_type (cairo_surface_t *surface) +{ + /* We don't use surface->backend->type here so that some of the + * special "wrapper" surfaces such as cairo_paginated_surface_t + * can override surface->type with the type of the "child" + * surface. */ + return surface->type; +} + /** * cairo_surface_status: * @surface: a #cairo_surface_t @@ -141,6 +154,8 @@ _cairo_surface_init (cairo_surface_t *surface, const cairo_surface_backend_t *backend) { surface->backend = backend; + + surface->type = backend->type; surface->ref_count = 1; surface->status = CAIRO_STATUS_SUCCESS; diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c index 5a2c92fff..a5b02c9b8 100644 --- a/src/cairo-svg-surface.c +++ b/src/cairo-svg-surface.c @@ -1221,6 +1221,7 @@ _cairo_svg_surface_get_font_options (void *abstract_surface, static const cairo_surface_backend_t cairo_svg_surface_backend = { + CAIRO_SURFACE_TYPE_SVG, _cairo_svg_surface_create_similar, _cairo_svg_surface_finish, NULL, /* acquire_source_image */ diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c index b1811a134..9dacd1d37 100644 --- a/src/cairo-win32-surface.c +++ b/src/cairo-win32-surface.c @@ -1030,6 +1030,7 @@ _cairo_surface_is_win32 (cairo_surface_t *surface) } static const cairo_surface_backend_t cairo_win32_surface_backend = { + CAIRO_SURFACE_TYPE_WIN32, _cairo_win32_surface_create_similar, _cairo_win32_surface_finish, _cairo_win32_surface_acquire_source_image, diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c index faa207c0d..78eafc0fa 100644 --- a/src/cairo-xcb-surface.c +++ b/src/cairo-xcb-surface.c @@ -1025,6 +1025,7 @@ _cairo_xcb_surface_get_extents (void *abstract_surface, } static const cairo_surface_backend_t cairo_xcb_surface_backend = { + CAIRO_SURFACE_TYPE_XCB, _cairo_xcb_surface_create_similar, _cairo_xcb_surface_finish, _cairo_xcb_surface_acquire_source_image, diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c index 1ce7e890b..dc7d394e1 100644 --- a/src/cairo-xlib-surface.c +++ b/src/cairo-xlib-surface.c @@ -1675,6 +1675,7 @@ _cairo_xlib_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph, cairo_scaled_font_t *scaled_font); static const cairo_surface_backend_t cairo_xlib_surface_backend = { + CAIRO_SURFACE_TYPE_XLIB, _cairo_xlib_surface_create_similar, _cairo_xlib_surface_finish, _cairo_xlib_surface_acquire_source_image, diff --git a/src/cairoint.h b/src/cairoint.h index a1978a90d..124612346 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -256,6 +256,11 @@ typedef enum cairo_int_status { CAIRO_INT_STATUS_CACHE_EMPTY } cairo_int_status_t; +typedef enum cairo_internal_surface_type { + CAIRO_INTERNAL_SURFACE_TYPE_META = 0x1000, + CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED +} cairo_internal_surface_type_t; + typedef enum cairo_direction { CAIRO_DIRECTION_FORWARD, CAIRO_DIRECTION_REVERSE @@ -604,6 +609,8 @@ typedef struct _cairo_stroke_style { } cairo_stroke_style_t; struct _cairo_surface_backend { + cairo_surface_type_t type; + cairo_surface_t * (*create_similar) (void *surface, cairo_content_t content, @@ -834,6 +841,11 @@ typedef struct _cairo_format_masks { struct _cairo_surface { const cairo_surface_backend_t *backend; + /* We allow surfaces to override the backend->type by shoving something + * else into surface->type. This is for "wrapper" surfaces that want to + * hide their internal type from the user-level API. */ + cairo_surface_type_t type; + unsigned int ref_count; cairo_status_t status; cairo_bool_t finished; From 5797f814852bb4f6ef559890640b8cd24ec5fa45 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 27 Feb 2006 23:12:43 -0800 Subject: [PATCH 08/13] Implement cairo_pattern_get_type --- src/cairo-pattern.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index 27ede9a64..a9628a3c9 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -524,6 +524,12 @@ cairo_pattern_reference (cairo_pattern_t *pattern) return pattern; } +cairo_pattern_type_t +cairo_pattern_get_type (cairo_pattern_t *pattern) +{ + return pattern->type; +} + /** * cairo_pattern_status: * @pattern: a #cairo_pattern_t From cd84e2ab32fe4648f9d172cdefe08798336938d2 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 27 Feb 2006 23:15:45 -0800 Subject: [PATCH 09/13] Add documentation for cairo_font_face_get_type, cairo_scaled_font_get_type, cairo_surface_get_type, and cairo_pattern_get_type. --- src/cairo-font.c | 6 ++++++ src/cairo-pattern.c | 6 ++++++ src/cairo-scaled-font.c | 6 ++++++ src/cairo-surface.c | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/src/cairo-font.c b/src/cairo-font.c index bb184c48d..65124803d 100644 --- a/src/cairo-font.c +++ b/src/cairo-font.c @@ -130,6 +130,12 @@ cairo_font_face_destroy (cairo_font_face_t *font_face) free (font_face); } +/** + * cairo_font_face_get_type: + * @font_face: a #cairo_font_face_t + * + * Return value: The type of @font_face. See #cairo_font_type_t. + **/ cairo_font_type_t cairo_font_face_get_type (cairo_font_face_t *font_face) { diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c index a9628a3c9..8aa296988 100644 --- a/src/cairo-pattern.c +++ b/src/cairo-pattern.c @@ -524,6 +524,12 @@ cairo_pattern_reference (cairo_pattern_t *pattern) return pattern; } +/** + * cairo_pattern_get_type: + * @pattern: a #cairo_pattern_t + * + * Return value: The type of @pattern. See #cairo_pattern_type_t. + **/ cairo_pattern_type_t cairo_pattern_get_type (cairo_pattern_t *pattern) { diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c index 46e1caccf..a0469046d 100644 --- a/src/cairo-scaled-font.c +++ b/src/cairo-scaled-font.c @@ -118,6 +118,12 @@ _cairo_scaled_font_set_error (cairo_scaled_font_t *scaled_font, _cairo_error (status); } +/** + * cairo_scaled_font_get_type: + * @scaled_font: a #cairo_scaled_font_t + * + * Return value: The type of @scaled_font. See #cairo_font_type_t. + **/ cairo_font_type_t cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font) { diff --git a/src/cairo-surface.c b/src/cairo-surface.c index a317e5b64..b1a36df90 100644 --- a/src/cairo-surface.c +++ b/src/cairo-surface.c @@ -121,6 +121,12 @@ _cairo_surface_set_error (cairo_surface_t *surface, _cairo_error (status); } +/** + * cairo_surface_get_type: + * @surface: a #cairo_surface_t + * + * Return value: The type of @surface. See #cairo_surface_type_t. + **/ cairo_surface_type_t cairo_surface_get_type (cairo_surface_t *surface) { From 1dd6e417c10c90894c87565d4f7fa3f63e97f212 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 28 Feb 2006 00:55:27 -0800 Subject: [PATCH 10/13] Add testing for cairo_surface_get_type. All test targets now list an expected cairo_surface_type_t. Add notes on current limitations of PDF/PS/meta-surface support that causes CAIRO_CONTENT_COLOR similar surfaces of PDF and PS surfaces to be returned as image surfaces. Add cairo_internal_surface_type_t for the meta, paginated, and various test surfaces. --- src/cairo-paginated-surface.c | 20 ++++++- src/cairoint.h | 6 +- src/test-fallback-surface.c | 1 + src/test-meta-surface.c | 1 + test/cairo-test.c | 107 +++++++++++++++++++++++++--------- 5 files changed, 103 insertions(+), 32 deletions(-) diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c index 4bb857265..acfe44ad3 100644 --- a/src/cairo-paginated-surface.c +++ b/src/cairo-paginated-surface.c @@ -97,6 +97,24 @@ const cairo_private cairo_surface_backend_t cairo_paginated_surface_backend; static cairo_int_status_t _cairo_paginated_surface_show_page (void *abstract_surface); +/* XXX: This would seem the natural thing to do here. But currently, + * PDF and PS surfaces do not yet work as source surfaces. So instead, + * we don't implement create_similar for the paginate_surface which + * means that any create_similar() call on a paginated_surfacae will + * result in a new image surface. */ +#if 0 +static cairo_surface_t * +_cairo_paginated_surface_create_similar (void *abstract_surface, + cairo_content_t content, + int width, + int height) +{ + cairo_paginated_surface_t *surface = abstract_surface; + return cairo_surface_create_similar (surface->target, content, + width, height); +} +#endif + cairo_surface_t * _cairo_paginated_surface_create (cairo_surface_t *target, cairo_content_t content, @@ -386,7 +404,7 @@ _cairo_paginated_surface_snapshot (void *abstract_other) const cairo_surface_backend_t cairo_paginated_surface_backend = { CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED, - NULL, /* create_similar */ + NULL, /* create_similar --- see note for _cairo_paginated_surface_create_similar */ _cairo_paginated_surface_finish, _cairo_paginated_surface_acquire_source_image, _cairo_paginated_surface_release_source_image, diff --git a/src/cairoint.h b/src/cairoint.h index 124612346..8db52ae00 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -258,7 +258,10 @@ typedef enum cairo_int_status { typedef enum cairo_internal_surface_type { CAIRO_INTERNAL_SURFACE_TYPE_META = 0x1000, - CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED + CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED, + CAIRO_INTERNAL_SURFACE_TYPE_TEST_META, + CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK, + CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED } cairo_internal_surface_type_t; typedef enum cairo_direction { @@ -2157,7 +2160,6 @@ cairo_private int _cairo_dtostr (char *buffer, size_t size, double d); /* Avoid unnecessary PLT entries. */ - slim_hidden_proto(cairo_get_current_point) slim_hidden_proto(cairo_fill_preserve) slim_hidden_proto(cairo_clip_preserve) diff --git a/src/test-fallback-surface.c b/src/test-fallback-surface.c index fe0cc6fb5..cb8fd92a0 100644 --- a/src/test-fallback-surface.c +++ b/src/test-fallback-surface.c @@ -175,6 +175,7 @@ _test_fallback_surface_get_extents (void *abstract_surface, } const cairo_surface_backend_t test_fallback_surface_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK, _test_fallback_surface_create_similar, _test_fallback_surface_finish, _test_fallback_surface_acquire_source_image, diff --git a/src/test-meta-surface.c b/src/test-meta-surface.c index bdabf31d3..6d36fcab2 100644 --- a/src/test-meta-surface.c +++ b/src/test-meta-surface.c @@ -296,6 +296,7 @@ _test_meta_surface_snapshot (void *abstract_other) } const cairo_surface_backend_t test_meta_surface_backend = { + CAIRO_INTERNAL_SURFACE_TYPE_TEST_META, NULL, /* create_similar */ _test_meta_surface_finish, _test_meta_surface_acquire_source_image, diff --git a/test/cairo-test.c b/test/cairo-test.c index 557ccb6fd..d782a92f4 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -47,6 +47,20 @@ #include "write-png.h" #include "xmalloc.h" +/* This is copied from cairoint.h. That makes it painful to keep in + * sync, but the slim stuff makes cairoint.h "hard" to include when + * not actually building the cairo library itself. Fortunately, since + * we're checking all these values, we do have a safeguard for keeping + * them in sync. + */ +typedef enum cairo_internal_surface_type { + CAIRO_INTERNAL_SURFACE_TYPE_META = 0x1000, + CAIRO_INTERNAL_SURFACE_TYPE_PAGINATED, + CAIRO_INTERNAL_SURFACE_TYPE_TEST_META, + CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK, + CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED +} cairo_internal_surface_type_t; + #ifdef _MSC_VER #define vsnprintf _vsnprintf #define access _access @@ -163,6 +177,7 @@ typedef void typedef struct _cairo_test_target { const char *name; + cairo_surface_type_t expected_type; cairo_content_t content; cairo_test_create_target_surface_t create_target_surface; cairo_test_write_to_png_t write_to_png; @@ -1387,6 +1402,13 @@ cairo_test_for_target (cairo_test_t *test, goto UNWIND_STRINGS; } + if (cairo_surface_get_type (surface) != target->expected_type) { + cairo_test_log ("Error: Created surface is of type %d (expected %d)\n", + cairo_surface_get_type (surface), target->expected_type); + ret = CAIRO_TEST_FAILURE; + goto UNWIND_SURFACE; + } + cr = cairo_create (surface); /* Clear to transparent (or black) depending on whether the target @@ -1436,6 +1458,7 @@ cairo_test_for_target (cairo_test_t *test, UNWIND_CAIRO: cairo_destroy (cr); +UNWIND_SURFACE: cairo_surface_destroy (surface); cairo_debug_reset_static_data (); @@ -1461,102 +1484,128 @@ cairo_test_expecting (cairo_test_t *test, cairo_test_draw_function_t draw, cairo_test_target_t **targets_to_test; cairo_test_target_t targets[] = { - { "image", CAIRO_CONTENT_COLOR_ALPHA, + { "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR_ALPHA, create_image_surface, cairo_surface_write_to_png, NULL}, - { "image", CAIRO_CONTENT_COLOR, + { "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, create_image_surface, cairo_surface_write_to_png, NULL}, #ifdef CAIRO_HAS_TEST_SURFACES - { "test-fallback", CAIRO_CONTENT_COLOR_ALPHA, + { "test-fallback", CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK, + CAIRO_CONTENT_COLOR_ALPHA, create_test_fallback_surface, cairo_surface_write_to_png, NULL }, - { "test-fallback", CAIRO_CONTENT_COLOR, + { "test-fallback", CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK, + CAIRO_CONTENT_COLOR, create_test_fallback_surface, cairo_surface_write_to_png, NULL }, - { "test-meta", CAIRO_CONTENT_COLOR_ALPHA, + { "test-meta", CAIRO_INTERNAL_SURFACE_TYPE_TEST_META, + CAIRO_CONTENT_COLOR_ALPHA, create_test_meta_surface, cairo_surface_write_to_png, NULL }, - { "test-meta", CAIRO_CONTENT_COLOR, + { "test-meta", CAIRO_INTERNAL_SURFACE_TYPE_TEST_META, + CAIRO_CONTENT_COLOR, create_test_meta_surface, cairo_surface_write_to_png, NULL }, - { "test-paginated", CAIRO_CONTENT_COLOR_ALPHA, + { "test-paginated", CAIRO_SURFACE_TYPE_IMAGE, + CAIRO_CONTENT_COLOR_ALPHA, create_test_paginated_surface, test_paginated_write_to_png, cleanup_test_paginated }, - { "test-paginated", CAIRO_CONTENT_COLOR, + { "test-paginated", CAIRO_SURFACE_TYPE_IMAGE, + CAIRO_CONTENT_COLOR, create_test_paginated_surface, test_paginated_write_to_png, cleanup_test_paginated }, #endif #ifdef CAIRO_HAS_GLITZ_SURFACE #if CAIRO_CAN_TEST_GLITZ_GLX_SURFACE - { "glitz-glx", CAIRO_CONTENT_COLOR_ALPHA, + { "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ,CAIRO_CONTENT_COLOR_ALPHA, create_cairo_glitz_glx_surface, cairo_surface_write_to_png, cleanup_cairo_glitz_glx }, - { "glitz-glx", CAIRO_CONTENT_COLOR, + { "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, create_cairo_glitz_glx_surface, cairo_surface_write_to_png, cleanup_cairo_glitz_glx }, #endif #if CAIRO_CAN_TEST_GLITZ_AGL_SURFACE - { "glitz-agl", CAIRO_CONTENT_COLOR_ALPHA, + { "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA, create_cairo_glitz_agl_surface, cairo_surface_write_to_png, cleanup_cairo_glitz_agl }, - { "glitz-agl", CAIRO_CONTENT_COLOR, + { "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, create_cairo_glitz_agl_surface, cairo_surface_write_to_png, cleanup_cairo_glitz_agl }, #endif #if CAIRO_CAN_TEST_GLITZ_WGL_SURFACE - { "glitz-wgl", CAIRO_CONTENT_COLOR_ALPHA, + { "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA, create_cairo_glitz_wgl_surface, cairo_surface_write_to_png, cleanup_cairo_glitz_wgl }, - { "glitz-wgl", CAIRO_CONTENT_COLOR, + { "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, create_cairo_glitz_wgl_surface, cairo_surface_write_to_png, cleanup_cairo_glitz_wgl }, #endif #endif /* CAIRO_HAS_GLITZ_SURFACE */ #if 0 && CAIRO_HAS_QUARTZ_SURFACE - { "quartz", CAIRO_CONTENT_COLOR, + { "quartz", CAIRO_SURFACE_TYPE_QUARTZ, CAIRO_CONTENT_COLOR, create_quartz_surface, cairo_surface_write_to_png, cleanup_quartz }, #endif #if CAIRO_HAS_WIN32_SURFACE - { "win32", CAIRO_CONTENT_COLOR, + { "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR, create_win32_surface, cairo_surface_write_to_png, cleanup_win32 }, #endif #if CAIRO_HAS_XCB_SURFACE - { "xcb", CAIRO_CONTENT_COLOR_ALPHA, + { "xcb", CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA, create_xcb_surface, cairo_surface_write_to_png, cleanup_xcb}, #endif #if CAIRO_HAS_XLIB_SURFACE - { "xlib", CAIRO_CONTENT_COLOR_ALPHA, + { "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR_ALPHA, create_xlib_surface, cairo_surface_write_to_png, cleanup_xlib}, - { "xlib", CAIRO_CONTENT_COLOR, + { "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR, create_xlib_surface, cairo_surface_write_to_png, cleanup_xlib}, #endif #if CAIRO_HAS_PS_SURFACE - { "ps", CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, + { "ps", CAIRO_SURFACE_TYPE_PS, + CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, create_ps_surface, ps_surface_write_to_png, cleanup_ps }, - { "ps", CAIRO_CONTENT_COLOR, + + /* XXX: We expect type image here only due to a limitation in + * the current PS/meta-surface code. A PS surface is + * "naturally" COLOR_ALPHA, so the COLOR-only variant goes + * through create_similar in create_ps_surface which results + * in the similar surface being used as a source. We do not yet + * have source support for PS/meta-surfaces, so the + * create_similar path for all paginated surfaces currently + * returns an image surface.*/ + { "ps", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, create_ps_surface, ps_surface_write_to_png, cleanup_ps }, #endif #if CAIRO_HAS_PDF_SURFACE && CAIRO_CAN_TEST_PDF_SURFACE - { "pdf", CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, + { "pdf", CAIRO_SURFACE_TYPE_PDF, + CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, create_pdf_surface, pdf_surface_write_to_png, cleanup_pdf }, - { "pdf", CAIRO_CONTENT_COLOR, + + /* XXX: We expect type image here only due to a limitation in + * the current PDF/meta-surface code. A PDF surface is + * "naturally" COLOR_ALPHA, so the COLOR-only variant goes + * through create_similar in create_pdf_surface which results + * in the similar surface being used as a source. We do not yet + * have source support for PDF/meta-surfaces, so the + * create_similar path for all paginated surfaces currently + * returns an image surface.*/ + { "pdf", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, create_pdf_surface, pdf_surface_write_to_png, cleanup_pdf }, #endif #if CAIRO_HAS_SVG_SURFACE && CAIRO_CAN_TEST_SVG_SURFACE - { "svg", CAIRO_CONTENT_COLOR_ALPHA, + { "svg", CAIRO_SURFACE_TYPE_SVG, CAIRO_CONTENT_COLOR_ALPHA, create_svg_surface, svg_surface_write_to_png, cleanup_svg }, #endif #if CAIRO_HAS_BEOS_SURFACE - { "beos", CAIRO_CONTENT_COLOR, + { "beos", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR, create_beos_surface, cairo_surface_write_to_png, cleanup_beos}, - { "beos_bitmap", CAIRO_CONTENT_COLOR, + { "beos_bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR, create_beos_bitmap_surface, cairo_surface_write_to_png, cleanup_beos_bitmap}, - { "beos_bitmap", CAIRO_CONTENT_COLOR_ALPHA, + { "beos_bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR_ALPHA, create_beos_bitmap_surface, cairo_surface_write_to_png, cleanup_beos_bitmap}, #endif #if CAIRO_HAS_DIRECTFB_SURFACE - { "directfb", CAIRO_CONTENT_COLOR, + { "directfb", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR, create_directfb_surface, cairo_surface_write_to_png, cleanup_directfb}, - { "directfb_bitmap", CAIRO_CONTENT_COLOR_ALPHA, + { "directfb_bitmap", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR_ALPHA, create_directfb_bitmap_surface, cairo_surface_write_to_png,cleanup_directfb}, #endif }; From f9534c856a71b0f56a1e5bc58141b7bc192a27e8 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 28 Feb 2006 01:30:58 -0800 Subject: [PATCH 11/13] test/pattern-get-type: Add new test case for cairo_pattern_get_type. --- test/.gitignore | 1 + test/Makefile.am | 2 ++ test/pattern-get-type.c | 74 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 test/pattern-get-type.c diff --git a/test/.gitignore b/test/.gitignore index 5173349b2..30554c8f1 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -43,6 +43,7 @@ operator-source paint paint-with-alpha path-data +pattern-get-type pdf2png png-flatten svg2png diff --git a/test/Makefile.am b/test/Makefile.am index 0da8b5a74..0d866365f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -35,6 +35,7 @@ operator-source \ paint \ paint-with-alpha \ path-data \ +pattern-get-type \ pixman-rotate \ rectangle-rounding-error \ scale-source-surface-paint \ @@ -317,6 +318,7 @@ operator_source_LDADD = $(LDADDS) paint_LDADD = $(LDADDS) paint_with_alpha_LDADD = $(LDADDS) path_data_LDADD = $(LDADDS) +pattern_get_type_LDADD = $(LDADDS) svg_surface_LDADD = $(LDADDS) svg_clip_LDADD = $(LDADDS) pixman_rotate_LDADD = $(LDADDS) diff --git a/test/pattern-get-type.c b/test/pattern-get-type.c new file mode 100644 index 000000000..0e8fe255d --- /dev/null +++ b/test/pattern-get-type.c @@ -0,0 +1,74 @@ +/* + * Copyright © 2005 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Red Hat, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Red Hat, Inc. makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Carl D. Worth + */ + +#include "cairo-test.h" + +int +main (void) +{ + cairo_surface_t *surface; + cairo_pattern_t *solid_rgb, *solid_rgba, *surface_pattern, *linear, *radial; + + cairo_test_init ("pattern-get-type"); + + cairo_test_log ("Creating patterns of all types\n"); + + solid_rgb = cairo_pattern_create_rgb (0.0, 0.1, 0.2); + solid_rgba = cairo_pattern_create_rgba (0.3, 0.4, 0.5, 0.6); + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + 1, 1); + surface_pattern = cairo_pattern_create_for_surface (surface); + linear = cairo_pattern_create_linear (0.0, 0.0, 10.0, 10.0); + radial = cairo_pattern_create_radial (10.0, 10.0, 0.1, + 10.0, 10.0, 1.0); + + cairo_test_log ("Verifying return values of cairo_pattern_get_type\n"); + + if (cairo_pattern_get_type (solid_rgb) != CAIRO_PATTERN_TYPE_SOLID) + return CAIRO_TEST_FAILURE; + + if (cairo_pattern_get_type (solid_rgba) != CAIRO_PATTERN_TYPE_SOLID) + return CAIRO_TEST_FAILURE; + + if (cairo_pattern_get_type (surface_pattern) != CAIRO_PATTERN_TYPE_SURFACE) + return CAIRO_TEST_FAILURE; + + if (cairo_pattern_get_type (linear) != CAIRO_PATTERN_TYPE_LINEAR) + return CAIRO_TEST_FAILURE; + + if (cairo_pattern_get_type (radial) != CAIRO_PATTERN_TYPE_RADIAL) + return CAIRO_TEST_FAILURE; + + cairo_test_log ("Cleaning up\n"); + + cairo_pattern_destroy (solid_rgb); + cairo_pattern_destroy (solid_rgba); + cairo_pattern_destroy (surface_pattern); + cairo_surface_destroy (surface); + cairo_pattern_destroy (linear); + cairo_pattern_destroy (radial); + + return CAIRO_TEST_SUCCESS; +} From bd2136a23f8a3d5f6a1306d18499fdcfc1e87f48 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 28 Feb 2006 01:31:15 -0800 Subject: [PATCH 12/13] Correct copyright date --- test/pattern-get-type.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pattern-get-type.c b/test/pattern-get-type.c index 0e8fe255d..a6aba03aa 100644 --- a/test/pattern-get-type.c +++ b/test/pattern-get-type.c @@ -1,5 +1,5 @@ /* - * Copyright © 2005 Red Hat, Inc. + * Copyright © 2006 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without From 210dd59a7441424f71658ca248f6657482c74c7e Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 28 Feb 2006 02:30:27 -0800 Subject: [PATCH 13/13] Add some basic testing of cairo_font_face_get_type and cairo_scaled_font_get_type. --- test/.gitignore | 1 + test/Makefile.am | 2 + test/font-face-get-type.c | 64 +++++++++++++++++++++++++++++++ test/ft-font-create-for-ft-face.c | 14 +++++++ 4 files changed, 81 insertions(+) create mode 100644 test/font-face-get-type.c diff --git a/test/.gitignore b/test/.gitignore index 30554c8f1..65741ca63 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -24,6 +24,7 @@ fill-and-stroke fill-rule filter-nearest-offset ft-font-create-for-ft-face +font-face-get-type get-and-set gradient-alpha imagediff diff --git a/test/Makefile.am b/test/Makefile.am index 0d866365f..8a67fc53e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -20,6 +20,7 @@ extend-reflect \ fill-and-stroke \ fill-rule \ filter-nearest-offset \ +font-face-get-type \ get-and-set \ gradient-alpha \ leaky-polygon \ @@ -300,6 +301,7 @@ dash_offset_negative_LDADD = $(LDADDS) extend_reflect_LDADD = $(LDADDS) fill_and_stroke_LDADD = $(LDADDS) fill_rule_LDADD = $(LDADDS) +font_face_get_type_LDADD = $(LDADDS) filter_nearest_offset_LDADD = $(LDADDS) ft_font_create_for_ft_face_LDADD = $(LDADDS) get_and_set_LDADD = $(LDADDS) diff --git a/test/font-face-get-type.c b/test/font-face-get-type.c new file mode 100644 index 000000000..c21d5c238 --- /dev/null +++ b/test/font-face-get-type.c @@ -0,0 +1,64 @@ +/* + * Copyright © 2006 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Red Hat, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Red Hat, Inc. makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Carl D. Worth + */ + +#include "cairo-test.h" + +int +main (void) +{ + cairo_surface_t *surface; + cairo_t *cr; + cairo_font_face_t *font_face; + + cairo_test_init ("font-face-get-type"); + + cairo_test_log ("Creating cairo context and obtaining a font face\n"); + + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); + cr = cairo_create (surface); + + cairo_select_font_face (cr, "Bitstream Vera Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + + font_face = cairo_get_font_face (cr); + + cairo_test_log ("Testing return value of cairo_font_face_get_type\n"); + + if (cairo_font_face_get_type (font_face) != CAIRO_FONT_TYPE_TOY) { + cairo_test_log ("Unexpected value %d from cairo_font_face_get_type (expected %d)\n", + cairo_font_face_get_type (font_face), CAIRO_FONT_TYPE_TOY); + return CAIRO_TEST_FAILURE; + } + + cairo_destroy (cr); + cairo_surface_destroy (surface); + + return CAIRO_TEST_SUCCESS; +} + + + + diff --git a/test/ft-font-create-for-ft-face.c b/test/ft-font-create-for-ft-face.c index bf668b9d8..0bb3b8c0d 100644 --- a/test/ft-font-create-for-ft-face.c +++ b/test/ft-font-create-for-ft-face.c @@ -64,6 +64,13 @@ draw (cairo_t *cr, int width, int height) font_face = cairo_ft_font_face_create_for_pattern (resolved); + if (cairo_font_face_get_type (font_face) != CAIRO_FONT_TYPE_FT) { + cairo_test_log ("Unexpected value from cairo_font_face_get_type: %d (expected %d)\n", + cairo_font_face_get_type (font_face), CAIRO_FONT_TYPE_FT); + cairo_font_face_destroy (font_face); + return CAIRO_TEST_FAILURE; + } + cairo_matrix_init_identity (&font_matrix); cairo_get_matrix (cr, &ctm); @@ -82,6 +89,13 @@ draw (cairo_t *cr, int width, int height) FcPatternDestroy (pattern); FcPatternDestroy (resolved); + if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_FT) { + cairo_test_log ("Unexpected value from cairo_scaled_font_get_type: %d (expected %d)\n", + cairo_scaled_font_get_type (scaled_font), CAIRO_FONT_TYPE_FT); + cairo_scaled_font_destroy (scaled_font); + return CAIRO_TEST_FAILURE; + } + if (!ft_face) { cairo_test_log ("Failed to get an ft_face with cairo_ft_scaled_font_lock_face\n"); cairo_scaled_font_destroy (scaled_font);