Skip to content

Commit

Permalink
Use fonts in system partition
Browse files Browse the repository at this point in the history
Revert README
  • Loading branch information
JingMatrix committed Nov 2, 2024
1 parent 2958773 commit 22d5af4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ This module configures fonts that you add for system-wise usage.
## Usage

1. Clone this repository: `git clone --depth=1 https://github.com/JingMatrix/MagiskFonts`;
2. Create a directory `product/fonts`: `mkdir -p product/fonts`;
3. Put your fonts inside `product/fonts`, currently `ttf` files work well;
2. Create a directory `system/fonts`: `mkdir -p system/fonts`;
3. Put your fonts inside `system/fonts`, currently `ttf` files work well;
4. Pack and install the zip module: `7z a MagiskFonts.zip META-INF customize.sh module.prop system tool`.

## Why do I need it?
Expand Down
5 changes: 3 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[[ -e MagiskFonts.zip ]] && rm MagiskFonts.zip
if [[ -z $TERMUX_VERSION ]]; then
echo "Skip building font-scan if not in termux"
7z a MagiskFonts.zip META-INF customize.sh module.prop product tool
7z a MagiskFonts.zip META-INF customize.sh module.prop system tool
exit
fi

Expand All @@ -14,5 +14,6 @@ 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 product tool
7z a MagiskFonts.zip META-INF customize.sh module.prop system tool
69 changes: 44 additions & 25 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,53 @@ if [ -z $MAGISK_VER ]; then
MODPATH=$PWD
fi

font_dir="/product"
font_config_file="$font_dir/etc/fonts_customization.xml"
config_end_mark="fonts-modification"

ui_print "Pull original $font_config_file"
mkdir -p $MODPATH/$font_dir/etc
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

set_perm_recursive $MODPATH/tool root root 700 700

ui_print "Injecting custom fonts"
cd $MODPATH/$font_dir/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 ' <family customizationType="new-named-family" name="%{family[0]|downcase}">\n <font postScriptName="%{postscriptname}" weight="400" style="normal">%{file}</font>\n </family>\n\n' \
"$fontfile" >>$MODPATH/$font_config_file
fscan -f "%{family}" "$fontfile" | grep ',' >/dev/null
if [ $? -eq 0 ]; then
fscan -f ' <alias name="%{family[1]}" to="%{family[0]|downcase}" />\n\n'\
"$fontfile" >>$MODPATH/$font_config_file

generate_config() {

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

echo "</fonts-modification>" >>$MODPATH/$font_config_file
ui_print "New $font_config_file generated"
ui_print "Pull original $font_config_file"
mkdir -p $MODPATH/$font_dir/etc
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 customizationType="new-named-family" name="%{family[0]|downcase}">\n'$sep$sep'<font postScriptName="%{postscriptname}" weight="400" style="normal">%{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 /

echo "</$config_end_mark>" >>$MODPATH/$font_config_file
ui_print "New $font_config_file generated"
ui_print ""
}

ui_print "Module directory is $MODPATH"

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="\t"
generate_config

0 comments on commit 22d5af4

Please sign in to comment.