[cairo] Stroke adjust for filled rectangles?

David Kastrup dak at gnu.org
Fri Jul 24 08:56:11 PDT 2015

Andreas Lobinger <lobingera at gmail.com> writes:

> Hello colleague,
> first to your question, if it would be possible to detect the case;
> closely looking at the rendering model which consecutively puts paint
> onto a surface it think it would be hard to do. The detection would
> need to look at consecutive stroke and fill operations and delaying
> the rendering until decision.
> Traditionally the concept of stroke adjustment is considered in
> rendering lines and in the first place i'd rather try to find a path
> construction of stems that is essentially a line stroked, that would
> have the bonus that you can at least ask the PDF viewer to apply
> stroke adjustment and see what it tries to forward to cairo path
> construction.

Shrug.  Because of the antialiasing behavior of Cairo, we can only do a
single stroke over the whole rectangle width.  In order to get the
rounded corners, there needs to be a clipping path set that will round
out the corners from this large stroke.  The clipping path needs to cut
off top and bottom but must not "accompany" the gist of the stroke in
order not to interfere with its stroke adjustment and aliasing.

The rounded corners are still bumpy since obviously the border of the
stroke is stroke-adjusted while the clipping path for rounding the
corners isn't.  So they don't join up perfectly.

Also the PDF file tends to be about 5 times the size compared to not
doing this.  Probably acerbated by us writing PostScript and using
Ghostscript's ps2pdf for converting to PDF.  But that's supposed to
leave stuff in a rather similar state regarding the rendering model.

>> I encountered the problem in the past that note stems in LilyPond
>> render rather inconsistently and generally too thick in PDF viewers
>> using Cairo.
>> Now the stems are rounded rectangles, and they are unsurprisingly
>> done by stroking a closed rectangle with a circular pen (or rather
>> with a given line thickness and rounded corners) and then filling the
>> path.

David Kastrup

More information about the cairo mailing list