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])
35 local function get_cidinfo(id) -- table
37 local a = t and (t.cidinfo or (t.resources and t.resources and t.resources.cidinfo)) or nulltable
40 aux.get_cidinfo = get_cidinfo
43 local function get_ascender(id) -- scaled points
44 if font_metric_table[id].ascender then return font_metric_table[id].ascender end
46 local a = t and t.parameters and t.parameters.ascender or 0
47 font_metric_table[id].ascender = a; return a
50 local function get_descender(id) -- scaled points
51 if font_metric_table[id].descender then return font_metric_table[id].descender end
53 local a = t and t.parameters and t.parameters.descender or 0
54 font_metric_table[id].descender = a; return a
56 aux.get_ascender, aux.get_descender = get_ascender, get_descender
58 local function get_vmet_table(tfmdata, dest)
59 if (not tfmdata) or (not tfmdata.shared) then return dest end
60 local rawdata = tfmdata.shared.rawdata
61 local ascender = rawdata.metadata.ascender or 0
63 = rawdata.metadata.defaultvheight
64 or (rawdata.metadata.descender and (ascender+rawdata.metadata.descender) or units)
65 local units = tfmdata.units
66 local t_vorigin, t_vheight, t_ind_to_uni = {}, {}, {}
67 for i,v in pairs(rawdata.descriptions) do
68 t_ind_to_uni[v.index] = i
70 local j = v.boundingbox[4] + v.tsb
71 if j~=ascender then t_vorigin[i]= j / units end
74 if v.vheight~=default_vheight then t_vheight[i] = v.vheight / units end
77 setmetatable(t_vheight, {__index = function () return default_vheight / units end } )
78 setmetatable(t_vorigin, {__index = function () return ascender / units end } )
80 dest.ind_to_uni = t_ind_to_uni
81 dest.vorigin = t_vorigin -- designed size = 1.0
82 dest.vheight = t_vheight -- designed size = 1.0
85 aux.get_vmet_table = get_vmet_table
87 local function loop_over_duplicates(id, func)
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.duplicates then
91 for i,v in pairs(t.resources.duplicates) do
96 aux.loop_over_duplicates = loop_over_duplicates
98 local function loop_over_feat(id, feature_name, func, universal)
99 -- feature_name: like { vert=true, vrt2 = true, ...}
100 -- func: return non-nil iff abort this fn
101 -- universal: true iff look up all (script, lang) pair
102 local t = (type(id)=="table") and id or getfont(id)
103 if t and t.resources and t.resources.sequences then
104 for _,i in pairs(t.resources.sequences) do
105 if i.order[1] and feature_name[i.order[1]] then
106 local f = i.features and i.features[i.order[1]]
107 if i.type == 'gsub_single' and i.steps
108 and f and (universal or (f[t.properties.script] and f[t.properties.script][t.properties.language])) then
109 for _,j in pairs(i.steps) do
110 if type(j)=='table' then
111 if type(j.coverage)=='table' then
112 for i,k in pairs(j.coverage) do
113 local s = func(i,k); if s then return s end
123 aux.loop_over_feat = loop_over_feat
125 local vert_vrt2 = { vert=true, vrt2=true }
126 function aux.replace_vert_variant(id, c)
127 return loop_over_feat(id, vert_vrt2,
128 function (i,k) if i==c then return k end end)
133 --for name, func in pairs(aux) do
134 -- if type(func)=="function" then
135 -- aux[name] = function(...)
136 -- print('LOTF_AUX', name, ...);
137 -- local a = func(...); print('RESULT', a); return a
143 search = function (t, key, prefix)
144 if type(t)=="table" then
145 prefix = prefix or ''
146 for i,v in pairs(t) do
147 if i==key then print(prefix..'.'..i, v)
148 else search(v,key,prefix..'.'..tostring(i)) end
152 aux.t_search = search