[cairo] Stroke a 'frame' around a complex shape. Possible?

Stefan Landvogt stefan.landvogt at gmail.com
Mon Mar 30 09:12:52 PDT 2009


Dear list,

lets assume, that I have two overlapping rectangles. A big one (0, 0, 100,
100 defined as bigBoxPath) and a small one ( 40, 60, 60, 120 defined as
smallBoxPath) that has some part of it outside the bigger rectangle. The
outer rect for that whould be something like (0, 0, 100, 120, defined as
outerBoxPath) without taking in account, that a stroke would make that
bounding rect bigger because of how the stroke works.

I can create a path and fill them both, but now I want to stroke around the
outline of the complete shape, but no 'stroke' should appear inside the
shape. Also it would be nice, if this stroke can happen with a dashed
line...

Any hints how to do that or where to look to find out? This also should work
with any shape for the two paths: rectangles are just the simplest ones...

The ultimate goal is actually to draw a speech bubble with multiple tipping
points, while the speech bubble might be an ellipse shape or even some
random shape...
I am not trying to do that with one path, because at some point the tipping
point needs to be moved, and then the construction of the path would get
crazy, so my goal at the moment is to draw the 'textbox' and the tipping
points as separate objects...

Thank you so much in advance,
Stefan

PS-1:
Yes, I searched the archive and saw the posts about interactive drawing
(which I am doing) and the union of paths, but they did not really help...

PS-2:
I experimented with some clipping like in the following code fragment, that
is using my own library that is wrapping the Cairo commands, but it should
be obvious what it does.
It does almost what I want but the outline of the smaller box is not drawn,
because the clipping of the bigger box is using the fill shape, so the
intersections are ugly...

    context->Save();

    context->SetColor(0, 0, 255, 128);
    context->Path(bigBoxPath);
    context->Path(smallBoxPath);
    context->Fill();

    context->SetFillRule(CAIRO_ FILL_RULE_EVEN_ODD);
    context->Path(smallBoxPath);
    context->Path(outerBoxPath);
    context->Clip();
    context->SetFillRule( CAIRO_FILL_RULE_WINDING);

    context->SetColor(128, 0, 0, 255);
    context->SetLineWidth(frameWidth);
    context->Path(bigBoxPath);
    context->Stroke();
    context->ResetClip();

    context->SetFillRule( CAIRO_FILL_RULE_EVEN_ODD);
    context->Path(outerBoxPath);
    context->Path(bigBoxPath);
    context->Clip();
    context->SetFillRule( CAIRO_FILL_RULE_WINDING);

    context->SetColor(128, 0, 0, 255);
    context->SetLineWidth(frameWidth);
    context->Path(smallBoxPath);
    context->Stroke();
    context->ResetClip();

    context->Restore();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20090330/777eaedb/attachment.html 


More information about the cairo mailing list