Jump to content
  • Advertisement
Sign in to follow this  
Jacob Jingle

freetype pen advance

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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:
2jwcvk.png

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!