Beispiel #1
0
static cairo_bool_t
cairo_test_target_has_similar (const cairo_test_t *test, cairo_boilerplate_target_t *target)
{
    cairo_surface_t *surface;
    cairo_bool_t has_similar = FALSE;

    /* ignore image intermediate targets */
    if (target->expected_type == CAIRO_SURFACE_TYPE_IMAGE)
	return FALSE;

    if (getenv ("CAIRO_TEST_IGNORE_SIMILAR"))
	return FALSE;

    surface = (target->create_surface) (test->name,
					target->content,
					test->width,
					test->height,
					CAIRO_BOILERPLATE_MODE_TEST,
					&target->closure);
    if (surface != NULL) {
	cairo_t * cr = cairo_create (surface);
	cairo_surface_t *similar;
	cairo_push_group_with_content (cr, target->content);
	similar = cairo_get_group_target (cr);
	has_similar = cairo_surface_get_type (similar) == cairo_surface_get_type (surface);

	cairo_destroy (cr);
	cairo_surface_destroy (surface);

	if (target->cleanup)
	    target->cleanup (target->closure);
    }

    return has_similar;
}
Beispiel #2
0
static JSBool
getGroupTarget_func(JSContext *context,
                    unsigned   argc,
                    jsval     *vp)
{
    JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
    JSObject *obj = JSVAL_TO_OBJECT(rec.thisv());

    cairo_t *cr;
    cairo_surface_t *surface;
    JSObject *surface_wrapper;

    if (argc > 0) {
        gjs_throw(context, "Context.getGroupTarget() takes no arguments");
        return JS_FALSE;
    }

    cr = gjs_cairo_context_get_context(context, obj);
    surface = cairo_get_group_target(cr);
    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
        return JS_FALSE;

    /* surface belongs to the context, so keep the reference */
    surface_wrapper = gjs_cairo_surface_from_surface(context, surface);
    if (!surface_wrapper) {
        /* exception already set */
        return JS_FALSE;
    }

    rec.rval().set(OBJECT_TO_JSVAL(surface_wrapper));

    return JS_TRUE;
}
static void
set_surface_pattern (cairo_t *cr, int x, int y)
{
    cairo_surface_t *source_surface;
    cairo_t *cr2;

    double width = (int)(0.6 * WIDTH);
    double height = (int)(0.6 * HEIGHT);
    x += 0.2 * WIDTH;
    y += 0.2 * HEIGHT;

    source_surface = cairo_surface_create_similar (cairo_get_group_target (cr),
						   CAIRO_CONTENT_COLOR_ALPHA,
						   width, height);
    cr2 = cairo_create (source_surface);
    cairo_surface_destroy (source_surface);

    cairo_set_source_rgb (cr2, 1, 0, 0); /* red */
    cairo_paint (cr2);

    cairo_set_source_rgb (cr2, 1, 1, 1); /* white */

    cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.5 * height, 0, 2 * M_PI);
    cairo_fill (cr2);

    cairo_set_source_surface (cr, cairo_get_target (cr2), x, y);
    cairo_destroy (cr2);
}
Beispiel #4
0
cairo_surface_t *
BitmapSource::GetSurface (cairo_t *cr)
{
	if (image_surface == NULL)
		return NULL;

	if (native_surface)
		return native_surface;
	
	if (cr == NULL)
		return image_surface;

	native_surface = cairo_surface_create_similar (cairo_get_group_target (cr), 
						       cairo_surface_get_content (image_surface), 
						       GetPixelWidth (), GetPixelHeight ());

	cairo_t *context = cairo_create (native_surface);

	cairo_set_source_surface (context, image_surface, 0, 0);
	cairo_pattern_set_filter (cairo_get_source (context), CAIRO_FILTER_FAST);

	cairo_paint (context);
	cairo_destroy (context);

	return native_surface;
}
Beispiel #5
0
static bool
getGroupTarget_func(JSContext *context,
                    unsigned   argc,
                    JS::Value *vp)
{
    GJS_GET_PRIV(context, argc, vp, rec, obj, GjsCairoContext, priv);
    cairo_t *cr = priv ? priv->cr : NULL;
    cairo_surface_t *surface;
    JSObject *surface_wrapper;

    if (argc > 0) {
        gjs_throw(context, "Context.getGroupTarget() takes no arguments");
        return false;
    }

    surface = cairo_get_group_target(cr);
    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
        return false;

    /* surface belongs to the context, so keep the reference */
    surface_wrapper = gjs_cairo_surface_from_surface(context, surface);
    if (!surface_wrapper) {
        /* exception already set */
        return false;
    }

    rec.rval().setObject(*surface_wrapper);

    return true;
}
Beispiel #6
0
static void
draw_mask (cairo_t *cr, int x, int y)
{
    cairo_surface_t *mask_surface;
    cairo_t *cr2;

    double width = (int)(0.9 * WIDTH);
    double height = (int)(0.9 * HEIGHT);
    x += 0.05 * WIDTH;
    y += 0.05 * HEIGHT;

    mask_surface = cairo_surface_create_similar (cairo_get_group_target (cr),
						 CAIRO_CONTENT_ALPHA,
						 width, height);
    cr2 = cairo_create (mask_surface);
    cairo_surface_destroy (mask_surface);

    cairo_save (cr2);
    cairo_set_source_rgba (cr2, 0, 0, 0, 0); /* transparent */
    cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
    cairo_paint (cr2);
    cairo_restore (cr2);

    cairo_set_source_rgb (cr2, 1, 1, 1); /* white */

    cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.45 * height, 0, 2 * M_PI);
    cairo_fill (cr2);

    cairo_mask_surface (cr, cairo_get_target (cr2), x, y);
    cairo_destroy (cr2);
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *surface, *target;
    cairo_t *cr2;

    /* First draw a shape in blue on the original destination. */
    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
    draw_square (cr);

    /* Then, create an offset surface and repeat the drawing in red. */
    target = cairo_get_group_target (cr);
    surface = cairo_surface_create_similar (target,
					    cairo_surface_get_content (target),
					    SIZE / 2, SIZE / 2);
    cr2 = cairo_create (surface);

    cairo_set_source_rgb (cr2, 1, 0, 0); /* red */
    draw_square (cr2);

    cairo_destroy (cr2);

    cairo_surface_set_device_offset (surface, + SIZE / 2, + SIZE / 2);

    /* Finally, copy the offset surface to the original destination.
    * The final result should be a blue square with the upper-left
    * quarter red. */
    cairo_set_source_surface (cr, surface, SIZE / 2, SIZE / 2);

    cairo_paint (cr);

    cairo_surface_destroy (surface);

    return CAIRO_TEST_SUCCESS;
}
	void clear (VGDevice * dev, int w, int h)
	{
		cairo_t * cr = (cairo_t *)dev->GetNativeContext();
		cairo_surface_t * surface = cairo_get_group_target (cr);
		int*  data = (int *)cairo_image_surface_get_data (surface);
		for (int i=0, n=w*h; i<n; i++) *data++ = 0;
	}
