[cairo] How to draw an invisible rectangle?

Baz brian.ewins at gmail.com
Sun Dec 16 12:18:19 PST 2007


On Dec 16, 2007 7:13 PM, Tuom Larsen <tuom.larsen at gmail.com> wrote:
>
>
>
> On Dec 16, 2007 7:27 PM, Baz <brian.ewins at gmail.com> wrote:
>
> > what's wrong with
> > cairo_set_source_rgba (cr, 0, 0, 0, 0);
> > cairo_fill (cr);
> >
> > which should emit "fill: rgb(0,0,0); fill-opacity: 0" instead of
> > "fill: none". The path will be transparent but used for flow
> > calculations.
> >
>
> I don't want to picky, this surely works for very most cases. However:
>
>
> - it requires PDF 1.4

That's what cairo emits. I'm struggling to think of a pdf reader that
doesn't support PDF 1.4 - do you mean as opposed to Postscript?

> - probably is slower to render

Possibly, but this case can be optimised - if we have a solid fill
with an opacity of 0 we can choose not to tesselate it (I don't know
if this is done at present).

> - doesn't work that well for lines and open curves because a line has a
> width which might grow the bbox

You used an svg example - in svg the bbox doesn't include stroke
width. There are differences between cairo's reported extents and
svg's bbox for lines; see this thread for details:
http://lists.cairographics.org/archives/cairo/2007-November/012011.html

> - that "rgb(0,0,0)" makes no sence for "invisible"

What's red and invisible? No tomatoes. :)

Any colour looks the same when its transparent. This choice zero-fills
memory in rgba bitmaps, which can be convenient.

>
> But as I said, this works for most practical purposes, so thank you!
>

No problem, have fun with cairo!

-Baz


More information about the cairo mailing list