Skip to content

Instantly share code, notes, and snippets.

@jul
Last active Nov 3, 2020
Embed
What would you like to do?
checking font substitution on firefox
#!/usr/bin/bash
MIN_FF_OPT=" --headless "
FF="firefox $MIN_FF_OPT"
die() { echo "$@"; exit 0;}
fc-match Andika || die "le test va pas marcher"
echo "basically if I could create profile from scratch I would put only this"
cat <<EOF
user_pref("font.default.x-western", "Andika");
user_pref("font.name-list.serif.x-western","Andika");
EOF
SUCC=0
FAIL=0
RZ='\e[0m'
GR=${GR-'\e[92m'}
RD=${RD-'\e[91m'}
HL=${HL-'\e[1m'}
TOTAL=$( fc-list | cut -d ":" -f 2 | cut -d "," -f 1 | sed -e 's/^ //' | sort | uniq | wc -l )
OK() { SUCC=$(( SUCC + 1 )); echo -n "$@ :"; echo -e "${HL}${GR}OK${RZ} ($SUCC/$TOTAL)"; echo "$@" >> success.txt; }
KO() { FAIL=$(( FAIL + 1 )); echo -n "$@ :"; echo -e "${HL}${RD}KO${RZ} ($SUCC/$TOTAL)"; echo "$@" >> failture.txt; }
echo "what is the name of the profile for the test ?"
read -r PROFILE
FF="firefox -P $PROFILE $MIN_FF_OPT"
rm success.txt failture.txt
$FF --screenshot ref.png 'data:text/html,<body style="font-family: serif">test'
diff -q ref.png ref2.png && OK serif || KO serif
$FF --screenshot ref2.png "data:text/html,<body style=\"font-family: 'DejaVu Serif', serif\">test"
diff -q ref.png ref2.png && OK Dejavu Serif || KO dejavu serif
while IFS= read -r font
do
$FF --screenshot ref2.png "data:text/html,<body style=\"font-family: '$font', serif\">test" &> /dev/null
diff -q ref.png ref2.png &> /dev/null && OK "$font" || KO "$font"
done <<< "$( fc-list | cut -d ":" -f 2 | cut -d "," -f 1 | sed -e 's/^ //' | sort | uniq ) "
fc-list -b | perl -ane 'm!/([a-zA-Z]+)\-!; print "$1\n";' | sort | uniq > installed_fonts
while IFS= read -r font; do fc-match "$font"; done < failture.txt | cut -d ":" -f 1 | sort | uniq > matched_fonts.txt
c
TOTAL=$( wc -l failture.txt | cut -d " " -f 1 )
SUCC=0
FAIL=0
while IFS= read -r font; do grep "$font" installed_fonts &> /dev/null && OK "$font" || KO "$font" ; done < matched_fonts.txt
[[ $SUCC == "0" ]] && echo -e "${HL}${RD}point proven if a font has no matched installed fonts in fc-match substitution fail${RZ}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment