Using fonts in app without installing them?

  1. ‹ Older
  2. 5 years ago

    Michel B

    24 Jan 2015 Testers, Xojo Pro

    @DerekDiBenedetto If I just copy this by itself to a module, adding a method:

      #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
            AddFontResourceExW( fontFile.AbsolutePath, FR_PRIVATE, 0 )
          else
            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 get a Syntax Error at 'End Sub'.

    remove end sub

  3. Michel B

    24 Jan 2015 Testers, Xojo Pro

    @DerekDiBenedetto Do I have to copy the whole code and plug it in there without changing it at all?

    You could simply copy the method from WFS. Select it in the navigator, right click/Copy.
    Then select the module in your project, right click/Paste. The method will be added to it.
    Then select the method in your project module, right click it, and select "Inspect"
    Make sure it is "Global"

  4. Derek D

    24 Jan 2015 Testers Newnan, GA. USA

    @Michel B remove end sub

    If I do that, I get a ton of "does not exist" errors in my code where I try to use the command. I inspected it, and it is Global.

  5. Derek D

    24 Jan 2015 Testers Newnan, GA. USA

    If I paste in the whole thing, then the 'End Function' lines give syntax errors...apparently this code is bugged, more than likely. Anyone have other suggestions for getting this done?

  6. Michel B

    24 Jan 2015 Testers, Xojo Pro

    Here is another way I just tested to work, step by step :

    • Open the Windows Functionaity Suite project
    • Select the "Windows Functionality Suite" folder in the WFS project. Go Edit/Copy
    • Create a new project. Go Edit menu/Paste

    This will put all the methods in your project. Do not worry about the size, only the methods used will be added to the compiled program.

    • Inside the folder, open Ui Extras/Modules/UIExtrasWFS/Methods
    • Select TemporaryInstallFont
    • Right click, select "TemporaryInstallFont"
    • In the inspector, change the scope from "Protected" to "Global"

    Now we need to remove a bug in WFS

    • Open UI Extras/Classes/StatusBarWFS/Methods/Constructor/Owner as Window
    • Comment the first line ConstructorHelper( owner.Handle, owner.GrowIcon )
    • Place a label on the window
    • Add a button and double click on it.
    • In the action event, put the Xojo code I posted above for my font Calebasse
    • Change the code to point to the font you want to install, modify Label1.TextFont accordingly.

    I have written that verifying step by step the instructions. Follow that and you should be fine.

  7. Derek D

    24 Jan 2015 Testers Newnan, GA. USA

    Open the Windows Functionaity Suite project
    Select the "Windows Functionality Suite" folder in the WFS project. Go Edit/Copy

    I tried selecting it (using Firefox) and it switches to a multiple folder view. There is no way to do Edit/Copy...they're greyed out.

  8. You have to download the project from github first...

  9. Michel B

    24 Jan 2015 Testers, Xojo Pro

    @DerekDiBenedetto I tried selecting it (using Firefox) and it switches to a multiple folder view. There is no way to do Edit/Copy...they're greyed out.

    As I told you, download the zip (on the right hand side), then when it is on your disk double click on it to open. Then drag the WFS folder onto your disk to extract.

  10. Derek D

    25 Jan 2015 Testers Newnan, GA. USA

    Ok, I followed the directions, got it set up, specified the font for a TextField on a screen after loading it, so it types in that font:

    Dim f as Folderitem
    f = SpecialFolder.Desktop.child("Anti-everything.ttf")
    TemporarilyInstallFont(f,false)
    TextField1.TextFont="Anti Everything"
    TextField1.TextSize=30

    Font is located in same folder as .exe. It does not work; it types in some large basic skinny system font. Am I doing anything wrong? File name and font system name are correct. Another label and button caption doesn't seem to work right either:

    f = SpecialFolder.Desktop.child("CorleoneDue.ttf")
     TemporarilyInstallFont(f,false)
     f = SpecialFolder.Desktop.child("TCM_____.ttf")
     TemporarilyInstallFont(f,false)
    PushButton1.TextFont="Corleone Due"
      PushButton1.TextSize=28
      PushButton1.Caption="OK"
      Label6.TextFont="Tw Cen MT"
      label6.Text="Choose your Influence Goal for this game:"

    Both seem to use some skinny system font instead of the designated font.

  11. Derek D

    25 Jan 2015 Testers Newnan, GA. USA

    Test system does not have the fonts installed and is Windows 7, fully updated.

  12. Michel B

    25 Jan 2015 Testers, Xojo Pro

    @DerekDiBenedetto Ok, I followed the directions, got it set up, specified the font for a TextField on a screen after loading it, so it types in that font:

    Dim f as Folderitem
    f = SpecialFolder.Desktop.child("Anti-everything.ttf")
    TemporarilyInstallFont(f,false)
    TextField1.TextFont="Anti Everything"
    TextField1.TextSize=30

    Font is located in same folder as .exe. It does not work; it types in some large basic skinny system font. Am I doing anything wrong? File name and font system name are correct. Another label and button caption doesn't seem to work right either:

    f = SpecialFolder.Desktop.child("CorleoneDue.ttf")
     TemporarilyInstallFont(f,false)
     f = SpecialFolder.Desktop.child("TCM_____.ttf")
     TemporarilyInstallFont(f,false)
    PushButton1.TextFont="Corleone Due"
      PushButton1.TextSize=28
      PushButton1.Caption="OK"
      Label6.TextFont="Tw Cen MT"
      label6.Text="Choose your Influence Goal for this game:"

    Both seem to use some skinny system font instead of the designated font.

    Derek, from your code the font should be on the desktop, not next to the exe. That is probably the problem. Place the Anti-everything.ttf file on the desktop, and you should be fine.

  13. Derek D

    25 Jan 2015 Testers Newnan, GA. USA

    Is there a way to specify loading the font from the main running folder? Don't necessarily want to install a bunch of fonts to a user's desktop (this is for a Steam app). :)

  14. Derek D

    25 Jan 2015 Testers Newnan, GA. USA

    Would SpecialFolder.CurrentWorkingDirectory work?

  15. Michel B

    25 Jan 2015 Testers, Xojo Pro

    @DerekDiBenedetto Would SpecialFolder.CurrentWorkingDirectory work?

    Would you be so kind to first test using Desktop and see if it works ? After that you can put the file anywhere you like.

    Next to the exe is GetFolderItem("").

  16. Antonio R

    25 Jan 2015 Testers, Xojo Pro, Third Party Store Europe (Italy)

    Put them in the lib folder with a copyStep command (after build)
    I use a font folder inside and then to load the fonts I use

    #if TargetWin32
        dim f as FolderItem=app.ExecutableFile.Parent.Child(app.ExecutableFile.Name.Replace(".exe"," Libs"))
        if f.Exists then
          f=f.Child("fonts")
          if f.Exists then
            for i as Integer=1 to f.Count
              fonts.Append f.Item(i)
            next
          end if
        end if
        for i as integer=0 to Fonts.Ubound
          TemporarilyInstallFont(fonts(i))
        next
      #endif

    fonts is an array that I use then for the UninstallTemporaryFont call
    The copy step is simple:
    create one after build, set applies to Both, subdirectory font, destination framework folder (that's the Lib folder for win build)

  17. 3 years ago

    Jürg O

    30 May 2017 Testers, Xojo Pro

    Here's an example Xojo project that shows how to use custom app fonts in Windows, macOS and Linux applications: CustomAppFonts

    The fonts are not being installed on the OS - they are only available while the Application is running. This may be necessary, depending on the license of your fonts. On Windows and Linux it's even possible to load/unload during runtime

    Notes

    1. macOS: Fonts are being added using Info.plist (see the corresponding project item) and a Post-Build CopyFiles-Step
    2. Windows/Linux: Fonts are being added using Declares in modCustomAppFonts (see the corresponding Module in the project) and a Post-Build CopyFiles-Step

    -image-

  18. Michel B

    30 May 2017 Testers, Xojo Pro
    Edited 3 years ago

    Note that this app, like others built with MBS ActivateFontMBS, does not work under Windows in anything > 2016R3, because apparently Direct2D does not support dynamic font activation.

    This thread is old now. There have been other threads about the same topic where that particular issue was discussed. So far no workaround has been found AFAIK.

  19. Antonio R

    30 May 2017 Testers, Xojo Pro, Third Party Store Europe (Italy)

    Right but at least now I know how to add them (for now) on Linux

  20. Michel B

    30 May 2017 Testers, Xojo Pro

    @Antonio R Right but at least now I know how to add them (for now) on Linux

    Indeed :)

  21. 3 months ago

    Jürg O

    Mar 28 Testers, Xojo Pro

    @Michel B does not work under Windows in anything > 2016R3

    Right. The first Direct2D Xojo Versions in 2017 have broken this.
    Works again in 2018+ Xojo Versions.

or Sign Up to reply!