Debian Codegraph @

texmf-dist/tex/lualatex/uninormalize/unicode-normalize-names.lua

raw
1 -- Unicode names
2
3 if not characters then
4 require "char-def"
5 end
6
7 unicode = unicode or { }
8 unicode.conformance = unicode.conformance or { }
9
10 unidata = characters.data
11
12 if not math.div then -- from l-math.lua
13 function math.div(n, m)
14 return math.floor(n/m)
15 end
16 end
17
18 local function is_hangul(char)
19 return char >= 0xAC00 and char <= 0xD7A3
20 end
21
22 local function is_han_character(char) -- from font-otf.lua (check)
23 return
24 (char>=0x04E00 and char<=0x09FFF) or
25 (char>=0x03400 and char<=0x04DFF) or
26 (char>=0x20000 and char<=0x2A6DF) or
27 (char>=0x0F900 and char<=0x0FAFF) or
28 (char>=0x2F800 and char<=0x2FA1F)
29 end
30
31 local SBase, LBase, VBase, TBase = 0xAC00, 0x1100, 0x1161, 0x11A7
32 local LCount, VCount, TCount = 19, 21, 28
33 local NCount = VCount * TCount
34 local SCount = LCount * NCount
35
36 local JAMO_L_TABLE = { [0] = "G", "GG", "N", "D", "DD", "R", "M", "B", "BB",
37 "S", "SS", "", "J", "JJ", "C", "K", "T", "P", "H" }
38 local JAMO_V_TABLE = { [0] = "A", "AE", "YA", "YAE", "EO", "E", "YEO", "YE",
39 "O", "WA", "WAE", "OE", "YO", "U", "WEO", "WE", "WI", "YU", "EU", "YI", "I" }
40 local JAMO_T_TABLE = { [0] = "", "G", "GG", "GS", "N", "NJ", "NH", "D", "L",
41 "LG", "LM", "LB", "LS", "LT", "LP", "LH", "M", "B", "BS", "S", "SS", "NG",
42 "J", "C", "K", "T", "P", "H" }
43
44 function unicode.conformance.name(char)
45 if is_hangul(char) then
46 local SIndex = char - SBase
47 local LIndex = math.div(SIndex, NCount)
48 local VIndex = math.div(SIndex % NCount, TCount)
49 local TIndex = SIndex % TCount
50 return string.format("HANGUL SYLLABLE %s%s%s", JAMO_L_TABLE[LIndex],
51 JAMO_V_TABLE[VIndex], JAMO_T_TABLE[TIndex])
52 elseif is_han_character(char)
53 then return string.format("CJK UNIFIED IDEOGRAPH-%04X", char)
54 elseif unidata[char] -- if unidata[char] exists, the name exists
55 then return unidata[char].description
56 end
57 end