I draw (canvas) a text using a custom typeface (precisely: I use a custom font). However, this font doesn't support many characters and thus some (unsupported) characters are looking differently. Now I am asking myself the following questions:
I digged through the Android code and would like to post my findings:
A Typeface.class instance is created using the static create-methods of the Typeface.class (createFromAsset/createFromFile/create/etc.). The instance then holds a list of fonts (unmodifiable List<Font>
). The first element of this list is the main font (specified) and the other elements (index: 1 - (size-1)) are default fonts which are retrieved from the FontLoader.class ( getFallBackFonts()
)
Among others, the Paint.class / Canvas.class ( drawText()
) use a Typeface.class instance to draw the texts (to measure characters / to draw / etc.). They try to use the main font ( Typeface.mFonts[0]
) when possible. If a character cannot be found in the main font then they try to use a fallback font ( Typeface.mFonts[1]
- Typeface.mFonts[size-1]
) to measure and draw the character.
Conclusion
You can use a Typeface.class instance if you want to use a custom font. If your custom font doesn't support certain characters that you want to draw (/that you use in your text) then the system tries to make use of fallback-fonts. These fallback fonts are loaded from the system by the FontLoader.class (from a system-xml).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.