Android font text difference - android

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?

Related

Deploying .otf font family to FMX application

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.

I want to add some specifict font to my app. I want to know, what is a font on android developer example

On this picture from android developer site, we can see a using of card layout. But they used some specific font there. On images there are some strings with this font. What is a font?
And if you can, tell me, how to implement a transparent toolbar, as in the picture?
Thanks
The font on the pictures is Roboto Slab

What are the requirements for a font (OTF or TTF) so it works well on Android?

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.

How can I remove extra padding in Pre-Lollipop Custom Fonts?

I am using a Custom font in my app(Gotham_book.ttf), and when I use it in a pre-Lollipop devices it includes a padding bottom that it's not showed in lollipop devices.
I tried to use the property android:includeFontPadding="false" but it didn't give me results. What is happening? Maybe a wrong font file?
Thank you!
I have discovered the question by searching for "Lollipop padding", but my problem is a bit different from OP's: instead of having extra padding on old devices my font (a custom image font, used via Callygraphy) mysteriously gained padding on some new versions (with difference between even "minor" Android versions!). I discovered, that in my case these issues have been caused by the font not having proper values in certain tables, so I had to fix it up myself in Fontforge font editor. See detailed explanations here: http://designwithfontforge.com/en-US/Line_Spacing.html.
TL;DR: do set contents of OS/2 font table properly. And if nothing else works, you can set corresponding values to zeroes (e.g. no padding) and/or manually adjust positions of font glyphs (Fontforge allows these kinds of operations en masse).

Rounded edges default font in Android textview

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.

Categories

Resources