[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cairo
Subject:    [cairo] Stroke a 'frame' around a complex shape. Possible?
From:       Stefan Landvogt <stefan.landvogt () gmail ! com>
Date:       2009-03-30 16:12:52
Message-ID: 8052c610903300912l54d26004m2c8682b4688220b0 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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();

[Attachment #5 (text/html)]

Dear list,<br><br>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.<br>
<br>I can create a path and fill them both, but now I want to stroke
around the outline of the complete shape, but no &#39;stroke&#39; should ap=
pear
inside the shape. Also it would be nice, if this stroke can happen with
a dashed line...<br>
<br>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...<br><br>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...<br>
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 &#39;textbox&#39; =
and
the tipping points as separate objects...<br>
<br>Thank you so much in advance,<br>Stefan<br><br>PS-1:<br>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...<br><br>=
PS-2:<br>
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.<br>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...<br>
<br>=A0=A0=A0 context-&gt;Save();<br><br>=A0=A0=A0 context-&gt;SetColor(0, =
0, 255, 128);<br>=A0=A0=A0 context-&gt;Path(bigBoxPath);<br>=A0=A0=A0 conte=
xt-&gt;Path(smallBoxPath);<br>=A0=A0=A0 context-&gt;Fill();<br><br>=A0=A0=
=A0 context-&gt;SetFillRule(CAIRO_<div>

FILL_RULE_EVEN_ODD);<br>
=A0=A0=A0 context-&gt;Path(smallBoxPath);<br>=A0=A0=A0 context-&gt;Path(out=
erBoxPath);<br>=A0=A0=A0 context-&gt;Clip();<br>=A0=A0=A0 context-&gt;SetFi=
llRule( CAIRO_FILL_RULE_WINDING);<br><br>=A0=A0=A0 context-&gt;SetColor(128=
, 0, 0, 255);<br>=A0=A0=A0 context-&gt;SetLineWidth(frameWidth);<br>


=A0=A0=A0 context-&gt;Path(bigBoxPath);<br>=A0=A0=A0 context-&gt;Stroke();<=
br>=A0=A0=A0 context-&gt;ResetClip();<br><br>=A0=A0=A0 context-&gt;SetFillR=
ule( CAIRO_FILL_RULE_EVEN_ODD);<br>=A0=A0=A0 context-&gt;Path(outerBoxPath)=
;<br>=A0=A0=A0 context-&gt;Path(bigBoxPath);<br>


=A0=A0=A0 context-&gt;Clip();<br>=A0=A0=A0 context-&gt;SetFillRule( CAIRO_F=
ILL_RULE_WINDING);<br><br>=A0=A0=A0 context-&gt;SetColor(128, 0, 0, 255);<b=
r>=A0=A0=A0 context-&gt;SetLineWidth(frameWidth);<br>=A0=A0=A0 context-&gt;=
Path(smallBoxPath);<br>=A0=A0=A0 context-&gt;Stroke();<br>


=A0=A0=A0 context-&gt;ResetClip();<br><br>=A0=A0=A0 context-&gt;Restore();<=
/div>


_______________________________________________
cairo mailing list
cairo@cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic