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
|
|
|
|
2022-11-19 21:34:58 +01:00
|
|
|
import logging
|
|
|
|
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
|
|
|
|
|
2021-10-08 23:13:22 +02:00
|
|
|
"""usage: ./gen-use-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt ArabicShaping.txt DerivedCoreProperties.txt UnicodeData.txt Blocks.txt Scripts.txt IndicSyllabicCategory-Additional.txt IndicPositionalCategory-Additional.txt
|
2020-02-10 14:49:23 +01:00
|
|
|
|
2020-08-13 19:37:45 +02:00
|
|
|
Input files:
|
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
|
2021-10-08 23:13:22 +02:00
|
|
|
* https://unicode.org/Public/UCD/latest/ucd/ArabicShaping.txt
|
2021-10-08 02:10:31 +02:00
|
|
|
* https://unicode.org/Public/UCD/latest/ucd/DerivedCoreProperties.txt
|
2020-02-10 14:49:23 +01:00
|
|
|
* 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
|
2021-10-08 23:13:22 +02:00
|
|
|
* https://unicode.org/Public/UCD/latest/ucd/Scripts.txt
|
2020-08-13 19:37:45 +02:00
|
|
|
* ms-use/IndicSyllabicCategory-Additional.txt
|
2020-10-06 22:51:40 +02:00
|
|
|
* ms-use/IndicPositionalCategory-Additional.txt
|
2020-05-28 12:31:15 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2021-10-08 23:13:22 +02:00
|
|
|
if len (sys.argv) != 10:
|
2020-05-28 20:21:29 +02:00
|
|
|
sys.exit (__doc__)
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2021-10-08 23:13:22 +02:00
|
|
|
DISABLED_SCRIPTS = {
|
|
|
|
'Arabic',
|
|
|
|
'Lao',
|
2020-08-13 19:37:45 +02:00
|
|
|
'Samaritan',
|
2021-10-08 23:13:22 +02:00
|
|
|
'Syriac',
|
2020-08-13 19:37:45 +02:00
|
|
|
'Thai',
|
2021-10-08 23:13:22 +02:00
|
|
|
}
|
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
|
|
|
|
2021-10-08 23:13:22 +02:00
|
|
|
headers = [[f.readline () for i in range (2)] for j,f in enumerate(files) if j != 4]
|
|
|
|
for j in range(7, 9):
|
2020-08-13 19:37:45 +02:00
|
|
|
for line in files[j]:
|
|
|
|
line = line.rstrip()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
headers[j - 1].append(line)
|
2015-07-20 16:56:19 +02:00
|
|
|
headers.append (["UnicodeData.txt does not have a header."])
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2022-03-06 18:26:37 +01:00
|
|
|
unicode_data = [{} for _ in files]
|
2020-07-13 19:02:15 +02:00
|
|
|
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)
|
|
|
|
|
2021-10-08 23:13:22 +02:00
|
|
|
t = fields[1 if i not in [2, 4] else 2]
|
2020-08-13 19:37:45 +02:00
|
|
|
|
2021-10-08 23:13:22 +02:00
|
|
|
if i == 2:
|
2020-08-13 19:37:45 +02:00
|
|
|
t = 'jt_' + t
|
2021-10-08 23:13:22 +02:00
|
|
|
elif i == 3 and t != 'Default_Ignorable_Code_Point':
|
|
|
|
continue
|
|
|
|
elif i == 7 and t == 'Consonant_Final_Modifier':
|
2020-08-13 19:37:45 +02:00
|
|
|
# TODO: https://github.com/MicrosoftDocs/typography-issues/issues/336
|
|
|
|
t = 'Syllable_Modifier'
|
2021-10-08 23:13:22 +02:00
|
|
|
elif i == 8 and t == 'NA':
|
2020-08-13 19:37:45 +02:00
|
|
|
t = 'Not_Applicable'
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2021-10-08 23:13:22 +02:00
|
|
|
i0 = i if i < 7 else i - 7
|
2015-07-20 12:32:48 +02:00
|
|
|
for u in range (start, end + 1):
|
2022-03-06 18:26:37 +01:00
|
|
|
unicode_data[i0][u] = t
|
2020-08-13 19:37:45 +02:00
|
|
|
values[i0][t] = values[i0].get (t, 0) + end - start + 1
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2021-10-08 23:13:22 +02:00
|
|
|
defaults = ('Other', 'Not_Applicable', 'jt_X', '', 'Cn', 'No_Block', 'Unknown')
|
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 = {}
|
2022-03-06 18:26:37 +01:00
|
|
|
for i,d in enumerate (unicode_data):
|
2015-07-20 12:32:48 +02:00
|
|
|
for u,v in d.items ():
|
|
|
|
if not u in combined:
|
2021-10-08 23:13:22 +02:00
|
|
|
if i >= 4:
|
|
|
|
continue
|
2015-07-20 12:32:48 +02:00
|
|
|
combined[u] = list (defaults)
|
|
|
|
combined[u][i] = v
|
2021-10-08 23:13:22 +02:00
|
|
|
combined = {k: v for k, v in combined.items() if v[6] not in DISABLED_SCRIPTS}
|
2015-07-20 12:32:48 +02:00
|
|
|
|
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',
|
2022-09-22 00:13:17 +02:00
|
|
|
'Symbol_Modifier',
|
2020-08-15 00:30:20 +02:00
|
|
|
'Hieroglyph',
|
|
|
|
'Hieroglyph_Joiner',
|
|
|
|
'Hieroglyph_Segment_Begin',
|
|
|
|
'Hieroglyph_Segment_End',
|
2015-07-20 16:56:19 +02:00
|
|
|
# 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',
|
2020-08-13 19:37:45 +02:00
|
|
|
# Joining_Type
|
|
|
|
'jt_C',
|
|
|
|
'jt_D',
|
|
|
|
'jt_L',
|
|
|
|
'jt_R',
|
|
|
|
'jt_T',
|
|
|
|
'jt_U',
|
|
|
|
'jt_X',
|
2015-07-20 16:56:19 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_BASE(U, UISC, UDI, UGC, AJT):
|
2018-06-06 18:57:28 +02:00
|
|
|
return (UISC in [Number, Consonant, Consonant_Head_Letter,
|
2016-05-06 18:41:49 +02:00
|
|
|
Tone_Letter,
|
2020-08-13 19:37:45 +02:00
|
|
|
Vowel_Independent,
|
2020-11-20 14:16:36 +01:00
|
|
|
] or
|
2020-08-13 19:37:45 +02:00
|
|
|
# TODO: https://github.com/MicrosoftDocs/typography-issues/issues/484
|
2020-10-17 04:41:12 +02:00
|
|
|
AJT in [jt_C, jt_D, jt_L, jt_R] and UISC != Joiner 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]))
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_BASE_NUM(U, UISC, UDI, UGC, AJT):
|
2015-07-20 16:56:19 +02:00
|
|
|
return UISC == Brahmi_Joining_Number
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_BASE_OTHER(U, UISC, UDI, UGC, AJT):
|
2020-08-13 19:37:45 +02:00
|
|
|
if UISC == Consonant_Placeholder: return True
|
2016-05-06 18:41:49 +02:00
|
|
|
return U in [0x2015, 0x2022, 0x25FB, 0x25FC, 0x25FD, 0x25FE]
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_CGJ(U, UISC, UDI, UGC, AJT):
|
2022-03-05 02:45:30 +01:00
|
|
|
# Also includes VARIATION_SELECTOR and ZWJ
|
|
|
|
return UISC == Joiner or UDI and UGC in [Mc, Me, Mn]
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_CONS_FINAL(U, UISC, UDI, UGC, AJT):
|
2015-07-20 16:56:19 +02:00
|
|
|
return ((UISC == Consonant_Final and UGC != Lo) or
|
|
|
|
UISC == Consonant_Succeeding_Repha)
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_CONS_FINAL_MOD(U, UISC, UDI, UGC, AJT):
|
2020-08-13 19:37:45 +02:00
|
|
|
return UISC == Syllable_Modifier
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_CONS_MED(U, UISC, UDI, UGC, AJT):
|
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)
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_CONS_MOD(U, UISC, UDI, UGC, AJT):
|
2022-09-22 00:13:17 +02:00
|
|
|
return UISC in [Nukta, Gemination_Mark, Consonant_Killer]
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_CONS_SUB(U, UISC, UDI, UGC, AJT):
|
2015-07-20 18:00:06 +02:00
|
|
|
return UISC == Consonant_Subjoined and UGC != Lo
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_CONS_WITH_STACKER(U, UISC, UDI, UGC, AJT):
|
2017-10-03 14:57:14 +02:00
|
|
|
return UISC == Consonant_With_Stacker
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_HALANT(U, UISC, UDI, UGC, AJT):
|
2022-06-25 17:33:44 +02:00
|
|
|
return UISC == Virama and not is_HALANT_OR_VOWEL_MODIFIER(U, UISC, UDI, UGC, AJT)
|
|
|
|
def is_HALANT_OR_VOWEL_MODIFIER(U, UISC, UDI, UGC, AJT):
|
|
|
|
# Split off of HALANT
|
|
|
|
return U == 0x0DCA
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_HALANT_NUM(U, UISC, UDI, UGC, AJT):
|
2015-07-20 16:56:19 +02:00
|
|
|
return UISC == Number_Joiner
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_HIEROGLYPH(U, UISC, UDI, UGC, AJT):
|
2020-08-15 00:30:20 +02:00
|
|
|
return UISC == Hieroglyph
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_HIEROGLYPH_JOINER(U, UISC, UDI, UGC, AJT):
|
2020-08-15 00:30:20 +02:00
|
|
|
return UISC == Hieroglyph_Joiner
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_HIEROGLYPH_SEGMENT_BEGIN(U, UISC, UDI, UGC, AJT):
|
2020-08-15 00:30:20 +02:00
|
|
|
return UISC == Hieroglyph_Segment_Begin
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_HIEROGLYPH_SEGMENT_END(U, UISC, UDI, UGC, AJT):
|
2020-08-15 00:30:20 +02:00
|
|
|
return UISC == Hieroglyph_Segment_End
|
2022-03-13 20:01:11 +01:00
|
|
|
def is_INVISIBLE_STACKER(U, UISC, UDI, UGC, AJT):
|
|
|
|
# Split off of HALANT
|
|
|
|
return (UISC == Invisible_Stacker
|
|
|
|
and not is_SAKOT(U, UISC, UDI, UGC, AJT)
|
|
|
|
)
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_ZWNJ(U, UISC, UDI, UGC, AJT):
|
2015-07-20 16:56:19 +02:00
|
|
|
return UISC == Non_Joiner
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_OTHER(U, UISC, UDI, UGC, AJT):
|
2022-03-06 18:26:37 +01:00
|
|
|
# Also includes BASE_IND and SYM
|
|
|
|
return ((UGC == Po or UISC in [Consonant_Dead, Joiner, Modifying_Letter, Other])
|
2021-10-08 02:10:31 +02:00
|
|
|
and not is_BASE(U, UISC, UDI, UGC, AJT)
|
|
|
|
and not is_BASE_OTHER(U, UISC, UDI, UGC, AJT)
|
|
|
|
and not is_CGJ(U, UISC, UDI, UGC, AJT)
|
|
|
|
and not is_SYM_MOD(U, UISC, UDI, UGC, AJT)
|
2022-03-05 02:45:30 +01:00
|
|
|
and not is_Word_Joiner(U, UISC, UDI, UGC, AJT)
|
2015-07-21 12:57:23 +02:00
|
|
|
)
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_REPHA(U, UISC, UDI, UGC, AJT):
|
2017-10-03 14:57:14 +02:00
|
|
|
return UISC in [Consonant_Preceding_Repha, Consonant_Prefixed]
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_SAKOT(U, UISC, UDI, UGC, AJT):
|
2021-10-08 19:25:46 +02:00
|
|
|
# Split off of HALANT
|
2019-05-26 17:05:54 +02:00
|
|
|
return U == 0x1A60
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_SYM_MOD(U, UISC, UDI, UGC, AJT):
|
2022-09-22 00:13:17 +02:00
|
|
|
return UISC == Symbol_Modifier
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_VOWEL(U, UISC, UDI, UGC, AJT):
|
2015-07-20 16:56:19 +02:00
|
|
|
return (UISC == Pure_Killer or
|
2022-03-06 21:35:31 +01:00
|
|
|
UGC != Lo and UISC in [Vowel, Vowel_Dependent])
|
2021-10-08 02:10:31 +02:00
|
|
|
def is_VOWEL_MOD(U, UISC, UDI, UGC, AJT):
|
2015-07-20 16:56:19 +02:00
|
|
|
return (UISC in [Tone_Mark, Cantillation_Mark, Register_Shifter, Visarga] or
|
2022-03-06 21:35:31 +01:00
|
|
|
UGC != Lo and UISC == Bindu)
|
2022-03-05 02:45:30 +01:00
|
|
|
def is_Word_Joiner(U, UISC, UDI, UGC, AJT):
|
2022-03-06 18:26:37 +01:00
|
|
|
# Also includes Rsv
|
2022-03-05 02:45:30 +01:00
|
|
|
return (UDI and U not in [0x115F, 0x1160, 0x3164, 0xFFA0, 0x1BCA0, 0x1BCA1, 0x1BCA2, 0x1BCA3]
|
|
|
|
and UISC == Other
|
|
|
|
and not is_CGJ(U, UISC, UDI, UGC, AJT)
|
2022-03-06 18:26:37 +01:00
|
|
|
) or UGC == Cn
|
2015-07-20 16:56:19 +02:00
|
|
|
|
|
|
|
use_mapping = {
|
|
|
|
'B': is_BASE,
|
|
|
|
'N': is_BASE_NUM,
|
|
|
|
'GB': is_BASE_OTHER,
|
2021-10-08 02:10:31 +02:00
|
|
|
'CGJ': is_CGJ,
|
2015-07-20 16:56:19 +02:00
|
|
|
'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,
|
2022-06-25 17:33:44 +02:00
|
|
|
'HVM': is_HALANT_OR_VOWEL_MODIFIER,
|
2015-07-20 16:56:19 +02:00
|
|
|
'HN': is_HALANT_NUM,
|
2022-03-13 20:01:11 +01:00
|
|
|
'IS': is_INVISIBLE_STACKER,
|
2020-08-15 00:30:20 +02:00
|
|
|
'G': is_HIEROGLYPH,
|
|
|
|
'J': is_HIEROGLYPH_JOINER,
|
|
|
|
'SB': is_HIEROGLYPH_SEGMENT_BEGIN,
|
|
|
|
'SE': is_HIEROGLYPH_SEGMENT_END,
|
2015-07-20 16:56:19 +02:00
|
|
|
'ZWNJ': is_ZWNJ,
|
|
|
|
'O': is_OTHER,
|
|
|
|
'R': is_REPHA,
|
2019-05-26 17:05:54 +02:00
|
|
|
'Sk': is_SAKOT,
|
2015-07-20 16:56:19 +02:00
|
|
|
'SM': is_SYM_MOD,
|
|
|
|
'V': is_VOWEL,
|
|
|
|
'VM': is_VOWEL_MOD,
|
2022-03-05 02:45:30 +01:00
|
|
|
'WJ': is_Word_Joiner,
|
2015-07-20 16:56:19 +02:00
|
|
|
}
|
|
|
|
|
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],
|
2020-08-13 19:37:45 +02:00
|
|
|
'Blw': [Bottom, Overstruck],
|
2015-07-20 19:01:10 +02:00
|
|
|
},
|
|
|
|
'V': {
|
|
|
|
'Abv': [Top, Top_And_Bottom, Top_And_Bottom_And_Right, Top_And_Right],
|
|
|
|
'Blw': [Bottom, Overstruck, Bottom_And_Right],
|
2020-08-13 19:37:45 +02:00
|
|
|
'Pst': [Right],
|
|
|
|
'Pre': [Left, Top_And_Left, Top_And_Left_And_Right, Left_And_Right],
|
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,
|
2022-06-25 17:33:44 +02:00
|
|
|
'HVM': None,
|
2022-03-13 20:01:11 +01:00
|
|
|
'IS': 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],
|
|
|
|
},
|
2020-08-13 19:37:45 +02:00
|
|
|
'R': None,
|
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()
|
2021-10-08 23:13:22 +02:00
|
|
|
for U, (UISC, UIPC, AJT, UDI, UGC, UBlock, _) in data.items():
|
2020-08-13 19:37:45 +02:00
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
2021-10-08 02:10:31 +02:00
|
|
|
values = [k for k,v in items if v(U, UISC, UDI, UGC, AJT)]
|
|
|
|
assert len(values) == 1, "%s %s %s %s %s %s" % (hex(U), UISC, UDI, UGC, AJT, values)
|
2015-07-20 19:01:10 +02:00
|
|
|
USE = values[0]
|
|
|
|
|
|
|
|
# Resolve Indic_Positional_Category
|
|
|
|
|
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
|
2020-08-13 19:37:45 +02:00
|
|
|
|
|
|
|
assert (UIPC in [Not_Applicable, Visual_Order_Left] or U == 0x0F7F or
|
2021-10-08 02:10:31 +02:00
|
|
|
USE in use_positions), "%s %s %s %s %s %s %s" % (hex(U), UIPC, USE, UISC, UDI, UGC, AJT)
|
2015-07-20 19:01:10 +02:00
|
|
|
|
|
|
|
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]
|
2021-10-08 02:10:31 +02:00
|
|
|
assert len(values) == 1, "%s %s %s %s %s %s %s %s" % (hex(U), UIPC, USE, UISC, UDI, UGC, AJT, values)
|
2015-07-20 19:01:10 +02:00
|
|
|
USE = USE + values[0]
|
|
|
|
|
|
|
|
out[U] = (USE, UBlock)
|
2015-07-20 18:00:06 +02:00
|
|
|
return out
|
|
|
|
|
2022-03-06 18:26:37 +01:00
|
|
|
use_data = map_to_use(combined)
|
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 (" *")
|
2021-10-08 23:13:22 +02:00
|
|
|
print (" * {} IndicSyllabicCategory.txt IndicPositionalCategory.txt ArabicShaping.txt DerivedCoreProperties.txt UnicodeData.txt Blocks.txt Scripts.txt IndicSyllabicCategory-Additional.txt IndicPositionalCategory-Additional.txt".format (sys.argv[0]))
|
2018-03-28 16:38:19 +02:00
|
|
|
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 ()
|
2022-06-03 10:54:33 +02:00
|
|
|
print ("#ifndef HB_OT_SHAPER_USE_TABLE_HH")
|
|
|
|
print ("#define HB_OT_SHAPER_USE_TABLE_HH")
|
2019-06-26 22:21:03 +02:00
|
|
|
print ()
|
2021-01-29 19:34:59 +01:00
|
|
|
print ('#include "hb.hh"')
|
2019-06-26 22:21:03 +02:00
|
|
|
print ()
|
2022-06-03 10:56:41 +02:00
|
|
|
print ('#include "hb-ot-shaper-use-machine.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
|
2022-03-06 18:26:37 +01:00
|
|
|
def print_block (block, start, end, use_data):
|
2015-07-20 12:32:48 +02:00
|
|
|
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='')
|
2022-03-06 18:26:37 +01:00
|
|
|
if u in use_data:
|
2015-07-20 12:32:48 +02:00
|
|
|
num += 1
|
2022-03-06 18:26:37 +01:00
|
|
|
d = use_data.get (u)
|
|
|
|
if d is not None:
|
|
|
|
d = d[0]
|
|
|
|
elif u in unicode_data[4]:
|
|
|
|
d = 'O'
|
|
|
|
else:
|
|
|
|
d = 'WJ'
|
|
|
|
print ("%6s," % d, end='')
|
2015-07-20 12:32:48 +02:00
|
|
|
|
|
|
|
total += end - start + 1
|
|
|
|
used += num
|
|
|
|
if block:
|
|
|
|
last_block = block
|
|
|
|
|
2022-03-06 18:26:37 +01:00
|
|
|
uu = sorted (use_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
|
2021-01-29 04:36:51 +01: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
|
2021-01-29 04:36:51 +01: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 ("")
|
2015-07-20 12:32:48 +02:00
|
|
|
|
2022-07-13 20:15:01 +02:00
|
|
|
|
|
|
|
import packTab
|
|
|
|
data = {u:v[0] for u,v in use_data.items()}
|
2022-11-19 21:40:33 +01:00
|
|
|
|
|
|
|
DEFAULT = 5
|
|
|
|
COMPACT = 9
|
|
|
|
for compression in (DEFAULT, COMPACT):
|
|
|
|
|
|
|
|
logging.info(' Compression=%d:' % compression)
|
|
|
|
print()
|
|
|
|
if compression == DEFAULT:
|
|
|
|
print('#ifndef HB_OPTIMIZE_SIZE')
|
|
|
|
elif compression == COMPACT:
|
|
|
|
print('#else')
|
|
|
|
else:
|
|
|
|
assert False
|
|
|
|
print()
|
|
|
|
|
|
|
|
code = packTab.Code('hb_use')
|
|
|
|
sol = packTab.pack_table(data, compression=compression, default='O')
|
|
|
|
logging.info(' FullCost=%d' % (sol.fullCost))
|
|
|
|
sol.genCode(code, f'get_category')
|
|
|
|
code.print_c(linkage='static inline')
|
|
|
|
print ()
|
|
|
|
|
|
|
|
print('#endif')
|
2022-07-13 20:15:01 +02:00
|
|
|
|
2018-03-28 16:38:19 +02:00
|
|
|
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 ()
|
2022-06-03 10:54:33 +02:00
|
|
|
print ("#endif /* HB_OT_SHAPER_USE_TABLE_HH */")
|
2018-03-28 16:38:19 +02:00
|
|
|
print ("/* == End of generated table == */")
|