How do I load a font?

Loading a font

There are so many great and permissively licensed fonts available that at some point you will want to use a font in your solution that is not installed by default on your target systems. LiveCode includes a command to load and unload a font from a file.

The syntax for font loading and unloading in LiveCode is as follows:

start using font file fontFile [globally]
stop using font file fontFile

Fonts are loaded by FileMaker when it starts up so we must call the start using font file command within a custom component's `FileMakerLoad` handler. We are going to implement this custom component as a script only stack with a folder of fonts next to it that are loaded by the component.

Creating a script only stack

Open the LiveCode IDE and choose `File > New Stack > Script only stack` from the menubar. Name the stack `FontLoader` and click `OK`

Because script only stacks have no user interface by default the new stack will open directly into the script editor.


Copy the script below to the `FontLoader` stack script:

on FileMakerLoad
   local tPath
   put __TheFontFolder() into tPath
   local tFiles
   put __TheFontFilesOfFolder(tPath) into tFiles
   repeat for each line tFile in tFiles
      start using font file (tPath & slash & tFile)
   end repeat
end FileMakerLoad

on FileMakerUnload
   local tPath
   put __TheFontFolder() into tPath
   local tFiles
   put __TheFontFilesOfFolder(tPath) into tFiles
   repeat for each line tFile in tFiles
      stop using font file (tPath & slash & tFile)
   end repeat
end FileMakerUnload

private function __TheFontFolder
   local tPath
   put the effective filename of me into tPath
   set the itemDelimiter to slash
   put "fonts" into the last item of tPath
   return tPath
end __TheFontFolder

private function __TheFontFilesOfFolder pPath
   local tFiles
   put files(pPath) into tFiles
   filter tFiles with "*.ttf"
   return tFiles
end __TheFontFilesOfFolder

on FileMakerAction pAction
end FileMakerAction

Now click `Apply` and choose `File > Save` from the menubar and save the file in a location you can remember.

Back to FileMaker

Open the LiveCode for FM plugin solution in FileMaker and click on the `Custom Components` button.

Click on the `+` icon and choose the stack file you saved in LiveCode. Name the custom component `FontLoader` and click `OK`

Adding a fonts folder

Back in LiveCode choose `LiveCode > Preferences` from the menubar and check the file path to your `User Extensions` folder.

Navigate to your user extensions folder in Finder and inside the `FileMaker Components/fontloader` create a folder named `fonts` and place one or more font files you would like loaded when in FileMaker.


Close FileMaker and re-open it and the fonts that were placed in the fonts folder will be available to use in your solutions in FileMaker.


Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.