Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Freefont error
#6
The reason why you're getting errors is because the font is still active.   

It's just like trying to turn the engine off on your car -- you have to be in park and not moving.  You certainly can't just turn if off while driving down the road and in drive!

Let me ask you this -- what Font is in use at line 16? 


As the line 24 issue, let me ask this:   What screen mode are you in?   Does SCREEN 0 have any limitations to the fonts that we can use with it?

Hint:  Screen 0 requires fonts to be MONOSPACED, as it doesn't work with variable-width fonts. 
Hinr2:  Screen 0 only uses ONE font for the whole screen.  When you change font on SCREEN 0, you change all the text to use that font.

Code: (Select All)

OPTION _EXPLICIT

DIM AS STRING rootpath, fontfile, fontfile2, style, style2
DIM AS LONG f, f2, myfont

rootpath = ENVIRON$("SYSTEMROOT") 'normally "C:\WINDOWS"

fontfile = rootpath + "\Fonts\cour.ttf" 'TTF file in Windows
style = "monospace" 'font style is not case sensitive

f = _LOADFONT(fontfile, 30, style)
_FONT f

PRINT "Hello!"
SLEEP
_FONT 16 'use a different font, such as the one built in to QB64PE, before trying to free a font in use.
SLEEP

_FREEFONT f

'fontfile2 = "C:\WINDOWS\Fonts\courbd.ttf"
'style2 = "Bold,Monospace"

fontfile2 = "C:\Windows\Fonts\Dauphinn.ttf"
style2 = "Bold"

myfont = _LOADFONT("C:\Windows\Fonts\courbd.ttf", 25, "Monospace") 'You're in SCREEN 0. MUST be monospaced.
_FONT myfont

'f2 = _LoadFont(fontfile2, 30, style2)
'_Font f2

LOCATE 3, 5
PRINT "Hello!"
SLEEP
_FONT 16
_FREEFONT myfont 'f2

END


See the above? No errors anymore, but since this is SCREEN 0, *all* the text on the screen changes fonts each time we change our font. The SLEEP statements here should allow you to slowly go through and see that.

If you want to use more than a single font for the whole screen, use a graphics screen such as SCREEN _NEWIMAGE(x, y, 32).
Reply


Messages In This Thread
Freefont error - by Kernelpanic - 06-27-2024, 07:57 PM
RE: Freefont error - by DSMan195276 - 06-27-2024, 08:02 PM
RE: Freefont error - by Kernelpanic - 06-27-2024, 08:27 PM
RE: Freefont error - by SMcNeill - 06-27-2024, 08:52 PM
RE: Freefont error - by Kernelpanic - 06-28-2024, 02:05 PM
RE: Freefont error - by SMcNeill - 06-28-2024, 02:55 PM
RE: Freefont error - by Pete - 06-28-2024, 04:11 PM
RE: Freefont error - by Kernelpanic - 06-28-2024, 07:31 PM
RE: Freefont error - by Pete - 06-28-2024, 10:03 PM
RE: Freefont error - by bplus - 06-28-2024, 10:38 PM
RE: Freefont error - by Pete - 06-29-2024, 03:26 AM



Users browsing this thread: 2 Guest(s)