Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem lining up same font with different heights.
#7
I think what you're seeing is just an affect of how fonts work.  Take a look at the following characters

fog

Notice how all the characters line up on an imaginary line on the screen?  The problem you're facing is rather obvious though, once you put that "o" in perspective with the other two characters.  The "f" prints taller, so the "o" isn't going to align to the top of our font character area.  The "g" prints lower, so the "o" isn't going to align to the bottom of the font character area.

That "o" has whitespace above and below it -- it just kind of "hovers" in its proper position there, in the middle of the top of the "f" and the bottom of the "g".

Thing is, when you increase the font size, you also increase the amount of whitespace above and below that "o".  

If you need pixel perfect alignment of that "o" on a line, like your demo, then you'd want to do 2 possible things:

1) Write a routine to use POINT or similar to find out exactly how many pixels of blank lines exist above/below that character, so you can strip them off and ignore them when positioning

OR 

2) Try and position by _Fontheight / 2.   <-- Seems to me that this would center those characters and probably align them proper along a line.  It'd just along the centerline and not the top or bottom of the character.


And then we have HACK #1)  Try and guess at the ratio of actual pixels and blank spaces, and modify all heights by that value.  (Such as your .8 in your test code.)  It'll vary a lot from font to font, depending on how they space things, but it's probably the easiest solution, if you're going for a limited font-use situation.
Reply


Messages In This Thread
RE: Problem lining up same font with different heights. - by SMcNeill - 08-02-2024, 10:55 PM



Users browsing this thread: 15 Guest(s)