42

Unicode contains a few special "characters" which are not displayable by most fonts. I want to use one of them, a video camera.

It seems that such a character exists indeed, and has the codepoint U+1F4F9. When I visit http://graphemica.com/%F0%9F%93%B9, I see it displayed both on the webpage and in Firefox's URL bar. So I assume that I have at least one font on my system which contains the glyph.

url with video camera glyph displays correctly

But when I paste it into Inkscape, I get the empty box for an unknown character, even if I choose a font which usually has many glyphs, like Arial.

How do I find out which of the fonts I have installed can display the "character"?

Rumi P.
  • 681

5 Answers5

27

Try this page: www.Fileformat.info

https://www.fileformat.info/info/unicode/char/1f4f9/fontsupport.htm

There you can query Unicode characters and get a list of supporting fonts.

24

The following Python script would print all fonts containing a character (tested on my Linux box).

import unicodedata
import os

fonts = []

for root,dirs,files in os.walk("/usr/share/fonts/"):
    for file in files:
       if file.endswith(".ttf"): fonts.append(os.path.join(root,file))


from fontTools.ttLib import TTFont

def char_in_font(unicode_char, font):
    for cmap in font['cmap'].tables:
        if cmap.isUnicode():
            if ord(unicode_char) in cmap.cmap:
                return True
    return False

def test(char):
    for fontpath in fonts:
        font = TTFont(fontpath)   # specify the path to the font in question
        if char_in_font(char, font):
            print(char + " "+ unicodedata.name(char) + " in " + fontpath) 

test(u"")
test(u"")

On my machine, this gives:

 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-Bold.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Oblique.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-Oblique.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansCondensed-BoldOblique.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-BoldOblique.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/dejavu/DejaVuSansCondensed.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Bold.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Oblique.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-BoldOblique.ttf
 SMILING CAT FACE WITH OPEN MOUTH  in /usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf
 CAT  in /usr/share/fonts/truetype/noto/NotoSansSymbols2-Regular.ttf
5

I completely understand the question as I ran into the same problem myself:

You know your computer has the font installed because one program displays the content properly, but another program displays the same content as a blank box because it doesn't know what font to use to display properly. And you don't want to scroll through all the fonts to find one that contains the character you want.

Try pasting the copied text/symbol into a blank Microsoft Word doc. The content should appear properly if Word is set to Keep Source Formatting by default for pasted text. If so, select the content and the Word font menu will show you the source font on your computer that contains the necessary character. Granted, there may be others, but at least this is a quick and dirty way to find one font that may be suitable.

Owen
  • 51
2

Finding installed fonts containing a given character is the purpose of the albatross command-line tool. It is distributed with the TeX distributions texlive and miktex but can be installed standalone as well. For example, the input

albatross U+1F4F9

on my system results in

        __ __           __
.---.-.|  |  |--.---.-.|  |_.----.-----.-----.-----.
|  _  ||  |  _  |  _  ||   _|   _|  _  |__ --|__ --|
|___._||__|_____|___._||____|__| |_____|_____|_____|
                Unicode glyph with code points [1F4F9]
                     mapping to [?] (AND search)

┌─────────────────────────────────────────────────────────────────────────────┐ │ Font name │ ├─────────────────────────────────────────────────────────────────────────────┤ │ Noto Color Emoji │ │ Noto Emoji │ │ Segoe UI Emoji │ │ Segoe UI Symbol │ │ Twemoji Mozilla │ └─────────────────────────────────────────────────────────────────────────────┘

See the documentation for more command options.

mbert
  • 121
0

An improvement to Martin Monperrus's answer that fixes the support for ttc files:

# https://superuser.com/a/1452828
from fontTools.ttLib import TTFont
def char_in_font(unicode_char, path):
    if path.endswith('.ttf'):
        font = TTFont(path)
    elif path.endswith('.ttc'):
        # https://github.com/fonttools/fonttools/issues/541
        font = TTFont(path, fontNumber=0)
    else:
        return False
    for cmap in font['cmap'].tables:
        if cmap.isUnicode():
            if ord(unicode_char) in cmap.cmap:
                return True
    return False

from matplotlib.font_manager import findSystemFonts def find_font_containing(unicode_char): for path in findSystemFonts(fontpaths=None, fontext='ttf'): if char_in_font(unicode_char, path): return path return None

Extend to checking multiple unicode characters:

from fontTools.ttLib import TTFont
def chars_in_cmap(unicode_chars, cmap):
    for char in unicode_chars:
        if ord(char) not in cmap.cmap:
            return False
    return True
def chars_in_font(unicode_chars, path):
    if path.endswith('.ttf'):
        font = TTFont(path)
    elif path.endswith('.ttc'):
        # https://github.com/fonttools/fonttools/issues/541
        font = TTFont(path, fontNumber=0)
    else:
        return False
    for cmap in font['cmap'].tables:
        if cmap.isUnicode():
            if chars_in_cmap(unicode_chars, cmap):
                return True
    return False

from matplotlib.font_manager import findSystemFonts def find_font_containing(unicode_chars): for path in findSystemFonts(fontpaths=None, fontext='ttf'): if chars_in_font(unicode_chars, path): return path return None