Jump to content
Lars Fosdal

Custom TrueType font in FMX Android app?

Recommended Posts

We use a font named Code128.ttf to generate bar codes on Windows.

Can that font be loaded for on-screen rendering in an FMX app on Android and/or iOS?

Does anyone have an example for loading a custom font and rendering text with it in FMX?

Share this post


Link to post
12 hours ago, Dave Nottage said:

There's a number of examples if you Google for: custom fonts delphi android

Do all of them involve creating a modified FMX.FontGlyphs.Android.pas !?

Is there a QP I can vote for to improve this somehow?

Share this post


Link to post

hi,

 

I have followed the method carried out by Landerson Gomes
like in the video on youtube . but on Android 10 it doesn't work, while on Android <10 it works fine. is there a newest way to do it?

Share this post


Link to post
8 hours ago, Aamgian said:

on Android 10 it doesn't work,

The same method works OK on mine with Font Awesome. Which font(s) are you using?

Share this post


Link to post
Posted (edited)
3 hours ago, Dave Nottage said:

Metode yang sama berfungsi baik pada saya dengan Font Awesome. Font apa yang Anda gunakan?

I use nunito sans font from Google font. I made an application using the third party taltext component alcinoe so that the method could not worked but in android 9 that work fine, after I tried it with the default TText component it worked fine. but the next problem if I use the bold font style then it doesn't work. The following sample file that I made

true_font.zip

Edited by Aamgian

Share this post


Link to post

You'll need to modify the patch in FMX.FontGlyphs.Android.pas to look like this:

    NameFont := TPath.Combine(TPath.GetDocumentsPath, CurrentSettings.Family);
    if not CurrentSettings.Style.Weight.IsRegular and TFile.Exists(NameFont + '-Bold.ttf') then
      NameFont := NameFont + '-Bold.ttf'
    else if CurrentSettings.Style.Weight.IsRegular and TFile.Exists(NameFont + '-Regular.ttf') then
      NameFont := NameFont + '-Regular.ttf'
    else
      NameFont := NameFont + '.ttf';

 

Share this post


Link to post
18 hours ago, Dave Nottage said:

You'll need to modify the patch in FMX.FontGlyphs.Android.pas to look like this:


    NameFont := TPath.Combine(TPath.GetDocumentsPath, CurrentSettings.Family);
    if not CurrentSettings.Style.Weight.IsRegular and TFile.Exists(NameFont + '-Bold.ttf') then
      NameFont := NameFont + '-Bold.ttf'
    else if CurrentSettings.Style.Weight.IsRegular and TFile.Exists(NameFont + '-Regular.ttf') then
      NameFont := NameFont + '-Regular.ttf'
    else
      NameFont := NameFont + '.ttf';

 

thanks you for you help, but still not work. I decided to leave this font problem in the application that I made.

Share this post


Link to post

Your example doesn't work on Android < 10 without those changes. I'm wondering how it ever would have, unless it included a font file without -Bold or -Regular on the end (which is not in the example).

 

I've attached an update to the example that works on my Android 5.0.1 and Android 10 devices.

true_font_b.zip

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×