You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glyphs 730B

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. if [[ ! -f "$1" ]]; then
  3. echo "Usage: ./glyphs [font.bdf]"
  4. exit 1
  5. fi
  6. fast_chr() {
  7. local __octal
  8. local __char
  9. printf -v __octal '%03o' "$1"
  10. printf -v __char \\$__octal
  11. REPLY="$__char"
  12. }
  13. unichr() {
  14. local c=$1 # ordinal of char
  15. local l=0 # byte ctr
  16. local o=63 # ceiling
  17. local p=128 # accum. bits
  18. local s='' # output string
  19. if (( c < 0x80 )); then
  20. fast_chr "$c"
  21. printf '%s' "$REPLY"
  22. return
  23. fi
  24. while (( c > o )); do
  25. fast_chr $(( t = 0x80 | c & 0x3f ))
  26. s="$REPLY$s"
  27. (( c >>= 6, l++, p += o+1, o>>=1 ))
  28. done
  29. fast_chr $((t = p | c))
  30. printf '%s%s' "$REPLY" "$s"
  31. }
  32. ## test harness
  33. for i in \
  34. $(grep -E '^ENCODING' "$1" |
  35. sed -e 's/ENCODING//' |
  36. tr -d '\n'); do
  37. unichr "$i"
  38. done