Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FontMgr
#1
This is basically a continuation of some code I posted here.

I originally planned this for an upcoming update to InForm-PE's UiEditor. However, while experimenting with this, it turned out to be nice little 4-function cross-platform library. I am sharing it here hoping it might be useful.

The library has 4 functions:

Code: (Select All)
''' @brief Builds an array of fonts from that are available in the host OS (user installed + system installed).
''' @param fontList This a dynamic string array. The function will redimension fontList starting from 1.
''' @return The count of fonts found.
FUNCTION FontMgr_BuildList~& (fontList() AS STRING)


''' @brief Returns the font name by directly probing a font file.
''' @param filePath This the font file path name.
''' @param fontIndex This is the font index inside a TTC and it is always zero based. Must be 0 for TTF & OTF.
''' @param nameId The component needed from the font's name table
''' @return The name of the font. Invalid filePath or fontIndex will return an empty string.
FUNCTION FontMgr_GetName$ (filePath AS STRING, fontIndex AS _UNSIGNED LONG, nameId AS _UNSIGNED _BYTE)


''' @brief Returns the number of fonts in a collection (TTC).
''' @param filePath This the font file path name.
''' @return 1 or more for valid font files. 0 for invalid font files.
FUNCTION FontMgr_GetCount~& (filePath AS STRING)


''' @brief Probes and returns the supported font size range (useful for bitmap fonts).
''' @param filePath This the font file path name.
''' @param fontIndex This is the font index inside a TTC and it is always zero based. Must be 0 for TTF & OTF.
''' @param outMinSize [OUT] The minimum size supported by the font
''' @param outMaxSize [OUT] The maximum size supported by the font
''' @return True if a valid size range was probed
FUNCTION FontMgr_GetSizeRange%% (filePath AS STRING, fontIndex AS _UNSIGNED LONG, outMinSize AS _UNSIGNED _BYTE, outMaxSize AS _UNSIGNED _BYTE)

Demo output:

[Image: Screenshot-2024-03-21-024631.png]

Update: Added functionality to read any string from the font name table like family name, style, full name, vendor, designer, copyright etc.


Attached Files
.zip   FontMgr.zip (Size: 7.88 KB / Downloads: 36)
Reply
#2
These would be great to have natively in QB64 itself, in my humble opinion.  Smile
Reply
#3
(03-20-2024, 03:01 AM)SMcNeill Wrote: These would be great to have natively in QB64 itself, in my humble opinion.  Smile

I agree. We could easily add functions for getting the font name and the TTC font count by directly using the FreeType API. I'll need to do some more tests.
Reply
#4
Added functionality to read any string from the font name table like family name, style, full name, vendor, designer, copyright etc.
Added routine to probe bitmap fonts for supported font sizes.

Updated library in the first post.

Cheers!
Reply
#5
Added fixes for macOS and Linux.

Get the zip file in the first post.
Reply
#6
This is neat. Thanks, man.
Tread on those who tread on you

Reply




Users browsing this thread: 1 Guest(s)