From eb3fecf55b2710ee7a0d4a54abd5f07eccaeec61 Mon Sep 17 00:00:00 2001 From: Rizal Martin <49640119+rizalmart@users.noreply.github.com> Date: Mon, 8 Jan 2024 08:56:57 +0800 Subject: [PATCH] Update fontmanager: Some improvements * Improved fonts.conf file parsing * Added lcd filter settings * More user-friendly hint style selection * Settings applied across GNOME, KDE, and XFCE desktop environments. --- .../rootfs-skeleton/usr/sbin/fontmanager | 131 +++++++++++++++--- 1 file changed, 108 insertions(+), 23 deletions(-) diff --git a/woof-code/rootfs-skeleton/usr/sbin/fontmanager b/woof-code/rootfs-skeleton/usr/sbin/fontmanager index b871099addd..32131db1bdc 100755 --- a/woof-code/rootfs-skeleton/usr/sbin/fontmanager +++ b/woof-code/rootfs-skeleton/usr/sbin/fontmanager @@ -10,18 +10,21 @@ export OUTPUT_CHARSET=UTF-8 #================================================================ #read current dpi setting... -CURRDPI=`grep "^Xft\\.dpi:" /root/.Xresources | tr '\t' ' ' | tr -s ' ' | cut -f 2 -d ' '` +CURRDPI=`grep "^Xft\\.dpi:" $HOME/.Xresources | tr '\t' ' ' | tr -s ' ' | cut -f 2 -d ' '` [ ! $CURRDPI ] && CURRDPI=78 CURRINDEX=$(( $CURRDPI / 6 - 9 )) +[ ! -d $HOME/.config/fontconfig ] && mkdir -p $HOME/.config/fontconfig + #read appearance values -if [ -f $HOME/.fonts.conf ];then - export antialiasing=$(grep '' $HOME/.fonts.conf|head -1|cut -d '>' -f2|cut -d '<' -f1) - export hinting=$(grep '' $HOME/.fonts.conf|head -2|tail -1|cut -d '>' -f2|cut -d '<' -f1) - export autohint=$(grep '' $HOME/.fonts.conf|head -3|tail -1|cut -d '>' -f2|cut -d '<' -f1) - export hintstyle=$(grep '' $HOME/.fonts.conf|cut -d '>' -f2|cut -d '<' -f1) +if [ -f $HOME/.config/fontconfig/fonts.conf ];then + export antialiasing=$(grep -A 2 'antialias' $HOME/.config/fontconfig/fonts.conf | awk -F'[<>]' '/bool/ {print $3}') + export hinting=$(grep -A 2 'hinting' $HOME/.config/fontconfig/fonts.conf | awk -F'[<>]' '/bool/ {print $3}') + export autohint=$(grep -A 2 'autohint' $HOME/.config/fontconfig/fonts.conf | awk -F'[<>]' '/bool/ {print $3}') + export hintstyle=$(grep -A 2 'hintstyle' $HOME/.config/fontconfig/fonts.conf | awk -F'[<>]' '/int/ {print $3}') + export lcdfilter=$(grep -A 2 'lcdfilter' $HOME/.config/fontconfig/fonts.conf | awk -F'[<>]' '/int/ {print $3}') else - export antialiasing=false hinting=false autohint=false hintstyle=0 + export antialiasing=false hinting=false autohint=false hintstyle=0 lcdfilter=1 fi #what tab should be active @@ -43,6 +46,19 @@ install (){ } export -f install +hintstyleval="none" + +[ $hintstyle -eq 1 ] && hintstyleval="slight" +[ $hintstyle -eq 2 ] && hintstyleval="medium" +[ $hintstyle -eq 3 ] && hintstyleval="full" + +lcdfilterval="none" + +[ $lcdfilter -eq 1 ] && lcdfilterval="default" +[ $lcdfilter -eq 2 ] && lcdfilterval="light" +[ $lcdfilter -eq 3 ] && lcdfilterval="legacy" +[ $lcdfilter -eq 4 ] && lcdfilterval="legacy1" + S=' @@ -103,13 +119,28 @@ S=' autohint '$autohint' + + - - + + + '$hintstyleval' hintstyle - '$hintstyle' - true - + none + slight + medium + full + + + + '$lcdfilterval' + lcdfilter + none + default + light + legacy + legacy1 + @@ -154,15 +185,15 @@ S=' gfontsel & ' S=$S' - + @@ -170,20 +201,53 @@ S=' export Font_Manager="$S" . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme -eval $(gtkdialog -p Font_Manager --styles=/tmp/gtkrc_xml_info.css) +eval $(gtkdialog -p Font_Manager) case $EXIT in save) + + rhintstyleval=0 + + [ $hintstyle == "slight" ] && rhintstyleval=1 + [ $hintstyle == "medium" ] && rhintstyleval=2 + [ $hintstyle == "full" ] && rhintstyleval=3 + + rlcdfilterval=0 + + [ $lcdfilter == "default" ] && rlcdfilterval=1 + [ $lcdfilter == "light" ] && rlcdfilterval=2 + [ $lcdfilter == "legacy" ] && rlcdfilterval=3 + [ $lcdfilter == "legacy1" ] && rlcdfilterval=4 + + antialiasingval=0 + hintingval=0 + autohintval=0 + + gnomeantialias="none" + + if [ "$antialiasing" == "true" ]; then + antialiasingval=1 + gnomeantialias="rgba" + fi + + [ "$hinting" == "true" ] && hintingval=1 + [ "$autohint" == "true" ] && autohintval=1 + #set size - sed -i -e '/^Xft.dpi:/ d' $HOME/.Xresources - echo "Xft.dpi: $NEWDPI" >> $HOME/.Xresources + sed -i -e 's#^Xft\.dpi:.*#Xft\.dpi:\ '$NEWDPI'#' $HOME/.Xresources + sed -i -e 's#^Xft\.autohint:.*#Xft\.autohint:\ '$autohintval'#' $HOME/.Xresources + sed -i -e 's#^Xft\.antialias:.*#Xft\.antialias:\ '$antialiasingval'#' $HOME/.Xresources + sed -i -e 's#^Xft\.hinting:.*#Xft\.hinting:\ '$hintingval'#' $HOME/.Xresources + sed -i -e 's#^Xft\.hintstyle:.*#Xft\.hintstyle:\ hint'$hintstyle'#' $HOME/.Xresources + sed -i -e 's#^Xft\.lcdfilter:.*#Xft\.lcdfilter:\ lcd'$lcdfilter'#' $HOME/.Xresources - if [[ "$antialiasing" = "false" && "$hinting" = "false" && "$autohint" = "false" && "$hintstyle" = 0 ]];then + if [[ "$antialiasing" = "false" && "$hinting" = "false" && "$autohint" = "false" && "$rhintstyle" = 0 && "$rlcdfilter" = 0 ]];then #don't write the file, delete if it's there. [ -f $HOME/.fonts.conf ] && rm $HOME/.fonts.conf echo "not writing file" else - cat > $HOME/.fonts.conf << _EOF + [ -f $HOME/.fonts.conf ] && rm $HOME/.fonts.conf + cat > $HOME/.config/fontconfig/fonts.conf << _EOF @@ -204,7 +268,10 @@ case $EXIT in $autohint - $hintstyle + $rhintstyleval + + + $rlcdfilterval @@ -216,6 +283,24 @@ case $EXIT in _EOF + + fc-cache -fv + + xrdb -merge $HOME/.Xresources + + gsettings set org.gnome.desktop.interface font-antialiasing ${gnomeantialias} 2>/dev/null + gsettings set org.gnome.desktop.interface font-hinting ${hintstyle} 2>/dev/null + + kwriteconfig5 --file kdeglobals --group General --key XftDPI $NEWDPI 2>/dev/null + kwriteconfig5 --file kdeglobals --group General --key XftAntialias --type bool $antialiasing 2>/dev/null + kwriteconfig5 --file kdeglobals --group General --key XftHinting --type bool $hinting 2>/dev/null + kwriteconfig5 --file kdeglobals --group General --key XftHintStyle --type string "hint${hintstyle}" 2>/dev/null # Use 'hintnone', 'hintslight', 'hintmedium', or 'hintfull' + + xfconf-query -c xsettings -p /Xft/DPI -s $NEWDPI + xfconf-query -c xsettings -p /Xft/Antialias -s $antialiasingval + xfconf-query -c xsettings -p /Xft/Hinting -s $hintingval + xfconf-query -c xsettings -p /Xft/HintStyle -s "hint${hintstyle}" + fi ;; esac