- if ltj.isglobal=='global' then tex.sprint('\\global') end
-end
-
-
-------------------------------------------------------------------------
--- MAIN PROCESS STEP 1: replace fonts (prefix: main1)
-------------------------------------------------------------------------
-
---- the following function is modified from jafontspec.lua (by K. Maeda).
---- Instead of "%", we use U+FFFFF for suppressing spaces.
-local function main1_process_input_buffer(buffer)
- local c = utf.byte(buffer, utf.len(buffer))
- local p = node_new(id_glyph)
- p.char = c
- if utf.len(buffer) > 0
- and rgjc_is_ucs_in_japanese_char(p) then
- buffer = buffer .. string.char(0xF3,0xBF,0xBF,0xBF) -- U+FFFFF
- end
- return buffer
-end
-
-local function main1_suppress_hyphenate_ja(head)
- local p
- for p in node.traverse(head) do
- if p.id == id_glyph then
- if rgjc_is_ucs_in_japanese_char(p) then
- local v = has_attr(p, attr_curjfnt)
- if v then
- p.font = v
- node.set_attribute(p,attr_jchar_class,
- ljfm_find_char_class(p.char, ltj.font_metric_table[v].jfm))
- end
- v = has_attr(p, attr_ykblshift)
- if v then
- node.set_attribute(p, attr_yablshift, v)
- else
- node.unset_attribute(p, attr_yablshift)
- end
- p.lang=lang_ja
- end
- end
- end
- lang.hyphenate(head)
- return head
-end
-
--- CALLBACKS
-luatexbase.add_to_callback('process_input_buffer',
- function (buffer)
- return main1_process_input_buffer(buffer)
- end,'ltj.process_input_buffer')
-luatexbase.add_to_callback('hpack_filter',
- function (head,groupcode,size,packtype)
- return main1_suppress_hyphenate_ja(head)
- end,'ltj.hpack_filter_pre',0)
-luatexbase.add_to_callback('hyphenate',
- function (head,tail)
- return main1_suppress_hyphenate_ja(head)
- end,'ltj.hyphenate')
-
-
-------------------------------------------------------------------------
--- MAIN PROCESS STEP 4: width of japanese chars (prefix: main4)
-------------------------------------------------------------------------
-
--- TeX's \hss
-local function main4_get_hss()
- local hss = node_new(id_glue)
- local fil_spec = node_new(id_glue_spec)
- fil_spec.width = 0
- fil_spec.stretch = 65536
- fil_spec.stretch_order = 2
- fil_spec.shrink = 65536
- fil_spec.shrink_order = 2
- hss.spec = fil_spec
- return hss
-end
-
-local function main4_set_ja_width(head)
- local p = head
- local met_tb, t, s, g, q, a, h
- local m = false -- is in math mode?
- while p do
- local v=has_attr(p,attr_yablshift) or 0
- if p.id==id_glyph then
- p.yoffset = p.yoffset-v
- if is_japanese_glyph_node(p) then
- met_tb = ltj.font_metric_table[p.font]
- t = ltj.metrics[met_tb.jfm]
- s = t.char_type[has_attr(p,attr_jchar_class)]
- if s.width ~= 'prop' and
- not(s.left==0.0 and s.down==0.0 and s.align=='left'
- and round(s.width*met_tb.size)==p.width) then
- -- must be encapsuled by a \hbox
- head, q = node.remove(head,p)
- p.next=nil
- p.yoffset=round(p.yoffset-met_tb.size*s.down)
- p.xoffset=round(p.xoffset-met_tb.size*s.left)
- if s.align=='middle' or s.align=='right' then
- h = node_insert_before(p, p, main4_get_hss())
- else h=p end
- if s.align=='middle' or s.align=='left' then
- node_insert_after(h, p, main4_get_hss())
- end
- g = node_hpack(h, round(met_tb.size*s.width), 'exactly')
- g.height = round(met_tb.size*s.height)
- g.depth = round(met_tb.size*s.depth)
- head, p = node_insert_before(head, q, g)
- p = q
- else p=node_next(p)
- end
- else p=node_next(p)
- end
- elseif p.id==id_math then
- m=(p.subtype==0); p=node_next(p)
- else
- if m then
- if p.id==id_hlist or p.id==id_vlist then
- p.shift=p.shift+v
- elseif p.id==id_rule then
- p.height=p.height-v; p.depth=p.depth+v
- end
- end
- p=node_next(p)
- end
- end
-return head