Skip to content

Commit

Permalink
Add alias support
Browse files Browse the repository at this point in the history
  • Loading branch information
JingMatrix committed Dec 7, 2022
1 parent c20a7bc commit a28ce2c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ This module configures fonts that you add for system-wise usage.
## Why do I need it?

Add fonts for applications like browsers and e-books readers, such as `Google Play Books`.

## Reference

Parser location in [Android Code Search](https://cs.android.com/): `frameworks/base/graphics/java/android/graphics/FontListParser.java`.
20 changes: 14 additions & 6 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ head -n -1 $(magisk --path)/.magisk/mirror/system/etc/fonts.xml >$MODPATH/system
set_perm_recursive $MODPATH/tool root root 700 700

ui_print "Injecting custom fonts"
for fontfile in $MODPATH/system/fonts/*.*; do
fontname=$(FONTCONFIG_PATH=$MODPATH/tool LD_LIBRARY_PATH=$MODPATH/tool $MODPATH/tool/fc-scan -f '%{postscriptname}' "$fontfile")
ui_print "Add custom fonts $fontname"
echo ' <family name="'$fontname'">' >>$MODPATH/system/etc/fonts.xml
echo " <font>$(basename fontfile)</font>" >>$MODPATH/system/etc/fonts.xml
echo " </family>" >>$MODPATH/system/etc/fonts.xml
cd $MODPATH/system/fonts/
fscan() {
FONTCONFIG_PATH=$MODPATH/tool LD_LIBRARY_PATH=$MODPATH/tool $MODPATH/tool/fc-scan "$@"
}
for fontfile in *.*; do
ui_print "Add custom fonts $fontfile"
fscan -f '\t<family name="%{family[0]}">\n\t\t<font postScriptName="%{postscriptname}">%{file}</font>\n\t</family>\n' \
"$fontfile" >>$MODPATH/system/etc/fonts.xml
fscan -f "%{family}" "$fontfile" | grep ',' >/dev/null
if [ $? -eq 0 ]; then
fscan -f '\t<alias name="%{family[1]}" to="%{family[0]}" />\n'\
"$fontfile" >>$MODPATH/system/etc/fonts.xml
fi
done
cd /

echo "</familyset>" >>$MODPATH/system/etc/fonts.xml
ui_print "New fonts.xml generated"
4 changes: 2 additions & 2 deletions module.prop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
id=costume_fonts
name=Costume Fonts
id=custom_fonts
name=Custom Fonts
version=1.0
versionCode=1
author=Jing Matrix
Expand Down

0 comments on commit a28ce2c

Please sign in to comment.