Public Group

This topic is 2445 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

What is the proper way to position the bitmaps generated by freetype?

Here is what I've been trying so far. Everything works fine except when I'm using the he phrase "The quick brown fox jumps over the lazy dog" the 'j' and the 'u' are stuck together.

int startx = 300.0f; int starty = 30.0f; // "Metrics" is the same metrics you get from face->glyph->metrics + kerning info (all divided by 64) // I'm using windows 2d coordinate system std::for_each(buff.begin(), buff.end(), [&] (Metrics &met) { int x = startx + met.horiBearingX + met.kerning.x; int y = starty - met.horiBearingY; int width = met.width; int height = met.height; // store x, y, width, height in vector for shader startx += met.horiAdvance; });

Share on other sites
How are you calculating the kerning info? My guess is that it has something to do with that.

Share on other sites

How are you calculating the kerning info? My guess is that it has something to do with that.

Here's my code:
FT_UInt glyph_index = 0; FT_Bool use_kerning = FT_HAS_KERNING( face ); FT_UInt previous = 0; // chars is "The quick brown fox jumps over the lazy dog" std::for_each(chars.begin(), chars.end(), [&] (FT_ULong &ULchar) { glyph_index = FT_Get_Char_Index(face, ULchar); FT_Vector delta = {0}; if(use_kerning && previous && glyph_index) FT_Get_Kerning(face, previous, glyph_index, FT_KERNING_DEFAULT, &delta); FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT); FT_Glyph glyph; FT_Get_Glyph(face->glyph, &glyph ); // store face->glyph->metrics + kerning info in my 'Metrics' class and insert into vector previous = glyph_index; });

Here is what it looks like:

Data for each letter:
Character = T kerning x = 0 horiAdvance = 20 horiBearingX = 0 width = 21 Character = h kerning x = 0 horiAdvance = 19 horiBearingX = 1 width = 17 Character = e kerning x = 0 horiAdvance = 18 horiBearingX = 0 width = 18 Character = kerning x = 0 horiAdvance = 9 horiBearingX = 0 width = 0 Character = q kerning x = 0 horiAdvance = 21 horiBearingX = 0 width = 28 Character = u kerning x = 0 horiAdvance = 19 horiBearingX = 1 width = 17 Character = i kerning x = 0 horiAdvance = 7 horiBearingX = 1 width = 5 Character = c kerning x = 0 horiAdvance = 18 horiBearingX = 0 width = 17 Character = k kerning x = 0 horiAdvance = 18 horiBearingX = 1 width = 17 Character = kerning x = 0 horiAdvance = 9 horiBearingX = 0 width = 0 Character = b kerning x = 0 horiAdvance = 19 horiBearingX = 1 width = 18 Character = r kerning x = 0 horiAdvance = 12 horiBearingX = 1 width = 11 Character = o kerning x = -1 horiAdvance = 20 horiBearingX = 0 width = 19 Character = w kerning x = 0 horiAdvance = 27 horiBearingX = 0 width = 27 Character = n kerning x = 0 horiAdvance = 19 horiBearingX = 1 width = 17 Character = kerning x = 0 horiAdvance = 9 horiBearingX = 0 width = 0 Character = f kerning x = 0 horiAdvance = 11 horiBearingX = 0 width = 11 Character = o kerning x = 0 horiAdvance = 20 horiBearingX = 0 width = 19 Character = x kerning x = 0 horiAdvance = 18 horiBearingX = 0 width = 19 Character = kerning x = 0 horiAdvance = 9 horiBearingX = 0 width = 0 Character = j kerning x = 0 horiAdvance = 10 horiBearingX = -4 width = 15 Character = u kerning x = 0 horiAdvance = 19 horiBearingX = 1 width = 17 Character = m kerning x = 0 horiAdvance = 28 horiBearingX = 1 width = 26 Character = p kerning x = 0 horiAdvance = 19 horiBearingX = 1 width = 18 Character = s kerning x = 0 horiAdvance = 18 horiBearingX = 0 width = 17 Character = kerning x = 0 horiAdvance = 9 horiBearingX = 0 width = 0 Character = o kerning x = 0 horiAdvance = 20 horiBearingX = 0 width = 19 Character = v kerning x = 0 horiAdvance = 19 horiBearingX = 0 width = 19 Character = e kerning x = -1 horiAdvance = 18 horiBearingX = 0 width = 18 Character = r kerning x = 0 horiAdvance = 12 horiBearingX = 1 width = 11 Character = kerning x = 0 horiAdvance = 9 horiBearingX = 0 width = 0 Character = t kerning x = 0 horiAdvance = 16 horiBearingX = 1 width = 15 Character = h kerning x = 0 horiAdvance = 19 horiBearingX = 1 width = 17 Character = e kerning x = 0 horiAdvance = 18 horiBearingX = 0 width = 18 Character = kerning x = 0 horiAdvance = 9 horiBearingX = 0 width = 0 Character = l kerning x = 0 horiAdvance = 7 horiBearingX = 1 width = 5 Character = a kerning x = 0 horiAdvance = 18 horiBearingX = 0 width = 17 Character = z kerning x = 0 horiAdvance = 16 horiBearingX = 0 width = 16 Character = y kerning x = 0 horiAdvance = 18 horiBearingX = 1 width = 17 Character = kerning x = 0 horiAdvance = 9 horiBearingX = 0 width = 0 Character = d kerning x = 0 horiAdvance = 19 horiBearingX = 0 width = 18 Character = o kerning x = 0 horiAdvance = 20 horiBearingX = 0 width = 19 Character = g kerning x = 0 horiAdvance = 19 horiBearingX = 0 width = 18

• 22
• 10
• 19
• 15
• 14