summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luaotfload/luaotfload-letterspace.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luaotfload/luaotfload-letterspace.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/luaotfload/luaotfload-letterspace.lua46
1 files changed, 28 insertions, 18 deletions
diff --git a/Master/texmf-dist/tex/luatex/luaotfload/luaotfload-letterspace.lua b/Master/texmf-dist/tex/luatex/luaotfload/luaotfload-letterspace.lua
index 007fa515b88..78df1d79ba1 100644
--- a/Master/texmf-dist/tex/luatex/luaotfload/luaotfload-letterspace.lua
+++ b/Master/texmf-dist/tex/luatex/luaotfload/luaotfload-letterspace.lua
@@ -28,9 +28,6 @@ local setfield = nodedirect.setfield
local field_setter = function (name) return function (n, ...) setfield (n, name, ...) end end
local field_getter = function (name) return function (n, ...) getfield (n, name, ...) end end
---- As of December 2014 the faster ``node.direct.*`` interface is
---- preferred.
-
local getfont = nodedirect.getfont
local getid = nodedirect.getid
@@ -277,7 +274,7 @@ local kernfactors = { } --- fontid -> factor
local kerncharacters
kerncharacters = function (head)
- local start, done = head, false
+ local start = head
local lastfont = nil
local keepligature = letterspace.keepligature --- function
local keeptogether = letterspace.keeptogether --- function
@@ -351,8 +348,7 @@ kerncharacters = function (head)
end
start = c
setfield(s, "components", nil)
- free_node(s)
- done = true
+ --free_node(s) --> double free with multipart components
c = getfield (start, "components")
end
end
@@ -378,7 +374,6 @@ kerncharacters = function (head)
local shrunk = (getfield(spec,"shrink") * newwd) / wd
setfield(prev, "spec",
spec_injector(fillup, newwd, stretched, shrunk))
- done = true
end
elseif pid == kern_code then
@@ -400,7 +395,6 @@ kerncharacters = function (head)
local prev_kern = getfield(prev, "kern")
prev_kern = prev_kern + quaddata[lastfont] * krn
setfield (prev, "kern", prev_kern)
- done = true
end
end
@@ -411,16 +405,23 @@ kerncharacters = function (head)
if keeptogether and keeptogether(prev, start) then
-- keep 'm
elseif identifiers[lastfont] then
- local kerns = chardata[lastfont] and chardata[lastfont][prevchar].kerns
- local kern = kerns and kerns[lastchar] or 0
- krn = kern + quaddata[lastfont]*krn -- here
- insert_node_before(head,start,kern_injector(fillup,krn))
- done = true
+ local lastfontchars = chardata[lastfont]
+ if lastfontchars then
+ local prevchardata = lastfontchars[prevchar]
+ if not prevchardata then
+ --- font doesn’t contain the glyph
+ else
+ local kern = 0
+ local kerns = prevchardata.kerns
+ if kerns then kern = kerns[lastchar] or kern end
+ krn = kern + quaddata[lastfont]*krn -- here
+ insert_node_before(head,start,kern_injector(fillup,krn))
+ end
+ end
end
else
krn = quaddata[lastfont]*krn -- here
insert_node_before(head,start,kern_injector(fillup,krn))
- done = true
end
elseif pid == disc_code then
@@ -477,10 +478,19 @@ kerncharacters = function (head)
and getid(prv) == glyph_code
and getfont(prv) == lastfont
then
+ local kern = 0
local prevchar = getchar(prv)
local lastchar = getchar(start)
- local kerns = chardata[lastfont] and chardata[lastfont][prevchar].kerns
- local kern = kerns and kerns[lastchar] or 0
+ local lastfontchars = chardata[lastfont]
+ if lastfontchars then
+ local prevchardata = lastfontchars[prevchar]
+ if not prevchardata then
+ --- font doesn’t contain the glyph
+ else
+ local kerns = prevchardata.kerns
+ if kerns then kern = kerns[lastchar] or kern end
+ end
+ end
krn = kern + quaddata[lastfont]*krn -- here
else
krn = quaddata[lastfont]*krn -- here
@@ -496,7 +506,7 @@ kerncharacters = function (head)
start = getnext(start)
end
end
- return head, done
+ return head
end
---=================================================================---
@@ -548,7 +558,7 @@ local enablefontkerning = function ( )
logreport ("term", 5, "letterspace",
"kerncharacters() invoked with node.direct interface \z
(``%s`` -> ``%s``)", tostring (hd), tostring (direct_hd))
- local direct_hd, _done = kerncharacters (direct_hd)
+ local direct_hd = kerncharacters (direct_hd)
if not direct_hd then --- bad
logreport ("both", 0, "letterspace",
"kerncharacters() failed to return a valid new head")