[cairo] dashes not rectangular

Vojtech Fried vfried at opentext.com
Wed Mar 2 09:58:17 PST 2011


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.

Vojtech



-----Original Message-----
From: Andrea Canciani [mailto:ranma42 at gmail.com] 
Sent: Wednesday, March 02, 2011 6:05 PM
To: Vojtech Fried
Cc: cairo at cairographics.org
Subject: Re: [cairo] dashes not rectangular

On Wed, Mar 2, 2011 at 4:46 PM, Vojtech Fried <vfried at opentext.com> wrote:
> Hi,
>
> When drawing a rectangle with a dashed line, the (individual) dash at the
> corner is not rectangular.
>
> It looks like (bottom right corner of the rectangle, horizontal line, two
> pixels wide):
>
> xxx
> xxxx
>
> instead of either
>
> xxx
> xxx
>
> or
>
> xxxx
> xxxx
>
>
> Is this normal? It makes sense because the dash is aligned with 45degree
> line - the axis of the right angle. But on the other hand it does not look
> pretty - it is not rectangular. Especially when the line is thicker i.e.
> when the 'x' from the example above represents more than one pixel but an
> area of 4x4 pixels or more.

I'm not sure if I understood your problem. There are some known
problems/bugs with Cairo path-stroking code, but your does not
look like one of them.

Could you provide a small code snippet to reproduce it or images showing it?

Andrea


More information about the cairo mailing list