PHP imagettftext height is wrong with accent

I'm creating a font converter (ttf to C array) using PHP and imagettftext. It works well but when I convert letters with accent (e.g. Á) the accent is out of the area. In the example I convert some letters with Arial font with 20 px height. (letter, y top coordinate, y bottom coordinate).

Generated by this code:

   $co = imagettftext($im, $h_pt, 0, 0, $h_pt, $white, $font, $letter);
   echo($letter . ": " .$co[7] . "  " . $co[1]. "<br>");

The top coordinate of 'Á' is -4 so it not fits to the 0 .. 20 range. How is it possible? I thought the font should fit into its height.

So my question is how to "force" imagettftext to put accents into the given height?

Upvotes: 2

Views: 252

Answers (1)

Meanwhile, I've found this article about how font metrics work.

It turned out that the 20px height doesn't mean the font will fit a 20px heigh line. There are several (sometimes confusing) metrics to determine the height of the ascent and descent parts. This Wikipedia article gives a quick overview.

Upvotes: 1

Related Questions