[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cairo
Subject:    Re: [cairo] a about draw line
From:       Zack Weinberg <zweinberg () mozilla ! com>
Date:       2009-09-20 17:45:31
Message-ID: 20090920104531.709c0d16 () trurl
[Download RAW message or body]

å¼ çŽ²æ˜¥ <zlc53@163.com> wrote:
> I use cairo to draw a horizontal line, regardless of how much the use
> of cairo_line_width set, I found it to be occupied by 2 pixels high
> census drawn. I would like to draw a precise line, may I ask how to do

The coordinate grid lies between the pixels, and stroke lines are
centered on their coordinates.  Thus, a horizontal line stroked at an
integer y-coordinate [for instance, (0,10) -- (10,10)] adds color to
*two* rows of pixels, no matter how narrow it is: the row directly
above its grid line, and the row directly below.

So if you want to stroke exactly one row of pixels, set the line width
to 1, then add (or subtract) 0.5 to the y-coordinate of both the start
and end points.  Similarly, for a single-pixel vertical line, do this
to the x-coordinates.

This gotcha does not apply when you are filling rather than stroking:
filling the box (0,10) -- (10,10) -- (10,11) -- (0,11) -- closepath is
another way to draw a single pixel horizontal line.

zw
_______________________________________________
cairo mailing list
cairo@cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic