Find the best font for rendering a codepoint

fontsunicode

How to find the appropriate font for rendering unicode codepoints ?

gnome-terminal find that characters like «?⼼???» can be rendered with fonts like Symbola rather than my terminal font or the codepoint-in-square fallback (?). How ?

Best Answer

Using fontconfig,

> fc-list ':charset=<hex_code1> <hex_code2>'

e.g.

> fc-list ':charset=2713 2717'

will display any font filenames containing ✓ and ✗.

To get the codepoint corresponding to the character use (for example)

> printf "%x" \'✓
2713>

This uses a somewhat obscure feature of the POSIX printf utility:

If the leading character is a single-quote or double-quote, the value shall be the numeric value in the underlying codeset of the character following the single-quote or double-quote.

Taken together,

> printf '%x' \'✓ | xargs -I{} fc-list ":charset={}"

This uses the xargs -I flag to replace {} with names from stdin. So this effectively boils down to:

> fc-list ":charset=2713"
Related Question