<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Tue, May 05 2020,Carl Worth <<a href="mailto:cworth@cworth.org" class="">cworth@cworth.org</a>>  wrote£º</div></blockquote><blockquote type="cite" class=""><div class=""><div class=""><br class="">Here's my best advice:<br class=""><br class="">1. Get (or make) a piece of graph paper, (paper with printed vertical<br class="">   and horizontal lines to form a grid of uniform squares.<br class=""><br class="">2. Label the line of the graph paper with integers.<br class=""><br class="">3. Plot the points of the path that you are constructing in cairo.<br class=""><br class="">Note: If you are filling the path, skip step 4.<br class=""><br class="">4. If you are going to stroke the path, plot new points that are<br class="">   separated orthogonally from the line segments of step (3) at a<br class="">   distance of one-half the current stroke width.<br class=""><br class="">Now, if all of the lines you drew in step (3), for cairo_fill, or in<br class="">step (4), for cairo_strike, lie precisely on the integer, printed lines<br class="">of your graph paper, then you should be seeing sharp results, (and<br class="">you should also not need to set CAIRO_ANTIALIAS_NONE to achieve that).<br class=""><br class="">Good luck. And have fun with cairo!<br class=""><br class="">-Carl<br class=""></div></div></blockquote></div><br class=""><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">How should I do to show a clear text like other apps by using cairo?<br class=""><div class=""><br class=""><div class="">picture url : <a href="https://i.stack.imgur.com/9q22H.png" class="">https://i.stack.imgur.com/9q22H.png</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">code:</div><div class=""><div style="color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Menlo, Monaco, "Courier New", monospace; line-height: 18px; white-space: pre;" class=""><div class=""><span style="color: rgb(78, 201, 176);" class="">cairo_surface_t</span> *surface;     </div><div class="">    <span style="color: rgb(78, 201, 176);" class="">cairo_t</span> *cr;                  </div><div class="">    surface = <span style="color: rgb(220, 220, 170);" class="">cairo_image_surface_create</span> (CAIRO_FORMAT_ARGB32, <span style="color: rgb(181, 206, 168);" class="">100</span>, <span style="color: rgb(181, 206, 168);" class="">100</span>);</div><div class="">    cr = <span style="color: rgb(220, 220, 170);" class="">cairo_create</span> (surface);</div><br class=""><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_set_source_rgb</span> (cr, <span style="color: rgb(181, 206, 168);" class="">0.0</span>, <span style="color: rgb(181, 206, 168);" class="">0.0</span>, <span style="color: rgb(181, 206, 168);" class="">0.0</span>);</div><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_paint</span>(cr);</div><br class=""><br class=""><div class="">    <span style="color: rgb(78, 201, 176);" class="">cairo_text_extents_t</span> extents;</div><div class="">    <span style="color: rgb(86, 156, 214);" class="">const</span> <span style="color: rgb(86, 156, 214);" class="">char</span> *utf8 = <span style="color: rgb(206, 145, 120);" class="">"bulrry text"</span>;</div><div class="">    <span style="color: rgb(86, 156, 214);" class="">double</span> x,y;</div><br class=""><div class="">    <span style="color: rgb(106, 153, 85);" class="">// cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);</span></div><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_select_font_face</span> (cr, <span style="color: rgb(206, 145, 120);" class="">"mono"</span>,</div><div class="">        CAIRO_FONT_SLANT_NORMAL,</div><div class="">        CAIRO_FONT_WEIGHT_NORMAL);</div><br class=""><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_set_font_size</span> (cr, <span style="color: rgb(181, 206, 168);" class="">14.0</span>);</div><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_text_extents</span> (cr, utf8, &extents);</div><div class="">    x = <span style="color: rgb(181, 206, 168);" class="">128.0</span>-(<span style="color: rgb(156, 220, 254);" class="">extents</span>.<span style="color: rgb(156, 220, 254);" class="">width</span>/<span style="color: rgb(181, 206, 168);" class="">2</span> );</div><div class="">    y = <span style="color: rgb(181, 206, 168);" class="">128.0</span>-(<span style="color: rgb(156, 220, 254);" class="">extents</span>.<span style="color: rgb(156, 220, 254);" class="">height</span>/<span style="color: rgb(181, 206, 168);" class="">2</span> );</div><br class=""><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_move_to</span> (cr, <span style="color: rgb(181, 206, 168);" class="">0</span>, <span style="color: rgb(181, 206, 168);" class="">15</span>);</div><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_set_source_rgba</span> (cr, <span style="color: rgb(181, 206, 168);" class="">1</span>, <span style="color: rgb(181, 206, 168);" class="">1</span>, <span style="color: rgb(181, 206, 168);" class="">1</span>, <span style="color: rgb(181, 206, 168);" class="">1</span>);</div><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_show_text</span> (cr, utf8);</div><br class=""><div class="">    <span style="color: rgb(106, 153, 85);" class="">/* draw helping lines */</span></div><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_set_source_rgb</span> (cr, <span style="color: rgb(181, 206, 168);" class="">1</span>, <span style="color: rgb(181, 206, 168);" class="">0</span>, <span style="color: rgb(181, 206, 168);" class="">0</span>);</div><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_set_line_width</span> (cr, <span style="color: rgb(181, 206, 168);" class="">1.0</span>);</div><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_rectangle</span>(cr, <span style="color: rgb(181, 206, 168);" class="">20.5</span>, <span style="color: rgb(181, 206, 168);" class="">20.5</span>, <span style="color: rgb(181, 206, 168);" class="">50</span>, <span style="color: rgb(181, 206, 168);" class="">50</span>);</div><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_stroke</span> (cr);</div><div class="">    <span style="color: rgb(220, 220, 170);" class="">cairo_surface_write_to_png</span>(surface , <span style="color: rgb(206, 145, 120);" class="">"./a.png"</span>);</div></div></div></div></div></body></html>