Beispiel #9
0
static void
draw_mask (cairo_t *cr)
{
    cairo_surface_t *surface;
    cairo_t *cr2;

    surface = cairo_surface_create_similar (cairo_get_group_target (cr),
	                                    CAIRO_CONTENT_ALPHA,
					    50, 50);
    cr2 = cairo_create (surface);
    cairo_surface_destroy (surface);

    cairo_rectangle (cr2,
	             0, 0,
	             40, 40);
    cairo_rectangle (cr2,
	             10, 10,
	             40, 40);
    cairo_clip (cr2);

    cairo_move_to (cr2, 0, 25);
    cairo_line_to (cr2, 50, 25);
    cairo_move_to (cr2, 25, 0);
    cairo_line_to (cr2, 25, 50);
    cairo_set_source_rgb (cr2, 1, 1, 1);
    cairo_stroke (cr2);

    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_mask_surface (cr, cairo_get_target (cr2), 50, 50);
    cairo_destroy (cr2);
}
Beispiel #10
0
static JSBool
getGroupTarget_func(JSContext *context,
                    uintN      argc,
                    jsval     *vp)
{
    JSObject *obj = JS_THIS_OBJECT(context, vp);
    cairo_t *cr;
    cairo_surface_t *surface;
    JSObject *surface_wrapper;

    if (argc > 0) {
        gjs_throw(context, "Context.getGroupTarget() takes no arguments");
        return JS_FALSE;
    }

    cr = gjs_cairo_context_get_context(context, obj);
    surface = cairo_get_group_target(cr);
    if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
        return JS_FALSE;

    /* surface belongs to the context, so keep the reference */
    surface_wrapper = gjs_cairo_surface_from_surface(context, surface);
    if (!surface_wrapper) {
        /* exception already set */
        return JS_FALSE;
    }

    JS_SET_RVAL(context, vp, OBJECT_TO_JSVAL(surface_wrapper));

    return JS_TRUE;
}
Beispiel #11
0
	value lime_cairo_get_group_target (value handle) {
		
		cairo_surface_t* surface = cairo_get_group_target ((cairo_t*)val_data (handle));
		cairo_surface_reference (surface);
		return CFFIPointer (surface, gc_cairo_surface);
		
	}
