[cairo] The line still blurry after I follow "Frequently Asked Questions" guide
mustodo
mryangjian at live.com
Sun May 3 05:32:55 UTC 2020
Hi,
Cairo and Skia is two best library for cross-platform GUI, but I prefer to use Cairo because it smaller and write by c, skia is too huge for apps.
when I used Cairo to draw a rectangle, the line is blurry even if I use round numbers.
func (me *canvas) DrawRectF(left, top, right, bottom float32, paint *Paint) {
if right <= left || bottom <= top {
return
}
C.cairo_set_antialias(me.ptr, C.CAIRO_ANTIALIAS_NONE)
fix := paint.Style == STROKE && int32(paint.Width)%2 != 0
fix = false
if fix {
me.Save()
me.TranslateF(0.5, 0.5)
}
C.cairo_rectangle(me.ptr, 100, 100, 500, 500)
C.cairo_rectangle(me.ptr, 110, 110, 510, 510)
me.drawPaint(paint)
if fix {
me.Restore()
}
}
this is a line in cairo
this is a line in code editor
I searched and found a guide at official website.I readed the "Frequently Asked Questions" > "How do I draw a sharp, single-pixel-wide line?" and follow the guide
cairo_user_to_device (cr, &x, &y);
do_rounding (&x, &y);
cairo_device_to_user (cr, &x, &y);
it is used round numbers, so it has none change
func (me *canvas) UserToDevice(x, y float32) {
dx := C.double(x)
dy := C.double(y)
C.cairo_user_to_device(me.ptr, &dx, &dy)
log.V("userToDevice x=%f, y=%f, dx=%f, dy=%f", x, y, dx, dy)
C.cairo_device_to_user(me.ptr, &dx, &dy)
log.V("deviceToUser x=%f, y=%f, dx=%f, dy=%f", x, y, dx, dy)
}
// output
// userToDevice x=100.000000, y=500.000000, dx=100.000000, dy=500.000000
// deviceToUser x=100.000000, y=500.000000, dx=100.000000, dy=500.000000
I tried Cairo versions cairo-1.14.12 cairo-1.16.0_2 cairo-1.16.0_3
So, how should I do to draw a sharp with single-pixel-wide line like code editor?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20200503/aab98fb1/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2020-05-03 ??1.29.37.png
Type: image/png
Size: 20098 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20200503/aab98fb1/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2020-05-03 ??1.30.19.png
Type: image/png
Size: 23475 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20200503/aab98fb1/attachment-0003.png>
More information about the cairo
mailing list