[cairo] Changing line color

Maarten Bosmans mkbosmans at gmail.com
Fri Aug 27 05:46:03 PDT 2010


2010/8/27 necko necko <opustenom at hotmail.com>:
> In order for my pdf file to look nicer, I changed the background to black,
> and now
> I need to emphasize a number of lines between certain coordinates. Some
> lines need
> to be shown as red, some as green, and some as blue, or a variation.
> I tested the above requirement with the code below:
>   cairo_set_line_width (cr, .5);
>   cairo_set_source_rgb(cr, 1, 0, 0);
>   cairo_move_to (cr, 152.84, -50.0);
>   cairo_line_to (cr, 83.97, 30.93);
>   cairo_stroke_preserve(cr);
>
>   cairo_set_source_rgb(cr, 0, 0, 1);
>   cairo_move_to(cr, 90, 1);
>   cairo_line_to(cr, 40, 1);
>   cairo_stroke_preserve(cr);
> ......................................
> However, both lines are displayed as blue, with a very thin red line in the
> middle of it.
> Is there a way to specify that one line needs to be only blue, and the other
> only red?
> What would be the code to try?
> I appreciate your help.

You'll want to user cairo_stroke instead of cairo_stroke_preserve.
Because in the code above the second path from the blue line gets
added to the already exisiting path you used for the red line, thus
rendering the two lines on top of eachother.

Maarten


More information about the cairo mailing list