diff options
author | Ting-Wei Lan <lantw44@gmail.com> | 2015-04-03 17:46:44 +0800 |
---|---|---|
committer | Ting-Wei Lan <lantw44@gmail.com> | 2015-04-03 17:46:44 +0800 |
commit | f3e66829788b671e1ebd86892c5094ed18d4f9ae (patch) | |
tree | 1dfbdf89721b555d427a46845c4bdb8732ab1b2b | |
parent | abe329340b62aacd9908312c2469cce8f6bcba5d (diff) | |
download | configfile-f3e66829788b671e1ebd86892c5094ed18d4f9ae.tar.gz configfile-f3e66829788b671e1ebd86892c5094ed18d4f9ae.tar.zst configfile-f3e66829788b671e1ebd86892c5094ed18d4f9ae.zip |
bash_include: 加入用來自動產生 fontconfig alias 設定檔的小工具bash_include-20150403
-rw-r--r-- | bash_include | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/bash_include b/bash_include index d47d505..4ae4d12 100644 --- a/bash_include +++ b/bash_include @@ -687,6 +687,112 @@ EOF } +# Group: Fontconfig Tools #################################################### + +function fontconfig_get_supported_lang () +{ + local font_file + local fc_query_cmd="fc-query" + + fc-list "$1" | cat -n + read -e -p " $1 >>> " choice + font_file="`fc-list "$1" | sed -n ${choice}p | cut -d ':' -f 1`" + echo " $1 >>> $font_file" + + if [ "`fc-query "$font_file" | safe_grep '^ lang: ' | wc -l`" -gt 1 ]; then + echo '' + echo " $font_file contains more than one font ..." + fc-query "$font_file" | safe_grep '^ fullname: ' | ( + declare -i i=0 + while read oneline; do + printf "%6d %s\n" "$i" "$oneline" + i=i+1 + done ) + read -e -p " Index of $1 >>> " choice + fc_query_cmd="fc-query -i $choice" + fi + + fontconfig_supported_lang="`$fc_query_cmd "$font_file" | safe_grep '^ lang: ' | cut -d : -f 2 | sed 's/ //'`" +} + +function fontconfig_set_alias () +{ + local alias_name="$1" + local main_font="$2" + local fallback_font="$3" + local use_match + local choice + + fontconfig_get_supported_lang "$main_font" + local main_font_lang="$fontconfig_supported_lang" + + echo '' + echo '' + + fontconfig_get_supported_lang "$fallback_font" + local fallback_font_lang="$fontconfig_supported_lang" + + echo '' + echo '' + + read -p 'Use <match> or <alias> ? ' choice + case "$choice" in + *M*|*m*) + use_match="true" + ;; + *) + use_match="false" + ;; + esac + + echo '' + echo '' + + if [ "$use_match" = "true" ]; then + echo '<match>' + echo ' <test name="family"><string>'"$alias_name"'</string></test>' + echo ' <edit name="family" mode="prepend" binding="strong">' + echo ' <string>'"$main_font"'</string>' + echo ' </edit>' + echo '</match>' + else + echo '<alias>' + echo ' <family>'"$alias_name"'</family>' + echo ' <prefer><family>'"$main_font"'</family></prefer>' + echo '</alias>' + fi + + echo '' + + diff -u \ + <(echo "$main_font_lang" | tr '|' '\n' | sort) \ + <(echo "$fallback_font_lang" | tr '|' '\n' | sort) | \ + sed -e '/@@/d' -e '/---/d' -e '/+++/d' | \ + safe_grep '\+' | sed 's/+//' | ( + + while read lang; do + if [ "$use_match" = "true" ]; then + echo '<match>' + echo ' <test name="family"><string>'"$alias_name"'</string></test>' + echo ' <test name="lang" compare="contains"><string>'"$lang"'</string></test>' + echo ' <edit name="family" mode="prepend" binding="strong">' + echo ' <string>'"$fallback_font"'</string>' + echo ' </edit>' + echo '</match>' + else + echo '<alias>' + echo ' <family>'"$alias_name"'</family>' + echo ' <test name="lang" compare="contains"><string>'"$lang"'</string></test>' + echo ' <prefer><family>'"$fallback_font"'</family></prefer>' + echo '</alias>' + fi + done + ) + + unset fontconfig_supported_lang +} + + # Group: New PATH Editor ##################################################### function newpath_init () @@ -1897,6 +2003,10 @@ function help_function () x fetch_remote_file local_file_name remote_url x fetch_and_merge local_file_name remote_url + <<< Group: Fontconfig Tools >>> + fontconfig_set_alias name main_font fallback_font + x fontconfig_get_supported_lang font_name + <<< Group: New PATH Editor >>> path_editor [variable] ldpath_editor |