Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetDelphiFiremonkey

Custom True Type Fonts On Android With Delphi XE5 and XE6 Firemonkey

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi XE5 Firemonkey TTF Fonts Android | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSOver on the Embarcadero forum for Firemonkey there is a question and answer thread about dynamically loading a TrueType font on Android in a Delphi XE5 Firemonkey app. This method also works with Delphi XE6 and should work with AppMethod. Douglas Rudd wrote the instructions for making it happen and they involve copying the FMX.FontGlyphs.Android file to your project directory. You then modify the Delphi unit with some custom code to load a TTF file from the directory of your application. The magic takes place in the createFromFile() function in TJTypeFace:
Typeface := TJTypeface.JavaClass.createFromFile(StringToJString(FontFile));
You also include your TrueType font file inside your APK using the Delphi Deployment functionality. Add the TTF file to your Deployment and change the directory to: .\assets\internal\ One gotcha that you have to watch out for is that you must use the actual name of the font file minus the .ttf in the Font Family property in Delphi. Using the name of the font and not the filename will not work and remember Java is case sensitive (and so are the filenames).
Copy FMX.FontGlyphs.Android to your project folder.

1. Add System.IOUtils to the uses clause;

In procedure TAndroidFontGlyphManager.LoadResource
2. Add variable FontFile: string;
3. change the line

Typeface := TJTypeface.JavaClass.Create(FamilyName, TypefaceFlag);

to

FontFile := TPath.GetDocumentsPath + PathDelim + CurrentSettings.Family + '.ttf';
if FileExists(FontFile) then
Typeface := TJTypeface.JavaClass.createFromFile(StringToJString(FontFile))
else
Typeface := TJTypeface.JavaClass.Create(FamilyName, TypefaceFlag);

The instructions are originally from two different blogs in Chinese here and here.

Head over and read the full forum thread on the Embarcadero site on using a custom font in Delphi Firemonkey on Android.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts
DelphiDemoFiremonkeyLinuxOSXShowcaseWindows

AutoBlogAI: FireMonkey Client To Leverage LLMs And Generative AI For Blogging

DelphiFiremonkeyShowcaseUtilityWindows

Unleashing Creativity With Song Writer AI: A Deep Dive

DelphiFiremonkeyShowcaseWindows

How To Build Stable Diffusion Text To Image Prompts

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

Sign up for our Newsletter and
stay informed

Leave a Reply