pycairo icon indicating copy to clipboard operation
pycairo copied to clipboard

clip_preserve()-related drawing bug on Windows

Open schmave opened this issue 4 years ago • 7 comments

The sample Python code below draws this on a Mac using pycairo 1.20.1 and cairo 1.16.0 (installed via Homebrew):

example

On Windows using pycairo 1.20.0 and 1.20.1 (installed via pip using the Windows wheel), it draws this:

Screen Shot 2021-09-10 at 2 44 16 PM

import cairo

WIDTH, HEIGHT = 400, 400

surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)

ctx.scale(WIDTH, HEIGHT)

points = [[200, 100], [222.45139882897308, 169.09830056251377], [295.10565162951536, 169.09830056250527], [236.32712640025804, 211.80339887498624], [258.7785252292473, 280.90169943749476], [200.0, 238.196601125], [141.22147477075268, 280.9016994374947], [163.67287359974196, 211.80339887498624], [104.89434837048466, 169.09830056250522], [177.54860117102692, 169.09830056251377]]

ctx.new_path()
ctx.move_to(points[0][0] / WIDTH, points[0][1] / HEIGHT)
for point in points[1:]:
    ctx.line_to(point[0] / WIDTH, point[1] / HEIGHT)
ctx.close_path()

ctx.set_source_rgb(1, 0 ,0)

ctx.fill_preserve()
ctx.clip_preserve()

ctx.set_source_rgb(0, 1, 0)
ctx.set_line_width(.05)
ctx.stroke()

surface.write_to_png("example.png")

Any ideas what might be causing this? Let me know if I can provide any more information that would be helpful.

schmave avatar Sep 10 '21 18:09 schmave

Any ideas what might be causing this?

The wheels are packaged with cairo version 1.17.2. I could only think of that being a problem. Probably it would be better to ask cairo mailing list about this.

naveen521kk avatar Sep 13 '21 04:09 naveen521kk

+1 on asking on the cairo mailinglist, in general they are very helpful - and if this is a bug in cairo itself, they will definitely want to know.

I think most of the people here are on that list as well :)

stuaxo avatar Sep 13 '21 09:09 stuaxo

Also, FYI this is what I get with your code example On Arch linux, Cairo Version 1.17.4 and Pycairo 1.20.1. So I guess something is wrong with the version distributed in wheels?

naveen521kk avatar Sep 13 '21 09:09 naveen521kk

Thanks for the suggestion. I'll keep investigating and email the cairo mailing list soon.

schmave avatar Sep 13 '21 15:09 schmave

I see that there is now a 1.17.4 release of Cairo, with lots of fixes, including changes to the Windows build process. Is it possible/easy to make a new release of https://github.com/preshing/cairo-windows that uses 1.17.4?

schmave avatar Oct 12 '21 16:10 schmave

I think cairo version 1.17.4 uses meson build system, so it should be easy to build it ourselves. But that would mean we would be distributing a development release, is it fine @lazka?

naveen521kk avatar Oct 13 '21 05:10 naveen521kk

yes, ideally we should update to the snapshot, and port our cairo build to meson

lazka avatar Oct 13 '21 06:10 lazka