Debian Codegraph @

texmf-dist/tex/lualatex/lua-ul/lua-ul-patches-preserve-attr.lua

raw
1 --
2 -- This is file `lua-ul-patches-preserve-attr.lua',
3 -- generated with the docstrip utility.
4 --
5 -- The original source files were:
6 --
7 -- lua-ul.dtx (with options: `preserve-attr')
8 --
9 -- Copyright (C) 2020-2024 by Marcel Krueger
10 --
11 -- This file may be distributed and/or modified under the
12 -- conditions of the LaTeX Project Public License, either
13 -- version 1.3c of this license or (at your option) any later
14 -- version. The latest version of this license is in:
15 --
16 -- http://www.latex-project.org/lppl.txt
17 --
18 -- and version 1.3 or later is part of all distributions of
19 -- LaTeX version 2005/12/01 or later.
20 local getfont = font.getfont
21
22 local direct = node.direct
23
24 local getattr = direct.getattributelist
25 local getid = direct.getid
26 local getpenalty = direct.getpenalty
27 local getprev = direct.getprev
28 local getwidth = direct.getwidth
29
30 local setattr = direct.setattributelist
31 local setkern = direct.setkern
32
33 local insert_after = direct.insert_after
34 local is_glyph = direct.is_glyph
35 local newnode = direct.new
36 local todirect = direct.todirect
37 local tonode = direct.tonode
38
39 local glue_id = node.id'glue'
40 local kern_t = node.id'kern'
41 local penalty_id = node.id'penalty'
42
43 local italcorr_sub
44 for i, n in next, node.subtypes'kern' do
45 if n == 'italiccorrection' then italcorr_sub = i break end
46 end
47 assert(italcorr_sub)
48
49 local nests = tex.nest
50
51 local funcid = luatexbase.new_luafunction'sw@slant'
52 token.set_lua('sw@slant', funcid, 'protected')
53 lua.get_functions_table()[funcid] = function()
54 local nest = nests.top
55 local tail, after = todirect(nest.tail), nil
56 local id = getid(tail)
57 if id == glue_id then
58 if getwidth(tail) == 0 then return end
59 tail, after = getprev(tail), tail
60 id = getid(tail)
61 end
62 if id == penalty_id then
63 if getpenalty(tail) == 0 then return end
64 tail, after = getprev(tail), tail
65 end
66 local cid, fontid = is_glyph(tail)
67 if not cid then return end
68 local fontdir = getfont(fontid)
69 local characters = fontdir and fontdir.characters
70 local char = characters and characters[cid]
71 local kern = newnode(kern_t, italcorr_sub)
72 setkern(kern, char and char.italic or 0)
73 setattr(kern, getattr(tail))
74 insert_after(tail, tail, kern)
75 if not after then nest.tail = tonode(kern) end
76 end
77 --
78 --
79 -- End of file `lua-ul-patches-preserve-attr.lua'.