sudipshil9862 / whichfont

Querying fontconfig for certain code point
GNU General Public License v3.0
1 stars 1 forks source link

add --language feature to list default font for a specific language #5

Open juhp opened 7 months ago

juhp commented 7 months ago

For example something like

$ whichfont --language ja
NotoSansCJK-VF.ttc: "Noto Sans CJK JP" "Regular"
$ whichfont --language mn # Mongolian
No font with coverage is available
$ whichfont <mongolian script>
No font with coverage is available
sudipshil9862 commented 7 months ago

I tried implementing this feature in code using fontconfig functions. But looks like, it is not able to calculate if any font is not there in system corresponding to specific language. Anyhow fontconfig gives a font

$ ./run.sh -l ja Noto Sans CJK JP

$ ./run.sh -l mn Noto Sans

juhp commented 7 months ago

(right and the latter is incorrect - no coverage)

sudipshil9862 commented 7 months ago

my latest code gives these outputs:

$ ./run.sh -l en Noto Sans

$ ./run.sh -l ko Noto Sans CJK KR

$ ./run.sh -l hi Noto Sans Devanagari

$ ./run.sh -l anp No font installed for (anp) language

which is working fine. But problem is with random letter which is not a language code. My doubt is, how can we determine if a language code is valid or not ?? like this: $ ./run.sh -l a No font installed for (a) language

It should give a output like: "Invalid languagecode used"

sudipshil9862 commented 7 months ago

Let me know if I can use this library from pypi langcodes to verify languagecode https://pypi.org/project/langcodes/

sudipshil9862 commented 7 months ago

is there any fedora package like this ?

juhp commented 7 months ago

Maybe you can ask around? Anyway I am less worried about the "wrong langcode" corner case, but it would be nice to catch that certainly.

Maybe @mike-fabian has an idea/input?

juhp commented 7 months ago

Also the "wrong font answer" applies to normal usage too (choosing first tofu (Santhili) I see on http://wikipedia.org/):

$ whichfont ᱥ
"ᱥ" <U+1C65>
NotoSans[wght].ttf: "Noto Sans" "Regular"
mike-fabian commented 7 months ago

Let me know if I can use this library from pypi langcodes to verify languagecode https://pypi.org/project/langcodes/

If you use pythoņ you could also use my langtable that will always list a superset of the languages we have in glibc:

$ python3
Python 3.12.1 (main, Dec 18 2023, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import langtable
>>> langtable.list_all_languages()
['aa', 'ab', 'af', 'agq', 'agr', 'ak', 'am', 'an', 'anp', 'ar', 'as', 'asa', 'ast', 'av', 'ay', 'ayc', 'ayr', 'az', 'ba', 'bas', 'be', 'bem', 'ber', 'bez', 'bg', 'bhb', 'bho', 'bi', 'bih', 
'bin', 'bm', 'bn', 'bo', 'br', 'brx', 'bs', 'bua', 'byn', 'ca', 'ca_ES_VALENCIA', 'ccp', 'ce', 'cgg', 'ch', 'chm', 'chr', 'ckb', 'cmn', 'co', 'cop', 'crh', 'cs', 'csb', 'cu', 'cv', 'cy', 'd
a', 'dav', 'de', 'dje', 'doi', 'dsb', 'dua', 'dv', 'dyo', 'dz', 'ebu', 'ee', 'el', 'en', 'eo', 'es', 'et', 'eu', 'ewo', 'fa', 'fat', 'ff', 'fi', 'fil', 'fj', 'fo', 'fr', 'fur', 'fy', 'ga', 
'gbm', 'gd', 'gez', 'gl', 'glk', 'gn', 'grc', 'gsw', 'gu', 'guz', 'gv', 'ha', 'hak', 'haw', 'he', 'hi', 'hif', 'hil', 'hne', 'ho', 'hr', 'hsb', 'ht', 'hu', 'hy', 'hz', 'ia', 'id', 'ie', 'ig
', 'ii', 'ik', 'ilo', 'io', 'is', 'it', 'iu', 'iw', 'ja', 'jgo', 'jmc', 'jv', 'ka', 'kaa', 'kab', 'kam', 'kde', 'kea', 'kg', 'khb', 'khq', 'ki', 'kj', 'kk', 'kkj', 'kl', 'kln', 'km', 'kn', 
'ko', 'kok', 'kr', 'ks', 'ks_Arab', 'ks_Deva', 'ksb', 'ksf', 'ksh', 'ku', 'kum', 'kv', 'kw', 'kwm', 'ky', 'la', 'lag', 'lah', 'lb', 'lez', 'lg', 'li', 'lij', 'lkt', 'ln', 'lo', 'lrc', 'lt',
 'lu', 'luo', 'luy', 'lv', 'lzh', 'mag', 'mai', 'mas', 'mer', 'mfe', 'mg', 'mgh', 'mgo', 'mh', 'mhr', 'mi', 'miq', 'mjw', 'mk', 'ml', 'mn', 'mni', 'mnw', 'mo', 'mos', 'mr', 'ms', 'mt', 'mua
', 'my', 'mzn', 'na', 'nan', 'naq', 'nb', 'nd', 'nds', 'ne', 'new', 'ng', 'nhn', 'niu', 'nl', 'nmg', 'nn', 'nnh', 'no', 'nqo', 'nr', 'nso', 'nus', 'nv', 'ny', 'nyn', 'oc', 'om', 'or', 'os',
 'osa', 'ota', 'pa', 'pap', 'pl', 'prg', 'ps', 'pt', 'qu', 'quh', 'quz', 'raj', 'rif', 'rm', 'rn', 'ro', 'rof', 'ru', 'rw', 'rwk', 'sa', 'sah', 'saq', 'sat', 'sbp', 'sc', 'sco', 'sd', 'sd_A
rab', 'sd_Deva', 'se', 'seh', 'sel', 'ses', 'sg', 'sgs', 'sh', 'shi', 'shn', 'shs', 'si', 'sid', 'sk', 'sl', 'sm', 'sma', 'smj', 'smn', 'sms', 'sn', 'so', 'sq', 'sr', 'sr_Cyrl', 'sr_Latn', 
'ss', 'ssy', 'st', 'su', 'sv', 'sw', 'syc', 'syr', 'szl', 'ta', 'tcy', 'te', 'teo', 'tet', 'tg', 'th', 'the', 'ti', 'tig', 'tk', 'tl', 'tn', 'to', 'tok', 'tpi', 'tr', 'ts', 'tt', 'tt_Cyrl',
 'tt_Latn', 'tw', 'twq', 'txg', 'ty', 'tyv', 'tzm', 'udm', 'ug', 'uk', 'unm', 'ur', 'uz', 'vai', 've', 'vi', 'vo', 'vot', 'vun', 'wa', 'wae', 'wal', 'wen', 'wo', 'wuu', 'xal', 'xh', 'xog', 
'xzh', 'yap', 'yav', 'yi', 'yo', 'yue', 'yuw', 'za', 'zgh', 'zh', 'zh_Hans', 'zh_Hans_CN', 'zh_Hans_SG', 'zh_Hant', 'zh_Hant_HK', 'zh_Hant_MO', 'zh_Hant_TW', 'zu']

But maybe you want to know which languages are supported by fontconfig, which is a different thing, fontconfig may not support all languages supported by glibc.

The languages supported by fontconfig are those where .orth files exist:
https://gitlab.freedesktop.org/fontconfig/fontconfig/-/tree/main/fc-lang?ref_type=heads

I am not sure whether fontconfig has an API to list those.