photopea / Typr.js

Typr.js - process fonts in Javascript
MIT License
914 stars 73 forks source link

Identify languages in font file. #31

Closed knowBalpreet closed 4 years ago

knowBalpreet commented 4 years ago

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

photopea commented 4 years ago

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.

knowBalpreet commented 4 years ago

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?

photopea commented 4 years ago

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.

knowBalpreet commented 4 years ago

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

photopea commented 4 years ago

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 ...

knowBalpreet commented 4 years ago

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.

photopea commented 4 years ago

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