Fwd: Regarding problem filling a closed curve.

Gaurav Pruthi <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAHnWcY3o5-E9PsLT3Y1cAP-v=bfa61nfaL6T6a8JPZU7Qd6S+Q@mail.gmail.com>
Hi,

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()
calls.
When I tried following snippet of code which is mentioned in most of the
tutorials, 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
    path.data = pathData;
    path.num_data = 4;
    path.status = CAIRO_STATUS_SUCCESS;

    cairo_move_to(cr, pathData[0].point.x, pathData[0].point.y);
    for(int i =0 ; i<= path.num_data -1; ++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 :

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
    path.data = pathData;
    path.num_data = 4;
    path.status = CAIRO_STATUS_SUCCESS;

    cairo_move_to(cr, pathData[0].point.x, pathData[0].point.y);
    for(int i =0 ; i< path.num_data; ++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);

}


Can somebody please tell why its showing different behavious than what is
mentioned in most of the places. even here also:
http://cairographics.org/samples/

 Thanks

 Gaurav Pruthi

 http://en.wikipedia.org/wiki/User:Gaurav_Pruthi<http://en.wikipedia.org/wiki/User:Gaurav_Pruthi>

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.