Author Topic: [SOLVED/CLARIFIED] Cannot Get FONTS to work in v1.5  (Read 5579 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
[SOLVED/CLARIFIED] Cannot Get FONTS to work in v1.5
« 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.
« Last Edit: March 20, 2021, 04:52:12 pm by odin »
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Cannot Get FONTS to work in v1.5
« Reply #1 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cannot Get FONTS to work in v1.5
« Reply #2 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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cannot Get FONTS to work in v1.5
« Reply #3 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.
« Last Edit: March 20, 2021, 04:33:55 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cannot Get FONTS to work in v1.5
« Reply #4 on: March 20, 2021, 04:36:02 pm »
Looks like a fine font:

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cannot Get FONTS to work in v1.5
« Reply #5 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 ;-))
« Last Edit: March 20, 2021, 04:42:52 pm by bplus »

FellippeHeitor

  • Guest
Re: Cannot Get FONTS to work in v1.5
« Reply #6 on: March 20, 2021, 04:42:15 pm »
bplus, he just said his font is actually called Veranda.ttf

FellippeHeitor

  • Guest
Re: Cannot Get FONTS to work in v1.5
« Reply #7 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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cannot Get FONTS to work in v1.5
« Reply #8 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.

FellippeHeitor

  • Guest
Re: Cannot Get FONTS to work in v1.5
« Reply #9 on: March 20, 2021, 04:45:21 pm »
He is in Linux, using a font he has that is called Veranda.ttf, man.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Cannot Get FONTS to work in v1.5
« Reply #10 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 :)

FellippeHeitor

  • Guest
Re: Cannot Get FONTS to work in v1.5
« Reply #11 on: March 20, 2021, 04:47:03 pm »
Aren't you, George?

   [ You are not allowed to view this attachment ]  

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Cannot Get FONTS to work in v1.5
« Reply #12 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.  
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

FellippeHeitor

  • Guest
Re: Cannot Get FONTS to work in v1.5
« Reply #13 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

FellippeHeitor

  • Guest
Re: Cannot Get FONTS to work in v1.5
« Reply #14 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.