Google fonts in BASIC

Name a font family and get real vector text instead of a bitmap sheet, with the wait that asynchronous loading requires and what happens once the game is exported.

What this is for#

Classic BASIC draws text from a font image: a sheet of glyphs you set with TextFontImage(text, image). It works, it is what the dialect has always done, and it stays exactly where it is. But a bitmap sheet does not scale, and it looks like what it is.

LoadGoogleFont names a family instead:

font = LoadGoogleFont("Inter")
PrintFont(font)
Print("Hello")
DO
  Sync()
LOOP

Nothing is removed. LoadFont, TextFontImage and the bitmap path all keep working, and a program can mix them.

The wait is not optional#

A font is a file, and the file arrives after the call returns. Print before it lands and the first frames come out in the fallback font, which reads as "the command did nothing".

GoogleFontReady is what you wait on:

font = LoadGoogleFont("Inter")
ready = 0
DO
  IF ready = 0
    IF GoogleFontReady(font) = 1
      PrintFont(font)
      ready = 1
    ENDIF
  ENDIF
  Print("Hello")
  Sync()
LOOP

Warning: the same trap caught the app's own modules once. Declaring a font is not loading it: a canvas only downloads a family when something asks for it, and the answer arrives a frame or several later.

Browsing the families#

The engine ships a list of families, and a program can read it, which is what a font picker inside a game needs:

count = GoogleFontCount()
FOR i = 0 TO count - 1
  Print(GoogleFontName(i))
NEXT i

The list populates a picker; it is not a limit. Any Google family loads by name through LoadGoogleFont, listed or not.

What happens when you export#

Where the game runsWhat happens
The editorThe family is fetched from Google the first time it is named.
Browser exportSame, and the file is served from the build when the exporter could bundle it.
Native or Bevy buildThe file must have travelled with the build. There is no network.

The exporter reads your program, finds every family you named in plain text, downloads it and writes it to assets/fonts/<Family>.woff2. That build then works offline.

Warning: a family computed at run time cannot be found by reading the program, so it cannot be bundled. The export report says so, and the build falls back to the default font. Write LoadGoogleFont("Inter"), not LoadGoogleFont(names[i]), for anything that must survive an export.

The commands#

CommandWhat it does
LoadGoogleFont(family)Loads the family, hands back an id
LoadGoogleFont(fontID, family)Same, with an id you choose
GoogleFontReady(fontID)1 once the file is usable
GoogleFontCount()How many families the list offers
GoogleFontName(index)One family name from the list

Everything else is the existing font machinery: PrintFont(id) for Print, TextFontSet(text, id) for a Text object, DeleteFont(id) to drop it.

Going further#