06-02-2023, 03:50 AM
With 0.7.0, QBJS now supports working with custom fonts via the QB64 methods: _Font, _LoadFont and _FreeFont. There are now three ways to load a font for use in your program:
1. From a Font File
As in QB64, fonts can be loaded from font file locations:
View in QBJS
2. From a Font Name
You can alternatively specify the font name. As long as the font is installed on the system it will load the requested font. You can also specify an HTML-style list of fallback font names as shown in the example below:
View in QBJS
3. From a URL
This option allows you to take advantage of the large collections of free fonts that are available online. The example below uses a font from the Google Font collection:
View in QBJS
1. From a Font File
As in QB64, fonts can be loaded from font file locations:
Code: (Select All)
Dim fnt As Long
fnt = _LoadFont("FONTS/SHOWG.TTF", 45)
_Font fnt
_PrintMode _KeepBackground
Cls , 15
Color 3
_PrintString (35, 170), "Custom Fonts are Cool!"
2. From a Font Name
You can alternatively specify the font name. As long as the font is installed on the system it will load the requested font. You can also specify an HTML-style list of fallback font names as shown in the example below:
Code: (Select All)
Import Gfx From "lib/graphics/2d.bas"
Dim f As Long
f = _LoadFont("Arial, Helvetica, sans-serif", 60)
_Font f
Dim img As Long
img = _NewImage(_PrintWidth("Hello World!"), _FontHeight)
_Dest img
Color 15
_PrintMode _KeepBackground
_PrintString (0, 0), "Hello World!"
_Dest 0
Dim As Integer a, x, y
x = _Width / 2
y = _Height / 2
Do
Line (1, 1)-(_Width, _Height), _RGBA(0, 0, 0, 70), BF
Gfx.RotoZoom x, y, img, 1, 1, a
a = a + 3
If a > 359 Then a = 0
_Limit 60
Loop
3. From a URL
This option allows you to take advantage of the large collections of free fonts that are available online. The example below uses a font from the Google Font collection:
Code: (Select All)
Import Dom From "lib/web/dom.bas"
Dim f
f = _LoadFont("https://fonts.gstatic.com/s/indieflower/v17/m8JVjfNVeKWVnh3QMuKkFcZVaUuH.woff2", 24)
_Font f
Cls , 15
Color 8
_PrintMode _KeepBackground
Print
Print " Day 27:"
Print " I am still trapped on the island with no hope of escape."
Print " I struggle against despair, but the realization that I will"
Print " never leave this place haunts my every waking thought..."
Print
Print " I saw the parrot again today."