Problem lining up same font with different heights. - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Problem lining up same font with different heights. (/showthread.php?tid=2901) Pages:
1
2
|
Problem lining up same font with different heights. - Pete - 08-02-2024 Code: (Select All)
I thought subtracting the height of the font from the row would make the bottoms of each character align themselves horizontally on the line. What I noticed is that as the font size is increased, the larger character prints progressively slightly higher, above the line. Is there a remedy for this, and not just with lucon fonts, but others as well? Pete RE: Problem lining up same font with different heights. - Pete - 08-02-2024 The best I can figure, without seeing the pixel grid, is the difficulty stems from different characters like a j and an I being at different bottom starting pixels, and when we increase the size, this causes the distortion. Oh, I had to edit the above post. Messing around with it to see how it looked with and without the _FontHeight, I forgot to put the underscore back when I pasted it in the post. It's correct now. Anyway, this code may not be the best, but it's getting close to whatever the correct algorithm might be to solve for this problem... Code: (Select All)
Pete RE: Problem lining up same font with different heights. - bplus - 08-02-2024 @Pete they, the developers, did some font fixing that controls the problem you are bringing up. It was a version or 3 ago that they started fixes with fonts. I am having senior moment what they called it _Q prefix to all normal font subs and functions, _Qprint or _QprintString, oh Lord the memory is like sieve... there is like a _QPrintWidth, _QFontHeight... oh let me see in Wiki if I am close... nope dang! it doesn't start with _Q because nothiong in QB64 starts with _Q @RhoSigma nothing in _font stuff mentions the new font fix prefixes for all the equivalent old _font functions ie when it says see such and such with links. I will start digging, I sort of remember where I was messing with new font fixes. RE: Problem lining up same font with different heights. - bplus - 08-02-2024 Found it _U was the prefix! _USee ? I think _UlineSpacing might be helpful for you @Pete RE: Problem lining up same font with different heights. - Pete - 08-02-2024 So far I can't see any way to use the _U keywords. This algorithm of .8 seems the closest for this font... Code: (Select All)
Not prefect in all instances, but probably close enough. Pete RE: Problem lining up same font with different heights. - TerryRitchie - 08-02-2024 I ran into something similar years ago when creating my menu library. I had to come up with a magic number (like your .8) to nudge fonts here and there to make the align properly. RE: Problem lining up same font with different heights. - SMcNeill - 08-02-2024 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. RE: Problem lining up same font with different heights. - Pete - 08-02-2024 We are on the same page here. I had tried the /2 thing, a few days ago. It looked promising when there was little difference as when writing with font sizes 16 to 20, but go something like 12 to 60 and it fell apart. That's when I started thinking about the ratios that font designer hav to take into account to make tall vs below the line characters like j look correct. I figured since most of all letters are top oriented, something around .75 would be close. As for the POINT suggestion, that's a neat idea, although I'm worried about slowing the WP process down a bunch. I wonder what approach software makers use for sites, like this one, to line up variable sized fonts... sIjP1z Just making each of those really makes me think each font has a ratio assigned to it in the software WP. Pete RE: Problem lining up same font with different heights. - SMcNeill - 08-03-2024 All that information tends to be stored in the font itself. Baseline, height, padding, line spacing, ect, ect. You can keep your execution times down, by pre-processing those calculations. Make an array of 0 to 255, slide each character through it, and calculate once what the blank pixels are going to be for each character and store it. Then instead of the row - fh&, it'd be row - char_height(ascii_value) for placement. RE: Problem lining up same font with different heights. - bplus - 08-03-2024 Am I mis-informed or under the wrong impression that all the _U prefix stuff is supposed to help with alignment problems better than the older font stuff? |