Beispiel #12
0
static int
cr_get_group_target (lua_State *L) {
    cairo_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_CONTEXT);
    SurfaceUserdata *surface = create_surface_userdata(L);
    surface->surface = cairo_get_group_target(*obj);
    cairo_surface_reference(surface->surface);
    return 1;
}
Beispiel #13
0
static PyObject *
pycairo_get_group_target (PycairoContext *o) {
  cairo_surface_t *surface = cairo_get_group_target (o->ctx);
  if (surface != NULL)
    return PycairoSurface_FromSurface (cairo_surface_reference (surface),
				       NULL);
  Py_RETURN_NONE;
}
Beispiel #14
0
na_tray_child_expose_event (GtkWidget      *widget,
                            GdkEventExpose *event)
#endif
{
  NaTrayChild *child = NA_TRAY_CHILD (widget);
  GdkWindow *window = gtk_widget_get_window (widget);

  if (na_tray_child_has_alpha (child))
    {
      /* Clear to transparent */
#if !GTK_CHECK_VERSION (3, 0, 0)
      cairo_t *cr = gdk_cairo_create (window);
#endif
      cairo_set_source_rgba (cr, 0, 0, 0, 0);
      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
#if GTK_CHECK_VERSION (3, 0, 0)
      cairo_paint (cr);
#else
      gdk_cairo_region (cr, event->region);
      cairo_fill (cr);
      cairo_destroy (cr);
#endif
    }
  else if (child->parent_relative_bg)
    {
      /* Clear to parent-relative pixmap */
#if GTK_CHECK_VERSION (3, 0, 0)
      GdkWindow *window;
      cairo_surface_t *target;
      GdkRectangle clip_rect;

      window = gtk_widget_get_window (widget);
      target = cairo_get_group_target (cr);

      gdk_cairo_get_clip_rectangle (cr, &clip_rect);

      /* Clear to parent-relative pixmap
       * We need to use direct X access here because GDK doesn't know about
       * the parent relative pixmap. */
      cairo_surface_flush (target);

      XClearArea (GDK_WINDOW_XDISPLAY (window),
                  GDK_WINDOW_XID (window),
                  clip_rect.x, clip_rect.y,
                  clip_rect.width, clip_rect.height,
                  False);
      cairo_surface_mark_dirty_rectangle (target,
                                          clip_rect.x, clip_rect.y,
                                          clip_rect.width, clip_rect.height);
#else
      gdk_window_clear_area (window,
                             event->area.x, event->area.y,
                             event->area.width, event->area.height);
#endif
    }

  return FALSE;
}
Beispiel #15
0
/* This test is designed to test painting a recording surface pattern with
 * CAIRO_EXTEND_NONE and a non identity pattern matrix.
 */
