2020-02-19 12:26:55 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-05-28 12:31:15 +02:00
|
|
|
# flake8: noqa: F821
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2020-05-28 12:31:15 +02:00
|
|
|
"""usage: ./gen-use-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt UnicodeData.txt Blocks.txt
|
2020-02-10 14:49:23 +01:00
|
|
|
|
2020-03-15 20:59:31 +01:00
|
|
|
Input file:
|
2020-02-10 14:49:23 +01:00
|
|
|
* https://unicode.org/Public/UCD/latest/ucd/IndicSyllabicCategory.txt
|
|
|
|
* https://unicode.org/Public/UCD/latest/ucd/IndicPositionalCategory.txt
|
|
|
|
* https://unicode.org/Public/UCD/latest/ucd/UnicodeData.txt
|
2020-05-28 12:31:15 +02:00
|
|
|
* https://unicode.org/Public/UCD/latest/ucd/Blocks.txt
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
if len (sys.argv) != 5:
|
2020-05-28 20:21:29 +02:00
|
|
|
sys.exit (__doc__)
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2018-10-02 18:43:29 +02:00
|
|
|
BLACKLISTED_BLOCKS = ["Thai", "Lao"]
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2020-05-28 21:41:19 +02:00
|
|
|
files = [open (x, encoding='utf-8') for x in sys.argv[1:]]
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2015-07-20 16:56:19 +02:00
|
|
|
headers = [[f.readline () for i in range (2)] for j,f in enumerate(files) if j != 2]
|
|
|
|
headers.append (["UnicodeData.txt does not have a header."])
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2020-07-13 19:02:15 +02:00
|
|
|
data = [{} for _ in files]
|
|
|
|
values = [{} for _ in files]
|
2015-07-20 12:32:48 +02:00
|
|
|
for i, f in enumerate (files):
|
|
|
|
for line in f:
|
|
|
|
|
|
|
|
j = line.find ('#')
|
|
|
|
if j >= 0:
|
|
|
|
line = line[:j]
|
|
|
|
|
|
|
|
fields = [x.strip () for x in line.split (';')]
|
|
|
|
if len (fields) == 1:
|
|
|
|
continue
|
|
|
|
|
|
|
|
uu = fields[0].split ('..')
|
|
|
|
start = int (uu[0], 16)
|
|
|
|
if len (uu) == 1:
|
|
|
|
end = start
|
|
|
|
else:
|
|
|
|
end = int (uu[1], 16)
|
|
|
|
|
2015-07-20 16:56:19 +02:00
|
|
|
t = fields[1 if i != 2 else 2]
|
2015-07-20 12:32:48 +02:00
|
|
|
|
|
|
|
for u in range (start, end + 1):
|
|
|
|
data[i][u] = t
|
|
|
|
values[i][t] = values[i].get (t, 0) + end - start + 1
|
|
|
|
|
2015-07-20 16:56:19 +02:00
|
|
|
defaults = ('Other', 'Not_Applicable', 'Cn', 'No_Block')
|
2015-07-21 12:57:23 +02:00
|
|
|
|
2015-07-21 17:46:37 +02:00
|
|
|
# TODO Characters that are not in Unicode Indic files, but used in USE
|
2015-07-21 12:57:23 +02:00
|
|
|
data[0][0x034F] = defaults[0]
|
2019-05-01 22:15:58 +02:00
|
|
|
data[0][0x1B61] = defaults[0]
|
|
|
|
data[0][0x1B63] = defaults[0]
|
|
|
|
data[0][0x1B64] = defaults[0]
|
|
|
|
data[0][0x1B65] = defaults[0]
|
|
|
|
data[0][0x1B66] = defaults[0]
|
|
|
|
data[0][0x1B67] = defaults[0]
|
|
|
|
data[0][0x1B69] = defaults[0]
|
|
|
|
data[0][0x1B6A] = defaults[0]
|
2015-07-21 17:46:37 +02:00
|
|
|
data[0][0x2060] = defaults[0]
|
2019-04-29 20:16:51 +02:00
|
|
|
# TODO https://github.com/harfbuzz/harfbuzz/pull/1685
|
|
|
|
data[0][0x1B5B] = 'Consonant_Placeholder'
|
|
|
|
data[0][0x1B5C] = 'Consonant_Placeholder'
|
|
|
|
data[0][0x1B5F] = 'Consonant_Placeholder'
|
|
|
|
data[0][0x1B62] = 'Consonant_Placeholder'
|
|
|
|
data[0][0x1B68] = 'Consonant_Placeholder'
|
2019-04-30 19:35:50 +02:00
|
|
|
# TODO https://github.com/harfbuzz/harfbuzz/issues/1035
|
2018-06-25 07:54:57 +02:00
|
|
|
data[0][0x11C44] = 'Consonant_Placeholder'
|
|
|
|
data[0][0x11C45] = 'Consonant_Placeholder'
|
2018-11-21 17:35:44 +01:00
|
|
|
# TODO https://github.com/harfbuzz/harfbuzz/pull/1399
|
|
|
|
data[0][0x111C8] = 'Consonant_Placeholder'
|
2015-07-21 17:46:37 +02:00
|
|
|
for u in range (0xFE00, 0xFE0F + 1):
|
|
|
|
data[0][u] = defaults[0]
|
2015-07-21 12:57:23 +02:00
|
|
|
|
|
|
|
# Merge data into one dict:
|
2015-07-20 12:32:48 +02:00
|
|
|
for i,v in enumerate (defaults):
|
|
|
|
values[i][v] = values[i].get (v, 0) + 1
|
|
|
|
combined = {}
|
|
|
|
for i,d in enumerate (data):
|
|
|
|
for u,v in d.items ():
|
2015-07-20 16:56:19 +02:00
|
|
|
if i >= 2 and not u in combined:
|
2015-07-20 12:32:48 +02:00
|
|
|
continue
|
|
|
|
if not u in combined:
|
|
|
|
combined[u] = list (defaults)
|
|
|
|
combined[u][i] = v
|
2015-07-20 16:56:19 +02:00
|
|
|
combined = {k:v for k,v in combined.items() if v[3] not in BLACKLISTED_BLOCKS}
|
2015-07-20 12:32:48 +02:00
|
|
|
data = combined
|
|
|
|
del combined
|
|
|
|
|
2015-07-20 16:56:19 +02:00
|
|
|
|
|
|
|
property_names = [
|
|
|
|
# General_Category
|
|
|
|
'Cc', 'Cf', 'Cn', 'Co', 'Cs', 'Ll', 'Lm', 'Lo', 'Lt', 'Lu', 'Mc',
|
|
|
|
'Me', 'Mn', 'Nd', 'Nl', 'No', 'Pc', 'Pd', 'Pe', 'Pf', 'Pi', 'Po',
|
|
|
|
'Ps', 'Sc', 'Sk', 'Sm', 'So', 'Zl', 'Zp', 'Zs',
|
|
|
|
# Indic_Syllabic_Category
|
2015-07-20 18:00:06 +02:00
|
|
|
'Other',
|
2015-07-20 16:56:19 +02:00
|
|
|
'Bindu',
|
|
|
|
'Visarga',
|
|
|
|
'Avagraha',
|
|
|
|
'Nukta',
|
|
|
|
'Virama',
|
|
|
|
'Pure_Killer',
|
|
|
|
'Invisible_Stacker',
|
|
|
|
'Vowel_Independent',
|
|
|
|
'Vowel_Dependent',
|
|
|
|
'Vowel',
|
|
|
|
'Consonant_Placeholder',
|
|
|
|
'Consonant',
|
|
|
|
'Consonant_Dead',
|
|
|
|
'Consonant_With_Stacker',
|
|
|
|
'Consonant_Prefixed',
|
|
|
|
'Consonant_Preceding_Repha',
|
|
|
|
'Consonant_Succeeding_Repha',
|
|
|
|
'Consonant_Subjoined',
|
|
|
|
'Consonant_Medial',
|
|
|
|
'Consonant_Final',
|
|
|
|
'Consonant_Head_Letter',
|
2018-06-06 02:31:46 +02:00
|
|
|
'Consonant_Initial_Postfixed',
|
2015-07-20 16:56:19 +02:00
|
|
|
'Modifying_Letter',
|
|
|
|
'Tone_Letter',
|
|
|
|
'Tone_Mark',
|
|
|
|
'Gemination_Mark',
|
|
|
|
'Cantillation_Mark',
|
|
|
|
'Register_Shifter',
|
|
|
|
'Syllable_Modifier',
|
|
|
|
'Consonant_Killer',
|
|
|
|
'Non_Joiner',
|
|
|
|
'Joiner',
|
|
|
|
'Number_Joiner',
|
|
|
|
'Number',
|
|
|
|
'Brahmi_Joining_Number',
|
|
|
|
# Indic_Positional_Category
|
2015-07-20 19:01:10 +02:00
|
|
|
'Not_Applicable',
|
2015-07-20 16:56:19 +02:00
|
|
|
'Right',
|
|
|
|
'Left',
|
|
|
|
'Visual_Order_Left',
|
|
|
|
'Left_And_Right',
|
|
|
|
'Top',
|
|
|
|
'Bottom',
|
|
|
|
'Top_And_Bottom',
|
2020-03-15 20:59:31 +01:00
|
|
|
'Top_And_Bottom_And_Left',
|
2015-07-20 16:56:19 +02:00
|
|
|
'Top_And_Right',
|
|
|
|
'Top_And_Left',
|
|
|
|
'Top_And_Left_And_Right',
|
2017-10-02 17:02:39 +02:00
|
|
|
'Bottom_And_Left',
|
2015-07-20 16:56:19 +02:00
|
|
|
'Bottom_And_Right',
|
|
|
|
'Top_And_Bottom_And_Right',
|
|
|
|
'Overstruck',
|
|
|
|
]
|
|
|
|
|
|
|
|
class PropertyValue(object):
|
|
|
|
def __init__(self, name_):
|
|
|
|
self.name = name_
|
2015-07-20 18:00:06 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
def __eq__(self, other):
|
2020-03-18 21:10:59 +01:00
|
|
|
return self.name == (other if isinstance(other, str) else other.name)
|
2015-07-20 18:00:06 +02:00
|
|
|
def __ne__(self, other):
|
|
|
|
return not (self == other)
|
2018-03-29 18:52:47 +02:00
|
|
|
def __hash__(self):
|
|
|
|
return hash(str(self))
|
2015-07-20 16:56:19 +02:00
|
|
|
|
|
|
|
property_values = {}
|
|
|
|
|
|
|
|
for name in property_names:
|
|
|
|
value = PropertyValue(name)
|
|
|
|
assert value not in property_values
|
|
|
|
assert value not in globals()
|
|
|
|
property_values[name] = value
|
|
|
|
globals().update(property_values)
|
|
|
|
|
|
|
|
|
|
|
|
def is_BASE(U, UISC, UGC):
|
2018-06-06 18:57:28 +02:00
|
|
|
return (UISC in [Number, Consonant, Consonant_Head_Letter,
|
2016-05-06 18:41:49 +02:00
|
|
|
#SPEC-DRAFT Consonant_Placeholder,
|
|
|
|
Tone_Letter,
|
|
|
|
Vowel_Independent #SPEC-DRAFT
|
|
|
|
] or
|
2015-07-20 16:56:19 +02:00
|
|
|
(UGC == Lo and UISC in [Avagraha, Bindu, Consonant_Final, Consonant_Medial,
|
|
|
|
Consonant_Subjoined, Vowel, Vowel_Dependent]))
|
|
|
|
def is_BASE_IND(U, UISC, UGC):
|
2016-05-06 18:41:49 +02:00
|
|
|
#SPEC-DRAFT return (UISC in [Consonant_Dead, Modifying_Letter] or UGC == Po)
|
2015-07-20 18:00:06 +02:00
|
|
|
return (UISC in [Consonant_Dead, Modifying_Letter] or
|
2019-04-29 20:16:51 +02:00
|
|
|
(UGC == Po and not U in [0x104B, 0x104E, 0x1B5B, 0x1B5C, 0x1B5F, 0x2022, 0x111C8, 0x11A3F, 0x11A45, 0x11C44, 0x11C45]) or
|
2016-05-06 18:41:49 +02:00
|
|
|
False # SPEC-DRAFT-OUTDATED! U == 0x002D
|
|
|
|
)
|
2015-07-20 16:56:19 +02:00
|
|
|
def is_BASE_NUM(U, UISC, UGC):
|
|
|
|
return UISC == Brahmi_Joining_Number
|
|
|
|
def is_BASE_OTHER(U, UISC, UGC):
|
2016-05-06 18:41:49 +02:00
|
|
|
if UISC == Consonant_Placeholder: return True #SPEC-DRAFT
|
|
|
|
#SPEC-DRAFT return U in [0x00A0, 0x00D7, 0x2015, 0x2022, 0x25CC, 0x25FB, 0x25FC, 0x25FD, 0x25FE]
|
|
|
|
return U in [0x2015, 0x2022, 0x25FB, 0x25FC, 0x25FD, 0x25FE]
|
2015-07-20 16:56:19 +02:00
|
|
|
def is_CGJ(U, UISC, UGC):
|
|
|
|
return U == 0x034F
|
|
|
|
def is_CONS_FINAL(U, UISC, UGC):
|
|
|
|
return ((UISC == Consonant_Final and UGC != Lo) or
|
|
|
|
UISC == Consonant_Succeeding_Repha)
|
|
|
|
def is_CONS_FINAL_MOD(U, UISC, UGC):
|
2016-05-06 18:41:49 +02:00
|
|
|
#SPEC-DRAFT return UISC in [Consonant_Final_Modifier, Syllable_Modifier]
|
2015-07-20 18:00:06 +02:00
|
|
|
return UISC == Syllable_Modifier
|
2015-07-20 16:56:19 +02:00
|
|
|
def is_CONS_MED(U, UISC, UGC):
|
2019-05-15 23:02:32 +02:00
|
|
|
# Consonant_Initial_Postfixed is new in Unicode 11; not in the spec.
|
|
|
|
return (UISC == Consonant_Medial and UGC != Lo or
|
|
|
|
UISC == Consonant_Initial_Postfixed)
|
2015-07-20 16:56:19 +02:00
|
|
|
def is_CONS_MOD(U, UISC, UGC):
|
|
|
|
return UISC in [Nukta, Gemination_Mark, Consonant_Killer]
|
|
|
|
def is_CONS_SUB(U, UISC, UGC):
|
2016-05-06 18:41:49 +02:00
|
|
|
#SPEC-DRAFT return UISC == Consonant_Subjoined
|
2015-07-20 18:00:06 +02:00
|
|
|
return UISC == Consonant_Subjoined and UGC != Lo
|
2017-10-03 14:57:14 +02:00
|
|
|
def is_CONS_WITH_STACKER(U, UISC, UGC):
|
|
|
|
return UISC == Consonant_With_Stacker
|
2015-07-20 16:56:19 +02:00
|
|
|
def is_HALANT(U, UISC, UGC):
|
2019-05-26 17:05:54 +02:00
|
|
|
return (UISC in [Virama, Invisible_Stacker]
|
|
|
|
and not is_HALANT_OR_VOWEL_MODIFIER(U, UISC, UGC)
|
|
|
|
and not is_SAKOT(U, UISC, UGC))
|
2018-10-03 12:29:56 +02:00
|
|
|
def is_HALANT_OR_VOWEL_MODIFIER(U, UISC, UGC):
|
|
|
|
# https://github.com/harfbuzz/harfbuzz/issues/1102
|
2018-11-13 21:51:10 +01:00
|
|
|
# https://github.com/harfbuzz/harfbuzz/issues/1379
|
|
|
|
return U in [0x11046, 0x1134D]
|
2015-07-20 16:56:19 +02:00
|
|
|
def is_HALANT_NUM(U, UISC, UGC):
|
|
|
|
return UISC == Number_Joiner
|
|
|
|
def is_ZWNJ(U, UISC, UGC):
|
|
|
|
return UISC == Non_Joiner
|
|
|
|
def is_ZWJ(U, UISC, UGC):
|
|
|
|
return UISC == Joiner
|
|
|
|
def is_Word_Joiner(U, UISC, UGC):
|
|
|
|
return U == 0x2060
|
|
|
|
def is_OTHER(U, UISC, UGC):
|
2015-07-20 18:00:06 +02:00
|
|
|
#SPEC-OUTDATED return UGC == Zs # or any other SCRIPT_COMMON characters
|
2015-07-21 12:57:23 +02:00
|
|
|
return (UISC == Other
|
2019-05-01 22:15:58 +02:00
|
|
|
and not is_SYM(U, UISC, UGC)
|
2015-07-21 12:57:23 +02:00
|
|
|
and not is_SYM_MOD(U, UISC, UGC)
|
|
|
|
and not is_CGJ(U, UISC, UGC)
|
2015-07-21 17:46:37 +02:00
|
|
|
and not is_Word_Joiner(U, UISC, UGC)
|
|
|
|
and not is_VARIATION_SELECTOR(U, UISC, UGC)
|
2015-07-21 12:57:23 +02:00
|
|
|
)
|
2015-07-20 16:56:19 +02:00
|
|
|
def is_Reserved(U, UISC, UGC):
|
|
|
|
return UGC == 'Cn'
|
|
|
|
def is_REPHA(U, UISC, UGC):
|
2017-10-03 14:57:14 +02:00
|
|
|
return UISC in [Consonant_Preceding_Repha, Consonant_Prefixed]
|
2019-05-26 17:05:54 +02:00
|
|
|
def is_SAKOT(U, UISC, UGC):
|
|
|
|
return U == 0x1A60
|
2015-07-20 16:56:19 +02:00
|
|
|
def is_SYM(U, UISC, UGC):
|
2016-05-06 18:41:49 +02:00
|
|
|
if U == 0x25CC: return False #SPEC-DRAFT
|
|
|
|
#SPEC-DRAFT return UGC in [So, Sc] or UISC == Symbol_Letter
|
2019-04-29 20:16:51 +02:00
|
|
|
return UGC in [So, Sc] and U not in [0x1B62, 0x1B68]
|
2015-07-20 16:56:19 +02:00
|
|
|
def is_SYM_MOD(U, UISC, UGC):
|
|
|
|
return U in [0x1B6B, 0x1B6C, 0x1B6D, 0x1B6E, 0x1B6F, 0x1B70, 0x1B71, 0x1B72, 0x1B73]
|
|
|
|
def is_VARIATION_SELECTOR(U, UISC, UGC):
|
|
|
|
return 0xFE00 <= U <= 0xFE0F
|
|
|
|
def is_VOWEL(U, UISC, UGC):
|
2019-04-30 19:35:50 +02:00
|
|
|
# https://github.com/harfbuzz/harfbuzz/issues/376
|
2015-07-20 16:56:19 +02:00
|
|
|
return (UISC == Pure_Killer or
|
2017-07-14 17:38:51 +02:00
|
|
|
(UGC != Lo and UISC in [Vowel, Vowel_Dependent] and U not in [0xAA29]))
|
2015-07-20 16:56:19 +02:00
|
|
|
def is_VOWEL_MOD(U, UISC, UGC):
|
2019-04-30 19:35:50 +02:00
|
|
|
# https://github.com/harfbuzz/harfbuzz/issues/376
|
2015-07-20 16:56:19 +02:00
|
|
|
return (UISC in [Tone_Mark, Cantillation_Mark, Register_Shifter, Visarga] or
|
2017-07-14 17:38:51 +02:00
|
|
|
(UGC != Lo and (UISC == Bindu or U in [0xAA29])))
|
2015-07-20 16:56:19 +02:00
|
|
|
|
|
|
|
use_mapping = {
|
|
|
|
'B': is_BASE,
|
|
|
|
'IND': is_BASE_IND,
|
|
|
|
'N': is_BASE_NUM,
|
|
|
|
'GB': is_BASE_OTHER,
|
|
|
|
'CGJ': is_CGJ,
|
|
|
|
'F': is_CONS_FINAL,
|
|
|
|
'FM': is_CONS_FINAL_MOD,
|
|
|
|
'M': is_CONS_MED,
|
|
|
|
'CM': is_CONS_MOD,
|
|
|
|
'SUB': is_CONS_SUB,
|
2017-10-03 14:57:14 +02:00
|
|
|
'CS': is_CONS_WITH_STACKER,
|
2015-07-20 16:56:19 +02:00
|
|
|
'H': is_HALANT,
|
2018-10-03 12:29:56 +02:00
|
|
|
'HVM': is_HALANT_OR_VOWEL_MODIFIER,
|
2015-07-20 16:56:19 +02:00
|
|
|
'HN': is_HALANT_NUM,
|
|
|
|
'ZWNJ': is_ZWNJ,
|
|
|
|
'ZWJ': is_ZWJ,
|
|
|
|
'WJ': is_Word_Joiner,
|
|
|
|
'O': is_OTHER,
|
|
|
|
'Rsv': is_Reserved,
|
|
|
|
'R': is_REPHA,
|
|
|
|
'S': is_SYM,
|
2019-05-26 17:05:54 +02:00
|
|
|
'Sk': is_SAKOT,
|
2015-07-20 16:56:19 +02:00
|
|
|
'SM': is_SYM_MOD,
|
|
|
|
'VS': is_VARIATION_SELECTOR,
|
|
|
|
'V': is_VOWEL,
|
|
|
|
'VM': is_VOWEL_MOD,
|
|
|
|
}
|
|
|
|
|
2015-07-20 19:01:10 +02:00
|
|
|
use_positions = {
|
|
|
|
'F': {
|
|
|
|
'Abv': [Top],
|
|
|
|
'Blw': [Bottom],
|
|
|
|
'Pst': [Right],
|
|
|
|
},
|
|
|
|
'M': {
|
|
|
|
'Abv': [Top],
|
2020-03-15 20:59:31 +01:00
|
|
|
'Blw': [Bottom, Bottom_And_Left, Bottom_And_Right],
|
2015-07-20 19:01:10 +02:00
|
|
|
'Pst': [Right],
|
2020-03-15 20:59:31 +01:00
|
|
|
'Pre': [Left, Top_And_Bottom_And_Left],
|
2015-07-20 19:01:10 +02:00
|
|
|
},
|
|
|
|
'CM': {
|
|
|
|
'Abv': [Top],
|
|
|
|
'Blw': [Bottom],
|
|
|
|
},
|
|
|
|
'V': {
|
|
|
|
'Abv': [Top, Top_And_Bottom, Top_And_Bottom_And_Right, Top_And_Right],
|
|
|
|
'Blw': [Bottom, Overstruck, Bottom_And_Right],
|
2018-10-01 12:45:06 +02:00
|
|
|
'Pst': [Right, Top_And_Left, Top_And_Left_And_Right, Left_And_Right],
|
|
|
|
'Pre': [Left],
|
2015-07-20 19:01:10 +02:00
|
|
|
},
|
|
|
|
'VM': {
|
|
|
|
'Abv': [Top],
|
|
|
|
'Blw': [Bottom, Overstruck],
|
|
|
|
'Pst': [Right],
|
|
|
|
'Pre': [Left],
|
|
|
|
},
|
|
|
|
'SM': {
|
|
|
|
'Abv': [Top],
|
|
|
|
'Blw': [Bottom],
|
|
|
|
},
|
|
|
|
'H': None,
|
2018-10-03 12:29:56 +02:00
|
|
|
'HVM': None,
|
2015-07-20 19:01:10 +02:00
|
|
|
'B': None,
|
2019-05-19 16:01:20 +02:00
|
|
|
'FM': {
|
|
|
|
'Abv': [Top],
|
|
|
|
'Blw': [Bottom],
|
|
|
|
'Pst': [Not_Applicable],
|
|
|
|
},
|
2015-07-20 19:01:10 +02:00
|
|
|
'SUB': None,
|
|
|
|
}
|
|
|
|
|
2015-07-20 18:00:06 +02:00
|
|
|
def map_to_use(data):
|
|
|
|
out = {}
|
|
|
|
items = use_mapping.items()
|
|
|
|
for U,(UISC,UIPC,UGC,UBlock) in data.items():
|
2015-07-20 19:01:10 +02:00
|
|
|
|
|
|
|
# Resolve Indic_Syllabic_Category
|
|
|
|
|
2020-03-15 20:59:31 +01:00
|
|
|
# TODO: These don't have UISC assigned in Unicode 13.0.0, but have UIPC
|
2015-07-20 19:01:10 +02:00
|
|
|
if 0x1CE2 <= U <= 0x1CE8: UISC = Cantillation_Mark
|
|
|
|
|
2018-10-02 18:43:29 +02:00
|
|
|
# Tibetan:
|
2020-03-15 20:59:31 +01:00
|
|
|
# TODO: These don't have UISC assigned in Unicode 13.0.0, but have UIPC
|
2018-10-02 18:43:29 +02:00
|
|
|
if 0x0F18 <= U <= 0x0F19 or 0x0F3E <= U <= 0x0F3F: UISC = Vowel_Dependent
|
|
|
|
if 0x0F86 <= U <= 0x0F87: UISC = Tone_Mark
|
|
|
|
# Overrides to allow NFC order matching syllable
|
|
|
|
# https://github.com/harfbuzz/harfbuzz/issues/1012
|
|
|
|
if UBlock == 'Tibetan' and is_VOWEL (U, UISC, UGC):
|
|
|
|
if UIPC == Top:
|
|
|
|
UIPC = Bottom
|
|
|
|
|
|
|
|
# TODO: https://github.com/harfbuzz/harfbuzz/pull/982
|
|
|
|
# also https://github.com/harfbuzz/harfbuzz/issues/1012
|
|
|
|
if UBlock == 'Chakma' and is_VOWEL (U, UISC, UGC):
|
|
|
|
if UIPC == Top:
|
|
|
|
UIPC = Bottom
|
|
|
|
elif UIPC == Bottom:
|
|
|
|
UIPC = Top
|
|
|
|
|
2017-11-22 22:32:52 +01:00
|
|
|
# TODO: https://github.com/harfbuzz/harfbuzz/pull/627
|
|
|
|
if 0x1BF2 <= U <= 0x1BF3: UISC = Nukta; UIPC = Bottom
|
|
|
|
|
2015-07-20 19:01:10 +02:00
|
|
|
# TODO: U+1CED should only be allowed after some of
|
|
|
|
# the nasalization marks, maybe only for U+1CE9..U+1CF1.
|
|
|
|
if U == 0x1CED: UISC = Tone_Mark
|
|
|
|
|
2018-04-14 00:45:37 +02:00
|
|
|
# TODO: https://github.com/harfbuzz/harfbuzz/issues/1105
|
|
|
|
if U == 0x11134: UISC = Gemination_Mark
|
|
|
|
|
2017-10-02 16:36:21 +02:00
|
|
|
values = [k for k,v in items if v(U,UISC,UGC)]
|
2015-07-20 18:00:06 +02:00
|
|
|
assert len(values) == 1, "%s %s %s %s" % (hex(U), UISC, UGC, values)
|
2015-07-20 19:01:10 +02:00
|
|
|
USE = values[0]
|
|
|
|
|
|
|
|
# Resolve Indic_Positional_Category
|
|
|
|
|
2020-03-15 20:59:31 +01:00
|
|
|
# TODO: These should die, but have UIPC in Unicode 13.0.0
|
2015-07-20 19:01:10 +02:00
|
|
|
if U in [0x953, 0x954]: UIPC = Not_Applicable
|
|
|
|
|
2019-10-10 02:55:52 +02:00
|
|
|
# TODO: https://github.com/harfbuzz/harfbuzz/pull/2012
|
|
|
|
if U == 0x1C29: UIPC = Left
|
|
|
|
|
2020-03-15 20:59:31 +01:00
|
|
|
# TODO: These are not in USE's override list that we have, nor are they in Unicode 13.0.0
|
2015-07-20 19:01:10 +02:00
|
|
|
if 0xA926 <= U <= 0xA92A: UIPC = Top
|
2018-06-25 07:54:57 +02:00
|
|
|
# TODO: https://github.com/harfbuzz/harfbuzz/pull/1037
|
2019-03-28 07:12:58 +01:00
|
|
|
# and https://github.com/harfbuzz/harfbuzz/issues/1631
|
|
|
|
if U in [0x11302, 0x11303, 0x114C1]: UIPC = Top
|
2015-07-20 19:01:10 +02:00
|
|
|
if 0x1CF8 <= U <= 0x1CF9: UIPC = Top
|
|
|
|
|
|
|
|
assert (UIPC in [Not_Applicable, Visual_Order_Left] or
|
2020-03-15 20:59:31 +01:00
|
|
|
USE == 'R' or
|
2015-07-20 19:01:10 +02:00
|
|
|
USE in use_positions), "%s %s %s %s %s" % (hex(U), UIPC, USE, UISC, UGC)
|
|
|
|
|
|
|
|
pos_mapping = use_positions.get(USE, None)
|
|
|
|
if pos_mapping:
|
|
|
|
values = [k for k,v in pos_mapping.items() if v and UIPC in v]
|
|
|
|
assert len(values) == 1, "%s %s %s %s %s %s" % (hex(U), UIPC, USE, UISC, UGC, values)
|
|
|
|
USE = USE + values[0]
|
|
|
|
|
|
|
|
out[U] = (USE, UBlock)
|
2015-07-20 18:00:06 +02:00
|
|
|
return out
|
|
|
|
|
|
|
|
defaults = ('O', 'No_Block')
|
|
|
|
data = map_to_use(data)
|
2015-07-20 16:56:19 +02:00
|
|
|
|
2018-03-28 16:38:19 +02:00
|
|
|
print ("/* == Start of generated table == */")
|
|
|
|
print ("/*")
|
|
|
|
print (" * The following table is generated by running:")
|
|
|
|
print (" *")
|
|
|
|
print (" * ./gen-use-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt UnicodeData.txt Blocks.txt")
|
|
|
|
print (" *")
|
|
|
|
print (" * on files with these headers:")
|
|
|
|
print (" *")
|
2015-07-20 12:32:48 +02:00
|
|
|
for h in headers:
|
|
|
|
for l in h:
|
2018-03-28 16:38:19 +02:00
|
|
|
print (" * %s" % (l.strip()))
|
|
|
|
print (" */")
|
|
|
|
print ()
|
2019-06-26 22:21:03 +02:00
|
|
|
print ('#include "hb.hh"')
|
|
|
|
print ()
|
|
|
|
print ('#ifndef HB_NO_OT_SHAPE')
|
|
|
|
print ()
|
2018-08-26 07:36:36 +02:00
|
|
|
print ('#include "hb-ot-shape-complex-use.hh"')
|
2018-03-28 16:38:19 +02:00
|
|
|
print ()
|
2015-07-20 12:32:48 +02:00
|
|
|
|
|
|
|
total = 0
|
|
|
|
used = 0
|
|
|
|
last_block = None
|
|
|
|
def print_block (block, start, end, data):
|
|
|
|
global total, used, last_block
|
|
|
|
if block and block != last_block:
|
2018-03-28 16:38:19 +02:00
|
|
|
print ()
|
|
|
|
print ()
|
|
|
|
print (" /* %s */" % block)
|
2015-07-20 18:00:06 +02:00
|
|
|
if start % 16:
|
2018-03-28 16:38:19 +02:00
|
|
|
print (' ' * (20 + (start % 16 * 6)), end='')
|
2015-07-20 12:32:48 +02:00
|
|
|
num = 0
|
|
|
|
assert start % 8 == 0
|
|
|
|
assert (end+1) % 8 == 0
|
|
|
|
for u in range (start, end+1):
|
2015-07-20 18:00:06 +02:00
|
|
|
if u % 16 == 0:
|
2018-03-28 16:38:19 +02:00
|
|
|
print ()
|
|
|
|
print (" /* %04X */" % u, end='')
|
2015-07-20 12:32:48 +02:00
|
|
|
if u in data:
|
|
|
|
num += 1
|
|
|
|
d = data.get (u, defaults)
|
2018-03-28 16:38:19 +02:00
|
|
|
print ("%6s," % d[0], end='')
|
2015-07-20 12:32:48 +02:00
|
|
|
|
|
|
|
total += end - start + 1
|
|
|
|
used += num
|
|
|
|
if block:
|
|
|
|
last_block = block
|
|
|
|
|
2018-03-29 18:52:47 +02:00
|
|
|
uu = sorted (data.keys ())
|
2015-07-20 12:32:48 +02:00
|
|
|
|
|
|
|
last = -100000
|
|
|
|
num = 0
|
|
|
|
offset = 0
|
|
|
|
starts = []
|
|
|
|
ends = []
|
2019-01-17 21:04:44 +01:00
|
|
|
print ('#pragma GCC diagnostic push')
|
|
|
|
print ('#pragma GCC diagnostic ignored "-Wunused-macros"')
|
2015-07-20 18:00:06 +02:00
|
|
|
for k,v in sorted(use_mapping.items()):
|
2015-07-20 19:01:10 +02:00
|
|
|
if k in use_positions and use_positions[k]: continue
|
2018-03-28 16:38:19 +02:00
|
|
|
print ("#define %s USE_%s /* %s */" % (k, k, v.__name__[3:]))
|
2015-07-20 19:01:10 +02:00
|
|
|
for k,v in sorted(use_positions.items()):
|
|
|
|
if not v: continue
|
|
|
|
for suf in v.keys():
|
|
|
|
tag = k + suf
|
2018-03-28 16:38:19 +02:00
|
|
|
print ("#define %s USE_%s" % (tag, tag))
|
2019-01-17 21:04:44 +01:00
|
|
|
print ('#pragma GCC diagnostic pop')
|
2018-03-28 16:38:19 +02:00
|
|
|
print ("")
|
|
|
|
print ("static const USE_TABLE_ELEMENT_TYPE use_table[] = {")
|
2015-07-20 12:32:48 +02:00
|
|
|
for u in uu:
|
|
|
|
if u <= last:
|
|
|
|
continue
|
2015-07-20 18:00:06 +02:00
|
|
|
block = data[u][1]
|
2015-07-20 12:32:48 +02:00
|
|
|
|
|
|
|
start = u//8*8
|
|
|
|
end = start+1
|
2015-07-20 18:00:06 +02:00
|
|
|
while end in uu and block == data[end][1]:
|
2015-07-20 12:32:48 +02:00
|
|
|
end += 1
|
|
|
|
end = (end-1)//8*8 + 7
|
|
|
|
|
|
|
|
if start != last + 1:
|
|
|
|
if start - last <= 1+16*3:
|
|
|
|
print_block (None, last+1, start-1, data)
|
|
|
|
else:
|
|
|
|
if last >= 0:
|
|
|
|
ends.append (last + 1)
|
|
|
|
offset += ends[-1] - starts[-1]
|
2018-03-28 16:38:19 +02:00
|
|
|
print ()
|
|
|
|
print ()
|
|
|
|
print ("#define use_offset_0x%04xu %d" % (start, offset))
|
2015-07-20 12:32:48 +02:00
|
|
|
starts.append (start)
|
|
|
|
|
|
|
|
print_block (block, start, end, data)
|
|
|
|
last = end
|
|
|
|
ends.append (last + 1)
|
|
|
|
offset += ends[-1] - starts[-1]
|
2018-03-28 16:38:19 +02:00
|
|
|
print ()
|
|
|
|
print ()
|
2015-07-20 12:32:48 +02:00
|
|
|
occupancy = used * 100. / total
|
|
|
|
page_bits = 12
|
2018-03-28 16:38:19 +02:00
|
|
|
print ("}; /* Table items: %d; occupancy: %d%% */" % (offset, occupancy))
|
|
|
|
print ()
|
|
|
|
print ("USE_TABLE_ELEMENT_TYPE")
|
|
|
|
print ("hb_use_get_category (hb_codepoint_t u)")
|
|
|
|
print ("{")
|
|
|
|
print (" switch (u >> %d)" % page_bits)
|
|
|
|
print (" {")
|
2018-01-03 15:27:34 +01:00
|
|
|
pages = set([u>>page_bits for u in starts+ends])
|
2015-07-20 12:32:48 +02:00
|
|
|
for p in sorted(pages):
|
2018-03-28 16:38:19 +02:00
|
|
|
print (" case 0x%0Xu:" % p)
|
2015-07-20 12:32:48 +02:00
|
|
|
for (start,end) in zip (starts, ends):
|
|
|
|
if p not in [start>>page_bits, end>>page_bits]: continue
|
2015-07-20 12:46:17 +02:00
|
|
|
offset = "use_offset_0x%04xu" % start
|
2018-03-28 16:38:19 +02:00
|
|
|
print (" if (hb_in_range<hb_codepoint_t> (u, 0x%04Xu, 0x%04Xu)) return use_table[u - 0x%04Xu + %s];" % (start, end-1, start, offset))
|
|
|
|
print (" break;")
|
|
|
|
print ("")
|
|
|
|
print (" default:")
|
|
|
|
print (" break;")
|
|
|
|
print (" }")
|
|
|
|
print (" return USE_O;")
|
|
|
|
print ("}")
|
|
|
|
print ()
|
2015-07-21 17:43:27 +02:00
|
|
|
for k in sorted(use_mapping.keys()):
|
|
|
|
if k in use_positions and use_positions[k]: continue
|
2018-03-28 16:38:19 +02:00
|
|
|
print ("#undef %s" % k)
|
2015-07-21 17:43:27 +02:00
|
|
|
for k,v in sorted(use_positions.items()):
|
|
|
|
if not v: continue
|
|
|
|
for suf in v.keys():
|
|
|
|
tag = k + suf
|
2018-03-28 16:38:19 +02:00
|
|
|
print ("#undef %s" % tag)
|
|
|
|
print ()
|
2019-06-26 22:21:03 +02:00
|
|
|
print ()
|
|
|
|
print ('#endif')
|
2018-03-28 16:38:19 +02:00
|
|
|
print ("/* == End of generated table == */")
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2015-07-20 18:00:06 +02:00
|
|
|
# Maintain at least 50% occupancy in the table */
|
|
|
|
if occupancy < 50:
|
2015-07-20 12:32:48 +02:00
|
|
|
raise Exception ("Table too sparse, please investigate: ", occupancy)
|