[cairo] Cairo's Arial font smaller than Arial in browsers

Simon Sapin simon.sapin at exyr.org
Tue Mar 26 07:07:57 PDT 2013

Le 24/03/2013 15:11, Ken Resander a écrit :
>     cairo_set_font_size(cr, 12);   // <<<<< assume this is in pts

It’s not. It’s in cairo’s "user coordinates", which default to pixels 
when drawing on screen without a scale or other transformation matrix.

> <p class="some_class" style="font-family:Arial;font-size:12pt;">This is
> text</p>
> </body>

In CSS units, 12pt equals 16px

> The three browsers showed the text in exactly the same way. The height
> of the capital letter T was 12 pixels for the browsers and only 8 pixels
> for the Cairo output.
> Why is this?

The "font size" (both in cairo and in CSS) defines the height of the "em 
box". It’s quite possible that a glyph such as T is a bit smaller than 
its em box.

Try either using the px unit in CSS, or multiplying cairo font sizes by 4/3.

Simon Sapin

More information about the cairo mailing list