Esempio n. 1
0
static cairo_surface_t *
byzanz_recorder_create_snapshot (ByzanzRecorder *recorder, const cairo_region_t *invalid)
{
  cairo_rectangle_int_t extents;
  cairo_surface_t *surface;
  cairo_t *cr;
  GSequenceIter *iter;
  int i, num_rects;
  
  cairo_region_get_extents (invalid, &extents);
  cr = gdk_cairo_create (recorder->window);
  surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR,
      extents.width, extents.height);
  cairo_destroy (cr);
  cairo_surface_set_device_offset (surface, -extents.x, -extents.y);

  cr = cairo_create (surface);

  num_rects = cairo_region_num_rectangles (invalid);
  for (i = 0; i < num_rects; i++) {
    cairo_rectangle_int_t rect;
    cairo_region_get_rectangle (invalid, i, &rect);
    cairo_rectangle (cr, rect.x, rect.y,
                     rect.width, rect.height);
  }

  cairo_clip (cr);

  for (iter = g_sequence_get_begin_iter (recorder->layers);
       !g_sequence_iter_is_end (iter);
       iter = g_sequence_iter_next (iter)) {
    ByzanzLayer *layer = g_sequence_get (iter);
    ByzanzLayerClass *klass = BYZANZ_LAYER_GET_CLASS (layer);

    cairo_save (cr);
    klass->render (layer, cr);
    if (cairo_status (cr))
      g_critical ("error capturing image: %s", cairo_status_to_string (cairo_status (cr)));
    cairo_restore (cr);
  }

  cairo_destroy (cr);

  surface = ensure_image_surface (surface, invalid);

  /* adjust device offset here - the layers work in GdkScreen coordinates, the rest
   * of the code works in coordinates realtive to the passed in area. */
  cairo_surface_set_device_offset (surface,
      recorder->area.x - extents.x, recorder->area.y - extents.y);

  return surface;
}
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;
}
Esempio n. 3
0
static int
surface_set_device_offset (lua_State *L) {
    cairo_surface_t **obj = luaL_checkudata(L, 1, OOCAIRO_MT_NAME_SURFACE);
    cairo_surface_set_device_offset(*obj, luaL_checknumber(L, 2),
                                    luaL_checknumber(L, 3));
    return 0;
}
Esempio n. 4
0
static cairo_surface_t *
_cairo_xcb_surface_map_to_image (void *abstract_surface,
				 const cairo_rectangle_int_t *extents)
{
    cairo_xcb_surface_t *surface = abstract_surface;
    cairo_surface_t *image;

    if (surface->fallback)
	return surface->fallback->base.backend->map_to_image (&surface->fallback->base, extents);

    image = _get_image (surface, TRUE,
			extents->x, extents->y,
			extents->width, extents->height);
    if (unlikely (image->status))
	return image;

    /* Do we have a deferred clear and this image surface does NOT cover the
     * whole xcb surface? Have to apply the clear in that case, else
     * uploading the image will handle the problem for us.
     */
    if (surface->deferred_clear &&
	! (extents->width == surface->width &&
	   extents->height == surface->height)) {
	cairo_status_t status = _cairo_xcb_surface_clear (surface);
	if (unlikely (status)) {
	    cairo_surface_destroy(image);
	    return _cairo_surface_create_in_error (status);
	}
    }
    surface->deferred_clear = FALSE;

    cairo_surface_set_device_offset (image, -extents->x, -extents->y);
    return image;
}
Esempio n. 5
0
/* A convenience function for when one needs to coerce an image
 * surface to an alternate format. */
