V
V
Vladimir Seregin2018-08-03 07:08:33
JavaScript
Vladimir Seregin, 2018-08-03 07:08:33

How to determine the fonts installed in the system from JS?

I want to write a phrase using a different font for each letter. At the same time, take those installed in the system so as not to load from the network.
It is necessary to get a list of fonts installed in the client system from JS.
As far as I understand, all existing definitions are based on hacks: determine if there is a particular font in the system, then take a list of popular fonts and run through it. Cons: If a user has a rare font, we won't know about it. The same if you take " safe fonts ".
Is there any standard API for this?
If not, I will be grateful for the definition with the largest list of checked fonts.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bhudh, 2018-08-05
@Bhudh

I can offer a script that checks for the presence of certain fonts in the user with a certain probability.
The disadvantages are as follows: first you will need to fill the database with the fonts you need yourself, and also add them to the array for verification; the check is ambiguous, because even if you bring the font size to astronomical values ​​​​(and not to 120pt, as in the example), it can still happen that for some fonts the width (and height, by the way) of the text will match up to a pixel ; if by "installed" we mean those located in the %FONTS% system folder, they cannot be distinguished from those in the cache of the browser that got them from some font CDN; Finally, I do not exclude the possibility that on different operating systems different engines for rendering fonts and for different systems, text sizes may not match.
The example checks arbitrary text, you can use pangramsor check sizes of individual letters/numbers/other glyphs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question