Skip to content

Commit

Permalink
Put fonts in product partition
Browse files Browse the repository at this point in the history
  • Loading branch information
JingMatrix committed Oct 26, 2024
1 parent db7e239 commit 2958773
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 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
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 `system/fonts`: `mkdir -p system/fonts`;
3. Put your fonts inside `system/fonts`, currently `ttf` files work well;
2. Create a directory `product/fonts`: `mkdir -p product/fonts`;
3. Put your fonts inside `product/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
6 changes: 3 additions & 3 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 system tool
7z a MagiskFonts.zip META-INF customize.sh module.prop product tool
exit
fi

Expand All @@ -13,6 +13,6 @@ meson build
ninja -C build
cp build/fc-scan/fc-scan build/src/libfontconfig.so* build/subprojects/freetype2/libfreetype.so* ../tool
popd
rm -rf system/etc
rm -rf product/etc
rm -rf MagiskFonts.zip
7z a MagiskFonts.zip META-INF customize.sh module.prop system tool
7z a MagiskFonts.zip META-INF customize.sh module.prop product tool
28 changes: 16 additions & 12 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,34 @@ 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
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/system/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 '\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 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 '\t<alias name="%{family[1]}" to="%{family[0]|downcase}" />\n'\
"$fontfile" >>$MODPATH/system/etc/fonts.xml
fscan -f ' <alias name="%{family[1]}" to="%{family[0]|downcase}" />\n\n'\
"$fontfile" >>$MODPATH/$font_config_file
fi
done
cd /

echo "</familyset>" >>$MODPATH/system/etc/fonts.xml
ui_print "New fonts.xml generated"
echo "</fonts-modification>" >>$MODPATH/$font_config_file
ui_print "New $font_config_file generated"
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 2958773

Please sign in to comment.