Hey all,
I have an app (a game) that needs to use a few .TTF fonts. It’s for Windows and i’m using Xojo 2016 R4.1.
What is the easiest current way to temporarily use and make available .TTF fonts for a Xojo app reliably without the need to install them? (which is frowned upon in certain circles). The method should work using Windows 7, 8, 8.1 and 10.
[quote=341761:@Jeff Tullin]true, but I need it both windows and OSX.
Look for Windows Functionality Suite at https://github.com/arbp/WFS
There is a method inside called TemporarilyInstallFont that does what you want in Xojo up to version 2016, and potentially after 2017R2[/quote]
Useful stuff. Where exactly is this located? is is inside of another file? I did a search and couldn’t find it in there anywhere.
#tag Method, Flags = &h1
Protected Sub TemporarilyInstallFont(fontFile as FolderItem, privateFont as Boolean = true) #if TargetWin32
Soft Declare Sub AddFontResourceExW Lib "Gdi32" ( filename as WString, flags as Integer, reserved as Integer )
Soft Declare Sub AddFontResourceA Lib "Gdi32" ( filename as CString )
Soft Declare Sub AddFontResourceW Lib "Gdi32" ( filename as WString )
Const FR_PRIVATE = &h10
if privateFont and System.IsFunctionAvailable( "AddFontResourceExW", "Gdi32" ) then
// If the user wants to install it as a private font, then we need to
// use the Ex APIs. Otherwise, use the regular APIs. We know
// that AddFontResourceEx is available in Win2k and up, so if
// the private flag is specified, we have to check to make sure
// we can load the API as well. We won't bother with the A
// version of the call since we know the W version will be there.
AddFontResourceExW( fontFile.AbsolutePath, FR_PRIVATE, 0 )
else
// The user wants to install it as a public font, or they are running
// on an OS without the ability to make private fonts
if System.IsFunctionAvailable( "AddFontResourceW", "Gdi32" ) then
AddFontResourceW( fontFile.AbsolutePath )
else
AddFontResourceA( fontFile.AbsolutePath )
end if
end if
#else
#pragma unused fontFile
#pragma unused privateFont
#endif
End Sub
#tag EndMethod
I’ve posted an example Xojo project a few weeks ago, which shows how to do this on all macOS, Windows (broken with 2016r4, should work again in 2017r2) and Linux.
See the post above yours… It won’t work with 2016r4, 2017r1 (for Windows builds). It should work again in 2017r2, according to <https://xojo.com/issue/46596>
I’ referring to Feedback Case #46596
No luck. In fact, using Xojo 2018r3 on windows 10, canvas and listbox objects show text in the system font.
But commenting the first part of the code below, that is, using
[quote] if System.IsFunctionAvailable( “AddFontResourceW”, “Gdi32” ) then
AddFontResourceW( fontFile.AbsolutePath )[/quote]
then the font can be used, although Bold and Italic do not work.
Has anybody found a workaround?
Thanks.
[quote]#if targetWindows
Soft Declare Sub AddFontResourceExW Lib “Gdi32” ( filename as WString, flags as Integer, reserved as Integer )
Soft Declare Sub AddFontResourceA Lib “Gdi32” ( filename as CString )
Soft Declare Sub AddFontResourceW Lib “Gdi32” ( filename as WString )
Const FR_PRIVATE = &h10
if privateFont and System.IsFunctionAvailable( “AddFontResourceExW”, “Gdi32” ) then
AddFontResourceExW( fontFile.AbsolutePath, FR_PRIVATE, 0 )
else
if System.IsFunctionAvailable( “AddFontResourceW”, “Gdi32” ) then
AddFontResourceW( fontFile.AbsolutePath )
else
AddFontResourceA( fontFile.AbsolutePath )
end if #endif[/quote]
Report (with a click in the Listbox / Canvas) the Listbox / Canvas "default text font (to be sure)
Or add a Break in the code and search that information in the debugger.
Or SysLog that value.
Or: Set the Listbox text font to Arial Black: what happens: if you get Arial Black on screen: the passed name of font who is not used probably because the name is wrong.
Yesterday I do not needed glasses to use my computer (or read the newspaper). Things changes with time.
My post was intended to help based on knowledge (manuals reading and experiences along the years).
An example - talking about Fonts - in QuarkXPress (QXP), check to True the Italic CheckBox (t set a text part in Italic) and try to print: you will get an error (forgot whose it was). Now, people have to have the Italic Font to print in Italic, the styles are no more active. [How old have to be your QXP ? I do not know).