[cairo] xor fill
Dan McMahill
dan at mcmahill.net
Wed Jan 21 04:33:16 PST 2009
Travis Griggs wrote:
> On Jan 20, 2009, at 7:18 PM, Dan McMahill wrote:
>
>> is there a way to do an xor fill with cairo? I know about
>> cairo_fill()
>> and cairo_fill_preserve() but can't seem to figure out how to do an
>> xor
>> fill.
>
>
> No, there is not. Having whined about it myself once upon a time, I
> feel obligated to pass on the news. That said, I've found that Cairo
> has allowed me to do graphical things in place of xor solutions that I
> liked way better anyway. In short, it's a bummer, because if you just
> want to port an older idea of portraying something, you can't, but
> OTOH, it's cool, because Cairo will force you to do it cooler anyway.
>
> It would be interesting to hear what you were hoping to use it for, we
> might suggest something cooler. :)
I'm writing a pstoedit cairo driver. pstoedit (www.pstoedit.net) is a
program that takes a postscript file and converts it into one of several
different possible vector formats. Often times the goal is to have
something editable. What my cairo driver does is you feed pstoedit a
postscript file and out comes c-code which has everything in it you need
to render the page(s) with cairo.
My application is I have a program I wrote many years ago that I was
converting over to use GtkPrint so I could support printing under win32
and have a much nicer print dialog under unix-like operating systems. I
have a dozen or so figures which were drawn with the program tgif. In
older versions of my program, I use xpm versions of my drawings (tgif
can produce those) for display in my dialogs and eps versions (tgif can
produce those too) for printing. However, I can't directly use
postscript for printing in the GtkPrint world. So.... I was looking for
a way, short of redrawing all of my figures, to be able to do a decent
rendering of them with cairo with printing in mind.
It turns out that it wasn't too hard to write the cairo pstoedit driver
and I'm down to a small number of issues[1]. Of these, implementing an
XOR fill is a big one. That is fairly key since it is a drawing model
that postscript uses.
I've tried cairo_set_operator (cr, CAIRO_OPERATOR_XOR); before a
cairo_fill() or cairo_fill_preserve() and then restore with
cairo_set_operator(cr, CAIRO_OPERATOR_OVER). But that just didn't turn
out to be even close. I ended up with the fill doing wierd things all
over my surface in places I didn't really expect.
-Dan
[1] In case anyone cares my list of issues is:
- fix font selection
- implement xor fill
- figure out how to deal with image and imagemask
More information about the cairo
mailing list