[cairo] ink_extents() returns garbage for nested RecordingSurface

Daniel Nouri daniel.nouri at gmail.com
Thu Apr 11 04:13:09 PDT 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear all,

I'm using cairo with Python via cairocffi and I'm trying to nest a
RecordingSurface into another.  Which works fine until I try to use
get_ink_extents() on a nesting RecordingSurface.

So in my little example, left and right are two recording surfaces,
which contain two recording surfaces each:

  +---------+---------+---------+---------+
  |         |         |         |         |
  | left1   | left2   | right1  | right2  |
  |         |         |         |         |
  |                   |                   |
  |       left        |       right       |
  |                   |                   |
  +---------+---------+---------+---------+

And here is the code example:

    surface = cairo.PSSurface('tut.eps', PAGE_WIDTH, PAGE_HEIGHT)
    surface.set_eps(True)
    context = cairo.Context(surface)

    surface_left = cairo.RecordingSurface(
        cairo.CONTENT_COLOR_ALPHA, None)
    context_left = cairo.Context(surface_left)

    surface_right = cairo.RecordingSurface(
        cairo.CONTENT_COLOR_ALPHA, None)
    context_right = cairo.Context(surface_right)

    surface_left1 = cairo.RecordingSurface(
        cairo.CONTENT_COLOR_ALPHA, None)
    context_left1 = cairo.Context(surface_left1)

    surface_left2 = cairo.RecordingSurface(
        cairo.CONTENT_COLOR_ALPHA, None)
    context_left2 = cairo.Context(surface_left2)

    surface_right1 = cairo.RecordingSurface(
        cairo.CONTENT_COLOR_ALPHA, None)
    context_right1 = cairo.Context(surface_right1)

    surface_right2 = cairo.RecordingSurface(
        cairo.CONTENT_COLOR_ALPHA, None)
    context_right2 = cairo.Context(surface_right2)

    context_left1.set_source_rgb(1.0, 0.0, 0.0)
    context_left1.rectangle(0, 0, 50, 50)
    context_left1.fill()

    context_left2.set_source_rgb(0.0, 1.0, 0.0)
    context_left2.rectangle(0, 0, 50, 50)
    context_left2.fill()

    context_right1.set_source_rgb(0.0, 0.0, 1.0)
    context_right1.rectangle(0, 0, 50, 50)
    context_right1.fill()

    context_right2.set_source_rgb(1.0, 1.0, 0.0)
    context_right2.rectangle(0, 0, 50, 50)
    context_right2.fill()

    context_left.set_source_surface(surface_left1)
    context_left.paint()

    x, y, width, height = surface_left1.ink_extents()
    context_left.translate(x + width, 0)
    context_left.set_source_surface(surface_left2)
    context_left.paint()

    context_right.set_source_surface(surface_right1)
    context_right.paint()

    x, y, width, height = surface_right1.ink_extents()
    context_right.translate(x + width, 0)
    context_right.set_source_surface(surface_right2)
    context_right.paint()

    context.set_source_surface(surface_left)
    context.paint()
    x, y, width, height = surface_left.ink_extents()
    context.translate(width, 0)  # width is -1 at this point

    context.set_source_surface(surface_right)
    context.paint()

Getting the ink_extents() from surface_left1 and surface_right1 works
fine.  But when I try to get the ink_extents() from surface_left
(which nests surface_left1 and surface_left2), I get:

    >>> surface_left.ink_extents()
    (-8388608.0, -8388608.0, -1.0, -1.0)

Anything I'm missing?  Maybe I'm not using the RecordingSurface the
way it's intended?


Thanks!
Daniel
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAlFmmsUACgkQi2kx5isbD8yUmQCcCBWmAufYDUN01ZojVtoWWuyd
dGsAmgOIy+LL0Q+1s4vUzUkkhQ+ZnOx+
=yV7p
-----END PGP SIGNATURE-----


More information about the cairo mailing list