cairo_image_surface_t *
_cairo_image_surface_clone (cairo_image_surface_t	*surface,
			    cairo_format_t		 format)
{
    cairo_image_surface_t *clone;
    cairo_status_t status;
    cairo_t *cr;
    double x, y;

    clone = (cairo_image_surface_t *)
	cairo_image_surface_create (format,
				    surface->width, surface->height);

    cairo_surface_get_device_offset (&surface->base, &x, &y);
    cairo_surface_set_device_offset (&clone->base, x, y);
    clone->transparency = CAIRO_IMAGE_UNKNOWN;

    /* XXX Use _cairo_surface_composite directly */
    cr = cairo_create (&clone->base);
    cairo_set_source_surface (cr, &surface->base, 0, 0);
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint (cr);
    status = cairo_status (cr);
    cairo_destroy (cr);

    if (status) {
	cairo_surface_destroy (&clone->base);
	return (cairo_image_surface_t *) _cairo_surface_create_in_error (status);
    }

    return clone;
}
Esempio n. 6
0
static gboolean
seed_cairo_surface_set_device_offset(SeedContext ctx,
				     SeedObject this_object,
				     SeedString property_name,
				     SeedValue value,
				     SeedException *exception)
{
  cairo_surface_t *surf;
  gdouble x, y;
  SeedValue jsx, jsy;
  CHECK_THIS_BOOL();

  if (!seed_value_is_object (ctx, value))
    {
      seed_make_exception(ctx, exception, "ArgumentError", "Cairo.Surface.device_offset must be an array [x,y]");
      return FALSE;
    }

  jsx = seed_object_get_property_at_index (ctx, (SeedObject) value, 0, exception);
  jsy = seed_object_get_property_at_index (ctx, (SeedObject) value, 1, exception);

  surf = seed_object_to_cairo_surface (ctx, this_object, exception);
  x = seed_value_to_double (ctx, jsx, exception);
  y = seed_value_to_double (ctx, jsy, exception);

  cairo_surface_set_device_offset (surf, x, y);
  return TRUE;
}
Esempio n. 7
0
static cairo_surface_t *
ensure_image_surface (cairo_surface_t *surface, const cairo_region_t *region)
{
  cairo_rectangle_int_t extents;
  cairo_surface_t *image;
  cairo_t *cr;
  int i, num_rects;

  if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE)
    return surface;

  cairo_region_get_extents (region, &extents);
  image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, extents.width, extents.height);
  cairo_surface_set_device_offset (image, -extents.x, -extents.y);

  cr = cairo_create (image);
  cairo_set_source_surface (cr, surface, 0, 0);
  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);

  num_rects = cairo_region_num_rectangles (region);
  for (i = 0; i < num_rects; i++) {
    cairo_rectangle_int_t rect;
    cairo_region_get_rectangle (region, i, &rect);
    cairo_rectangle (cr, rect.x, rect.y,
                     rect.width, rect.height);
  }

  cairo_fill (cr);
  cairo_destroy (cr);

  cairo_surface_destroy (surface);
  return image;
}
Esempio n. 8
0
void draw_tile(cairo_t *cr, cairo_matrix_t m, cairo_rectangle_t r, int tx, int ty)
{
	if (cr !=NULL)
	{
		cairo_save(cr); 
	
		/* Use the rect and pattern */
		c_rect(cr, r);
		cairo_set_source (cr, tile_pattern);
	
		/* Pull the tile we need */
		cairo_surface_set_device_offset(graphical_tiles, tx - r.x, ty - r.y);
	
		/* Use transparency */
		cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
	
		/* Use the matrix with our pattern */
		cairo_pattern_set_matrix(tile_pattern, &m);
	
		/* Draw it */
		cairo_fill(cr);
	
		cairo_restore(cr);
	}
}
Esempio n. 9
0
static void
drag_begin_callback (GtkWidget      *widget,
		     GdkDragContext *context,
		     gpointer        data)
{
	NemoIconContainer *container;
	cairo_surface_t *surface;
	double x1, y1, x2, y2, winx, winy;
	int x_offset, y_offset;
	int start_x, start_y;

	container = NEMO_ICON_CONTAINER (widget);

	start_x = container->details->dnd_info->drag_info.start_x +
		gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
	start_y = container->details->dnd_info->drag_info.start_y +
		gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));

        /* create a pixmap and mask to drag with */
        surface = nemo_icon_canvas_item_get_drag_surface (container->details->drag_icon->item);

        /* compute the image's offset */
	eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (container->details->drag_icon->item),
				    &x1, &y1, &x2, &y2);
	eel_canvas_world_to_window (EEL_CANVAS (container), 
				    x1, y1,  &winx, &winy);
        x_offset = start_x - winx;
        y_offset = start_y - winy;

        cairo_surface_set_device_offset (surface, -x_offset, -y_offset);
        gtk_drag_set_icon_surface (context, surface);
        cairo_surface_destroy (surface);
}
Esempio n. 10
0
void DragAndDropHandler::startDrag(Ref<SelectionData>&& selection, DragOperation dragOperation, RefPtr<ShareableBitmap>&& dragImage)
{
#if GTK_CHECK_VERSION(3, 16, 0)
    m_draggingSelectionData = WTFMove(selection);
    GRefPtr<GtkTargetList> targetList = PasteboardHelper::singleton().targetListForSelectionData(*m_draggingSelectionData);
#else
    RefPtr<SelectionData> selectionData = WTFMove(selection);
    GRefPtr<GtkTargetList> targetList = PasteboardHelper::singleton().targetListForSelectionData(*selectionData);
#endif

    GUniquePtr<GdkEvent> currentEvent(gtk_get_current_event());
    GdkDragContext* context = gtk_drag_begin(m_page.viewWidget(), targetList.get(), dragOperationToGdkDragActions(dragOperation),
        GDK_BUTTON_PRIMARY, currentEvent.get());

#if GTK_CHECK_VERSION(3, 16, 0)
    // WebCore::EventHandler does not support more than one DnD operation at the same time for
    // a given page, so we should cancel any previous operation whose context we might have
    // stored, should we receive a new startDrag event before finishing a previous DnD operation.
    if (m_dragContext)
        gtk_drag_cancel(m_dragContext.get());
    m_dragContext = context;
#else
    // We don't have gtk_drag_cancel() in GTK+ < 3.16, so we use the old code.
    // See https://bugs.webkit.org/show_bug.cgi?id=138468
    m_draggingSelectionDataMap.set(context, WTFMove(selectionData));
#endif

    if (dragImage) {
        RefPtr<cairo_surface_t> image(dragImage->createCairoSurface());
        // Use the center of the drag image as hotspot.
        cairo_surface_set_device_offset(image.get(), -cairo_image_surface_get_width(image.get()) / 2, -cairo_image_surface_get_height(image.get()) / 2);
        gtk_drag_set_icon_surface(context, image.get());
    } else
        gtk_drag_set_icon_default(context);
}
Esempio n. 11
0
static VALUE
cr_surface_set_device_offset (VALUE self, VALUE x_offset, VALUE y_offset)
{
  cairo_surface_set_device_offset (_SELF,
                                   NUM2DBL (x_offset),
                                   NUM2DBL (y_offset));
  cr_surface_check_status (_SELF);
  return self;
}
Esempio n. 12
0
IoObject *IoCairoSurface_setDeviceOffset(IoCairoSurface *self, IoObject *locals, IoMessage *m)
{
	double x = IoMessage_locals_doubleArgAt_(m, locals, 0);
	double y = IoMessage_locals_doubleArgAt_(m, locals, 1);

	cairo_surface_set_device_offset(SURFACE(self), x, y);
	CHECK_STATUS(self);
	return self;
}
Esempio n. 13
0
cairo_t *
gsk_cairo_blur_start_drawing (cairo_t         *cr,
                              float            radius,
                              GskBlurFlags     blur_flags)
{
  cairo_rectangle_int_t clip_rect;
  cairo_surface_t *surface;
  cairo_t *blur_cr;
  gdouble clip_radius;
  gdouble x_scale, y_scale;
  gboolean blur_x = (blur_flags & GSK_BLUR_X) != 0;
  gboolean blur_y = (blur_flags & GSK_BLUR_Y) != 0;

  if (!needs_blur (radius))
    return cr;

  gdk_cairo_get_clip_rectangle (cr, &clip_rect);

  clip_radius = gsk_cairo_blur_compute_pixels (radius);

  x_scale = y_scale = 1;
  cairo_surface_get_device_scale (cairo_get_target (cr), &x_scale, &y_scale);

  if (blur_flags & GSK_BLUR_REPEAT)
    {
      if (!blur_x)
        clip_rect.width = 1;
      if (!blur_y)
        clip_rect.height = 1;
    }

  /* Create a larger surface to center the blur. */
  surface = cairo_surface_create_similar_image (cairo_get_target (cr),
                                                CAIRO_FORMAT_A8,
                                                x_scale * (clip_rect.width + (blur_x ? 2 * clip_radius : 0)),
                                                y_scale * (clip_rect.height + (blur_y ? 2 * clip_radius : 0)));
  cairo_surface_set_device_scale (surface, x_scale, y_scale);
  cairo_surface_set_device_offset (surface,
                                    x_scale * ((blur_x ? clip_radius : 0) - clip_rect.x),
                                    y_scale * ((blur_y ? clip_radius : 0) - clip_rect.y));

  blur_cr = cairo_create (surface);
  cairo_set_user_data (blur_cr, &original_cr_key, cairo_reference (cr), (cairo_destroy_func_t) cairo_destroy);

  if (cairo_has_current_point (cr))
    {
      double x, y;

      cairo_get_current_point (cr, &x, &y);
      cairo_move_to (blur_cr, x, y);
    }

  return blur_cr;
}
Esempio n. 14
0
static cairo_status_t
_cairo_boilerplate_xcb_finish_surface (cairo_surface_t *surface)
{
    xcb_target_closure_t *xtc = cairo_surface_get_user_data (surface,
							     &xcb_closure_key);
    xcb_generic_event_t *ev;

    if (xtc->surface != NULL) {
	cairo_t *cr;

	cr = cairo_create (xtc->surface);
	cairo_surface_set_device_offset (surface, 0, 0);
	cairo_set_source_surface (cr, surface, 0, 0);
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
	cairo_paint (cr);
	cairo_destroy (cr);

	surface = xtc->surface;
    }

    cairo_surface_flush (surface);
    if (cairo_surface_status (surface))
	return cairo_surface_status (surface);

    while ((ev = xcb_poll_for_event (xtc->c)) != NULL) {
	cairo_status_t status = CAIRO_STATUS_SUCCESS;

	if (ev->response_type == 0 /* trust me! */) {
	    xcb_generic_error_t *error = (xcb_generic_error_t *) ev;

#if XCB_GENERIC_ERROR_HAS_MAJOR_MINOR_CODES
	    fprintf (stderr,
		     "Detected error during xcb run: %d major=%d, minor=%d\n",
		     error->error_code, error->major_code, error->minor_code);
#else
	    fprintf (stderr,
		     "Detected error during xcb run: %d\n",
		     error->error_code);
#endif
	    free (error);

	    status = CAIRO_STATUS_WRITE_ERROR;
	}

	if (status)
	    return status;
    }

    if (xcb_connection_has_error (xtc->c))
	return CAIRO_STATUS_WRITE_ERROR;

    return CAIRO_STATUS_SUCCESS;
}
Esempio n. 15
0
static PyObject *
surface_set_device_offset (PycairoSurface *o, PyObject *args)
{
    double x_offset, y_offset;

    if (!PyArg_ParseTuple (args, "dd:Surface.set_device_offset",
			   &x_offset, &y_offset))
	return NULL;

    cairo_surface_set_device_offset (o->surface, x_offset, y_offset);
    Py_RETURN_NONE;
}
Esempio n. 16
0
cairo_status_t
cairo_xml_for_recording_surface (cairo_device_t	 *device,
				 cairo_surface_t *recording_surface)
{
    cairo_box_t bbox;
    cairo_rectangle_int_t extents;
    cairo_surface_t *surface;
    cairo_xml_t *xml;
    cairo_status_t status;

    if (unlikely (device->status))
	return device->status;

    if (unlikely (recording_surface->status))
	return recording_surface->status;

    if (unlikely (device->backend->type != CAIRO_DEVICE_TYPE_XML))
	return _cairo_error (CAIRO_STATUS_DEVICE_TYPE_MISMATCH);

    if (unlikely (! _cairo_surface_is_recording (recording_surface)))
	return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);

    status = _cairo_recording_surface_get_bbox ((cairo_recording_surface_t *) recording_surface,
						&bbox, NULL);
    if (unlikely (status))
	return status;

    _cairo_box_round_to_rectangle (&bbox, &extents);
    surface = _cairo_xml_surface_create_internal (device,
						  recording_surface->content,
						  extents.width,
						  extents.height);
    if (unlikely (surface->status))
	return surface->status;

    xml = (cairo_xml_t *) device;

    _cairo_xml_printf (xml,
		       "<surface content='%s' width='%d' height='%d'>",
		       _content_to_string (recording_surface->content),
		       extents.width, extents.height);
    _cairo_xml_indent (xml, 2);

    cairo_surface_set_device_offset (surface, -extents.x, -extents.y);
    status = _cairo_recording_surface_replay (recording_surface, surface);
    cairo_surface_destroy (surface);

    _cairo_xml_indent (xml, -2);
    _cairo_xml_printf (xml, "</surface>");

    return status;
}
Esempio n. 17
0
static cairo_test_status_t
preamble (cairo_test_context_t *ctx)
{
    cairo_surface_t *surface;

    /* get the error surface */
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX);

