Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script: fontcharlist #21

Open
webframp opened this issue Oct 5, 2023 · 1 comment
Open

Script: fontcharlist #21

webframp opened this issue Oct 5, 2023 · 1 comment

Comments

@webframp
Copy link
Owner

webframp commented Oct 5, 2023

This SO answer has been pretty useful. Convert it to a script called fontcharlist installed via nix.

#!/bin/bash -

Usage() { echo "$0 FontFile"; exit 1; }
SayError() { local error=$1; shift; echo "$0: $@"; exit "$error"; }

[ "$#" -ne 1 ] && Usage

width=70
fontfile="$1"

[ -f "$fontfile" ] || SayError 4 'File not found'

list=$(fc-query --format='%{charset}\n' "$fontfile")

for    range in $list
do     IFS=- read start end <<<"$range"
       if    [ "$end" ]
       then
             start=$((16#$start))
         end=$((16#$end))
         for((i=start;i<=end;i++)); do
         printf -v char '\\U%x' "$i"
         printf '%b' "$char"
         done
       else
         printf '%b' "\\U$start"
       fi
done | grep -oP '.{'"$width"'}'
@webframp
Copy link
Owner Author

webframp commented Nov 3, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant