X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-jfont.lua;h=7e10815cf26f9ac92b1bc5a8c514539533c08b6d;hb=a693b63eadfcabe5f4f513a4cc90302f2360b18b;hp=6fccf822501c31bb340ae62ae4cbf2f1177d021c;hpb=72ac1fbce6745896b98e48ead84394aaabfe68e8;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-jfont.lua b/src/ltj-jfont.lua index 6fccf82..7e10815 100644 --- a/src/ltj-jfont.lua +++ b/src/ltj-jfont.lua @@ -3,7 +3,7 @@ -- luatexbase.provides_module({ name = 'luatexja.jfont', - date = '2014/01/02', + date = '2014/02/01', description = 'Loader for Japanese fonts', }) module('luatexja.jfont', package.seeall) @@ -11,6 +11,8 @@ module('luatexja.jfont', package.seeall) luatexja.load_module('base'); local ltjb = luatexja.base luatexja.load_module('charrange'); local ltjc = luatexja.charrange +local mem_leak_glue, mem_leak_gs, mem_leak_kern = 0, 0, 0 + local Dnode = node.direct or node local setfield = (Dnode ~= node) and Dnode.setfield or function(n, i, c) n[i] = c end @@ -131,6 +133,7 @@ function define_jfm(t) defjfm_res = t end +local update_jfm_cache do local function mult_table(old,scale) -- modified from table.fastcopy if old then @@ -148,28 +151,29 @@ do else return nil end end - function update_jfm_cache(j,sz) + update_jfm_cache = function (j,sz) if metrics[j].size_cache[sz] then return end local t = {} metrics[j].size_cache[sz] = t t.chars = metrics[j].chars t.char_type = mult_table(metrics[j].char_type, sz) for i,v in pairs(t.char_type) do + v.align = (v.align=='left') and 0 or + ((v.align=='right') and 1 or 0.5) if type(i) == 'number' then -- char_type for k,w in pairs(v.glue) do - local g, h = node_new(id_glue), node_new(id_glue_spec) - v[k] = {true, g, (w[5] and w[5]/sz or 0)} + local h = node_new(id_glue_spec) +mem_leak_gs = mem_leak_gs+1 + v[k] = {true, h, (w[5] and w[5]/sz or 0), FROM_JFM + (w[4] and w[4]/sz or 0)} setfield(h, 'width', w[1]) setfield(h, 'stretch', w[2]) setfield(h, 'shrink', w[3]) setfield(h, 'stretch_order', 0) setfield(h, 'shrink_order', 0) - setfield(g, 'subtype', 0) - setfield(g, 'spec', h) - set_attr(g, attr_icflag, FROM_JFM + (w[4] and w[4]/sz or 0)); end for k,w in pairs(v.kern) do local g = node_new(id_kern) +mem_leak_kern = mem_leak_kern +1 setfield(g, 'kern', w[1]) setfield(g, 'subtype', 1) set_attr(g, attr_icflag, FROM_JFM) @@ -183,7 +187,7 @@ do t.zh = round(metrics[j].zh*sz) end end -local update_jfm_cache = update_jfm_cache + luatexbase.create_callback("luatexja.find_char_class", "data", function (arg, fmtable, char) return 0 @@ -250,6 +254,7 @@ do return end update_jfm_cache(j, f.size) + --print('MEMORY LEAK (acc): ', mem_leak_glue, mem_leak_gs, mem_leak_kern) local sz = metrics[j].size_cache[f.size] local fmtable = { jfm = j, size = f.size, var = jfm_var, zw = sz.zw, zh = sz.zh, @@ -265,15 +270,14 @@ do end do --- EXT: zw, zh - function load_zw() + -- PUBLIC function + function get_zw() local a = font_metric_table[tex.attribute[attr_curjfnt]] - tex.setdimen('ltj@zw', a and a.zw or 0) + return a and a.zw or 0 end - - function load_zh() + function get_zh() local a = font_metric_table[tex.attribute[attr_curjfnt]] - tex.setdimen('ltj@zh', a and a.zh or 0) + return a and a.zw or 0 end end @@ -314,6 +318,57 @@ do end ------------------------------------------------------------------------ +-- LATEX INTERFACE +------------------------------------------------------------------------ +do + -- these function are called from ltj-latex.sty + local kyenc_list, ktenc_list = {}, {} + function add_kyenc_list(enc) kyenc_list[enc] = 'true ' end + function add_ktenc_list(enc) ktenc_list[enc] = 'true ' end + function is_kyenc(enc) + tex.sprint(cat_lp, '\\let\\ifin@\\if' .. (kyenc_list[enc] or 'false ')) + end + function is_kyenc(enc) + tex.sprint(cat_lp, '\\let\\ifin@\\if' .. (kyenc_list[enc] or 'false ')) + end + function is_kenc(enc) + tex.sprint(cat_lp, '\\let\\ifin@\\if' + .. (kyenc_list[enc] or ktenc_list[enc] or 'false ')) + end + + local kfam_list, Nkfam_list = {}, {} + function add_kfam_list(enc, fam) + if not kfam_list[enc] then kfam_list[enc] = {} end + kfam_list[enc][fam] = 'true ' + end + function add_Nkfam_list(enc, fam) + if not Nkfam_list[enc] then Nkfam_list[enc] = {} end + Nkfam_list[enc][fam] = 'true ' + end + function is_kfam(enc, fam) + tex.sprint(cat_lp, '\\let\\ifin@\\if' + .. (kfam_list[enc] and kfam_list[enc][fam] or 'false ')) end + function is_Nkfam(enc, fam) + tex.sprint(cat_lp, '\\let\\ifin@\\if' + .. (Nkfam_list[enc] and Nkfam_list[enc][fam] or 'false ')) end + + local ffam_list, Nffam_list = {}, {} + function add_ffam_list(enc, fam) + if not ffam_list[enc] then ffam_list[enc] = {} end + ffam_list[enc][fam] = 'true ' + end + function add_Nffam_list(enc, fam) + if not Nffam_list[enc] then Nffam_list[enc] = {} end + Nffam_list[enc][fam] = 'true ' + end + function is_ffam(enc, fam) + tex.sprint(cat_lp, '\\let\\ifin@\\if' + .. (ffam_list[enc] and ffam_list[enc][fam] or 'false ')) end + function is_Nffam(enc, fam) + tex.sprint(cat_lp, '\\let\\ifin@\\if' + .. (Nffam_list[enc] and Nffam_list[enc][fam] or 'false ')) end +end +------------------------------------------------------------------------ -- ALTERNATE FONTS ------------------------------------------------------------------------ alt_font_table = {} @@ -366,8 +421,8 @@ end ------ used in ltjp.suppress_hyphenate_ja callback function replace_altfont(pf, pc) - return (alt_font_table[pf] and alt_font_table[pf][pc]) - and alt_font_table[pf][pc] or pf + local a = alt_font_table[pf] + return a and a[pc] or pf end ------ for LaTeX interface @@ -423,26 +478,30 @@ end -- ここから先は 新 \selectfont の内部でしか実行されない do local alt_font_base, alt_font_base_num - --- EXT - function print_aftl_address(bbase) - local t = alt_font_table_latex[bbase] - if not t then t = {}; alt_font_table_latex[bbase] = t end - tex.sprint(cat_lp, (tostring(t):gsub('table: ','ltjaltfont'))) + local aftl_base + -- EXT + function does_alt_set(bbase) + aftl_base = alt_font_table_latex[bbase] + tex.sprint(cat_lp, '\\if' .. (aftl_base and 'true' or 'false')) end + -- EXT + function print_aftl_address() + tex.sprint(cat_lp, ';ltjaltfont' .. tostring(aftl_base):sub(8)) + end + -- EXT function output_alt_font_cmd(bbase) alt_font_base = bbase alt_font_base_num = tex.getattribute(attr_curjfnt) local t = alt_font_table[alt_font_base_num] if t then - for i,_ in pairs(t) do t[i]=nil end + for i,_ in pairs(t) do t[i]=nil end end t = alt_font_table_latex[bbase] if t then - for i,_ in pairs(t) do - tex.sprint(cat_lp, '\\ltj@pickup@altfont@aux{' .. i .. '}') - end + for i,_ in pairs(t) do + tex.sprint(cat_lp, '\\ltj@pickup@altfont@aux{' .. i .. '}') + end end end @@ -450,18 +509,18 @@ do function pickup_alt_font_a(size_str) local t = alt_font_table_latex[alt_font_base] if t then - for i,v in pairs(t) do - tex.sprint(cat_lp, '\\expandafter\\ltj@pickup@altfont@copy' - .. '\\csname ' .. i .. '/' .. size_str .. '\\endcsname{' .. i .. '}') - end + for i,v in pairs(t) do + tex.sprint(cat_lp, '\\expandafter\\ltj@pickup@altfont@copy' + .. '\\csname ' .. i .. '/' .. size_str .. '\\endcsname{' .. i .. '}') + end end - end + end local function pickup_alt_font_class(class, afnt_num, afnt_chars) local t = alt_font_table[alt_font_base_num] local tx = font_metric_table[alt_font_base_num].chars for i,v in pairs(tx) do - if v==class and afnt_chars[i] then t[i]=afnt_num end + if v==class and afnt_chars[i] then t[i]=afnt_num end end end @@ -471,17 +530,17 @@ do local ac = font_getfont(afnt_num).characters if not t then t = {}; alt_font_table[alt_font_base_num] = t end for i,v in pairs(alt_font_table_latex[alt_font_base]) do - if i == afnt_base then - for j,_ in pairs(v) do - if j>=0 then - if ac[j] then t[j]=afnt_num end - else -- -n (n>=1) means that the character class n, - -- which is defined in the JFM - pickup_alt_font_class(-j, afnt_num, ac) - end - end - return - end + if i == afnt_base then + for j,_ in pairs(v) do + if j>=0 then + if ac[j] then t[j]=afnt_num end + else -- -n (n>=1) means that the character class n, + -- which is defined in the JFM + pickup_alt_font_class(-j, afnt_num, ac) + end + end + return + end end end