Post by (X) on Feb 24, 2022 1:18:47 GMT 1
Did you ever run into the problem that a user's PC does not have the same fonts that you used on your PC to develop that "special look" you spent hours tweaking, then, because your special font is not found on the user's PC, the default font is used and your wonderful program looks like crap and you as a developer look like you don't know what you are doing?
Well, you can make sure that your program has access to the 'special' fonts that your code uses by:
1) embedding them as a resource in your code (you could also provide them as separate font files)
2) adding (installing) as a temporary font resources
3) removing them before your program terminates
1) embedding them as a resource in your code (you could also provide them as separate font files)
2) adding (installing) as a temporary font resources
3) removing them before your program terminates
In this example, I have loaded the font files into the :Files resource section as: ":ErikasBuero" and ":Zerlina_otf".
It may be necessary to temporarily save them to a system generated temp directory* instead of the application path for this to work with a user that does not have admin rights.
* See GFA help for: TempDir Function, Purpose: Returns the path of the directory designated for temporary files.
Code snippets based on: www.vb-helper.com/howto_install_temporary_font.html
'
' AddFont(...)* Temporarily installs a font for use while your program is running.
' RemoveFont(...) Removes it.
'
' * You must call AddFont(<fontfilename>) to install the
' font BEFORE loading any form that uses that font, or
' you'll generate an error.
'
Declare Function AddFontResource Lib "gdi32.dll" Alias "AddFontResourceA" ( _
ByVal lpFileName As String) As Long
Declare Function RemoveFontResource Lib "gdi32.dll" Alias "RemoveFontResourceA" ( _
ByVal lpFileName As String) As Long
Function AddFont(ByVal sFontFile As String) As Bool
Try
'
' e.g.: AddFontResource("c:\myApp\myFont.ttf")
'
Return (AddFontResource(sFontFile) <> 0)
Catch
Trace Err$
EndCatch
End Function
Function RemoveFont(ByVal sFontFile As String) As Bool
Try
'
' e.g.: RemoveFontResource("c:\myApp\myFont.ttf")
'
Return (RemoveFontResource(sFontFile) <> 0)
Catch
Trace Err$
EndCatch
End Func
Proc P_Init_Temp_Fonts
Try
Local fn$ = App.Path & "\ErikasBuero.ttf"
FileCopy ":ErikasBuero" To fn$
Trace AddFont(fn$)
fn$ = App.Path & "\Zerlina.otf"
FileCopy ":Zerlina_otf" To fn$
Trace AddFont(fn$)
Catch
Trace Err$(Err)
EndCatch
Proc P_Remove_Temp_Fonts
Try
Local fn$ = App.Path & "\ErikasBuero.ttf"
Trace RemoveFont(fn$)
fn$ = App.Path & "\Zerlina.otf"
Trace RemoveFont(fn$)
Catch
Trace Err$(Err)
EndCatch
So instead of some users seeing this:
All users will see your original work: