1

I want to know the font name of displayed characters on any X application. Of course, I can know the font name by comparing the displayed characters with each font characters, but it takes a very long time. Is there any easier and wiser way?

When I copy & paste characters, the font information seems to be copied, too. So, I think there is some way to know the font name. Copy characters and peek the clipboard?

3
  • Do you actually mean "displayed" iow the glyphs you can "see" on your screen. (v.s. glyphs rendered by your printer, vs fonts more or less specified as part of some document / html page, vs font used by the application for displaying its menues / dialog boxes) ?
    – MC68020
    Jun 18, 2022 at 8:03
  • In addition, do you run these apps from some DE (which one) or immediately under Xorg ?
    – MC68020
    Jun 18, 2022 at 8:16
  • X11 and Xft are server-side and client-side, respectively. For the former, there's no general solution; for the latter strace helps (which is probably a duplicate). Jun 18, 2022 at 9:59

4 Answers 4

2

I don't think there is a general solution. Once the text has been rendered, there's no reason why any component of the system would have kept the information of what font it was rendered from around.

So I'll add some tools that can help:

  • To list all available fonts on Linux, open terminal and run the command:

    fc-list

The output should be such as:

/usr/share/fonts/opentype/mathjax/MathJax_SansSerif-Regular.otf: MathJax_SansSerif:style=Regular
/usr/share/fonts/opentype/urw-base35/NimbusRoman-Italic.otf: Nimbus Roman:style=Italic
/usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf: DejaVu Sans:style=Bold Oblique
/usr/share/fonts/truetype/kacst/KacstOffice.ttf: KacstOffice:style=Medium
/usr/share/fonts/type1/gsfonts/n019003l.pfb: Nimbus Sans L:style=Regular
/usr/share/fonts/truetype/abyssinica/AbyssinicaSIL-Regular.ttf: Abyssinica SIL:style=Regular

where:

/usr/share/fonts/opentype/mathjax/MathJax_SansSerif-Regular.otf       File name
:                                                                     Separator 
MathJax_SansSerif                                                     Font name 
:                                                                     Separator
style=Regular                                                         The font 'style'

check man fc-list for more details

  • You can also get the accessed font n minutes ago using the command:

    find /usr/share/fonts -type f -amin +n

chek man find for more details...

  • The last thing I can think about is to use FC_DEBUG. Since most programs render through the fontconfig library. If you start a fontconfig-using program with the FC_DEBUG environment variable set to a suitable value, it will show some information about fonts being loaded. For example:

    FC_DEBUG=2053 gedit

1
  • agreeing, but that only gives a good guess (fontconfig will suggest fonts, which the application may not use). Jun 18, 2022 at 10:29
1

I want to know the font name of displayed characters on any X application.

There is no way to do that for any X application.

When I copy & paste characters, the font information seems to be copied, too.

I have never seen this happening in general, and you don't mention which application you are copying from. However, X applications can offer selections in different formats, and particular applications like browsers often offer HTML as one of the formats (if you select text on a web page). And the HTML will of course include the font tags.

So if that is the effect you have been observing, you can get the selection in HTML format e.g. with command line tools, see this question.

But that won't work if the X application you are copying from doesn't supply the selection in such a format.

1

For hundreds of (good) reasons including but not limited to :

  • The fact that most modern documents / applications might not specify more than a font family (sans, mono, serif…)
  • The fact that themes, DE's settings can force use of precisely defined fonts irrespective of app's (default) requirements, (This could BTW explain why copy/pasting via clipboard might (sometimes) display identical glyphs)
  • Font aliases initially needed in order to provide copyright free alternatives to commercial fonts,
  • html pages / pdf documents / office documents might embed dedicated font files that just do not exist on your system…

The only reliable way to go is proceeding with image comparison with some database of glyphs. Yes ! Automate what you said actually doing with your eyes !

There are a good bunch of commercial programs dedicated to font design (in their vast majority for MacOS) that offer this facility. Unfortunately good old fontforge just cannot compete.

You can however try some online ressources such as :

Not to tell about dedicated Chrome / Firefox browser extensions.

Of course; since it is all about image processing, it might take some time before delivering and the accuracy of the result will depend on the richness of the font database used. (Matcherator claims 900 000, MyFonts 130 000)

You'll just need to provide the most precise screenshot possible.

1

When I copy & paste characters, the font information seems to be copied,

  • Paste the buffer into e.g. LibreOffice and you'll probably see the font name being used.

  • Another option is to run the application via strace -f -e file application 2>&1 | grep -i ttf and you'll see all the font files being actually opened.

  • Font names are often hard-coded, you may run the app along with its libraries through strings. This will narrow the search field.

5
  • 1
    The first sentence is incorrect (will never be true). Jun 18, 2022 at 9:57
  • 1
    Good luck on that - do go and read the ICCCM and some source code. The selection mechanism doesn't convey that information. You're apparently confusing a special case with the OP's request for a general solution. Jun 18, 2022 at 10:18
  • "you'll probably see" I said nothing about the first option working at all times. In absolute most applications you cannot select anything other than edit/text fields. Jun 18, 2022 at 10:32
  • 1
    OP said "I want to know the font name of displayed characters on any X application." Jun 18, 2022 at 12:34
  • I don't understand why you're <skipped>-ing with me just because you didn't like my first option. Is there a particular reason? Jun 18, 2022 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .