DAY 013: _FONTWIDTH - 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: DAY 013: _FONTWIDTH (/showthread.php?tid=1145) |
DAY 013: _FONTWIDTH - SMcNeill - 11-18-2022 What is it?: _FontWidth is a nice simple function which tells us how wide the current font is for the screen we specify. (Or by itself, for the current _DEST screen.) How do we use it?: We simply just call it like any other function. Something as simple as FW = _FontWidth will work just fine. An example for people: Code: (Select All) Screen _NewImage(800, 600, 32) Copy. Paste. Compile. Run the code above. Linux and Mac folks will probably get a whole bunch of zeros and maybe even a few error messages as no fonts are loaded. You'll need to adjust the links to wherever your fonts are found on your system, and then you can get some sensible results out of the above code. As for Windows users, your fonts are in a standard place usually: C:\Windows\Fonts\... QB64-PE knows what folder to try and look for them at, so chances are everything will run as advertised for you guys, without any issues. So what are the results once the proper fonts are found and pointed to?? Default Font Size: 8 wide, 16 high Courier New, Bold, Font Size: 12 wide 16 high Times New Roman Font Size: 0 wide 20 high So, as everyone who's plotted text to the screen ever before should know, the standard font in qb64pe is 8x16 pixels in size. The courier font, which I chose to load at size 16, happens to be 12 pixels wide and 16 pixels high. The Times New Roman font however... ????? How the heck is it 0 pixels wide???? It's not. When _FontWidth reports a font width of 0, what it's telling you is, "That's not a monospaced font." Run the program once again. Look at the Times New Roman text on the screen. How many pixels wide is the "T"? "How many pixels wide is the "i"? Add the next two lines to the end of the program and run it once again, if you need to be convinced of the widths: Code: (Select All) Locate 5: Print "TTT" Six "i" characters are about the same width as three "3" characters! Times New Roman is a variable width font, and I didn't specify "monospace" when loading it, and as such it's impossible to say that the font's width is any set value. It's 0 -- variable width -- based upon which character is printed to the screen. And that's the basic rundown on _FontWidth -- it'll basically tell you the width of the font on the screen you specify, or else it'll tell you ZERO, if it's a variable-width font. RE: DAY 013: _FONTWIDTH - Pete - 11-18-2022 Is this a keyword of today, tomorrow, or yesterday. I'm losing track. Someone please fix the friggin' Magic 8-bull, or stop feeding it Red Bull. This is an extremely useful keyword along with _FONTHEIGHT for determining SCREEN size proportions in SCREEN 0. With them, you can size the width, height, and location of your program window in relation to your desktop and keep that ratio and placement relatively close if you change font sizes while running your app. The most recent app I've used this in is Sam Clip. I also coded a SCREEN _NEWIMAGE example for hanness, here... https://qb64phoenix.com/forum/showthread.php?tid=337 Pete RE: DAY 013: _FONTWIDTH - mnrvovrfc - 11-19-2022 OFF TOPIC: I guess there's no other place to make such a proposal but... how about this one? |