[cairo] Newbie questions on fonts

BJörn Lindqvist bjourne at gmail.com
Sun Oct 14 18:09:32 PDT 2007


On 10/12/07, Fred Clare <fred at ucar.edu> wrote:
>    freetype-2.3.5
>    fontconfig-2.4.2
>    cairo-1.4.10
> I have put /home/myhome/cairo/lib on my DYLD_LIBRARY_PATH and
> /home/myhome/cairo/lib/pkgconfig on my PKG_CONFIG_PATH as well as
> putting /home/myhome/cairo/bin on my PATH.
> Some questions:
>    1.)  Just what are the "toy" fonts?  What font database is
>         being used for those?  When I execute:

I think this thread might provide some clues:


The font database comes from the platforms font database. On OS X that
probably is ATSUI even if you have FreeType installed because Cairo
prefers that. You can of course force the issue using:

./configure --enable-freetype=yes --enable-atsui=no

>           cairo_select_font_face (cr, "serif",
>           cairo_show_text (cr, "Text");
>         I do not get an Italic font, but just the normal font.

Same here. It seems like cairo manages to pick a face without italic
glyphs for serif. Try another family like monospace or sans.

>         in an xml file created using the fonts.conf file as a template.
>         I was hoping that this would then give me access to the
>         fonts in /Library/Fonts using the font name in a
>         cairo_select_font_face call with the font name as the second
>         argument.  But a subsequent call to cairo_show_text
>         just gives me the default serif font.

Have you updated the fontconfigs font cache? fc-cache -fv will at
least tell you which directories fontconfig looks in.

>         Should the above work?  Is my assumption correct that cairo
>         is looking at the files in /etc/fonts to find its fonts?

Cairo doesn't look for fonts at all. It lets the font backend handle

>    3.)  Since the above did not work, I tried accessing the fonts
>         directly using the calls:
>             error = FT_Init_FreeType( &library );
>             error = FT_New_Face( library,
>                       "/Library/Fonts/ArialHBBold.ttf", 0, &face );
>             font_face = cairo_ft_font_face_create_for_ft_face(face,0);
>             cairo_set_font_face(cr, font_face);

This code works fine for me (on Ubuntu Linux). My uneducated guess is
that your cairo library uses ATSUI and not FreeType. You should also
of course check so that the FT functions doesn't throw any error..
Maybe there is also some encoding issue involved? You often get
"rectangles" when that happens.

mvh Björn

More information about the cairo mailing list