freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ft] Can't get offset of glyphs right.


From: Erlend Langseth
Subject: [ft] Can't get offset of glyphs right.
Date: Sun, 7 Jun 2015 11:41:30 +0200

Hi!

I'm trying to render text, using FreeType 2. My problem is in offsetting each glyph with respect to their own origin. In this mail, with "offset", I refer to what is called bearingX and bearingY in this illustration.

I first render all glyphs, storing necessary metrics, then use the results to render text.
Given an unsigned char c, this is how I render glyphs, and need to obtain the correct offsets (C++):

FT_Face face;

if (!FT_Load_Char(face, c, 0)) {
      if (!FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL)) {
             if (!FT_Get_Char_Index( face, c )) continue;
                   // Set offset of glyphs accessing face->glyph here.

I have tried to use face->glyph->bitmap_left (and bitmap_top), and also face->glyph->metrics.horiBearingX / 64.0f (and Y), but the results always look arbitrary:

http://a.pomf.se/iudwvo.png      And with inverted yoffset: http://a.pomf.se/jlkngl.png

This is how I render text at the moment (no kerning yet). (Additional question: is width, height, xadvance, yadvance, xoffset and yoffset all metrics I need to render text?)

On lines 27 and 28, you see how I apply the offset. size is the pixel size of the font (note that I "normalize" the metrics by dividing by pixel size in the first place).

Thanks in xadvance!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]