Repository navigation
tkFontList
Home › All Categories › tkControls › tkFontList
Lists the fonts installed on the machine by family, style and file.
SDL_ttf opens font files and has no list of installed fonts, so tkFontList builds one: tkFontList_Scan walks font folders and asks SDL_ttf about every face of every .ttf, .otf and .ttc file (family, style, bold, italic, fixed pitch). Use it for a font picker, or to turn a family name a user typed into the file a tkControls font call needs. tkApp uses it to find an installed family when a font file it was given is missing.
Scanning opens every face, so it is not free: scan once, when a picker first needs the list. SDL_ttf must be started first (tkApp_Init does it).
#import "std/containers"
#import "vendor/tkControls/tkFontList"
using containers
using tkFontListtkFontList_Families returns an Array( of string ), so import std/containers to declare one. tkFontList imports std/fs and std/containers itself and re-exports tkHost.
dim as long n = tkFontList_Scan() ' this platform's font folders
print n & " faces in " & int( tkFontList_ScanMs() ) & " ms"
dim as Array( of string ) mono = tkFontList_Families( true ) ' fixed-pitch families only
for each fam as string in mono
print fam
next
dim as string f = tkFontList_Find( "DejaVu Sans Mono", true ) ' its bold file
if len( f ) = 0 then print "not installed"-
tkFontList_Scan( dirs )takes folders separated by line feeds; with none it scanstkFontList_SystemDirs(): the Windows fonts folder and the per-user one on Windows,/usr/share/fonts,/usr/local/share/fontsand~/.local/share/fontson Linux, the system, library and user font folders on macOS. Each scan replaces the last; a folder that does not exist is skipped. -
tkFontList_Families( bMonoOnly )gives each family once, sorted, ignoring case. -
tkFontList_Find( family, bBold, bItalic )gives the file, or""when the family is not installed. A missing bold or italic cut falls back to the regular face, then to any face of the family. -
tkFontList_CountandtkFontList_Face( i )walk every face asTKFONT_FACErecords.
A .ttc file holds several faces, so its face is written "path|Family": the family selects the face inside the file. That is the spelling tkCodeEdit's tkCodeEdit_SetFontFace and tkCodeEdit_SetFallbackFonts take. A plain TTF_OpenFont or tkHost_OpenFont wants a bare path, so skip a result that contains | there, or split it first.
Every public name the module declares, as the source declares it. Signatures are exact; type bodies keep their field comments and drop the rest.
type TKFONT_FACE
family as string ' UTF-8, as the font names itself
style as string ' "Regular", "Bold", "Italic", "Bold Italic", ...
file as string ' "path", or "path|family" for a face of a .ttc
bMono as boolean ' fixed pitch
bBold as boolean
bItalic as boolean
end typefunction tkFontList_SystemDirs() as string
function tkFontList_Scan( byref dirs as string = "" ) as long
function tkFontList_ScanMs() as double
function tkFontList_Count() as long
function tkFontList_Face( byval i as long ) as TKFONT_FACE
function tkFontList_Families( byval bMonoOnly as boolean = false ) as Array( of string )
function tkFontList_Find( byref family as string, byval bBold as boolean = false, byval bItalic as boolean = false ) as stringtiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing