Skip to content

Commit

Permalink
Merge pull request #2 from JingMatrix/android15
Browse files Browse the repository at this point in the history
Support for Android 15, but custom fonts are only avaible for Firefox browser.
  • Loading branch information
JingMatrix authored Nov 2, 2024
2 parents db7e239 + b91a60f commit 199b646
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
system
system/fonts/*.ttf
product/fonts/*.ttf
system/etc/fonts.xml
product/etc/fonts.xml
MagiskFonts.zip
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ meson build
ninja -C build
cp build/fc-scan/fc-scan build/src/libfontconfig.so* build/subprojects/freetype2/libfreetype.so* ../tool
popd
rm -rf product/etc
rm -rf system/etc
rm -rf MagiskFonts.zip
7z a MagiskFonts.zip META-INF customize.sh module.prop system tool
72 changes: 51 additions & 21 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,60 @@ if [ -z $MAGISK_VER ]; then
MODPATH=$PWD
fi

ui_print "Pull original fonts.xml"
mkdir -p $MODPATH/system/etc
sed '/^<!-- <\/familyset> -->/q' /system/etc/fonts.xml >$MODPATH/system/etc/fonts.xml
sed -i '$ d' $MODPATH/system/etc/fonts.xml
echo '<!-- </familyset> -->' >>$MODPATH/system/etc/fonts.xml

set_perm_recursive $MODPATH/tool root root 700 700

ui_print "Injecting custom fonts"
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]|downcase}">\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]|downcase}" />\n'\
"$fontfile" >>$MODPATH/system/etc/fonts.xml

generate_config() {

if [ ! -f $font_config_file ]; then
return 0
fi
done
cd /

echo "</familyset>" >>$MODPATH/system/etc/fonts.xml
ui_print "New fonts.xml generated"
# tmpfile="$MODPATH/part_tmp.xml"
ui_print "Pull original $font_config_file"
mkdir -p $MODPATH/$font_dir/etc
# awk '{print >out}; /<familyset>/{out="'$tmpfile'"}' out=$MODPATH/$font_config_file $font_config_file
sed "/^<!-- <\/$config_end_mark> -->/q" $font_config_file >$MODPATH/$font_config_file
sed -i '$ d' $MODPATH/$font_config_file
echo "<!-- </$config_end_mark> -->" >>$MODPATH/$font_config_file

font_family_config=$sep'<family'$locale'>\n'$sep$sep'<font postScriptName="%{postscriptname}">%{file}</font>\n'$sep'</family>\n'
alia_config=$sep'<alias name="%{family[1]}" to="%{family[0]|downcase}" />\n'

cd $MODPATH/$font_dir/fonts/
for fontfile in *.*; do
ui_print "Add custom font $fontfile"
fscan -f "$font_family_config" "$fontfile" >>$MODPATH/$font_config_file
# fscan -f "%{family}" "$fontfile" | grep ',' >/dev/null
# if [ $? -eq 0 ]; then
# fscan -f "$alia_config" "$fontfile" >>$MODPATH/$font_config_file
# fi
done
cd /

# cat $tmpfile >>$MODPATH/$font_config_file
# rm $tmpfile
echo "</$config_end_mark>" >>$MODPATH/$font_config_file
cp $MODPATH/$font_config_file /data/local/tmp
ui_print "New $font_config_file generated"
ui_print ""
}

ui_print "Module directory is $MODPATH"

# locale=' lang="zh-Hans"'
locale=''

font_dir="/system"
font_config_file="$font_dir/etc/fonts.xml"
config_end_mark="familyset"
sep="\t"
generate_config

font_dir="/system"
font_config_file="$font_dir/etc/font_fallback.xml"
config_end_mark="familyset"
sep=" "
generate_config
2 changes: 1 addition & 1 deletion module.prop
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ id=custom_fonts
name=Custom Fonts
version=1.1
versionCode=2
author=Jing Matrix
author=JingMatrix
description=Add custom fonts for system-wise usage

0 comments on commit 199b646

Please sign in to comment.