QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: George McGinn on March 20, 2021, 02:44:13 pm

Title: [SOLVED/CLARIFIED] Cannot Get FONTS to work in v1.5
Post by: George McGinn on March 20, 2021, 02:44:13 pm
UPDATE: I just tried the programs below with the cyberbit.ttf font file that came with QB64 and everything works. Now the question is why does it not work for any other FONT that came with Linux or imported from Windows?

For those who do not have it, I have also attached the veranda.ttf file to this post.


I've been working on a game, and in v1.4 the FONTS worked great. Now with the new v1.5, they no longer work.

I've created a program from several past posts as well as included a snippet from what I used that worked previously.

Below is the code I am having issues with, but first let me give you some information on what I am getting and my OS environment.

I have been using Linux for more than 10 years, and am a UNIX Mainframe expert, working with it for more than 35 years. I also use macOS, but I have yet to try this on this OS. My Linux is Linux Mint Ubuntu 20.1 with the Cinnamon desktop. I've been using Linux Mint Ubuntu for the past 3 years.

In my testing, I have used the Linux FONTS to install them in usr/share/fonts, as well as placing the fonts into the same directory as my executable, and in every case, the program is unable to load the fonts.

I've tested more than 24 different fonts besides Veranda. All the files exist and have an installed status, yet QB64 cannot load them.

I am not sure whether this is a Linux problem, so anyone who uses other OS's I would like to hear your perspective on this.

Also, if this is a problem running QB64 on Linux, then this maybe a bug in QB64 v1.5.

I would be able to spend the time to do this, but I am currently working with an astrophysics grad student in helping him analyze data from NASA and ESA satellites using both PYTHON and QB64, and while I would love to have FONTS working, I can for this project get by without it (FONTS work fine in PYTHON, so I can use that if I need to show bold, or other font attributes).

Any help or suggestions is greatly appreciated. I've gone as far as I can in QB64 without scouring QB64 source code for the problem.

Below are the code snippet and a program I put together from prior posts on this issue, along with the results I am getting.

First, this snippet is from a program I wrote that allows a user to input values to the Drake Equation. It is the same snippet that I used in many other programs I wrote in v1.4 and worked:

Code: QB64: [Select]
  1. '--------------------------------
  2. '*** Initialize SCREEN
  3. 'SCREEN 12
  4. SCREEN _NEWIMAGE(1500, 700, 32)
  5.  
  6. '*** Setup Font Type and Size
  7. fontpath$ = "veranda.ttf"
  8. font& = _LOADFONT(fontpath$, 8, "")
  9. '_FONT font&
  10.  


This program is a combo from several other posts in BUGS from people (SMcNeill is one of them) that was solved back in 2017.
Code: QB64: [Select]
  1. 'MultipleFontLoad
  2. 'SCREEN 0 may use only one FONT. When changed, changes full screen
  3. 'Otherwise graphic modes preserve the screen contents when change font
  4. '_LOADFONT needs the use of style$ variable instead of constant
  5.  
  6. CONST MINSIZE = 8, MAXSIZE = 100
  7. DIM i AS INTEGER, hFont(MAXSIZE) AS LONG
  8. f$ = "veranda.ttf"
  9. style$ = "MONOSPACE"
  10.  
  11.  
  12. SCREEN _NEWIMAGE(640, 500, 32)
  13.  
  14. FOR i = 0 TO 10
  15.     _DELAY 1
  16.     f(i) = _LOADFONT("veranda.ttf", 16, "")
  17.     PRINT i; ": ";
  18.     PRINT f(i)
  19.  
  20.  
  21. PRINT: PRINT "LOADING MIN/MAX: "; f$; " style: "; style$
  22. FOR i = MINSIZE TO MAXSIZE
  23.     PRINT i;
  24.     hFont&(i) = _LOADFONT(f$, i, style$)
  25.     IF hFont&(i) <= 0 THEN EXIT FOR
  26.  
  27. IF i > MAXSIZE THEN
  28.     PRINT
  29.     DO
  30.         PRINT "Font sizes:"; MINSIZE; "-"; MAXSIZE;
  31.         INPUT ". Select size"; fontsize%
  32.         IF fontsize% < MINSIZE OR fontsize% > MAXSIZE THEN EXIT DO
  33.         _FONT hFont&(fontsize%)
  34.     LOOP
  35.     PRINT "Fail"; i; hFont&(i)
  36.  
  37. FOR i = MINSIZE TO MAXSIZE
  38.     PRINT hFont&(i)
  39.     _FREEFONT hFont&(i)
  40.  
  41.  

When I run the program that tests various uses of FONTS I get the following output:

Code: QB64: [Select]
  1. 0 : -1
  2. 1 : -1
  3. 2 : -1
  4. 3 : -1
  5. 4 : -1
  6. 5 : -1
  7. 6 : -1
  8. 7 : -1
  9. 8 : -1
  10. 9 : -1
  11. 10 : -1
  12.  
  13. LOADING MIN/MAX: veranda.ttf style: MONOSPACE
  14. 8 Fail 8 -1
  15.  

