photopea/Typr.js

Identify languages in font file.

knowBalpreet opened this issue · 7 comments

Thank you @photopea for this amazing library.
I would like to know if there is a possibility to identify languages supported in the font file. I went through the response of parse API and didn't find anything. I want to check if in a given font file Arabic support is there or not. Or some other language.

Thanks in Advance

Hi, I don't think there is such thing as a "language" of an OpenType font.

The function Typr.U.codeToGlyph(font, code) takes a unicode number of a specific character, and returns an index of a glyph. If it returns 0, the character is not supported by the font.

You can try to call this function for various arabic characters (like 0x646 for "ن" - see https://www.fileformat.info/info/unicode/char/0646/index.htm ). If it supports plenty enough arabic characters, you can consider it to support Arabic. The same goes for Latin, Cyrillic, Greek, various symbols, smileys, etc.

Thank you @photopea for reverting back so quick. And this will work if I need to check against one language. But I want an exhaustive list of multiple supported languages. These can be english, arabic, hindi, urdu, mandarin, etc. Is there a common way to identify these?

As I said, the OpenType font does not mention supported languages.

You have to ask for specific characters, if they are supported. So you have to find out what characters are used in a language you ask for.

Okay, thanks will create an exhaustive list of such characters and will add them if they are present with the above-mentioned method.

Unicode charaters are separated into groups / blocks https://en.wikipedia.org/wiki/Unicode_block

E.g. first 400 characters (Basic Latin, Latin 1 - Supplement, Latin Extended-A) cover about 100 languages.

When a font creator draws all characters for English, they can add only 5 - 10 more characters, to support German, Polish, Italian, French, Portuguese, Swedish, Italian, Spanish ...

What according to you is the best way to do/handle this? I will follow your lead. And thank you for reverting back so quick.

Use Typr.U.codeToGlyph to check, if a character is supported.