[cairo] cairo-1.13 finally opens

Krzysztof Kosiński tweenk.pl at gmail.com
Fri Sep 6 06:04:41 PDT 2013


2013/9/6 Henry (Yu) Song - SISA <henry.song at samsung.com>:
> Hi, Bill
>
>
> Draw a drop shadow is in the following sequence
>
> /* set up shadow spec */
> cairo_set_shadow (cr, CAIRO_SHADOW_DROP);
> cairo_set_shadow_rgba (cr, ....);
> cairo_set_shadow_offset (cr, x, y);
> cairo_set_shadow_blur (cr, blur_x, blur_y);
>
> /* setup draw path */
> cairo_arc (cr, ......);
> cairo_set_source_rgba (cr, ......);
>
> /* draw both shadow and object */
> cairo_fill/stroke (cr);

>From an application programmer perspective, I find this API really
strange. It tacks on the shadow as an extra context attribute, like
line parameters, which is not how I think about filter effects. A much
better API from my point of view would be something like this:

cairo_set_blur(cr, blur_x, blur_y);
cairo_fill(cr);

Drop / inset shadow is a "high level" effect and I don't think it has
to be implemented directly in the API, unless there are substantial
performance gains from doing so.

> cairo_set_draw_shadow_only (cr, TRUE);  // this inform cairo to draw shadow with current path without drawing the object itself */

This is a really ugly hack that should not be necessary.

> Inset shadow is a different story, inset shadow requires blur inwards instead of outwards.  so the ugly API I come up with is used for draw a custom shadow path, tells cairo to blur it inwards. and app uses clip to bound the drawing area.  This is only if you want to have a custom shadow path for inset shadow.  If you don't need a custom shadow path,  it is drawn like example above. for example

Why not:
cairo_fill_preserve(cr);
cairo_clip_preserve(cr);
cairo_set_blur(...);
cairo_set_source(...); // change shadow color
cairo_fill(cr);

This also allows patterned shadows, which are not possible under your approach.

Regards, Krzysztof


More information about the cairo mailing list