After this, I get a box that says: Unhandled Error #258, Line 45 (in main module) Invalid handle, Continue?

After this, the program loops when I hit Yes until I click on No.

Thanks for taking the time to look into this.
Title: Re: Cannot Get FONTS to work in v1.5
Post by: SMcNeill on March 20, 2021, 03:26:41 pm
Can you share the font for testing?  Are you certain it’s not verdana.ttf instead of veranda.ttf?  Spelling matters.
Title: Re: Cannot Get FONTS to work in v1.5
Post by: bplus on March 20, 2021, 03:39:41 pm
I don't know if Linux improved on spaces in filename but I know it is picky about cases upper/lower cases.
Title: Re: Cannot Get FONTS to work in v1.5
Post by: bplus on March 20, 2021, 04:27:47 pm
I can verify the code from 2017 doesn't work in Windows 10 with QB64 v1.5.

And this doesn't work either:
Code: QB64: [Select]
  1. '*** Initialize SCREEN
  2. 'SCREEN 12
  3. Screen _NewImage(1024, 700, 32)
  4.  
  5. '*** Setup Font Type and Size
  6. fontpath$ = "veranda.ttf"
  7. font& = _LoadFont(fontpath$, 8, "")
  8. Print font&
  9.  
  10. '_FONT font&
  11.  

Update, I can verify neither work with QB64 v1.4 either (Windows)

I think it's the font or the call to load it.
Title: Re: Cannot Get FONTS to work in v1.5
Post by: bplus on March 20, 2021, 04:36:02 pm
Looks like a fine font:
Title: Re: Cannot Get FONTS to work in v1.5
Post by: bplus on March 20, 2021, 04:40:46 pm
Aha!

Code: QB64: [Select]
  1. '--------------------------------
  2. '*** Initialize SCREEN
  3. 'SCREEN 12
  4. SCREEN _NEWIMAGE(1024, 700, 32)
  5.  
  6. '*** Setup Font Type and Size
  7.  
  8. f& = _LOADFONT("verdana.ttf", 18, "MONOSPACE")
  9.  
  10.  

spell verdana ;-))


Why couldn't I see the spelling right off, Steve did ;-))
Title: Re: Cannot Get FONTS to work in v1.5
Post by: FellippeHeitor on March 20, 2021, 04:42:15 pm
bplus, he just said his font is actually called Veranda.ttf
Title: Re: Cannot Get FONTS to work in v1.5
Post by: FellippeHeitor on March 20, 2021, 04:43:07 pm
I cannot reproduce the issue on macOS and I cannot reproduce it in Windows 10. Font loading and displaying works fine in both for me. I'll try a Linux VM and get back to you.
Title: Re: Cannot Get FONTS to work in v1.5
Post by: bplus on March 20, 2021, 04:44:45 pm
bplus, he just said his font is actually called Veranda.ttf

Yes, I assumed George saw that because he edited his post after Steve's post.

The spelling is verdana.ttf for the font George gave us to sample.
Title: Re: Cannot Get FONTS to work in v1.5
Post by: FellippeHeitor on March 20, 2021, 04:45:21 pm
He is in Linux, using a font he has that is called Veranda.ttf, man.
Title: Re: Cannot Get FONTS to work in v1.5
Post by: bplus on March 20, 2021, 04:46:38 pm
He is in Linux, using a font he has that is called Veranda.ttf, man.

Man I am talking about the verdana.ttf he gave us to test :)
Title: Re: Cannot Get FONTS to work in v1.5
Post by: FellippeHeitor on March 20, 2021, 04:47:03 pm
Aren't you, George?

   [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Cannot Get FONTS to work in v1.5
Post by: George McGinn on March 20, 2021, 04:48:00 pm
Aha!

Code: QB64: [Select]
  1. '--------------------------------
  2. '*** Initialize SCREEN
  3. 'SCREEN 12
  4. SCREEN _NEWIMAGE(1024, 700, 32)
  5.  
  6. '*** Setup Font Type and Size
  7.  
  8. f& = _LOADFONT("verdana.ttf", 18, "MONOSPACE")
  9.  
  10.  

spell verdana ;-))


Why couldn't I see the spelling right off, Steve did ;-))

I checked my code and veranda is spelled correctly.

Anyway, I modified your code and the PRINT does not print a larger sized character. Below code should print Hello World with a size of 28 and 64, yet they both appear the same. To me this does not work.

Code: QB64: [Select]
  1. '--------------------------------
  2. '*** Initialize SCREEN
  3. 'SCREEN 12
  4. SCREEN _NEWIMAGE(1024, 700, 32)
  5.  
  6. '*** Setup Font Type and Size
  7.  
  8. f& = _LOADFONT("verdana.ttf", 28, "MONOSPACE")
  9.  
  10. PRINT "Hello World"
  11.  
  12. f& = _LOADFONT("verdana.ttf", 64, "MONOSPACE")
  13.  PRINT "Hello World"
  14.  