static cairo_pattern_t *create_pattern (cairo_t *target)
{
    cairo_surface_t *surface;
    cairo_pattern_t *pattern;
    cairo_t *cr;

    surface = cairo_surface_create_similar (cairo_get_group_target (target),
					    CAIRO_CONTENT_COLOR_ALPHA,
					    PAT_WIDTH, PAT_HEIGHT);
    cr = cairo_create (surface);
    cairo_surface_destroy (surface);

    cairo_set_source_rgba (cr, 1, 0, 1, 0.5);
    cairo_rectangle (cr, PAT_WIDTH/6.0, PAT_HEIGHT/6.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
    cairo_fill (cr);

    cairo_set_source_rgba (cr, 0, 1, 1, 0.5);
    cairo_rectangle (cr, PAT_WIDTH/2.0, PAT_HEIGHT/2.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
    cairo_fill (cr);

    cairo_set_line_width (cr, 1);
    cairo_move_to (cr, PAT_WIDTH/6.0, 0);
    cairo_line_to (cr, 0, 0);
    cairo_line_to (cr, 0, PAT_HEIGHT/6.0);
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_stroke (cr);
    cairo_move_to (cr, PAT_WIDTH/6.0, PAT_HEIGHT);
    cairo_line_to (cr, 0, PAT_HEIGHT);
    cairo_line_to (cr, 0, 5*PAT_HEIGHT/6.0);
    cairo_set_source_rgb (cr, 0, 1, 0);
    cairo_stroke (cr);
    cairo_move_to (cr, 5*PAT_WIDTH/6.0, 0);
    cairo_line_to (cr, PAT_WIDTH, 0);
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/6.0);
    cairo_set_source_rgb (cr, 0, 0, 1);
    cairo_stroke (cr);
    cairo_move_to (cr, 5*PAT_WIDTH/6.0, PAT_HEIGHT);
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT);
    cairo_line_to (cr, PAT_WIDTH, 5*PAT_HEIGHT/6.0);
    cairo_set_source_rgb (cr, 1, 1, 0);
    cairo_stroke (cr);

    cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
    cairo_set_line_width (cr, PAT_WIDTH/10.0);

    cairo_move_to (cr, 0,         PAT_HEIGHT/4.0);
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/4.0);
    cairo_stroke (cr);

    cairo_move_to (cr, PAT_WIDTH/4.0,         0);
    cairo_line_to (cr, PAT_WIDTH/4.0, PAT_WIDTH);
    cairo_stroke (cr);

    pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
    cairo_destroy (cr);

    return pattern;
}
	void bimap_copy (VGDevice * dev, jint* dstBitmap, int w, int h)
	{
		cairo_t * cr = (cairo_t *)dev->GetNativeContext();
		cairo_surface_t * surface = cairo_get_group_target (cr);
		int*  data = (int *)cairo_image_surface_get_data (surface);
		for (int i=0, n=w*h; i<n; i++) {
			*dstBitmap++ = *data++;
		}
	}
