Skip to content

Instantly share code, notes, and snippets.

@Artoria2e5
Last active June 5, 2016 03:07
Show Gist options
  • Save Artoria2e5/36c6bfafe36b86a9db0966a82f119cf2 to your computer and use it in GitHub Desktop.
Save Artoria2e5/36c6bfafe36b86a9db0966a82f119cf2 to your computer and use it in GitHub Desktop.
Fontconfig ConfGen
#!/bin/bash
# My brain is not feeling well so I will be doing a wizard instead.
# It should hopefully be self-explainatory then.
# ref: https://fedoraproject.org/wiki/Fontconfig_packaging_tips
fc_head='<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fontconfig SYSTEM "../fonts.dtd">
<fontconfig>'
fc_tail='</fontconfig>'
declare -A fc_segment
declare -a fc_seg_ord
__xml_esc(){
declare -n __var="$1" || return
__var=${__var//'&'/'&amp;'} \
__var=${__var//'<'/'&lt;'} \
__var=${__var//'>'/'&gt;'} \
__var=${__var//'"'/'&quot;'}
}
seg_add(){
(($# == 1 || $# == 2)) || return
(($# == 2)) && fc_segment["$1"]="$2"
seg_del "$1"
fc_seg_ord+=("$1")
}
seg_del(){
local __seg_idx;
for __seg_idx in "${!fc_seg_ord[@]}"; do
if [[ $fc_seg_ord[__seg_idx] == $1 ]]; then
unset 'fc_seg_ord[__seg_idx]'
fi
done
}
add_equiv(){
(($# >= 2)) && local generic=$1 as_font=$2 || return
local seg=equiv:${1//'/'/_}:${2//'/'/_}
__xml_esc generic
__xml_esc as_font
seg_add "$seg" "<alias binding='same'>
<family>$generic</family>
<accept>
<family>$as_font</family>
</accept>
</alias>"
}
show_segs(){
printf '* %s\n' "${fc_seg_ord[@]}"
}
stringify_segs(){
local i
for i in "${fc_seg_ord[@]}"; do
printf '<!-- %s -->\n%s\n' "$i" "${fc_segment["$i"]}"
done
}
save_segs(){
}
echo
BASH_ENV="$(readlink -f "$0")" exec bash -i -$- -- "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment