• R/O
  • HTTP
  • SSH
  • HTTPS

luatexja: Commit

ソースコードの管理場所


Commit MetaInfo

Revisiona00e5b3031e9f05ce170683a777ed94040041f7e (tree)
Time2019-09-11 23:04:39
AuthorHironori Kitagawa <h_kitagawa2001@yaho...>
CommiterHironori Kitagawa

Log Message

new file: ltj-lotf_aux.lua

luaotfload のキャッシュにアクセスするルーチンはこちらにまとめる予定 (WIP)

Change Summary

Incremental Difference

--- a/src/ltj-jfmglue.lua
+++ b/src/ltj-jfmglue.lua
@@ -12,7 +12,8 @@ luatexja.load_module('base'); local ltjb = luatexja.base
1212 luatexja.load_module('stack'); local ltjs = luatexja.stack
1313 luatexja.load_module('jfont'); local ltjf = luatexja.jfont
1414 luatexja.load_module('direction'); local ltjd = luatexja.direction
15-luatexja.load_module('setwidth'); local ltjw = luatexja.setwidth
15+luatexja.load_module('setwidth'); local ltjw = luatexja.setwidth
16+luatexja.load_module('lotf_aux'); local ltju = luatexja.lotf_aux
1617 local pairs = pairs
1718
1819 --local to_node = node.direct.tonode
@@ -312,13 +313,11 @@ do -- 002 ---------------------------------------
312313 local getwhd = node.direct.getwhd
313314 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
314315 local attr_jchar_code = luatexbase.attributes['ltj@charcode']
315- local identifiers = fonts.hashes.identifiers
316+ local font_getfont = font.getfont
316317 local function calc_np_notdef(lp)
317- local ident = identifiers[getfont(lp)]
318- if not ident.descriptions[getchar(lp)] then
318+ if not font_getfont(getfont(lp)).characters[getchar(lp)] then
319319 local ln = node_next(lp)
320- if (ident.shared and ident.shared.features and ident.shared.features.notdef)
321- and ln and getid(ln)==id_glyph then
320+ if ltju.specified_feature(getfont(lp), 'notdef') and ln and getid(ln)==id_glyph then
322321 set_attr(lp, attr_icflag, PROCESSED)
323322 set_attr(ln, attr_jchar_code, has_attr(lp, attr_jchar_code) or getchar(lp))
324323 set_attr(ln, attr_jchar_class, has_attr(lp, attr_jchar_class) or 0)
--- a/src/ltj-jfont.lua
+++ b/src/ltj-jfont.lua
@@ -11,6 +11,7 @@ luatexja.load_module('base'); local ltjb = luatexja.base
1111 luatexja.load_module('charrange'); local ltjc = luatexja.charrange
1212 luatexja.load_module('rmlgbm'); local ltjr = luatexja.rmlgbm
1313 luatexja.load_module('direction'); local ltjd = luatexja.direction
14+luatexja.load_module('lotf_aux'); local ltju = luatexja.lotf_aux
1415
1516 local setfield = node.direct.setfield
1617 local getid = node.direct.getid
@@ -310,8 +311,6 @@ do
310311 luatexbase.create_callback("luatexja.define_jfont", "data", function (ft, fn) return ft end)
311312
312313 -- EXT
313- local identifiers = fonts.hashes.identifiers
314- local provides_feature = luaotfload.aux.provides_feature
315314 function luatexja.jfont.jfontdefY()
316315 local j = load_jfont_metric(jfm_dir)
317316 local fn = font.id(cstemp)
@@ -328,25 +327,17 @@ do
328327 end
329328 if not f then return end
330329 update_jfm_cache(j, f.size)
331- local ad = identifiers[fn].parameters
332330 local sz = metrics[j].size_cache[f.size]
333331 local fmtable = { jfm = j, size = f.size, var = jfm_var,
334332 with_kanjiskip = jfm_ksp,
335333 zw = sz.zw, zh = sz.zh,
336- ascent = ad.ascender,
337- descent = ad.descender,
338334 chars = sz.chars, char_type = sz.char_type,
339335 kanjiskip = sz.kanjiskip, xkanjiskip = sz.xkanjiskip,
340336 chars_cbcache = {},
341337 vert_activated = vert_activated,
342338 }
343- local t = identifiers[fn]
344339 if auto_enable_vrt2 then
345- local lang, scr = t.properties.language, t.properties.script
346- local vrt2_exist = provides_feature(
347- fn, t.properties.script, t.properties.language, 'vrt2'
348- )
349- t.shared.features[vrt2_exist and 'vrt2' or 'vert'] = true
340+ ltju.enable_feature(fn, ltju.exist_feature(fn, 'vrt2') and 'vrt2' or 'vert')
350341 end
351342
352343 --texio.write_nl('term and log',
@@ -809,18 +800,20 @@ local prepare_fl_data
809800 do
810801 local sort = table.sort
811802 prepare_fl_data = function (dest, id)
812- local ascent = id.shared.rawdata.metadata.ascender
803+ local rawdata = id.shared.rawdata
804+ local ascender = rawdata.metadata.ascender
805+ local units = id.units
813806 local t_vorigin, t_ind_to_uni = {}, {}
814- for i,v in pairs(id.shared.rawdata.descriptions) do
807+ for i,v in pairs(rawdata.descriptions) do
815808 t_ind_to_uni[v.index] = i
816809 if v.tsb then
817810 local j = v.boundingbox[4] + v.tsb
818- if j~=ascent then t_vorigin[i]=j end
811+ if j~=ascender then t_vorigin[i]=j / units end
819812 end
820813 end
821814 dest = dest or {}
822815 dest.ind_to_uni = t_ind_to_uni
823- dest.vorigin = t_vorigin
816+ dest.vorigin = t_vorigin -- designed size = 1.0
824817 return dest
825818 end
826819 end
@@ -860,11 +853,11 @@ do
860853 local nulltable = {} -- dummy
861854 ltjr.vert_addfunc = function (n) font_extra_info[n] = nulltable end
862855
863- local identifiers = fonts.hashes.identifiers
864856 for i=1,font.nextid()-1 do
865- if identifiers[i] then
866- prepare_extra_data_base(identifiers[i])
867- prepare_extra_data_font(i,identifiers[i])
857+ local t = font.getfont(i)
858+ if t then
859+ prepare_extra_data_base(t)
860+ prepare_extra_data_font(i,t)
868861 end
869862 end
870863 end
@@ -922,9 +915,7 @@ luatexbase.add_to_callback(
922915 local vform = {}; fmtable.vform = vform
923916 local t = font_getfont(fnum)
924917 if t.specification and t.resources then
925- local add_vert
926- = not (provides_feature(fnum, t.properties.script, t.properties.language, 'vert'))
927- and not (provides_feature(fnum, t.properties.script, t.properties.language, 'vrt2'))
918+ local add_vert = not ltju.exist_feature(fnum, 'vert') and not ltju.exist_feature(fnum, 'vrt2')
928919 local jpotf_vert = t.shared.features.jpotf
929920 -- 現在の language, script で vert もvrt2 も有効にできない場合,強制的に vert 適用
930921 for _,i in pairs(t.resources.sequences) do
--- /dev/null
+++ b/src/ltj-lotf_aux.lua
@@ -0,0 +1,62 @@
1+--
2+-- ltj-lotf_aux.lua
3+--
4+
5+-- functions which access to fonts.* will be gathered in this file.
6+local aux = {}
7+luatexja.lotf_aux = aux
8+
9+local getfont = font.getfont
10+local provides_feature = luaotfload.aux.provides_feature
11+function aux.exist_feature(id, name)
12+ local t = getfont(id)
13+ if t and t.properties then
14+ return provides_feature(id, t.properties.script, t.properties.language, name)
15+ else return false
16+ end
17+end
18+
19+function aux.enable_feature(id, name)
20+ local t = getfont(id)
21+ if t and t.shared and t.shared.features then
22+ t.shared.features[name] = true
23+ end
24+end
25+function aux.specified_feature(id, name)
26+ local t = getfont(id)
27+ return (t and t.shared and t.shared.features and t.shared.features[name])
28+end
29+
30+local function get_ascender(id) -- scaled points
31+ local t = getfont(id)
32+ return (t and t.parameters and t.parameters.ascender) or 0
33+end
34+local function get_descender(id) -- scaled points
35+ local t = getfont(id)
36+ return (t and t.parameters and t.parameters.descender) or 0
37+end
38+aux.get_ascender, aux.get_descender = get_ascender, get_descender
39+
40+function aux.get_vheight(id, c) -- scaled points
41+ local t = getfont(id)
42+ if t and t.descriptions and t.descriptions[c] and t.descriptions[c].vheight then
43+ return t.descriptions[c].vheight / t.units * t.size
44+ elseif t and t.shared and t.shared.rawdata and t.shared.rawdata.metadata then
45+ return t.shared.rawdata.metadata.defaultvheight / t.units * t.size
46+ else
47+ return get_ascender(id) + get_descender(id)
48+ end
49+end
50+
51+local search
52+search = function (t, key, prefix)
53+ if type(t)=="table" then
54+ for i,v in pairs(t) do
55+ if i==key then print(prefix..'.'..i, v)
56+ else search(v,key,prefix..'.'..tostring(i)) end
57+ end
58+ end
59+end
60+aux.t_search = search
61+
62+-- EOF
--- a/src/ltj-otf.lua
+++ b/src/ltj-otf.lua
@@ -44,7 +44,7 @@ local attr_ykblshift = luatexbase.attributes['ltj@ykblshift']
4444 local attr_tablshift = luatexbase.attributes['ltj@tablshift']
4545 local attr_tkblshift = luatexbase.attributes['ltj@tkblshift']
4646 local lang_ja = luatexja.lang_ja
47-local identifiers = fonts.hashes.identifiers
47+local font_getfont = font.getfont
4848
4949 local ltjf_font_metric_table = ltjf.font_metric_table
5050 local ltjf_font_extra_info = ltjf.font_extra_info
@@ -74,7 +74,7 @@ local function get_ucs_from_rmlgbm(c)
7474 if v>=0x200000 then -- table
7575 local curjfnt_num = tex_get_attr((ltjd_get_dir_count()==dir_tate)
7676 and attr_curtfnt or attr_curjfnt)
77- local curjfnt = identifiers[curjfnt_num].resources
77+ local curjfnt = font_getfont(curjfnt_num).resources
7878 local base, ivs = v % 0x200000, 0xE00FF + math.floor(v/0x200000)
7979 curjfnt = curjfnt and curjfnt.variants
8080 curjfnt = curjfnt and curjfnt[ivs]
@@ -106,7 +106,7 @@ local function get_ucs_from_rmlgbm(c)
106106 -- CID が縦組用字形だった場合
107107 local curjfnt_num = tex_get_attr((ltjd_get_dir_count()==dir_tate)
108108 and attr_curtfnt or attr_curjfnt)
109- local t = identifiers[curjfnt_num]
109+ local t = font_getfont(curjfnt_num)
110110 if t.resources.sequences then
111111 for _,i in pairs(t.resources.sequences) do
112112 if (i.order[1]=='vert' or i.order[1]=='vrt2')
@@ -145,7 +145,7 @@ do
145145 if ltjd_get_dir_count()==dir_tate then
146146 local curjfnt_num = tex_get_attr((ltjd_get_dir_count()==dir_tate)
147147 and attr_curtfnt or attr_curjfnt)
148- local t = identifiers[curjfnt_num]
148+ local t = font_getfont(curjfnt_num)
149149 if t.resources.sequences then
150150 for _,i in pairs(t.resources.sequences) do
151151 if (i.order[1]=='vert' or i.order[1]=='vrt2')
@@ -173,7 +173,7 @@ do
173173 if key==0 then return append_jglyph(0) end
174174 local curjfnt_num = tex_get_attr((ltjd_get_dir_count()==dir_tate)
175175 and attr_curtfnt or attr_curjfnt)
176- local curjfnt = identifiers[curjfnt_num]
176+ local curjfnt = font_getfont(curjfnt_num)
177177 local cidinfo = curjfnt.resources.cidinfo
178178 if not cidinfo or
179179 cidinfo.ordering ~= "Japan1" and
@@ -243,7 +243,7 @@ ltjb.add_to_callback('pre_linebreak_filter', extract,'ltj.otf',
243243
244244 -- 和文フォント読み込み時に,ind -> unicode 対応をとっておく.
245245 local function ind_to_uni(fmtable, fn)
246- local fi = identifiers[fn]
246+ local fi = font_getfont(fn)
247247 local t = ltjf_font_extra_info[fn].ind_to_uni
248248 if t and fi.resources and fi.resources.cidinfo
249249 and fi.resources.cidinfo.ordering == "Japan1" then
--- a/src/ltj-rmlgbm.lua
+++ b/src/ltj-rmlgbm.lua
@@ -228,9 +228,10 @@ do
228228 local getfont = node.direct.getfont
229229 local getchar = node.direct.getchar
230230 local setchar = node.direct.setchar
231+ local font_getfont = font.getfont
231232 cidf_vert_processor = {
232233 function (head, fnum)
233- local fontdata = identifiers[fnum]
234+ local fontdata = font_getfont(fnum)
234235 if head and luatexja.jfont.font_metric_table[fnum].vert_activated then
235236 local vt = fontdata.shared.ltj_vert_table
236237 local nh = is_node(head) and to_direct(head) or head
--- a/src/ltj-setwidth.lua
+++ b/src/ltj-setwidth.lua
@@ -6,6 +6,7 @@ luatexja.load_module('base'); local ltjb = luatexja.base
66 luatexja.load_module('stack'); local ltjs = luatexja.stack
77 luatexja.load_module('jfont'); local ltjf = luatexja.jfont
88 luatexja.load_module('direction'); local ltjd = luatexja.direction
9+luatexja.load_module('lotf_aux'); local ltju = luatexja.lotf_aux
910
1011 local setfield = node.direct.setfield
1112 local getfield = node.direct.getfield
@@ -173,24 +174,22 @@ local function capsule_glyph_tate_rot(p, met, char_data, head, dir, asc)
173174 return q, head, box
174175 end
175176
177+local font_getfont = font.getfont
178+local get_ascender, get_descender = ltju.get_ascender, ltju.get_descender
176179 local function capsule_glyph_tate(p, met, char_data, head, dir)
177180 if not char_data then return node_next(p), head end
178- local ascent, descent = met.ascent, met.descent
179- local fwidth, pwidth = char_data.width
181+ local fwidth, pwidth, ascender = char_data.width
180182 do
181183 local pf, pc = getfont(p), getchar(p)
182184 local feir = ltjf_font_extra_info[pf]
183185 if feir and feir.rotation and met.vert_activated then
184186 if feir.rotation[pc] and (has_attr(p, attr_vert_ori) or 0)<=0 then
185- return capsule_glyph_tate_rot(p, met, char_data, head, dir, 0.5*(ascent-descent))
187+ return capsule_glyph_tate_rot(p, met, char_data, head, dir,
188+ 0.5*(get_ascender(pf)-get_descender(pf)))
186189 end
187190 end
188- local ident = fonts.hashes.identifiers[pf]
189- pwidth = (ident.descriptions and ident.descriptions[pc]
190- and ident.descriptions[pc].vheight
191- and ident.descriptions[pc].vheight / ident.units * met.size)
192- or (ident.metadata and ident.metadata.defaultvheight) or (ascent+descent)
193- ascent = feir.vorigin[pc] and (feir.vorigin[pc] / ident.units * met.size) or ascent
191+ pwidth = ltju.get_vheight(pf, pc, met.size)
192+ ascender = feir.vorigin[pc] and (feir.vorigin[pc] * met.size) or get_ascender(pf)
194193 end
195194 fwidth = fwidth or pwidth
196195 fshift.down = char_data.down; fshift.left = char_data.left
@@ -207,7 +206,7 @@ local function capsule_glyph_tate(p, met, char_data, head, dir)
207206 setdir(box, dir)
208207
209208 setoffsets(p, -fshift.down,
210- yo -(ascent + char_data.align*(fwidth-pwidth) - fshift.left) )
209+ yo -(ascender + char_data.align*(fwidth-pwidth) - fshift.left) )
211210 local ws = node_new(id_whatsit, sid_save)
212211 local wm = node_new(id_whatsit, sid_matrix)
213212 setfield(wm, 'data', '0 1 -1 0')
Show on old repository browser