1"""fontTools.misc.encodingTools.py -- tools for working with OpenType encodings. 2""" 3 4from __future__ import print_function, division, absolute_import 5from fontTools.misc.py23 import * 6import fontTools.encodings.codecs 7 8# Map keyed by platformID, then platEncID, then possibly langID 9_encodingMap = { 10 0: { # Unicode 11 0: 'utf_16_be', 12 1: 'utf_16_be', 13 2: 'utf_16_be', 14 3: 'utf_16_be', 15 4: 'utf_16_be', 16 5: 'utf_16_be', 17 6: 'utf_16_be', 18 }, 19 1: { # Macintosh 20 # See 21 # https://github.com/fonttools/fonttools/issues/236 22 0: { # Macintosh, platEncID==0, keyed by langID 23 15: "mac_iceland", 24 17: "mac_turkish", 25 18: "mac_croatian", 26 24: "mac_latin2", 27 25: "mac_latin2", 28 26: "mac_latin2", 29 27: "mac_latin2", 30 28: "mac_latin2", 31 36: "mac_latin2", 32 37: "mac_romanian", 33 38: "mac_latin2", 34 39: "mac_latin2", 35 40: "mac_latin2", 36 Ellipsis: 'mac_roman', # Other 37 }, 38 1: 'x_mac_japanese_ttx', 39 2: 'x_mac_trad_chinese_ttx', 40 3: 'x_mac_korean_ttx', 41 6: 'mac_greek', 42 7: 'mac_cyrillic', 43 25: 'x_mac_simp_chinese_ttx', 44 29: 'mac_latin2', 45 35: 'mac_turkish', 46 37: 'mac_iceland', 47 }, 48 2: { # ISO 49 0: 'ascii', 50 1: 'utf_16_be', 51 2: 'latin1', 52 }, 53 3: { # Microsoft 54 0: 'utf_16_be', 55 1: 'utf_16_be', 56 2: 'shift_jis', 57 3: 'gb2312', 58 4: 'big5', 59 5: 'euc_kr', 60 6: 'johab', 61 10: 'utf_16_be', 62 }, 63} 64 65def getEncoding(platformID, platEncID, langID, default=None): 66 """Returns the Python encoding name for OpenType platformID/encodingID/langID 67 triplet. If encoding for these values is not known, by default None is 68 returned. That can be overriden by passing a value to the default argument. 69 """ 70 encoding = _encodingMap.get(platformID, {}).get(platEncID, default) 71 if isinstance(encoding, dict): 72 encoding = encoding.get(langID, encoding[Ellipsis]) 73 return encoding 74