5 -- functions which access to fonts.* will be gathered in this file.
7 luatexja.lotf_aux = aux
11 local font_getfont = font.getfont
12 getfont = function (id) return (type(id)=="table") and id or font_getfont(id) end
14 -- accept font number or table
15 local provides_feature = luaotfload.aux.provides_feature
16 function aux.exist_feature(id, name)
18 if t and t.properties then
19 return provides_feature(id, t.properties.script, t.properties.language, name)
24 function aux.enable_feature(id, name)
26 if t and t.shared and t.shared.features then
27 t.shared.features[name] = true
30 function aux.specified_feature(id, name)
32 return (t and t.shared and t.shared.features and t.shared.features[name])
35 local function get_ascender(id) -- scaled points
37 return (t and t.parameters and t.parameters.ascender) or 0
39 local function get_descender(id) -- scaled points
41 return (t and t.parameters and t.parameters.descender) or 0
43 aux.get_ascender, aux.get_descender = get_ascender, get_descender
45 function aux.get_vheight(id, c) -- scaled points
47 if t and t.descriptions and t.descriptions[c] and t.descriptions[c].vheight then
48 return t.descriptions[c].vheight / t.units * t.size
49 elseif t and t.shared and t.shared.rawdata and t.shared.rawdata.metadata then
50 return t.shared.rawdata.metadata.defaultvheight / t.units * t.size
52 return get_ascender(id) + get_descender(id)
56 local function loop_over_feat(id, feature_name, func)
57 -- feature_name: like { vert=true, vrt2 = true, ...}
58 -- func: return non-nil iff abort this fn
60 if t and t.resources and t.resources.sequences then
61 for _,i in pairs(t.resources.sequences) do
62 if i.order[1] and feature_name[i.order[1]] then
63 local f = i.features and i.features[i.order[1]]
64 if i.type == 'gsub_single' and i.steps
65 and f and f[t.properties.script] and f[t.properties.script][t.properties.language] then
66 for _,j in pairs(i.steps) do
67 if type(j)=='table' then
68 if type(j.coverage)=='table' then
69 for i,k in pairs(j.coverage) do
70 local s = func(i,k); if s then return s end
80 aux.loop_over_feat = loop_over_feat
82 local vert_vrt2 = { vert=true, vrt2=true }
83 function aux.replace_vert_variant(id, c)
84 return loop_over_feat(id, vert_vrt2,
85 function (i,k) if i==c then return k end end)
92 search = function (t, key, prefix)
93 if type(t)=="table" then
94 for i,v in pairs(t) do
95 if i==key then print(prefix..'.'..i, v)
96 else search(v,key,prefix..'.'..tostring(i)) end
100 aux.t_search = search