Fills the internal font information with the contents of a string.
_Font$= a$
a$: svar
Used to fill the internal LOGFONT structure with a previously saved string using _Font$.
The contents of the _Font$ string could look like this:
SYSTEM_FONT | "System,16,w7,7,q2,f34,p513" |
SYSTEM_FIXED_FONT | "Fixedsys,15,w8,4,q2,f49,p513" |
ANSI_FIXED_FONT | "Courier,12,w9,q2,f1,p512" |
ANSI_VAR_FONT | "MS Sans Serif,12,w9,q2,f2,p512" |
OEM_FIXED_FONT | "Terminal,12,w8,c255,q2,f1,p512" |
DEVICE_DEFAULT_FONT | ",0,f1" |
The string is built according the following format: first the name of the font followed by the character height (if necessary with sign); then, optional and separated with commas, the rest of the LOGFONT members. Zero values are left out, so ",i0" for ITALIC 0 is not included. Almost all values are prefixed with a character (i for ITALIC, w for WIDTH, etc),, the two exceptions being WEIGHT and HEIGHT - their position in the _Font$ string determines their value.
Overview of the characters
w | WIDTH |
e | ESCAPEMENT |
o | ORIENTATION |
WEIGHT | |
i | ITALIC |
u | UNDERLINE |
s | STRIKEOUT |
c | CHARSET |
q | QUALITY |
f | FAMILY+PITCH |
p | PRECISION (OUTPRECISION + CLIPPRECISION*256) |
Using _Font$=, all font parameters can be set in one instruction.
The order of the parameters is not relevant, except for the font-name and the character height. White spaces are ignored.
After setting the font parameters the font can be selected into the current window using "Font To var%" and "SetFont var%"
_Font$="" clears all font parameters.
$Library "gfawinx"
$Library "UpdateRT"
UpdateRuntime ' Patches GfaWin23.Ocx
Global cont?, cfont As Handle
OpenW 1
// Shows the default System and System Fixed Font
GetFont SYSTEM_FONT
SetFont SYSTEM_FONT
Text 10, 10, "SYSTEM_Font: " & _Font$
GetFont SYSTEM_FIXED_FONT
SetFont SYSTEM_FIXED_FONT
Text 10, 40, "SYSTEM_FIXED_FONT: " & _Font$
cfont = _hFont
Ocx Command cmd = "Next", 10, 70, 100, 25
Do : Sleep : Until IsNothing(Win_1) Or cont?
ChangeFont("Arial,48,7", "Bold Arial in 48 Pixel high")
ChangeFont("Arial,48,700", "Bold Arial in 48 Pixel high") // Same as above
ChangeFont(",48,7,f34", "Bold, Swiss-Family, Variable-Pitch: Arial, Helvetica..., in 48 pixels high")
ChangeFont(",-48,f49", "Morn fixed font (usually Courier New),"#13#10"Text-Height 48 Pixel")
ChangeFont(",0,c1", "some Font")
ChangeFont(",0,c0", "some ANSI Font")
ChangeFont(",0", "some ANSI font")
ChangeFont(",0,c255", "some IBM-PC font (Terminal?)")
CloseW 1
Function ChangeFont(f$, t$)
Local hfont As Handle, th%
// Reset cont? to prevent form closing and clear the screen
cont? = False : Cls
// Set the LOGFONT fields
_Font$ = f$
// Create a handle to represent the new font in LOGFONT
Font To hfont
// Update the current system font
SetFont hfont
// Print using the new font
Text 10, 10, t$ & " (" & f$ & ")"
// Record the textheight (in case cmd needs redrawing)
th% = TextHeight("H")
// Redraw cmd if window closed
If IsNothing(cmd) Then SetFont cfont : Ocx Command cmd = "Next", 10, 20 + th%, 100, 25
// Move cmd to the new position
cmd.Move , 20 + th%
// Await user input before moving on
Do : Sleep : Until IsNothing(Win_1) Or cont?
EndFunction
Sub cmd_Click
cont? = True
EndSub
The Windows API function GetTextFace() may be used to determine the name of the actual used font:
Local a$ = Space(80), hFont As Handle
_Font$ = "Arial,48,7"
Font To hFont
SetFont hFont
~GetTextFace(_DC(), 80, V:a$)
Print a$
Font, Font To, SetFont, GetFont, RFont, Dlg Font, _hFont, _Font$, _Font$=, FreeFont, DelFont
{Created by Sjouke Hamstra; Last updated: 29/06/2022 by James Gaite}