4 luatexbase.provides_module({
8 description = 'The OTF Lua module for LuaTeX-ja',
10 module('luatexja.otf', package.seeall)
12 require('luatexja.base'); local ltjb = luatexja.base
13 require('luatexja.jfont'); local ltjf = luatexja.jfont
15 local id_glyph = node.id('glyph')
16 local id_whatsit = node.id('whatsit')
17 local sid_user = node.subtype('user_defined')
19 local node_new = node.new
20 local node_remove = node.remove
21 local node_next = node.next
22 local node_free = node.free
23 local has_attr = node.has_attribute
24 local set_attr = node.set_attribute
25 local unset_attr = node.unset_attribute
26 local node_insert_after = node.insert_after
28 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
29 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
30 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
31 local attr_ykblshift = luatexbase.attributes['ltj@ykblshift']
33 -- Append a whatsit node to the list.
34 -- This whatsit node will be extracted to a glyph_node
35 function append_jglyph(char)
36 local p = node_new(id_whatsit,sid_user)
37 local v = tex.attribute[attr_curjfnt]
38 p.user_id=30113; p.type=100; p.value=char
39 set_attr(p, attr_yablshift, tex.attribute[attr_ykblshift])
44 local curjfnt = fonts.ids[tex.attribute[attr_curjfnt]]
45 if curjfnt.cidinfo.ordering ~= "Japan1" then
46 ltjb.package_error('luatexja-otf',
47 'Current Japanese font "'..curjfnt.psname..'" is not a CID-Keyed font (Adobe-Japan1)',
48 'Select a CID-Keyed font using \jfont.')
51 local char = curjfnt.unicodes['Japan1.'..tostring(key)]
53 ltjb.package_warning('luatexja-otf',
54 'Current Japanese font "'..curjfnt.psname..'" does not include the specified CID character ('..tostring(key)..')',
55 'Use a font including the specified CID character.')
61 function extract(head)
64 if p.id==id_whatsit then
65 if p.subtype==sid_user and p.user_id==30113 then
66 local g = node_new(id_glyph)
67 g.subtype = 0; g.char = p.value
68 v = has_attr(p, attr_curjfnt); g.font = v
69 set_attr(g, attr_jchar_class,
70 ltjf.find_char_class(g.char, ltjf.font_metric_table[v].jfm))
71 set_attr(g, attr_curjfnt, v)
72 v = has_attr(p, attr_yablshift)
74 set_attr(g, attr_yablshift, v)
76 unset_attr(g, attr_yablshift)
78 head = node_insert_after(head, p, g)
79 head = node_remove(head, p)
88 luatexbase.add_to_callback('hpack_filter',
89 function (head) return extract(head) end,'ltj.hpack_filter_otf',
90 luatexbase.priority_in_callback('pre_linebreak_filter',
91 'ltj.pre_linebreak_filter'))
92 luatexbase.add_to_callback('pre_linebreak_filter',
93 function (head) return extract(head) end, 'ltj.pre_linebreak_filter_otf',
94 luatexbase.priority_in_callback('pre_linebreak_filter',
95 'ltj.pre_linebreak_filter'))
98 -------------------- all done