[cairo] fractional positioning + glyph caching

Cosmin Apreutesei cosmin.apreutesei at gmail.com
Thu Jun 27 05:40:49 PDT 2013

>> A related question. I tried:
>> cairo_set_antialias(CAIRO_ANTIALIAS_SUBPIXEL)
>> font_options:set_antialias(CAIRO_ANTIALIAS_SUBPIXEL)
>> cairo_set_font_options(font_options)
>> but it does not affect cairo_show_glyphs(), which always renders in
>> grayscale, but it does work with cairo_show_text() - a bug?
> Not expected.  Test case?

Actually, I rebuilt freetype with subpixel rendering support and now
it works with cairo_show_glyphs() which renders glyphs with freetype's
renderer it seems, while cairo_show_text() was rendering with winapi
because it was using a windows font not a freetype-loaded font. It
would be nice if these details would get a mention in the cairo doc
(i.e. the fact that cairo uses font backend rasterizer instead of it's
own rasterizer, like with cairo_glyph_path() and thus different
rendering options are available and/or behave differently).

Anyway, I have an interactive demo that covers all combinations but
it's windows only. Download the zip files from here
https://code.google.com/p/lua-files/downloads/list and then run

> bin\luajit.exe harfbuzz_demo.lua

>> Also, I noticed that CAIRO_ANTIALIAS_BEST makes cairo_show_glyphs() to
>> render each glyph horizontally stretched 3x - a bug?
> Wow.  Definitely.

To test this just set CAIRO_ANTIALIAS_BEST on any freetype-loaded font.

Here's a snippet:

FT_Library ft_lib = FT_New_Library()
FT_Face ft_face = FT_New_Face(ft_lib, 'DejaVuSerif.ttf')
cairo_font_face_t cairo_face = cairo_ft_font_face_create_for_ft_face(ft_face, 0)
cairo_font_options_t font_options = cairo_font_options_create()
cairo_font_options_set_antialias(font_options, CAIRO_ANTIALIAS_BEST)
cairo_set_font_options(cr, font_options)
cairo_set_source_rgb(cr, 1, 1, 1)
cairo_set_font_face(cr, cairo_face)
cairo_set_font_size(cr, 200)
cairo_move_to(cr, 400, 300)
cairo_show_text(cr, 'M')

More information about the cairo mailing list