Jump to content
  • Advertisement
Sign in to follow this  
FantasyVII

[FreeType] Characters are not on the base line

This topic is 489 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

Hi everyone,

I have been struggling with this issue for the past two days. I cannot render all my letters on the base line.

dqwdqwd.thumb.png.6b24e0e029283928843d5c6336e985a8.png

newwww.png.cc5c3f2fb6ece6fb62f6bf5a5952248b.png

I have used this function to set my font size 

unsigned int charPixelSize = 50;
FT_Set_Pixel_Sizes(face, 0, charPixelSize);

 

and when it's time to render a character I do this

y = face->glyph->bitmap.rows - face->glyph->bitmap_top;

But the line of code above will produce the image above.

 

The only way I could get all my characters to render properly is by doing this

y = (50 / 1.33333) - face->glyph->bitmap_top;

new.thumb.png.bb902187f871077395510cb140835675.png

xxxxxx.png.65956f847760980e67e1145740c70712.png

in theory 50 should be my font size in pixels. But it seems that it is in points?? I don't know.

If I divide 50 by 1.3333 this woks somewhat.  The reason I'm diving by 1.33333 is because each point has 1.33333 pixels.

I feel this whole division thing is a hacky way of getting this to work. Because 50 should be the font size in pixels not points.

 

I don't know. I'm just lost.

 

Any help would be appreciated.

Cheers.

 

[Edit]

Alright, after a lot of reading and digging around, I finally was able to make this work. So what I did was loop through the entire list of characters and find the largest face->glyph->metrics.horiBearingY.

After that I simply subtracted face->glyph->bitmap_top from the largest horiBearingY.

 

int maxY = 0;

//Loop through every character and get the biggest horiBearingY.
for()
{
     if (face->glyph->metrics.horiBearingY > maxY)
          maxY = face->glyph->metrics.horiBearingY >> 6;
}

void RenderText(std::string& text, Vector2 position)
{
     Vector2 pos = position;
     
     //Loop through my text
     for()
     {
          pos.y = position.y + maxY - face->glyph->bitmap_top;
     }
}

xxxxxx.png.a05f7c59671d777c70efd0e5900d1d5f.png

Hope this will help someone else.

Cheers.

 

 

Edited by Kylotan
removed the 'solved' tag

Share this post


Link to post
Share on other sites
Advertisement

It is normal that letters are not on the baseline, letter like "j" should be partly below it.

If you look at the documentation (like https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html ) you can see it's bearingY rather than top of the image, since the image is fully cropped. (That is, the top of the lowercase letters is not transparent or so, it's simply not there).

Edited by Alberth

Share this post


Link to post
Share on other sites
1 hour ago, Alberth said:

It is normal that letters are not on the baseline, letter like "j" should be partly below it.

If you look at the documentation (like https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html ) you can see it's bearingY rather than top of the image, since the image is fully cropped. (That is, the top of the lowercase letters is not transparent or so, it's simply not there).

Sorry if I wasn't clear. I'm not talking about letters like j. Letters like j, g, p, q look fine to me. I'm taking about letters like a, c e, m, n, u. If you look at the first picture you will notice that all of these letters are above the base line where they should actually be on same line.

 

I did try to do this, it gave me the same result as the first image.

y = face->glyph->bitmap.rows - (face->glyph->metrics.horiBearingY >> 6);

As far as I can tell from the values in my code both horiBearingY and bitmap_top are the same.

 

This is a better image

newwww.png.a2805073418590e8d5949b5b4e6aa499.png

 

 

[Edit]

Alright, this is the most progress that I have done in two days.

if I do this

unsigned int height = (face->bbox.yMax - face->bbox.yMin) >> 6;
pos.y = height - face->glyph->bitmap.rows;

all the characters line up nicely, but characters like j, g, p, q are now messed up.

newwwwww22213123.png.9ee6aa08eeb63b137289fd6ab3adecbe.png

Edited by FantasyVII

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!