Re: Query regarding Cairo.
"Bryce W. Harrington" <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <5A5FB412583EA944A1D0228D52A9C57263A8B9@sisaex02sj> |
Hi Gaurav, If you use all the cairo_move_to() calls then you end up with a rectangle made up of four discontinuous line segments. http://www.bryceharrington.org/files/g.pruthi.before.png Instead just use the first cairo_move_to() and then only cairo_line_to() after that. See: http://www.bryceharrington.org/files/g.pruthi.c http://www.bryceharrington.org/files/g.pruthi.after.png Btw, the final cairo_line_to() call (when i==3) is unnecessary in this case; the cairo_close_path() call will complete the last line of the rect. http://www.bryceharrington.org/files/g.pruthi.c I couldn't find the tutorial that this sample code comes from. If you could please point me at it; if it's a cairographics.org tutorial it may need to be improved. -- Bryce Harrington Senior Open Source Developer - [email protected] Open Source Group - Samsung Research America ________________________________ From: Gaurav Pruthi [[email protected]] Sent: Thursday, July 04, 2013 1:07 AM To: Bryce W. Harrington Subject: Query regarding Cairo. Hi Bryce, I found you on cairo mailing list. Just have one query if you have time to look into. I have just started using cairo library... I have seen examples to fill a polygon which are repetitive calls to move_to() and line_to() routines. When I tried following snippet of code which is mentioned in most of the tutorials, but it didn't worked. void drawRectangle(cairo_t* cr) { cairo_path_t path; cairo_path_data_t pathData[4]; pathData[0].point.x = 10 ; pathData[0].point.y = 20; pathData[1].point.x = 210; pathData[1].point.y = 20; pathData[2].point.x = 210; pathData[2].point.y = 320; pathData[3].point.x = 10; pathData[3].point.y = 320; //Set path data in path cairo_move_to(cr, pathData[0].point.x, pathData[0].point.y); for(int i =0 ; i<= 3; ++i) { cairo_move_to(cr, pathData[i].point.x, pathData[i].point.y); if(i == 3){ cairo_line_to(cr, pathData[0].point.x, pathData[0].point.y); } else cairo_line_to(cr, pathData[i+1].point.x, pathData[i+1].point.y); } cairo_close_path(cr); cairo_set_source_rgb(cr,1.0,0.0,0.0); cairo_fill_preserve(cr); cairo_set_source_rgba(cr,0.0,1.0,0.0,0.5); cairo_set_line_width(cr,10.0); cairo_stroke(cr); } But this one worked where I am moving to the first point and just making line_to() calls is working .. below one: void drawRectangle(cairo_t* cr) { cairo_path_t path; cairo_path_data_t pathData[4]; pathData[0].point.x = 10 ; pathData[0].point.y = 20; pathData[1].point.x = 210; pathData[1].point.y = 20; pathData[2].point.x = 210; pathData[2].point.y = 320; pathData[3].point.x = 10; pathData[3].point.y = 320; cairo_move_to(cr, pathData[0].point.x, pathData[0].point.y); for(int i =0 ; i< =3 ; ++i) { cairo_line_to(cr, pathData[i].point.x, pathData[i].point.y); } cairo_close_path(cr); cairo_set_source_rgb(cr,1.0,0.0,0.0); cairo_fill_preserve(cr); cairo_set_source_rgba(cr,0.0,1.0,0.0,0.5); cairo_set_line_width(cr,10.0); cairo_stroke(cr); } First sample is based on the examples available on internet. Can you pls tell whats the problem with the first one. Thanks a lot for your time. Gaurav Pruthi Display Platform Samsung R&D India - Delhi Lab [UrlBlockedError.aspx] -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo