5 -- functions which access to fonts.* will be gathered in this file.
7 luatexja.lotf_aux = aux
8 local font_metric_table = {}
9 aux.font_metric_table = font_metric_table
11 local getfont = font.getfont
12 local provides_feature = luaotfload.aux.provides_feature
13 function aux.exist_feature(id, name)
15 if t and t.properties then
16 return provides_feature(id, t.properties.script, t.properties.language, name)
21 function aux.enable_feature(id, name)
23 if t and t.shared and t.shared.features then
24 t.shared.features[name] = true
27 function aux.specified_feature(id, name)
29 return (t and t.shared and t.shared.features and t.shared.features[name])
32 local function get_ascender(id) -- scaled points
33 if font_metric_table[id].ascender then return font_metric_table[id].ascender end
35 local a = t and t.parameters and t.parameters.ascender or 0
36 font_metric_table[id].ascender = a; return a
38 local function get_descender(id) -- scaled points
39 if font_metric_table[id].descender then return font_metric_table[id].descender end
41 local a = t and t.parameters and t.parameters.descender or 0
42 font_metric_table[id].descender = a; return a
44 aux.get_ascender, aux.get_descender = get_ascender, get_descender
46 local function get_vmet_table(tfmdata, dest)
47 if tfmata and tfmdata.shared then return dest end
48 local rawdata = tfmdata.shared.rawdata
49 local ascender = rawdata.metadata.ascender or 0
51 = rawdata.metadata.defaultvheight
52 or (rawdata.metadata.descender and (ascender+rawdata.metadata.descender) or units)
53 local units = tfmdata.units
54 local t_vorigin, t_vheight, t_ind_to_uni = {}, {}, {}
55 for i,v in pairs(rawdata.descriptions) do
56 t_ind_to_uni[v.index] = i
58 local j = v.boundingbox[4] + v.tsb
59 if j~=ascender then t_vorigin[i]= j / units end
62 if v.vheight~=default_vheight then t_vheight[i] = v.vheight / units end
65 setmetatable(t_vheight, {__index = function () return default_vheight / units end } )
66 setmetatable(t_vorigin, {__index = function () return ascender / units end } )
68 dest.ind_to_uni = t_ind_to_uni
69 dest.vorigin = t_vorigin -- designed size = 1.0
70 dest.vheight = t_vheight -- designed size = 1.0
73 aux.get_vmet_table = get_vmet_table
75 local function loop_over_duplicates(id, func)
76 -- func: return non-nil iff abort this fn
77 local t = (type(id)=="table") and id or getfont(id)
78 if t and t.resources and t.resources.duplicates then
79 for i,v in pairs(t.resources.duplicates) do
84 aux.loop_over_duplicates = loop_over_duplicates
86 local function loop_over_feat(id, feature_name, func)
87 -- feature_name: like { vert=true, vrt2 = true, ...}
88 -- func: return non-nil iff abort this fn
89 local t = (type(id)=="table") and id or getfont(id)
90 if t and t.resources and t.resources.sequences then
91 for _,i in pairs(t.resources.sequences) do
92 if i.order[1] and feature_name[i.order[1]] then
93 local f = i.features and i.features[i.order[1]]
94 if i.type == 'gsub_single' and i.steps
95 and f and f[t.properties.script] and f[t.properties.script][t.properties.language] then
96 for _,j in pairs(i.steps) do
97 if type(j)=='table' then
98 if type(j.coverage)=='table' then
99 for i,k in pairs(j.coverage) do
100 local s = func(i,k); if s then return s end
110 aux.loop_over_feat = loop_over_feat
112 local vert_vrt2 = { vert=true, vrt2=true }
113 function aux.replace_vert_variant(id, c)
114 return loop_over_feat(id, vert_vrt2,
115 function (i,k) if i==c then return k end end)
122 search = function (t, key, prefix)
123 if type(t)=="table" then
124 prefix = prefix or ''
125 for i,v in pairs(t) do
126 if i==key then print(prefix..'.'..i, v)
127 else search(v,key,prefix..'.'..tostring(i)) end
131 aux.t_search = search