[cairo] here is pycairo +numpy example (Re: one question answered, and another comes (Re: FT_Bitmap_Convert, and FreeType's bitmap format vs Cairo's))

Hin-Tak Leung htl10 at users.sourceforge.net
Thu Apr 27 20:54:53 UTC 2017


Sorry this is the 3rd time I answer my own question... I worked out that it is possible to expose the buffer of a clipped region of an existing cairo surface directly as a multi-dimensional numpy array. So one could do a rather fast vector product between that and another region to see if there is there is any overlap. The code is from line 150 onwards:

https://github.com/rougier/freetype-py/pull/55/commits/e94090455dfb871581cc3c242a086d725f743389

and the result of packed drawings:
https://github.com/rougier/freetype-py/pull/55#issuecomment-297804370

I think it might be possible to do such things without using numpy, with a combination of drawing the 2nd shape as a reverse mask and see if cairo_fill_extents() goes to zero... anyway, for another time.

There is also something not-obvious in the cairo documentation: what do drawing operations do to FORMAT_A1/FORMAT_A8 surfaces, if I am just using them as plain gray drawing surfaces? I thought I'd just get 1-bit/8-bit equivalent operations (i.e. things going B/W or gray-scale). The answer is only obvious on hind-sight - A1/A8 means "alpha". Only the alpha channel of any drawing operation has any effect. Can somebody update the documentation to make it a bit more obvious?
(https://cairographics.org/manual/cairo-Image-Surfaces.html
http://pycairo.readthedocs.io/en/latest/reference/surfaces.html
http://pycairo.readthedocs.io/en/latest/reference/constants.html#constants-format )

--------------------------------------------
On Tue, 25/4/17, Hin-Tak Leung <htl10 at users.sourceforge.net> wrote:

... One of freetype-py's drawing example
 uses a vector sum between a clip of the drawing surface with
 the current drawing pattern to see if we are drawing over
 something that's already drawn in this single line:
 
 if (I[y-h//2:y-h//2+h,
 x-w//2:x-w//2+w,0] * L).sum() == 0:
 
 i.e. this calculates if L will draw on
 anything previously drawn in I. I am trying to figure out
 how to do this in cairo.
 
 How does one check if two shapes
 overlap, or two paths intersect, in cairo?
...


More information about the cairo mailing list