#if CAIRO_HAS_GL_SURFACE
    cairo_gl_surface_set_size (surface, 0, 0);
    cairo_gl_surface_swapbuffers (surface);
#endif

#if CAIRO_HAS_OS2_SURFACE
    cairo_os2_surface_set_hwnd (surface, 0);
    cairo_os2_surface_set_size (surface, 0, 0);
    cairo_os2_surface_set_manual_window_refresh (surface, FALSE);
#endif

#if CAIRO_HAS_PDF_SURFACE
    cairo_pdf_surface_restrict_to_version (surface, CAIRO_PDF_VERSION_1_4);
    cairo_pdf_surface_set_size (surface, 0, 0);
#endif

#if CAIRO_HAS_PS_SURFACE
    cairo_ps_surface_set_eps (surface, FALSE);
    cairo_ps_surface_set_size (surface, 0, 0);
    cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2);
    cairo_ps_surface_dsc_comment (surface, NULL);
    cairo_ps_surface_dsc_begin_setup (surface);
    cairo_ps_surface_dsc_begin_page_setup (surface);
#endif

#if CAIRO_HAS_XCB_SURFACE
    cairo_xcb_surface_set_size (surface, 0, 0);
#endif

#if CAIRO_HAS_XLIB_SURFACE
    cairo_xlib_surface_set_size (surface, 0, 0);
    cairo_xlib_surface_set_drawable (surface, 0, 0, 0);
