Debian Codegraph @

texmf-dist/tex/luatex/luaotfload/luaotfload-scripts.lua

raw
1 -----------------------------------------------------------------------
2 -- FILE: luaotfload-script.lua
3 -- DESCRIPTION: part of luaotfload / script
4 -----------------------------------------------------------------------
5
6 assert(luaotfload_module, "This is a part of luaotfload and should not be loaded independently") {
7 name = "luaotfload-script",
8 version = "3.29", --TAGVERSION
9 date = "2024-12-03", --TAGDATE
10 description = "luaotfload submodule / Script helpers",
11 license = "CC0 1.0 Universal",
12 author = "Marcel Krüger"
13 }
14
15 local canonical_name = {
16 dflt = "DFLT",
17 hira = "kana",
18 laoo = "lao",
19 yiii = "yi",
20 nkoo = "nko",
21 yaii = "vai",
22 ["lao "] = "lao",
23 ["yi "] = "yi",
24 ["nko "] = "nko",
25 ["vai "] = "vai",
26 }
27 local versioned_script = {
28 mym = "mymr", mymr = "mym",
29 bng = "beng", beng = "bng",
30 dev = "deva", deva = "dev",
31 gjr = "gujr", gujr = "gjr",
32 gur = "guru", guru = "gur",
33 knd = "knda", knda = "knd",
34 mlm = "mlym", mlym = "mlm",
35 ory = "orya", orya = "ory",
36 tml = "taml", taml = "tml",
37 tel = "telu", telu = "tel",
38 }
39 local function get_versioned(original)
40 local base = original:gsub("%d$", "") -- Strip any existing version
41 local versioned = versioned_script[base]
42 if not versioned then
43 return original
44 end
45 if #base == 3 then
46 local t = base
47 base = versioned
48 versioned = t
49 end
50 if base == "mymr" then
51 return "mym2", "mymr"
52 end
53 return versioned .. '3', versioned .. '2', base
54 end
55
56 -- We never return trailing spaces because I consider them implementation details.
57 local function script_to_ot(iso)
58 iso = iso:lower()
59 return get_versioned(canonical_name[iso] or iso)
60 end
61
62 local function script_to_iso(tag)
63 tag = tag:lower()
64 tag = canonical_name[tag] or tag
65 local stripped, did_strip = tag:gsub("%d$", "")
66 tag = did_strip == 1 and versioned_script[stripped] or tag
67 local tag_length = #tag
68 if tag_length == 4 then return tag end -- Optimization for common case
69 -- I promise you, I am not making this one up
70 return tag .. string.rep(tag:sub(tag_length, tag_length), 4-tag_length)
71 end
72
73 local function to_harfbuzz(script, language)
74 local otscript = script_to_iso(script)
75 -- if script_to_ot(otscript) == script then
76 -- return otscript, language
77 -- end
78 return otscript, "x-hbot" .. language .. "-hbsc" .. script
79 end
80
81 return {
82 to_harfbuzz = to_harfbuzz,
83 script = {
84 to_ot = script_to_ot,
85 to_iso = script_to_iso,
86 },
87 }