Finding if a Font is Available

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Post Reply
MattC
Posts: 51
Joined: Mon 16 Apr 2018, 06:17

Finding if a Font is Available

Post by MattC » Tue 28 May 2019, 05:15

Hi.

My program uses a particular font, which I believe to be standard on most Windows computers. However, I need a way to check if it is installed. If the font is unavailable, the system reverts to a default one, which is not compatible with my program's layout. I therefore need to test it and then end the program if it is not there.

Any ideas?

The font, incidentally, is 'Terminal'

Matt

Zaphod
Posts: 78
Joined: Sat 23 Jun 2018, 15:51

Re: Finding if a Font is Available

Post by Zaphod » Tue 28 May 2019, 13:02

The answer is in the Wiki.

Code: Select all

      INSTALL @lib$+"CALLBACK"

      DIM font$(999)
      index% = 0
      SYS FN_syscalls("EnumFonts"), @memhdc%, 0, FN_callback(FNenumfontfunc(), 4), \
      \                             0 TO !FN_systo(result%)
      PRINT "Exit code = ";result%
      PRINT "Number of fonts enumerated = ";index%

      FOR I% =0 TO index%-1
        IF font$(I%)="Terminal" THEN PRINT "Yes, Terminal exists"
      NEXT
      END

      DEF FNenumfontfunc(lplf%, lptm%, type%, data%)
      font$(index%) = $$(lplf%+28)
      index% += 1
      IF index% <= 999 THEN = 1 ELSE = 0
Z

MattC
Posts: 51
Joined: Mon 16 Apr 2018, 06:17

Re: Finding if a Font is Available

Post by MattC » Tue 28 May 2019, 17:21

Thanks Zaphod.

I did, in fact, look at that Wiki page, but my brain must have skipped right over it :oops: . Thanks for repointing me there. You code adaptation works great.

Matt

Post Reply