Using fonts just for an app

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.

Thanks!

Maybe search the forum first? In that case you’ll see the current thread https://forum.xojo.com/1992-using-custom-fonts-in-application/

That thread deals with mostly OSX, and/or using MBS plugins. Is there a native Xojo way to do it?

true, but I need it both windows and OSX.

Look for Windows Functionality Suite at GitHub - arbp/WFS: Windows Functionality Suite

There is a method inside called TemporarilyInstallFont that does what you want in Xojo up to version 2016, and potentially after 2017R2

[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.

Did you download it?
It was in UIExtras

#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.

[quote=341780:@Jeff Tullin]Did you download it?
It was in UIExtras

#tag Method, Flags = &h1
Protected Sub TemporarilyInstallFont(fontFile as FolderItem, privateFont as Boolean = true)
#if TargetWin32[/quote]

Does this work with 2016R4 or higher?

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>

Thanks Jurg! Well, so am I out of luck, or is there an internal (non-plugin) method that will work with all recent versions?

Nope. Either use 2016R3, or wait for 2017R2.

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]

Isn’t AbsolutePath deprecated ?

http://documentation.xojo.com/api/files/folderitem.html.AbsolutePath

Edit
Also: Gdi32 ? for 64 Bits ?

The font is loaded all right, and it renders more or less fine in textareas and other objects; but canvas and listbox show text in System font.

The used font name is wrong ? (probably)

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.

Of course: IMHO.

Emile, as the bug-report says, things work OK in previous versions of Xojo such as 2016r3.

“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).

I just read the Feedback bug.