From 37f1bb93a832e691f61cb06e771759d2602de827 Mon Sep 17 00:00:00 2001 From: Hironori Kitagawa Date: Tue, 28 Oct 2014 14:22:31 +0900 Subject: [PATCH 1/1] Use lang field for judgement if a glyph_node repr. a JAchar or not. --- src/#ltj-pretreat.lua# | 158 +++++++++++++++++++++++++++++++++++++++++++++++++ src/ltj-adjust.lua | 4 +- src/ltj-jfmglue.lua | 18 +++--- src/ltj-jfont.lua | 3 +- src/ltj-otf.lua | 79 ++++++++++++++----------- src/ltj-pretreat.lua | 13 ++-- 6 files changed, 220 insertions(+), 55 deletions(-) create mode 100644 src/#ltj-pretreat.lua# diff --git a/src/#ltj-pretreat.lua# b/src/#ltj-pretreat.lua# new file mode 100644 index 0000000..6d2cbf7 --- /dev/null +++ b/src/#ltj-pretreat.lua# @@ -0,0 +1,158 @@ +-- +-- luatexja/ltj-pretreat.lua +-- + +luatexja.load_module('base'); local ltjb = luatexja.base +luatexja.load_module('charrange'); local ltjc = luatexja.charrange +luatexja.load_module('stack'); local ltjs = luatexja.stack +luatexja.load_module('jfont'); local ltjf = luatexja.jfont +luatexja.load_module('direction'); local ltjd = luatexja.direction + +local Dnode = node.direct or node + +local nullfunc = function(n) return n end +local to_node = (Dnode ~= node) and Dnode.tonode or nullfunc +local to_direct = (Dnode ~= node) and Dnode.todirect or nullfunc + +local setfield = (Dnode ~= node) and Dnode.setfield or function(n, i, c) n[i] = c end +local getid = (Dnode ~= node) and Dnode.getid or function(n) return n.id end +local getfont = (Dnode ~= node) and Dnode.getfont or function(n) return n.font end +local getchar = (Dnode ~= node) and Dnode.getchar or function(n) return n.char end +local getfield = (Dnode ~= node) and Dnode.getfield or function(n, i) return n[i] end +local getsubtype = (Dnode ~= node) and Dnode.getsubtype or function(n) return n.subtype end + +local pairs = pairs +local floor = math.floor +local has_attr = Dnode.has_attribute +local set_attr = Dnode.set_attribute +local node_traverse = Dnode.traverse +local node_remove = Dnode.remove +local node_next = (Dnode ~= node) and Dnode.getnext or node.next +local node_free = Dnode.free +local node_end_of_math = Dnode.end_of_math +local tex_getcount = tex.getcount + +local id_glyph = node.id('glyph') +local id_math = node.id('math') +local id_whatsit = node.id('whatsit') +local sid_user = node.subtype('user_defined') + +local attr_dir = luatexbase.attributes['ltj@dir'] +local attr_curjfnt = luatexbase.attributes['ltj@curjfnt'] +local attr_curtfnt = luatexbase.attributes['ltj@curtfnt'] +local attr_icflag = luatexbase.attributes['ltj@icflag'] + +local is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char_direct +local ltjf_get_vert_glyph = ltjf.get_vert_glyph +local ltjf_replace_altfont = ltjf.replace_altfont +local attr_orig_char = luatexbase.attributes['ltj@origchar'] +local STCK = luatexja.userid_table.STCK +local DIR = luatexja.userid_table.DIR +local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG + +local dir_tate = luatexja.dir_table.dir_tate +local lang_ja = token.create('ltj@@japanese')[2] +------------------------------------------------------------------------ +-- MAIN PROCESS STEP 1: replace fonts +------------------------------------------------------------------------ +local wt, wtd = {}, {} +do + local ltjd_get_dir_count = ltjd.get_dir_count + local start_time_measure, stop_time_measure + = ltjb.start_time_measure, ltjb.stop_time_measure + local head + local is_dir_tate + local suppress_hyphenate_ja_aux = {} + suppress_hyphenate_ja_aux[id_glyph] = function(p) + if (has_attr(p, attr_icflag) or 0)<=0 and is_ucs_in_japanese_char(p) then + local pc = getchar(p) + local pf = ltjf_replace_altfont(has_attr(p, attr_curjfnt) or getfont(p), pc) + setfield(p, 'font', pf); set_attr(p, attr_curjfnt, pf) + setfield(p, 'lang', lang_ja) + set_attr(p, attr_orig_char, pc) + end + return p + end + suppress_hyphenate_ja_aux[id_math] = function(p) + return node_end_of_math(node_next(p)) end + suppress_hyphenate_ja_aux[50] = function(p) return p end + suppress_hyphenate_ja_aux[id_whatsit] = function(p) + if getsubtype(p)==sid_user then + local uid = getfield(p, 'user_id') + if uid==STCK then + wt[#wt+1] = p; node_remove(head, p) + elseif uid==DIR then + if has_attr(p, attr_icflag)0) and max(getfield(lp, 'depth') + y_adjust, adj_depth) or adj_depth + adj_depth = (y_adjust>0) and max(getfield(lx, 'depth') + y_adjust, adj_depth) or adj_depth setfield(lx, 'yoffset', getfield(lx, 'yoffset') - y_adjust) elseif lid==id_kern then local ls = getsubtype(lx) @@ -633,7 +629,7 @@ do local s = Nx.last_char if s then if getid(s)==id_glyph then - if getfont(s) == (has_attr(s, attr_curjfnt) or -1) then + if getfield(s, 'lang') == lang_ja then set_np_xspc_jachar(Nx, s) else set_np_xspc_alchar(Nx, getchar(s), s, 2) diff --git a/src/ltj-jfont.lua b/src/ltj-jfont.lua index 0669b83..8adf19a 100644 --- a/src/ltj-jfont.lua +++ b/src/ltj-jfont.lua @@ -665,6 +665,7 @@ end -- MISC ------------------------------------------------------------------------ do + local get_dir_count = ltjd.get_dir_count local is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char_direct local tex_set_attr = tex.setattribute local font = font @@ -677,7 +678,7 @@ do setfield(g, 'subtype', 1) set_attr(g, attr_icflag, ITALIC) if is_ucs_in_japanese_char(p) then - f = has_attr(p, attr_curjfnt) + f = has_attr(p, (get_dir_count()==dir_tate) and attr_curtfnt or attr_curjfnt) local j = font_metric_table[f] setfield(g, 'kern', j.char_type[find_char_class(getchar(p), j)].italic) else diff --git a/src/ltj-otf.lua b/src/ltj-otf.lua index 861bd32..70a946f 100644 --- a/src/ltj-otf.lua +++ b/src/ltj-otf.lua @@ -8,6 +8,8 @@ luatexja.load_module('base'); local ltjb = luatexja.base luatexja.load_module('jfont'); local ltjf = luatexja.jfont luatexja.load_module('rmlgbm'); local ltjr = luatexja.rmlgbm luatexja.load_module('charrange'); local ltjc = luatexja.charrange +luatexja.load_module('direction'); local ltjd = luatexja.direction +luatexja.load_module('stack'); local ltjs = luatexja.stack local id_glyph = node.id('glyph') local id_whatsit = node.id('whatsit') @@ -41,13 +43,18 @@ local node_traverse_id = Dnode.traverse_id local identifiers = fonts.hashes.identifiers local attr_curjfnt = luatexbase.attributes['ltj@curjfnt'] +local attr_curtfnt = luatexbase.attributes['ltj@curtfnt'] local attr_yablshift = luatexbase.attributes['ltj@yablshift'] local attr_ykblshift = luatexbase.attributes['ltj@ykblshift'] +local attr_tablshift = luatexbase.attributes['ltj@tablshift'] +local attr_tkblshift = luatexbase.attributes['ltj@tkblshift'] +local lang_ja = token.create('ltj@@japanese')[2] local ltjf_font_metric_table = ltjf.font_metric_table local ltjf_find_char_class = ltjf.find_char_class local ltjr_cidfont_data = ltjr.cidfont_data local ltjc_is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char +local ltjd_get_dir_count = ltjd.get_dir_count luatexja.userid_table.OTF = luatexbase.newuserwhatsitid('char_by_cid', 'luatexja') luatexja.userid_table.VSR = luatexbase.newuserwhatsitid('replace_vs', 'luatexja') @@ -80,43 +87,51 @@ end -- This whatsit node will be extracted to a glyph_node local function append_jglyph(char) local p = node_new(id_whatsit,sid_user) - local v = tex.attribute[attr_curjfnt] setfield(p, 'user_id', OTF) setfield(p, 'type', 100) setfield(p, 'value', char) - set_attr(p, attr_yablshift, tex.attribute[attr_ykblshift]) node_write(p) end -local function cid(key) - if key==0 then return append_jglyph(char) end - local curjfnt = identifiers[tex.attribute[attr_curjfnt]] - if not curjfnt.cidinfo or - curjfnt.cidinfo.ordering ~= "Japan1" and - curjfnt.cidinfo.ordering ~= "GB1" and - curjfnt.cidinfo.ordering ~= "CNS1" and - curjfnt.cidinfo.ordering ~= "Korea1" then --- ltjb.package_warning('luatexja-otf', --- 'Current Japanese font (or other CJK font) "' --- ..curjfnt.psname..'" is not a CID-Keyed font (Adobe-Japan1 etc.)') - return append_jglyph(get_ucs_from_rmlgbm(key)) - end - local char = curjfnt.resources.unicodes[curjfnt.cidinfo.ordering..'.'..tostring(key)] - if not char then - ltjb.package_warning('luatexja-otf', - 'Current Japanese font (or other CJK font) "' - ..curjfnt.psname..'" does not have the specified CID character (' - ..tostring(key)..')', - 'Use a font including the specified CID character.') - char = 0 +local cid +do + local dir_tate = luatexja.dir_table.dir_tate + local tex_get_attr = tex.getattribute + cid = function (key) + if key==0 then return append_jglyph(char) end + local curjfnt = identifiers[tex_get_attr((ltjd_get_dir_count()==dir_tate) + and attr_curtfnt or attr_curjfnt)] + if not curjfnt.cidinfo or + curjfnt.cidinfo.ordering ~= "Japan1" and + curjfnt.cidinfo.ordering ~= "GB1" and + curjfnt.cidinfo.ordering ~= "CNS1" and + curjfnt.cidinfo.ordering ~= "Korea1" then + -- ltjb.package_warning('luatexja-otf', + -- 'Current Japanese font (or other CJK font) "' + -- ..curjfnt.psname..'" is not a CID-Keyed font (Adobe-Japan1 etc.)') + return append_jglyph(get_ucs_from_rmlgbm(key)) + end + local char = curjfnt.resources.unicodes[curjfnt.cidinfo.ordering..'.'..tostring(key)] + if not char then + ltjb.package_warning('luatexja-otf', + 'Current Japanese font (or other CJK font) "' + ..curjfnt.psname..'" does not have the specified CID character (' + ..tostring(key)..')', + 'Use a font including the specified CID character.') + char = 0 + end + return append_jglyph(char) end - return append_jglyph(char) end local function extract(head) head = to_direct(head) local p = head local v + local is_dir_tate = ltjs.list_dir == dir_tate + local attr_ablshift = is_dir_tate and attr_tablshift or attr_yablshift + local attr_kblshift = is_dir_tate and attr_tkblshift or attr_ykblshift + local attr_curfnt = is_dir_tate and attr_curtfnt or attr_curjfnt while p do if getid(p)==id_whatsit then if getsubtype(p)==sid_user then @@ -125,14 +140,12 @@ local function extract(head) local g = node_new(id_glyph) setfield(g, 'subtype', 0) setfield(g, 'char', getfield(p, 'value')) - v = has_attr(p, attr_curjfnt); setfield(g, 'font',v) - set_attr(g, attr_curjfnt, puid==OTF and v or -1) - -- VSR yields ALchar - v = has_attr(p, attr_yablshift) - if v then - set_attr(g, attr_yablshift, v) + v = has_attr(p, attr_curfnt); setfield(g, 'font',v) + if puid==OTF then + setfield(g, 'lang', lang_ja) + set_attr(g, attr_kblshift, has_attr(p, attr_kblshift)) else - unset_attr(g, attr_yablshift) + set_attr(g, attr_ablshift, has_attr(p, attr_ablshift)) end head = node_insert_after(head, p, g) head = node_remove(head, p) @@ -290,8 +303,6 @@ do setfield(p, 'user_id', uid) setfield(p, 'type', 100) setfield(p, 'value', char) - set_attr(p, attr_curjfnt, pf) - set_attr(p, attr_yablshift, has_attr(bp, attr_ykblshift) or 0) return p end @@ -314,7 +325,7 @@ do node_free(q) if pt then local np = ivs_jglyph(pt, p, pf, - (has_attr(p,attr_curjfnt) or 0)==pf and OTF or VSR) + (getfield(p, 'lang') or 0)==lang_ja and OTF or VSR) head = node_insert_after(head, p, np) head = node_remove(head,p) node_free(p) diff --git a/src/ltj-pretreat.lua b/src/ltj-pretreat.lua index 249927a..79961cc 100644 --- a/src/ltj-pretreat.lua +++ b/src/ltj-pretreat.lua @@ -51,14 +51,14 @@ local DIR = luatexja.userid_table.DIR local PROCESSED_BEGIN_FLAG = luatexja.icflag_table.PROCESSED_BEGIN_FLAG local dir_tate = luatexja.dir_table.dir_tate -local lang_ja = token.create('ltj@japanese')[2] +local lang_ja = token.create('ltj@@japanese')[2] ------------------------------------------------------------------------ -- MAIN PROCESS STEP 1: replace fonts ------------------------------------------------------------------------ local wt, wtd = {}, {} do local ltjd_get_dir_count = ltjd.get_dir_count - local start_time_measure, stop_time_measure + local start_time_measure, stop_time_measure = ltjb.start_time_measure, ltjb.stop_time_measure local head local is_dir_tate @@ -67,9 +67,8 @@ do if (has_attr(p, attr_icflag) or 0)<=0 and is_ucs_in_japanese_char(p) then local pc = getchar(p) local pf = ltjf_replace_altfont(has_attr(p, attr_curjfnt) or getfont(p), pc) - setfield(p, 'font', pf); set_attr(p, attr_curjfnt, pf) + setfield(p, 'font', pf); --set_attr(p, attr_curjfnt, pf) setfield(p, 'lang', lang_ja) - --setfield(p, 'subtype', floor(getsubtype(p)*0.5)*2) set_attr(p, attr_orig_char, pc) end return p @@ -78,7 +77,7 @@ do return node_end_of_math(node_next(p)) end suppress_hyphenate_ja_aux[50] = function(p) return p end suppress_hyphenate_ja_aux[id_whatsit] = function(p) - if getsubtype(p)==sid_user then + if getsubtype(p)==sid_user then local uid = getfield(p, 'user_id') if uid==STCK then wt[#wt+1] = p; node_remove(head, p) @@ -130,14 +129,14 @@ local function set_box_stack_level(head, mode) is_dir_tate = ltjs.list_dir == dir_tate if is_dir_tate then for p in Dnode.traverse_id(id_glyph,to_direct(head)) do - if (has_attr(p, attr_icflag) or 0)<=0 and has_attr(p, attr_curjfnt)==getfont(p) then + if (has_attr(p, attr_icflag) or 0)<=0 and getfield(p, 'lang')==lang_ja then local pfn = has_attr(p, attr_curtfnt) or getfont(p) local pc = getchar(p) local pf = ltjf_replace_altfont(pfn, pc) set_attr(p, attr_dir, pc) pc = ltjf_get_vert_glyph(pf, pc) or pc setfield(p, 'char', pc); set_attr(p, attr_orig_char, pc) - setfield(p, 'font', pf); set_attr(p, attr_curjfnt, pf) + setfield(p, 'font', pf); --set_attr(p, attr_curjfnt, pf) end end end -- 2.11.0