I'm trying to implement a custom font family (multiple .otf files for different weights such as heavy, light, regular, ultralight...) for my Firemonkey application, which will be deployed for both Android and iOS.
Implementing the font family on iOS was pretty simple, all I had to do was include them in the info.plist file. When applying font to label, under Font > Family I only need to type "Font name" and it gets applied. Keep in mind that there is no actual "Font name" file, only "Font name Heavy" and other weights.
Extra question here, how do I use font weight in FMX anyway? I didn't find any property for setting font weight.
However, when doing the same thing in Android, it's a completely different outcome. I include the fonts in deployment, and entering "Font name" doesn't apply it at all, but if I enter "Font name Ultralight" for example, then that font with that weight gets applied (while on iOS, adding " Ultralight" has no effect).
To make things worse, adding styles to font such as italic and bold do not apply on Android at all, while they do get applied on iOS.
Why are these two acting so differently, and how can one overcome the differences so they both display the same thing?
Support for custom fonts in Android on Delphi FMX has been recently implemented on Sydney 10.4 and its still rudimentary as of Alexandria 11. As you have noted you must enter the "complete" font name to make it work on Android as there is no official support for font weights yet.
However you can still achieve your desired results by editing and recompiling some source code located in the file FMX.FontGlyphs.Android.pas from your Delphi installation. You can do something like this:
Locate procedure LoadResource from class TAndroidFontGlyphManager. You can see how FMX looks for fonts taking only the Family name and the file extension.
Check the inner procedure CreateTypefaceFromFamilyName and how it determines the weight of the current font.
Following the logic of CreateTypefaceFromFamilyName add something like this just before the FontFile variable is initialized (don't forget to declare FontStyle):
FontStyle:='';
if not CurrentSettings.Style.Slant.IsRegular and not CurrentSettings.Style.Weight.IsRegular then
FontStyle:=' Bold Italic'
else if not CurrentSettings.Style.Weight.IsRegular then
FontStyle:=' Bold'
else if not CurrentSettings.Style.Slant.IsRegular then
FontStyle:=' Italic';
Change the assignment to FontFile from:
TPath.Combine(TPath.GetDocumentsPath, CurrentSettings.Family + '.otf');
to:
TPath.Combine(TPath.GetDocumentsPath, CurrentSettings.Family + FontStyle + '.otf');
(repeat for .ttf as well)
This should add support for Bold, Italic and Bold Italic for Android. This can be further extended to support more font weights as well, just check the TFontWeight enum in unit FMX.Graphics.pas.
Related
I found a list of the default fonts in this answer but I'm not able to find which font is used for displaying emojis (if there is one).
I’ve looked far and wide for an answer to this, e.g., the androidx docs:
https://developer.android.com/develop/ui/views/text-and-emoji/emoji2
At the end of the day, the emoji2 library loads Noto Emoji but could load other fonts, too.
The font name in use (can also be used in CSS font-family declarations) is
Noto Color Emoji Compat.
I want to use custom font Avenir-Roman in tff format in android, but both on the device and in the preview window of Android Studio it looks totally different from real one.
I try to use different approaches such as standard fontFamily attribute, set typeface from assets folder, Caligraphy library - all the same effect. What the reason of such distortion and how to fix this?
The project I worked on has some rare characters that are not supported by Unicode
"private-use area" (PUA) code points in the range U+EE80 through U+EFF. One custom open type font range from U+0000 to U+FFFF and the other has characters beyond U+FFFF. Both fonts are in the same language.
I need to display the characters based on their PUA range(characters are retrieved from database in random lines, no fixed location for a particular character). I tried different solutions but none of them works(bidi class with typeface, composite fonts, merging fonts, fallback, etc).
Has somebody used custom fonts that can display different font based on their range of PUA code points(character by character) on Android?
If you are using java to develop your android app, java only support unicode system so you cannot use characters beyond unicode system.
I'm having have some issues with using a custom font ( Typeface ) in Android.
What happens is that when rendering text in a TextView, the last line is often partially cut off vertically (the lower parts of letters like g, j, y, etc missing) , even if there's PLENTY of space below the text. I assume this is because there's something wrong with the custom font file ( an OTF file) that I'm using. This does only happen when using this custom font. If I use Android standard fonts, not setting my custom typeface, everything works fine.
Question: What are the requirements for font files for Android, so that they work correctly. (Please don't post workarounds for the issue, I'm aware of those. )
Both OTF & TTF fonts Will work fine in android,You have to take care of textsize and paddings arround it.
Is there a default font or font-combination for android in fontFamily or typeface that has rounded edges in each letter, similar to comic sans?
The reason why is because I am trying to display a bubbly like font that has smoothly-rounded edges for each letter.
I have looked around the web for a while and haven't been able to find a simple solution because I don't want to use other libraries or import a font for various reasons (e.g. memory, space, etc.) in my android project files. It shouldn't be this hard to find this but has taken me awhile for some reason.
There is no such font, you need to add a .ttf file for the typeface you want.
This site has a lot of free fonts like what you're looking for. The first one I looked at has a file size of only 50kb.
http://www.fontsquirrel.com/fonts/list/classification/comic
See Android - Using Custom Font for how to add it.