Extended KotD #18: _ULINESPACING - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Official Links (https://qb64phoenix.com/forum/forumdisplay.php?fid=16) +--- Forum: Learning Resources and Archives (https://qb64phoenix.com/forum/forumdisplay.php?fid=13) +---- Forum: Keyword of the Day! (https://qb64phoenix.com/forum/forumdisplay.php?fid=49) +---- Thread: Extended KotD #18: _ULINESPACING (/showthread.php?tid=2819) |
Extended KotD #18: _ULINESPACING - a740g - 06-24-2024 Welcome to another KotD. In this edition, we're exploring _ULineSpacing. I'm hosting KotD this week. While my writing skills may not match Steve's, I will do my best. Full disclosure: I'm not a typography expert. Much of the content below is based on what I learned during the rewrite of the QB64-PE font support. In the last KotD, Steve discussed _UFontHeight. You might be curious about the difference between _UFontHeight and _ULineSpacing, as they seem similar and can even return identical values. However, they are quite different; _UFontHeight returns the global glyph height of a font, whereas _ULineSpacing returns the height from one baseline to the next (baseline-to-baseline height). The baseline is the imaginary line on which characters sit, serving as a reference point for glyph placement within a font. The ascent is the maximum pixel height above the baseline and is typically a positive value. The descent is the maximum pixel depth below the baseline, usually a negative value. The line gap represents the extra spacing required between two lines of text. Therefore, baseline-to-baseline height can be expressed using the following formula: baseline-to-baseline height = ascent − descent + linegap So, what does this all mean? Essentially, it means that when printing multiple lines and needing to calculate the Y pixel positions, one should use _ULineSpacing instead of _UFontHeight. That's all there is to it! _ULINESPACING - QB64 Phoenix Edition Wiki RE: Extended KotD #18: _ULineSpacing - SMcNeill - 06-24-2024 For me, personally, I think the biggest difference in _UFontHeight and _ULineSpacing all boils down to what you're wanting to do with your font. For general printing, such as "This is me printing junk," then you'd probably want to use _ULineSpacing as it'll give you the fontheight PLUS the recommended line gap between fonts. This is quite useful when using unicode and dealing with characters that print above and below the line. Example: j and the A with the accent above it. If those two characters appear directly above/below each other, the graphic of one might blur in and overwrite into the graphic of the other. The lower part of the "j", which is below the line, may intermingle with the accent on that "A" below it, ending up with some crappy looking (or even illegable) text. Having the recommended line spacing included in that _ULineSpacing, gives you the gap necessary to make certain that those characters don't touch or mux together. So when might one want to use _UFontHeight instead? When you want to print characters which are SUPPOSED to touch! Think of the extended ASCII characters which QB45/QB64 both use to make boxes and such in SCREEN 0. They'd look more than a little funny, if there was line spaces between those characters. Generally, I'd recommend going with the _ULineSpacing for proper line spacement, unless you just had some reason in particular where you think it looks/works better without that extra spacing. At the end of the day, sometimes the programmer has to decide what they think looks/works best for them. We offer both commands so you can choose between them for your prefered display preference. Do you want compact text, with a few extra lines and the screen and don't care about those minor collisions? Are they not worth worrying over with what you're doing with the chracter set you need for your stuff? Then use the _UFontHeight, if you prefer it. But, if you're looking for the font-recommended spacing, so stuff all renders and looks pretty and doesn't possibly overlap, then use the _ULineSpace. One gives you font height. The other gives you font height PLUS recommended line gap. Choose which one you like the most for your own needs. RE: Extended KotD #18: _ULineSpacing - luke - 06-25-2024 Or to put it another way: _ULINESPACING is how much you advance vertically to print the next line, _UFONTHEIGHT is how high you draw a blue rectangle around the text to do text selection like in a graphical text editor. |