[cairo] dashes not rectangular

Andrea Canciani ranma42 at gmail.com
Wed Mar 2 10:25:55 PST 2011


On Wed, Mar 2, 2011 at 6:58 PM, Vojtech Fried <vfried at opentext.com> wrote:
> Here is a sample:
>
> import cairo
>
> width = 800
> height = 600
> thickness = 20
>
> surf = cairo.ImageSurface(
>    cairo.FORMAT_ARGB32,
>    int(width),
>    int(height) )
> cairoctx = cairo.Context( surf )
> cairoctx.set_fill_rule( cairo.FILL_RULE_EVEN_ODD )
> cairoctx.set_antialias( cairo.ANTIALIAS_GRAY )
>
> #only background
> cairoctx.set_source_rgba( 1.0, 1.0, 1.0 )
> cairoctx.rectangle( 0.0, 0.0, width, height )
> cairoctx.fill()
> cairoctx.set_source_rgba( 0.0, 0.0, 0.0 )
>
> dash_koef = 3.0
> gap_koef = 1.0
> cairoctx.set_dash( [ dash_koef * thickness, gap_koef * thickness ] )
> cairoctx.set_line_join( cairo.LINE_JOIN_MITER )
> cairoctx.set_line_cap( cairo.LINE_CAP_BUTT )
> cairoctx.set_line_width( thickness )
> cairoctx.rectangle( 10.0, 10.0, 100, 100 )
> cairoctx.stroke()
>
> surf.write_to_png( "sample.png" )
>
> And here is the result:
> http://img849.imageshack.us/i/samplev.png
>
> What I don't like is the top left and bottom left dash.

I don't like them either!
Here is the bug tracking this issue:
https://bugs.freedesktop.org/show_bug.cgi?id=17973

The behavior is currently different depending on the backend,
I think we want to implement the PDF or PS behavior, but
that is unlikely to happen before the stroke code is rewritten
to implement stroke-to-path.

Andrea


More information about the cairo mailing list