Title: Re: Cannot Get FONTS to work in v1.5
Post by: FellippeHeitor on March 20, 2021, 04:50:23 pm
Ok, so we've probably solved the problem.

1- George had the wrong spelling all along.
2- Fonts are working fine in v1.5 - across platforms.
3- @George McGinn after you use _LoadFont, you have to check that the resulting handle (f& for you) is greater than 0. After you check that, you have to actually apply the font using the _FONT statement. http://www.qb64.org/wiki/FONT
Title: Re: Cannot Get FONTS to work in v1.5
Post by: FellippeHeitor on March 20, 2021, 04:51:17 pm
Also, before you reuse the same variable for holding a new font loaded (f& in your case), makes sure you're not using that font anymore (revert back to default _FONT 16) and use _FreeFont f& first.
Title: Re: Cannot Get FONTS to work in v1.5
Post by: George McGinn on March 20, 2021, 04:51:22 pm
Fillippe, yes, it was originally Veranda.ttf and that was the name I was using in my code.

Then I renamed it to veranda.ttf (all lowercase) and no changes to my results.

I just posted code that seems to now load it, but the PRINT does not reflect the size of the font.
Title: Re: [SOLVED/CLARIFIED] Cannot Get FONTS to work in v1.5
Post by: FellippeHeitor on March 20, 2021, 04:52:23 pm
Take time to check my replies above.
Title: Re: [SOLVED/CLARIFIED] Cannot Get FONTS to work in v1.5
Post by: FellippeHeitor on March 20, 2021, 04:53:41 pm
Making it clearer:

Code: QB64: [Select]
  1. '--------------------------------
  2. '*** Initialize SCREEN
  3. 'SCREEN 12
  4. SCREEN _NEWIMAGE(1024, 700, 32)
  5.  
  6. '*** Setup Font Type and Size
  7.  
  8. f28& = _LOADFONT("verdana.ttf", 28, "MONOSPACE")
  9. PRINT f28&
  10. IF f28& > 0 THEN _FONT f28&  'This is where you apply the font
  11. PRINT "Hello World"
  12.  
  13. f64& = _LOADFONT("verdana.ttf", 64, "MONOSPACE")
  14. PRINT f64&
  15. IF f64& > 0 THEN _FONT f64&  'This is where you apply the font
  16.  PRINT "Hello World"
  17.  
Title: Re: Cannot Get FONTS to work in v1.5
Post by: George McGinn on March 20, 2021, 04:54:45 pm
Spelling was not the issue, as I copied the name directly from the file into my program after my first attempt failed. I even used the Veranda Bold.ttf and it also did not work.

Any spelling mistakes was due to fat-fingering the keyboard and I made sure that all spelling was corrected before posting this.

I even make it all lowercase as you suggested in the Discord talk.

Ok, so we've probably solved the problem.

1- George had the wrong spelling all along.
2- Fonts are working fine in v1.5 - across platforms.
3- @George McGinn after you use _LoadFont, you have to check that the resulting handle (f& for you) is greater than 0. After you check that, you have to actually apply the font using the _FONT statement. http://www.qb64.org/wiki/FONT
Title: Re: [SOLVED/CLARIFIED] Cannot Get FONTS to work in v1.5
Post by: George McGinn on March 20, 2021, 04:56:23 pm
The code below does not show differences in font sizes. Why?

Code: QB64: [Select]
  1. '--------------------------------
  2. '*** Initialize SCREEN
  3. 'SCREEN 12
  4. SCREEN _NEWIMAGE(1024, 700, 32)
  5.  
  6. '*** Setup Font Type and Size
  7.  
  8. f& = _LOADFONT("verdana.ttf", 28, "MONOSPACE")
  9.  
  10. PRINT "Hello World"
  11.  
  12. f& = _LOADFONT("verdana.ttf", 64, "MONOSPACE")
  13.  PRINT "Hello World"
  14.  
Title: Re: [SOLVED/CLARIFIED] Cannot Get FONTS to work in v1.5
Post by: bplus on March 20, 2021, 04:56:45 pm
For font sizes the verdana.ttf you, @George McGinn, gave us to test allows larger sizes of 24, 36, 48, see my screen shot of verdana.ttf you gave us to sample.

Update: Maybe being ttf you can do all sizes in between, if you spell the name right ;-))
Title: Re: [SOLVED/CLARIFIED] Cannot Get FONTS to work in v1.5
Post by: FellippeHeitor on March 20, 2021, 04:57:07 pm
Take time to read all my replies above, @George McGinn - you're just replying blindly at this point.
Title: Re: [SOLVED/CLARIFIED] Cannot Get FONTS to work in v1.5
Post by: George McGinn on March 20, 2021, 04:59:49 pm
You are right. I did not see your other posts.

I just read them and tested the code you provided and it works on Linux.

Sorry, just things were happening too fast! When you turn 62, things will slow down :-)

Thanks. I just flagged your response as "Best Answer" and consider this closed.

George.

Take time to read all my replies above, @George McGinn - you're just replying blindly at this point.