[cairo] Strange cropping issues with record surfaces in 1.11.2 (simplified)

Ross Alexander Ross.Alexander at EU.NEC.COM
Mon Mar 21 08:31:49 PDT 2011


Hello,

My previous email was a bit big so I have created a new one with C and a simple example.  If you look at PDF from playing back the recorded surfaces one of them is oddly clipped.  Included are the script files and the C code.  I've also pasted the code below.

Cheers,
Ross

#include <stdio.h>
#include <cairo.h>
#include <cairo-pdf.h>
#include <cairo-script.h>

void draw(cairo_surface_t *surface, double x, double y)
{
  cairo_t *cr = cairo_create(surface);
  if ((x != 0.0) && (y != 0.0))
    cairo_translate(cr, x, y);

  cairo_set_line_width(cr, 2.0);
  cairo_save(cr);
  cairo_translate(cr, 10, 10);
  cairo_rectangle(cr, 0, 0, 60, 50);
  cairo_set_source_rgb(cr, 0.5, 0.9, 0.7);
  cairo_fill_preserve(cr);
  cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
  cairo_stroke(cr);
  cairo_restore(cr);
  cairo_show_page(cr);
  cairo_destroy(cr);
}

void paint(cairo_surface_t *surface, cairo_surface_t *record, double x, double y)
{
  cairo_t *cr = cairo_create(surface);
  cairo_set_source_surface(cr, record, -x, -y);
  cairo_paint(cr);
  cairo_destroy(cr);
}

int main()
{
  cairo_rectangle_t r;
  cairo_surface_t *urecord = cairo_recording_surface_create(CAIRO_CONTENT_COLOR, 0);
  draw(urecord, 0.0, 0.0);

  cairo_recording_surface_ink_extents(urecord, &r.x, &r.y, &r.width, &r.height);

  printf("x=%f y=%f, width=%f height=%f\n", r.x, r.y, r.width, r.height);

  cairo_surface_t *record = cairo_recording_surface_create(CAIRO_CONTENT_COLOR, &r);
  draw(record, 0.0, 0.0);

  cairo_surface_t *pdf = cairo_pdf_surface_create("c-record-test.pdf", r.width, r.height);
  draw(pdf, -r.x, -r.y);
  cairo_surface_destroy(pdf);

  pdf = cairo_pdf_surface_create("c-record-test-record-zero.pdf", r.width, r.height);
  paint(pdf, record, 0.0, 0.0);
  cairo_surface_destroy(pdf);

  pdf = cairo_pdf_surface_create("c-record-test-record-offset.pdf", r.width, r.height);
  paint(pdf, record, r.x, r.y);
  cairo_surface_destroy(pdf);

  /* --------------------
     Script direct
     -------------------- */

  cairo_device_t *device = cairo_script_create("c-record-test.cs");
  cairo_surface_t *script = cairo_script_surface_create(device, CAIRO_CONTENT_COLOR, r.width, r.height);
  draw(script, -r.x, -r.y);
  cairo_surface_destroy(script);
  cairo_device_destroy(device);


  /* --------------------
     Script via record playback
     -------------------- */

  device = cairo_script_create("c-record-test-record-zero.cs");
  script = cairo_script_surface_create(device, CAIRO_CONTENT_COLOR, r.width, r.height);
  paint(script, record, 0.0, 0.0);
  cairo_surface_destroy(script);
  cairo_device_destroy(device);

  /* --------------------
     Script via record playback
     -------------------- */

  device = cairo_script_create("c-record-test-record-offset.cs");
  script = cairo_script_surface_create(device, CAIRO_CONTENT_COLOR, r.width, r.height);
  paint(script, record, r.x, r.y);
  cairo_surface_destroy(script);
  cairo_device_destroy(device);


  /* --------------------
     Script via record direct
     -------------------- */

  device = cairo_script_create("c-record-test-record-d.cs");
  cairo_script_from_recording_surface(device, record);
  cairo_device_destroy(device);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: c-clip.tar.xz
Type: application/octet-stream
Size: 1928 bytes
Desc: c-clip.tar.xz
URL: <http://lists.cairographics.org/archives/cairo/attachments/20110321/36aadd0d/attachment.obj>


More information about the cairo mailing list