<div dir="ltr"><br><div class="gmail_quote"><div dir="ltr">Hi,<br><br>I had just started using cairo library... I have seen examples to fill a closed curve, where I found the method is repetitive of move_to() and line_to()<br>
calls.<br>When I tried following snippet of code which is mentioned in most of the tutorials, it didn't worked<br>
<br>void drawRectangle(cairo_t* cr)<br>{<br> cairo_path_t path;<br> cairo_path_data_t pathData[4];<br> pathData[0].point.x = 10 ;<br> pathData[0].point.y = 20;<br> <br> pathData[1].point.x = 210;<br> pathData[1].point.y = 20;<br>
<br> pathData[2].point.x = 210;<br> pathData[2].point.y = 320;<br><br> pathData[3].point.x = 10;<br> pathData[3].point.y = 320;<br> //Set path data in path<br> path.data = pathData;<br> path.num_data = 4;<br>
path.status = CAIRO_STATUS_SUCCESS;<br><br> cairo_move_to(cr, pathData[0].point.x, pathData[0].point.y);<br> for(int i =0 ; i<= path.num_data -1; ++i)<br> {<br> cairo_move_to(cr, pathData[i].point.x, pathData[i].point.y);<br>
if(i == 3){<br> cairo_line_to(cr, pathData[0].point.x, pathData[0].point.y);<br> }<br> else<br> cairo_line_to(cr, pathData[i+1].point.x, pathData[i+1].point.y);<br> }<br> <br>
cairo_close_path(cr);<br><br> cairo_set_source_rgb(cr,1.0,0.0,0.0);<br> cairo_fill_preserve(cr);<br><br> cairo_set_source_rgba(cr,0.0,1.0,0.0,0.5);<br> cairo_set_line_width(cr,10.0);<br> cairo_stroke(cr);<br>
<br>}<br><br><br>But this one worked where I am moving to the first point and just making line_to() calls :<br><br>void drawRectangle(cairo_t* cr)<br>{<br> cairo_path_t path;<br> cairo_path_data_t pathData[4];<br>
pathData[0].point.x = 10 ;<br> pathData[0].point.y = 20;<br> <br> pathData[1].point.x = 210;<br> pathData[1].point.y = 20;<br><br> pathData[2].point.x = 210;<br> pathData[2].point.y = 320;<br><br> pathData[3].point.x = 10;<br>
pathData[3].point.y = 320;<br> //Set path data in path<br> path.data = pathData;<br> path.num_data = 4;<br> path.status = CAIRO_STATUS_SUCCESS;<br><br> cairo_move_to(cr, pathData[0].point.x, pathData[0].point.y);<br>
for(int i =0 ; i< path.num_data; ++i)<br> {<br> <br> cairo_line_to(cr, pathData[i].point.x, pathData[i].point.y);<br> }<br> <br> cairo_close_path(cr);<br><br> cairo_set_source_rgb(cr,1.0,0.0,0.0);<br>
cairo_fill_preserve(cr);<br><br> cairo_set_source_rgba(cr,0.0,1.0,0.0,0.5);<br> cairo_set_line_width(cr,10.0);<br> cairo_stroke(cr);<br> <br>}<br><br><br>Can somebody please tell why its showing different behavious than what is mentioned in most of the places. even here also:<br>
<a href="http://cairographics.org/samples/" target="_blank">http://cairographics.org/samples/</a><br><div><div><br></div><div> Thanks<br></div><div><div dir="ltr"><font face="Default Sans Serif,Verdana,Arial,Helvetica,sans-serif">
<p style="margin:0px"><font color="#500050"> </font><span style="color:rgb(80,0,80)">Gaurav Pruthi</span></p><p style="font-size:small;margin:0px"><a href="http://en.wikipedia.org/wiki/User:Gaurav_Pruthi" style="color:rgb(17,85,204);font-size:13px" target="_blank"> http://en.wikipedia.org/wiki/User:Gaurav_Pruthi</a><br>
</p></font><font face="Default Sans Serif,Verdana,Arial,Helvetica,sans-serif"><br></font></div></div></div></div></div>
</div>