Beispiel #17
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *target_surface;
    cairo_t *cr2, *cr3;

    target_surface = cairo_get_group_target (cr);

    cr2 = cairo_create (target_surface);

    /* Draw a diagonal line and clip to it */

    cairo_move_to (cr2, BORDER,                     BORDER);
    cairo_line_to (cr2, BORDER + LINE_WIDTH,        BORDER);
    cairo_line_to (cr2, SIZE - BORDER,              SIZE - BORDER);
    cairo_line_to (cr2, SIZE - BORDER - LINE_WIDTH, SIZE - BORDER);

    cairo_clip (cr2);
    cairo_set_source_rgb (cr2, 0, 0, 1); /* Blue */
    cairo_paint (cr2);

    /* Clipping affects this cairo_t */

    cairo_set_source_rgb (cr2, 1, 1, 1); /* White */
    cairo_rectangle (cr2,
		     SIZE / 2 - LINE_WIDTH / 2, BORDER,
		     LINE_WIDTH,                SIZE - 2 * BORDER);
    cairo_fill (cr2);

    /* But doesn't affect another cairo_t that we create temporarily for
     * the same surface
     */
    cr3 = cairo_create (target_surface);
    cairo_set_source_rgb (cr3, 1, 1, 1); /* White */
    cairo_rectangle (cr3,
		     SIZE - BORDER - LINE_WIDTH, BORDER,
		     LINE_WIDTH,                 SIZE - 2 * BORDER);
    cairo_fill (cr3);

    _propagate_status (cr, cr3);
    cairo_destroy (cr3);

    _propagate_status (cr, cr2);
    cairo_destroy (cr2);

    /* And doesn't affect anything after this cairo_t is destroyed */

    cairo_set_source_rgb (cr, 1, 1, 1); /* White */
    cairo_rectangle (cr,
		     BORDER,     BORDER,
		     LINE_WIDTH, SIZE - 2 * BORDER);
    cairo_fill (cr);

    return CAIRO_TEST_SUCCESS;

}
static VALUE
cr_get_group_target (VALUE self)
{
  cairo_surface_t *surface;

  surface = cairo_get_group_target (_SELF);
  if (!surface)
    return Qnil;
  rb_cairo_check_status (cairo_surface_status (surface));
  return CRSURFACE2RVAL (surface);
}
Beispiel #19
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *mask;
    cairo_pattern_t *pattern;
    cairo_t *cr2;
    cairo_text_extents_t extents;

    cairo_set_source_rgb (cr, 0, 0, 1.0);
    cairo_paint (cr);

    mask = cairo_surface_create_similar (cairo_get_group_target (cr),
                                         CAIRO_CONTENT_ALPHA,
                                         width, height);
    cr2 = cairo_create (mask);
    cairo_surface_destroy (mask);

    cairo_save (cr2);
    {
        cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
        cairo_paint (cr2);
    }
    cairo_restore (cr2);

    pattern = cairo_pattern_create_linear (0, 0, width, height);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5);
    cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.);
    cairo_set_source (cr2, pattern);
    cairo_pattern_destroy (pattern);

    cairo_select_font_face (cr2,
                            CAIRO_TEST_FONT_FAMILY " Sans",
                            CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_NORMAL);
    cairo_set_font_size (cr2, 0.5 * height);

    cairo_text_extents (cr2, "cairo", &extents);
    cairo_move_to (cr2,
                   floor ((width - extents.width) / 2 + 0.5) - extents.x_bearing,
                   floor ((height - extents.height) / 2 - 0.5) - extents.y_bearing);
    cairo_show_text (cr2, "cairo");

    cairo_set_source_rgb (cr, 1.0, 0, 0);
    cairo_mask_surface (cr, cairo_get_target (cr2), 0, 0);
    cairo_destroy (cr2);

    return CAIRO_TEST_SUCCESS;
}
Beispiel #20
0
static void
set_source_similar_surface_rgba (cairo_t	*cr,
				 int		 width,
				 int		 height)
{
    cairo_surface_t *source;

    source = cairo_surface_create_similar (cairo_get_group_target (cr),
					   CAIRO_CONTENT_COLOR_ALPHA,
					   width, height);
    init_and_set_source_surface (cr, source, width, height);

    cairo_surface_destroy (source);
}
Beispiel #21
0
static void
draw_image (const cairo_test_context_t *ctx, cairo_t *cr)
{
    cairo_surface_t *surface, *similar;

    surface = cairo_test_create_surface_from_png (ctx, png_filename);
    similar = clone_similar_surface (cairo_get_group_target (cr), surface);
    cairo_surface_destroy (surface);

    cairo_set_source_surface (cr, similar, 0, 0);
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint (cr);
    cairo_surface_destroy (similar);
}
Beispiel #22
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    uint32_t data[] = {
	0xaa000000, 0x55000000,
	0x55000000, 0xaa000000,
    };

    cairo_surface_t *mask, *mask2;
    cairo_pattern_t *pattern;
    cairo_t *cr2;

    mask = cairo_surface_create_similar (cairo_get_group_target (cr),
				         CAIRO_CONTENT_ALPHA,
					 width, height);
    cr2 = cairo_create (mask);

    cairo_save (cr2); {
	cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr2);
    } cairo_restore (cr2);

    pattern = cairo_pattern_create_linear (0, 0, width, height);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5);
    cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.);
    cairo_set_source (cr2, pattern);
    cairo_pattern_destroy (pattern);

    mask2 = cairo_image_surface_create_for_data ((unsigned char *) data,
						CAIRO_FORMAT_ARGB32, 2, 2, 8);
    pattern = cairo_pattern_create_for_surface (mask2);
    cairo_surface_destroy (mask2);
    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
    cairo_mask (cr2, pattern);
    cairo_pattern_destroy (pattern);
    cairo_destroy (cr2);

    cairo_set_source_rgb (cr, 0, 0, 1.0);
    cairo_paint (cr);

    cairo_set_source_rgb (cr, 1.0, 0, 0);
    cairo_mask_surface (cr, mask, 0, 0);
    cairo_surface_destroy (mask);

    return CAIRO_TEST_SUCCESS;
}
Beispiel #23
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *group;
    double x, y;

    /* First paint background in blue. */
    cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
    cairo_paint (cr);

    /* Then clip so that the group surface ends up smaller than the
     * original surface. */
    cairo_rectangle (cr, PAD, PAD, width - 2 * PAD, height - 2 * PAD);
    cairo_clip (cr);

    /* Paint the clipped region in red (which should all be overwritten later). */
    cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
    cairo_paint (cr);

    /* Redirect to a new group and get that surface. */
    cairo_push_group (cr);
    group = cairo_get_group_target (cr);

    /* Then paint in green what we query the group surface size to be. */
    cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
    cairo_surface_get_device_offset (group, &x, &y);
    /* Or rather, we calculate the group surface size based on the
     * only thing we can query which is the device offset. Ideally,
     * the size would always be the minimal (width - 2 * PAD, height -
     * 2 * PAD) based on the clip. But currently, group targets are
     * created oversized for paginated surfaces, so we only subtract
     * anything from the size if there is a non-zero device offfset.
     *
     * The calculation below might also be less confusing if the sign
     * convention on the device offset were reversed, but it is what
     * it is. Oh well. */
    cairo_rectangle (cr,
		     -x, -y,
		     width + 2 * x,
		     height + 2 * y);
    cairo_fill (cr);

    /* Finish up the group painting. */
    cairo_pop_group_to_source (cr);
    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;
}
Beispiel #24
0
already_AddRefed<gfxASurface>
gfxContext::CurrentSurface(gfxFloat *dx, gfxFloat *dy)
{
    cairo_surface_t *s = cairo_get_group_target(mCairo);
    if (s == mSurface->CairoSurface()) {
        if (dx && dy)
            cairo_surface_get_device_offset(s, dx, dy);
        gfxASurface *ret = mSurface;
        NS_ADDREF(ret);
        return ret;
    }

    if (dx && dy)
        cairo_surface_get_device_offset(s, dx, dy);
    return gfxASurface::Wrap(s);
}
Beispiel #25
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *mask;
    cairo_pattern_t *pattern;
    cairo_t *cr2;

    mask = cairo_surface_create_similar (cairo_get_group_target (cr),
				         CAIRO_CONTENT_ALPHA,
					 width, height);
    cr2 = cairo_create (mask);
    cairo_surface_destroy (mask);

    cairo_save (cr2); {
	cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr2);
    } cairo_restore (cr2);

    pattern = cairo_pattern_create_linear (0, 0, width, height);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 1., 1., .5);
    cairo_pattern_add_color_stop_rgba (pattern, 0.75, 1., 1., 1., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 1.00, 0., 0., 0., 0.);
    cairo_set_source (cr2, pattern);
    cairo_pattern_destroy (pattern);

    cairo_paint (cr2);

    cairo_set_source_rgb (cr, 0, 0, 1.0);
    cairo_paint (cr);

    pattern = cairo_pattern_create_radial (
	    0.5 * width, 0.5 * height, 0,
	    0.5 * width, 0.5 * height, 0.5 *height);
    cairo_pattern_add_color_stop_rgba (pattern, 0.00, 0., 0., 0., 0.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1., 0., 0., 1.);
    cairo_pattern_add_color_stop_rgba (pattern, 0.50, 1., 0., 0., .5);
    cairo_pattern_add_color_stop_rgba (pattern, 1.00, 1., 0., 0., 1.);
    cairo_set_source (cr, pattern);
    cairo_pattern_destroy (pattern);

    cairo_mask_surface (cr, cairo_get_target (cr2), 0, 0);
    cairo_destroy (cr2);

    return CAIRO_TEST_SUCCESS;
}
Beispiel #26
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;
    cairo_matrix_t matrix;

    /* Paint a diagonal division as a test image */
    cairo_set_source_rgb (cr, 1, 1, 1);	/* White */
    cairo_paint (cr);

    cairo_move_to (cr, SIZE,    0);
    cairo_line_to (cr, SIZE, SIZE);
    cairo_line_to (cr, 0,    SIZE);

    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_fill (cr);

    /* Create a pattern with the target surface as the source,
     * offset by SIZE/2
     */
    pattern = cairo_pattern_create_for_surface (cairo_get_group_target (cr));

    cairo_matrix_init_translate (&matrix, - SIZE / 2, - SIZE / 2);
    cairo_pattern_set_matrix (pattern, &matrix);

    cairo_set_source (cr, pattern);
    cairo_pattern_destroy (pattern);

    /* Copy two rectangles from the upper-left quarter of the image to
     * the lower right.  It will work if we use cairo_fill(), but the
     * cairo_clip() cairo_paint() combination fails because the clip
     * on the surface as a destination affects it as the source as
     * well.
     */
    cairo_rectangle (cr,
                     2 * SIZE / 4, 2 * SIZE / 4,
                     SIZE / 4,     SIZE / 4);
    cairo_rectangle (cr,
                     3 * SIZE / 4, 3 * SIZE / 4,
                     SIZE / 4,     SIZE / 4);
    cairo_clip (cr);
    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;

}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *surface;
    cairo_surface_t *similar;

    surface = cairo_test_create_surface_from_png (png_filename);
    similar = clone_similar_surface (cairo_get_group_target (cr), surface);
    cairo_set_source_surface (cr, similar, 32, 32);
    cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REFLECT);

    cairo_paint (cr);

    cairo_surface_destroy (similar);
    cairo_surface_destroy (surface);

    return CAIRO_TEST_SUCCESS;
}
Beispiel #28
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *source;
    cairo_t *cr2;

    source = cairo_surface_create_similar (cairo_get_group_target (cr),
					   CAIRO_CONTENT_COLOR_ALPHA,
					   SIZE, SIZE);
    cr2 = cairo_create (source);
    cairo_surface_destroy (source);

    /* Fill the source surface with green */
    cairo_set_source_rgb (cr2, 0, 1, 0);
    cairo_paint (cr2);

    /* Draw a blue square in the middle of the source with clipping.
     * Note that we are only clipping within a save/restore block but
     * the buggy behavior demonstrates that the clip remains present
     * on the surface. */
    cairo_save (cr2);
    cairo_rectangle (cr2,
		     SIZE / 4, SIZE / 4,
		     SIZE / 2, SIZE / 2);
    cairo_clip (cr2);
    cairo_set_source_rgb (cr2, 0, 0, 1);
    cairo_paint (cr2);
    cairo_restore (cr2);

    /* Fill the destination surface with solid red (should not appear
     * in final result) */
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_paint (cr);

    /* Now draw the source surface onto the destination with scaling. */
    cairo_scale (cr, 2.0, 1.0);

    cairo_set_source_surface (cr, cairo_get_target (cr2), 0, 0);
    cairo_destroy (cr2);

    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;
}
Beispiel #29
0
/* Draw the word cairo at NUM_TEXT different angles */
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *stamp;
    cairo_t *cr2;

    stamp = cairo_surface_create_similar (cairo_get_group_target (cr),
					  CAIRO_CONTENT_COLOR_ALPHA,
					  WIDTH, HEIGHT);
    cr2 = cairo_create (stamp);
    {
	cairo_new_path (cr2);
	cairo_rectangle (cr2, WIDTH / 4, HEIGHT / 4, WIDTH / 2, HEIGHT / 2);
	cairo_set_source_rgba (cr2, 1, 0, 0, 0.8);
	cairo_fill (cr2);

	cairo_rectangle (cr2, 0, 0, WIDTH, HEIGHT);
	cairo_set_line_width (cr2, 2);
	cairo_set_source_rgb (cr2, 0, 0, 0);
	cairo_stroke (cr2);
    }
    cairo_destroy (cr2);

    /* Draw a translucent rectangle for reference where the rotated
     * image should be. */
    cairo_new_path (cr);
    cairo_rectangle (cr, WIDTH, HEIGHT, WIDTH, HEIGHT);
    cairo_set_source_rgba (cr, 1, 1, 0, 0.3);
    cairo_fill (cr);

#if 1 /* Set to 0 to generate reference image */
    cairo_translate (cr, 2 * WIDTH, 2 * HEIGHT);
    cairo_rotate (cr, M_PI);
#else
    cairo_translate (cr, WIDTH, HEIGHT);
#endif

    cairo_set_source_surface (cr, stamp, 0, 0);
    cairo_paint (cr);

    cairo_surface_destroy (stamp);

    return CAIRO_TEST_SUCCESS;
}
Beispiel #30
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *surface;
    cairo_t *cr_surface;

    /* Create a 4-pixel similar surface with my favorite four colors in each
     * quadrant. */
    surface = cairo_surface_create_similar (cairo_get_group_target (cr),
					    CAIRO_CONTENT_COLOR, 2, 2);
    cr_surface = cairo_create (surface);
    cairo_surface_destroy (surface);

    /* upper-left = white */
    cairo_set_source_rgb (cr_surface, 1, 1, 1);
    cairo_rectangle (cr_surface, 0, 0, 1, 1);
    cairo_fill (cr_surface);

    /* upper-right = red */
    cairo_set_source_rgb (cr_surface, 1, 0, 0);
    cairo_rectangle (cr_surface, 1, 0, 1, 1);
    cairo_fill (cr_surface);

    /* lower-left = green */
    cairo_set_source_rgb (cr_surface, 0, 1, 0);
    cairo_rectangle (cr_surface, 0, 1, 1, 1);
    cairo_fill (cr_surface);

    /* lower-right = blue */
    cairo_set_source_rgb (cr_surface, 0, 0, 1);
    cairo_rectangle (cr_surface, 1, 1, 1, 1);
    cairo_fill (cr_surface);

    /* Now use extend pad to cover the entire surface with those 4 colors */
    cairo_set_source_surface (cr, cairo_get_target (cr_surface),
			      width/2  - 1,
			      height/2 - 1);
    cairo_destroy (cr_surface);
    cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);
    cairo_paint (cr);

    return CAIRO_TEST_SUCCESS;
}