Search code examples
firemonkeytruetype

Loading a custom True Type font


In a Mac Firemonkey app (Delphi XE7) how do I load my custom TrueType font?

For Windows, my app's installer adds my font to Windows itself.


Solution

  • I have done this with FPC/Lazarus, but not with Delphi so far. You only need to do two things (it works even if you have multiple custom fonts):

    1) Add the custom font location to info.plist (it refers to the Resources folder):

    <key>ATSApplicationFontsPath</key>
        <string>Fonts</string>
    

    2) Add the font(s) to the application bundle in the specified location: \Contents\Resources\Fonts

    Translating these two tasks to Delphi XE7, it will be:

    1) Go to Project options and choose "Version Info" and set target to "All configurations - OS X platform". Right-click in the list of keys and choose Add key. Then add ATSApplicationFontsPath with the value "Fonts"

    2) Go to the Project > Deployment page and add the custom font(s). Specify the location where they are now on your Windows computer and set the Remote Path to "Contents\Resources\Fonts".

    Now all fonts in the "Fonts" folder will be loaded automatically by OS X when you run the program and you can choose your font from the program.

    Notice: the font name you specify in your Delphi code is NOT the file name, but the title of the font as specified inside the font file (often it the same name though).