[cairo] The line still blurry after I follow "Frequently Asked Questions" guide

mryangjian mryangjian at live.com
Tue May 5 01:51:05 UTC 2020

> On Tue, May 05 2020,Carl Worth <cworth at cworth.org>  wrote:
> Here's my best advice:
> 1. Get (or make) a piece of graph paper, (paper with printed vertical
>   and horizontal lines to form a grid of uniform squares.
> 2. Label the line of the graph paper with integers.
> 3. Plot the points of the path that you are constructing in cairo.
> Note: If you are filling the path, skip step 4.
> 4. If you are going to stroke the path, plot new points that are
>   separated orthogonally from the line segments of step (3) at a
>   distance of one-half the current stroke width.
> Now, if all of the lines you drew in step (3), for cairo_fill, or in
> step (4), for cairo_strike, lie precisely on the integer, printed lines
> of your graph paper, then you should be seeing sharp results, (and
> you should also not need to set CAIRO_ANTIALIAS_NONE to achieve that).
> Good luck. And have fun with cairo!
> -Carl

Hi, Thank your guide, and now I know this is not cairo's problem but SDL2, SDL2 need to set SDL_WINDOW_ALLOW_HIGHDPI to show a single pixel line, but I found another problem, and this time I use cairo_surface_write_to_png without SDL2, the line is clear and bright, but the text is blurry. the blew picture is a text compare between cairo and other apps.

How should I do to show a clear text like other apps by using cairo?

picture url : https://i.stack.imgur.com/9q22H.png <https://i.stack.imgur.com/9q22H.png>

cairo_surface_t *surface;     
    cairo_t *cr;                  
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 100, 100);
    cr = cairo_create (surface);

    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);

    cairo_text_extents_t extents;
    const char *utf8 = "bulrry text";
    double x,y;

    // cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);
    cairo_select_font_face (cr, "mono",

    cairo_set_font_size (cr, 14.0);
    cairo_text_extents (cr, utf8, &extents);
    x = 128.0-(extents.width/2 );
    y = 128.0-(extents.height/2 );

    cairo_move_to (cr, 0, 15);
    cairo_set_source_rgba (cr, 1, 1, 1, 1);
    cairo_show_text (cr, utf8);

    /* draw helping lines */
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_set_line_width (cr, 1.0);
    cairo_rectangle(cr, 20.5, 20.5, 50, 50);
    cairo_stroke (cr);
    cairo_surface_write_to_png(surface , "./a.png");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20200505/89209e0b/attachment.htm>

More information about the cairo mailing list