Where is android reading the file fonts.xml to load fonts correctly?

4.6k views Asked by At

I been looking for this many days now.

My company's android device (manufactured by us) uses Android 2.1. We need to support Arabic for one of our customers. We were able to get a third party software to join Arabic correctly and bought a font from another third party to display Arabic in 2.1.

Android 2.1 has a file called fonts.xml that specifies when a font is to be used including fallback fonts.

I want to know what component in the code reads the fonts.xml file (currently located in /frameworks/base/data/fonts) so that I can change this file to another location and change it dynamically per customer without having to rebuild a new image of the system each time.

Thank you!

UPDATE:

Doing a search of fonts.xml I found sdk.atree contains the following lines:

# fonts for layoutlib.
frameworks/base/data/fonts/fonts.xml                 platforms/${PLATFORM_NAME}/data/fonts/fonts.xml
frameworks/base/data/fonts/DroidSans.ttf             platforms/${PLATFORM_NAME}/data/fonts/DroidSans.ttf
frameworks/base/data/fonts/DroidSans-Bold.ttf        platforms/${PLATFORM_NAME}/data/fonts/DroidSans-Bold.ttf
frameworks/base/data/fonts/DroidSansMono.ttf         platforms/${PLATFORM_NAME}/data/fonts/DroidSansMono.ttf
frameworks/base/data/fonts/DroidSerif-Bold.ttf       platforms/${PLATFORM_NAME}/data/fonts/DroidSerif-Bold.ttf
frameworks/base/data/fonts/DroidSerif-BoldItalic.ttf platforms/${PLATFORM_NAME}/data/fonts/DroidSerif-BoldItalic.ttf
frameworks/base/data/fonts/DroidSerif-Italic.ttf     platforms/${PLATFORM_NAME}/data/fonts/DroidSerif-Italic.ttf
frameworks/base/data/fonts/DroidSerif-Regular.ttf    platforms/${PLATFORM_NAME}/data/fonts/DroidSerif-Regular.ttf
frameworks/base/data/fonts/DroidSansFallback.ttf     platforms/${PLATFORM_NAME}/data/fonts/DroidSansFallback.ttf
frameworks/base/data/fonts/DroidSansJapanese.ttf     platforms/${PLATFORM_NAME}/data/fonts/DroidSansJapanese.ttf

However, I do not see the files fonts.xm and DroidSansJapanese.ttf in my /system/fonts/

I suggested to my work to rename the Arabic font to DroidSansJapanese.ttf so that the system will read it, but this will cause confusion for sure in the future.

I also tried manually putting a modified fonts.xml in the /sytem/fonts and rebooting the device, but did not work.

Also, FontLoader.java loads fonts.xml but it does not specify the whole path as it gets passed by Bridge.java. Bridge.java also gets passed the full path. the variable used is String fontOsLocation. Its named like this in both classes, so I did a search but found nothing specifying the exact location in the source:

public static FontLoader create(String fontOsLocation) {}

My last option would be to try re-write FontLoader so even if it takes a string for the fontOsLocation, I just give it a hardcoded path that comes from the SD card. But I don't know what effect this might have on the system. Thank you.

1

There are 1 answers

4
Juan Acevedo On BEST ANSWER

Ok, so I found one solution. For anyone running into this problem, here it goes:

external/skia/src/ports/SkFontHost_android.cpp -> specified which .ttf files are used for which style

and the font files need to be added to:

frameworks/base/data/fonts/ -> here are all the .ttf files

and Android.mk inside frameworks/base/data/fonts/ folder needs to be modified also so the new font files get copied from this folder to /system/fonts

Hope this helps someone.