Clipping of subpixel anti-aliased text

Ben Harris bjh21 at bjh21.me.uk
Mon Apr 14 15:13:46 UTC 2025


I have a question that essentially boils down to: if I set the clipping 
region to a pixel-aligned rectangle, should I expect pixels outside that 
rectangle to be unaffected by drawing operations?

The specific example that leads me to ask this is demonstrated by the 
attached program.  It creates a 20 × 20 pixel image surface sets the 
clipping region to precisely the left half of the surface, and then 
repeatedly shows a ']' character and then erases it using cairo_paint().

My hope was that this would leave the whole image black because the last 
operation is to paint the entire clip region.  But on my test systems 
(Debian bookworm and trixie, Cairo 1.16.0 and 1.18.4 respectively) I get a 
column of red pixels just outside the clipping rectangle.

What is the expected behaviour here?  I can see that for an arbitrary 
clipping region it's not possible to clip drawing operations in a way that 
can be perfectly undone.  But in the special case of a pixel-aligned 
rectangle it should be possible.  Or do I need to use 
cairo_surface_create_for_rectangle() to get perfect clipping?

Aside: the context where I found this problem was the GTK version of the 
PuTTY terminal emulator, which needs to be able to reliably update only 
part of the terminal screen.

-- 
Ben Harris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: overflow.c
Type: text/x-csrc
Size: 1245 bytes
Desc: Demonstration C program
URL: <https://lists.cairographics.org/archives/cairo/attachments/20250414/c82d6417/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: out.png
Type: image/png
Size: 114 bytes
Desc: Output PNG file from the program
URL: <https://lists.cairographics.org/archives/cairo/attachments/20250414/c82d6417/attachment.png>


More information about the cairo mailing list