#endif

    cairo_surface_set_mime_data (surface, NULL, NULL, 0, NULL, 0);
    cairo_surface_set_device_offset (surface, 0, 0);
    cairo_surface_set_fallback_resolution (surface, 0, 0);

    cairo_surface_destroy (surface);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 18
0
Context::Surface::~Surface ()
{
	if (surface) {

		/* restore device offset */
		if (!box.IsEmpty ())
			cairo_surface_set_device_offset (surface,
							 device_offset.x,
							 device_offset.y);

		cairo_surface_destroy (surface);
	}

	native->unref ();
}
Esempio n. 19
0
void draw_tile(term_data* td, int x, int y, int tx, int ty, bool trans)
{
	cairo_t* cr;
	cr = cairo_create(td->surface);
	
	cairo_rectangle(cr, x * td->font.w, y * td->font.h, td->font.w, td->font.h);
	cairo_set_source(cr, tile_pattern);
	cairo_surface_set_device_offset(graphical_tiles, (tx - x) * td->font.w, (ty - y) * td->font.h);
	
	// Use transparency.
	if (trans) cairo_set_operator(cr, CAIRO_OPERATOR_ADD);
	
	/* Draw it */
	cairo_fill(cr);
}
Esempio n. 20
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_matrix_t m;
    int xoffset = 50;
    int yoffset = 50;

    cairo_surface_t *shadow;
    cairo_t *shadow_cr;
    cairo_path_t *path;

    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);

    cairo_translate (cr, 130, 130);
    cairo_rotate (cr, .5);//2*M_PI*angle/360);
    cairo_rectangle (cr, 0, 0, 50, 100);
    cairo_get_matrix (cr, &m);

    shadow = cairo_surface_create_similar (cairo_get_target (cr),
					   CAIRO_CONTENT_COLOR_ALPHA,
					   600 - xoffset,
					   600 - yoffset);
    cairo_surface_set_device_offset (shadow, xoffset, yoffset);
    shadow_cr = cairo_create (shadow);
    cairo_surface_destroy (shadow);

    cairo_set_source_rgb (shadow_cr, 0, 1, 0);
    cairo_set_matrix (shadow_cr, &m);

    path = cairo_copy_path (cr);
    cairo_new_path (shadow_cr);
    cairo_append_path (shadow_cr, path);
    cairo_fill (shadow_cr);
    cairo_path_destroy (path);

    cairo_identity_matrix (cr);
    cairo_translate (cr, 10, 50);
    cairo_set_source_surface (cr, cairo_get_target (shadow_cr), 0, 0);
    cairo_paint (cr);
    cairo_set_matrix (cr, &m);
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_fill (cr);

    cairo_destroy (shadow_cr);

    return CAIRO_TEST_SUCCESS;
}
Esempio n. 21
0
cairo_surface_t *
_cairo_boilerplate_svg_get_image_surface (cairo_surface_t *surface,
					  int width,
					  int height)
{
    cairo_surface_t *image;

    image = _cairo_boilerplate_svg_convert_to_image (surface);
    cairo_surface_set_device_offset (image,
				     cairo_image_surface_get_width (image) - width,
				     cairo_image_surface_get_height (image) - height);
    surface = _cairo_boilerplate_get_image_surface (image, width, height);
    cairo_surface_destroy (image);

    return surface;
}
static cairo_int_status_t
_paint_fallback_image (cairo_paginated_surface_t *surface,
		       cairo_rectangle_int_t     *rect)
{
    double x_scale = surface->base.x_fallback_resolution / surface->target->x_resolution;
    double y_scale = surface->base.y_fallback_resolution / surface->target->y_resolution;
    int x, y, width, height;
    cairo_status_t status;
    cairo_surface_t *image;
    cairo_surface_pattern_t pattern;
    cairo_clip_t *clip;

    x = rect->x;
    y = rect->y;
    width = rect->width;
    height = rect->height;
    image = _cairo_paginated_surface_create_image_surface (surface,
							   ceil (width  * x_scale),
							   ceil (height * y_scale));
    _cairo_surface_set_device_scale (image, x_scale, y_scale);
    /* set_device_offset just sets the x0/y0 components of the matrix;
     * so we have to do the scaling manually. */
    cairo_surface_set_device_offset (image, -x*x_scale, -y*y_scale);

    status = _cairo_recording_surface_replay (surface->recording_surface, image);
    if (unlikely (status))
	goto CLEANUP_IMAGE;

    _cairo_pattern_init_for_surface (&pattern, image);
    cairo_matrix_init (&pattern.base.matrix,
		       x_scale, 0, 0, y_scale, -x*x_scale, -y*y_scale);
    /* the fallback should be rendered at native resolution, so disable
     * filtering (if possible) to avoid introducing potential artifacts. */
    pattern.base.filter = CAIRO_FILTER_NEAREST;

    clip = _cairo_clip_intersect_rectangle (NULL, rect);
    status = _cairo_surface_paint (surface->target,
				   CAIRO_OPERATOR_SOURCE,
				   &pattern.base, clip);
    _cairo_clip_destroy (clip);
    _cairo_pattern_fini (&pattern.base);

CLEANUP_IMAGE:
    cairo_surface_destroy (image);

    return (cairo_int_status_t)status;
}
Esempio n. 23
0
static void
drag_set_color_icon (GdkDragContext *context,
                     const GdkRGBA  *color)
{
    cairo_surface_t *surface;
    cairo_t *cr;

    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 48, 32);
    cr = cairo_create (surface);
    gdk_cairo_set_source_rgba (cr, color);
    cairo_paint (cr);

    cairo_surface_set_device_offset (surface, -4, -4);
    gtk_drag_set_icon_surface (context, surface);

    cairo_destroy (cr);
    cairo_surface_destroy (surface);
}
Esempio n. 24
0
cairo_surface_t *
Context::Surface::Cairo ()
{
	if (!surface) {
		surface = native->Cairo ();

		/* replace device offset */
		if (!box.IsEmpty ()) {
			cairo_surface_get_device_offset (surface,
							 &device_offset.x,
							 &device_offset.y);
			cairo_surface_set_device_offset (surface,
							 -box.x,
							 -box.y);
		}
	}

	return cairo_surface_reference (surface);
}
cairo_status_t
_cairo_boilerplate_svg_finish_surface (cairo_surface_t		*surface)
{
    svg_target_closure_t *ptc = cairo_surface_get_user_data (surface,
	                                                     &svg_closure_key);
    cairo_status_t status;

    /* Both surface and ptc->target were originally created at the
     * same dimensions. We want a 1:1 copy here, so we first clear any
     * device offset on surface.
     *
     * In a more realistic use case of device offsets, the target of
     * this copying would be of a different size than the source, and
     * the offset would be desirable during the copy operation. */
    cairo_surface_set_device_offset (surface, 0, 0);

    if (ptc->target) {
	cairo_t *cr;
	cr = cairo_create (ptc->target);
	cairo_set_source_surface (cr, surface, 0, 0);
	cairo_paint (cr);
	cairo_show_page (cr);
	status = cairo_status (cr);
	cairo_destroy (cr);

	if (status)
	    return status;

	cairo_surface_finish (surface);
	status = cairo_surface_status (surface);
	if (status)
	    return status;

	surface = ptc->target;
    }

    cairo_surface_finish (surface);
    status = cairo_surface_status (surface);
    if (status)
	return status;

    return CAIRO_STATUS_SUCCESS;
}
Esempio n. 26
0
static cairo_int_status_t
_paint_fallback_image (cairo_paginated_surface_t *surface,
		       cairo_box_int_t           *box)
{
    double x_scale = surface->base.x_fallback_resolution / surface->target->x_resolution;
    double y_scale = surface->base.y_fallback_resolution / surface->target->y_resolution;
    cairo_matrix_t matrix;
    int x, y, width, height;
    cairo_status_t status;
    cairo_surface_t *image;
    cairo_pattern_t *pattern;

    x = box->p1.x;
    y = box->p1.y;
    width = box->p2.x - x;
    height = box->p2.y - y;
    image = _cairo_paginated_surface_create_image_surface (surface,
							   ceil (width  * x_scale),
							   ceil (height * y_scale));
    _cairo_surface_set_device_scale (image, x_scale, y_scale);
    /* set_device_offset just sets the x0/y0 components of the matrix;
     * so we have to do the scaling manually. */
    cairo_surface_set_device_offset (image, -x*x_scale, -y*y_scale);

    status = _cairo_meta_surface_replay (surface->meta, image);
    if (status)
	goto CLEANUP_IMAGE;

    pattern = cairo_pattern_create_for_surface (image);
    cairo_matrix_init (&matrix, x_scale, 0, 0, y_scale, -x*x_scale, -y*y_scale);
    cairo_pattern_set_matrix (pattern, &matrix);

    status = _cairo_surface_paint (surface->target,
				   CAIRO_OPERATOR_SOURCE,
				   pattern);

    cairo_pattern_destroy (pattern);
CLEANUP_IMAGE:
    cairo_surface_destroy (image);

    return status;
}
cairo_surface_t *
_cairo_boilerplate_svg_get_image_surface (cairo_surface_t *surface,
					  int page,
					  int width,
					  int height)
{
    cairo_surface_t *image;

    if (page != 0)
	return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);

    image = _cairo_boilerplate_svg_convert_to_image (surface);
    cairo_surface_set_device_offset (image,
				     cairo_image_surface_get_width (image) - width,
				     cairo_image_surface_get_height (image) - height);
    surface = _cairo_boilerplate_get_image_surface (image, 0, width, height);
    cairo_surface_destroy (image);

    return surface;
}
static cairo_status_t
_cairo_skia_context_push_group (void *abstract_cr, cairo_content_t content)
{
    cairo_skia_context_t *cr = (cairo_skia_context_t *) abstract_cr;
    cairo_surface_t *group_surface;
    cairo_status_t status;
    int width, height;

    //clip = _cairo_gstate_get_clip (cr->gstate);
    width = cr->target->image.width;
    height = cr->target->image.height;
    group_surface = cr->target->image.base.backend->create_similar (&cr->target->image.base,
								    content, width, height);

#if 0
    /* Set device offsets on the new surface so that logically it appears at
     * the same location on the parent surface -- when we pop_group this,
     * the source pattern will get fixed up for the appropriate target surface
     * device offsets, so we want to set our own surface offsets from /that/,
     * and not from the device origin. */
    cairo_surface_set_device_offset (group_surface,
				     parent_surface->device_transform.x0 - extents.x,
				     parent_surface->device_transform.y0 - extents.y);

    /* If we have a current path, we need to adjust it to compensate for
     * the device offset just applied. */
    _cairo_path_fixed_transform (cr->path,
				 &group_surface->device_transform);
#endif

    status = _cairo_skia_context_save (cr);
    if (unlikely (status)) {
	cairo_surface_destroy (group_surface);
	return status;
    }

    cairo_surface_destroy (&cr->target->image.base);
    cr->target = (cairo_skia_surface_t *) group_surface;

    return CAIRO_STATUS_SUCCESS;
}
Esempio n. 29
0
static cairo_surface_t *
red_acquire (cairo_pattern_t *pattern, void *closure,
	     cairo_surface_t *target,
	     const cairo_rectangle_int_t *extents)
{
    cairo_surface_t *image;
    cairo_t *cr;

    image = cairo_surface_create_similar_image (target,
						CAIRO_FORMAT_RGB24,
						extents->width,
						extents->height);
    cairo_surface_set_device_offset (image, extents->x, extents->y);

    cr = cairo_create (image);
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_paint (cr);
    cairo_destroy (cr);

    return image;
}
Esempio n. 30
0
cairo_image_surface_t *
_cairo_image_surface_map_to_image (void *abstract_other,
				   const cairo_rectangle_int_t *extents)
{
    cairo_image_surface_t *other = abstract_other;
    cairo_surface_t *surface;
    uint8_t *data;

    data = other->data;
    data += extents->y * other->stride;
    data += extents->x * PIXMAN_FORMAT_BPP (other->pixman_format)/ 8;

    surface =
	_cairo_image_surface_create_with_pixman_format (data,
							other->pixman_format,
							extents->width,
							extents->height,
							other->stride);

    cairo_surface_set_device_offset (surface, -extents->x, -extents->y);
    return (cairo_image_surface_t *) surface;
}