summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/good-ctx.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/good-ctx.lua')
-rw-r--r--tex/context/base/mkiv/good-ctx.lua105
1 files changed, 37 insertions, 68 deletions
diff --git a/tex/context/base/mkiv/good-ctx.lua b/tex/context/base/mkiv/good-ctx.lua
index 00e4ed78d..c4c632ae9 100644
--- a/tex/context/base/mkiv/good-ctx.lua
+++ b/tex/context/base/mkiv/good-ctx.lua
@@ -29,14 +29,13 @@ local registerotffeature = fonts.handlers.otf.features.register
local fontgoodies = fonts.goodies or { }
-local glyph_code = nodes.nodecodes.glyph
-
local nuts = nodes.nuts
local tonut = nuts.tonut
local getfont = nuts.getfont
local getchar = nuts.getchar
local getattr = nuts.getattr
-local traverse_id = nuts.traverse_id
+
+local nextglyph = nuts.traversers.glyph
-- colorschemes
@@ -128,68 +127,9 @@ local function setcolorscheme(tfmdata,scheme)
end
local fontproperties = fonts.hashes.properties
-
local a_colorscheme = attributes.private('colorscheme')
local setnodecolor = nodes.tracers.colors.set
-
--- function colorschemes.coloring(head)
--- local lastfont, lastscheme
--- local done = false
--- for n in traverse_id(glyph_code,tonut(head)) do
--- local a = getattr(n,a_colorscheme)
--- if a then
--- local f = getfont(n)
--- if f ~= lastfont then
--- lastscheme = fontproperties[f].colorscheme
--- lastfont = f
--- end
--- if lastscheme then
--- local sc = lastscheme[getchar(n)]
--- if sc then
--- done = true
--- setnodecolor(n,"colorscheme:"..a..":"..sc) -- slow
--- end
--- end
--- end
--- end
--- return head, done
--- end
-
--- seldom used, mostly in manuals, so non critical .. anyhow, somewhat faster:
-
--- function colorschemes.coloring(head)
--- local lastfont = nil
--- local lastattr = nil
--- local lastscheme = nil
--- local lastprefix = nil
--- local done = nil
--- for n in traverse_id(glyph_code,tonut(head)) do
--- local a = getattr(n,a_colorscheme)
--- if a then
--- if a ~= lastattr then
--- lastattr = a
--- lastprefix = "colorscheme:" .. a .. ":"
--- end
--- local f = getfont(n)
--- if f ~= lastfont then
--- lastfont = f
--- lastscheme = fontproperties[f].colorscheme
--- end
--- if lastscheme then
--- local sc = lastscheme[getchar(n)]
--- if sc then
--- setnodecolor(n,lastprefix .. sc) -- slow
--- done = true
--- end
--- end
--- end
--- end
--- return head, done
--- end
-
--- ok, in case we have hundreds of pages colored:
-
-local cache = { } -- this could be a weak table
+local cache = { } -- this could be a weak table
setmetatableindex(cache,function(t,a)
local v = { }
@@ -207,8 +147,7 @@ function colorschemes.coloring(head)
local lastattr = nil
local lastcache = nil
local lastscheme = nil
- local done = nil
- for n in traverse_id(glyph_code,tonut(head)) do
+ for n in nextglyph, head do
local a = getattr(n,a_colorscheme)
if a then
local f = getfont(n)
@@ -224,16 +163,46 @@ function colorschemes.coloring(head)
local sc = lastscheme[getchar(n)]
if sc then
setnodecolor(n,lastcache[sc]) -- we could inline this one
- done = true
end
end
end
end
- return head, done
+ return head
+end
+
+if LUATEXVERSION >= 1.090 then
+
+ function colorschemes.coloring(head)
+ local lastfont = nil
+ local lastattr = nil
+ local lastcache = nil
+ local lastscheme = nil
+ for n, f, char in nextglyph, head do
+ local a = getattr(n,a_colorscheme)
+ if a then
+ if f ~= lastfont then
+ lastfont = f
+ lastscheme = fontproperties[f].colorscheme
+ end
+ if a ~= lastattr then
+ lastattr = a
+ lastcache = cache[a]
+ end
+ if lastscheme then
+ local sc = lastscheme[char]
+ if sc then
+ setnodecolor(n,lastcache[sc]) -- we could inline this one
+ end
+ end
+ end
+ end
+ return head
+ end
+
end
function colorschemes.enable()
- nodes.tasks.appendaction("processors","fonts","fonts.goodies.colorschemes.coloring")
+ nodes.tasks.enableaction("processors","fonts.goodies.colorschemes.coloring")
function colorschemes.enable() end
end