summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/good-ctx.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/good-ctx.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/good-ctx.lua84
1 files changed, 75 insertions, 9 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/good-ctx.lua b/Master/texmf-dist/tex/context/base/mkiv/good-ctx.lua
index 82ef25e29de..00e4ed78d89 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/good-ctx.lua
+++ b/Master/texmf-dist/tex/context/base/mkiv/good-ctx.lua
@@ -29,10 +29,14 @@ 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 nextglyph = nuts.traversers.glyph
+local traverse_id = nuts.traverse_id
-- colorschemes
@@ -96,10 +100,10 @@ local function setcolorscheme(tfmdata,scheme)
end
end
if privatestoo then
- local privateoffset = fonts.constructors.privateoffset
- local descriptions = tfmdata.descriptions
+ local private = fonts.constructors.privateoffset
+ local descriptions = tfmdata.descriptions
for unicode, data in next, characters do
- if unicode >= privateoffset then
+ if unicode >= private then
if not reverse[unicode] then
local d = descriptions[unicode]
if d then
@@ -124,9 +128,68 @@ local function setcolorscheme(tfmdata,scheme)
end
local fontproperties = fonts.hashes.properties
+
local a_colorscheme = attributes.private('colorscheme')
local setnodecolor = nodes.tracers.colors.set
-local cache = { } -- this could be a weak table
+
+-- 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
setmetatableindex(cache,function(t,a)
local v = { }
@@ -144,9 +207,11 @@ function colorschemes.coloring(head)
local lastattr = nil
local lastcache = nil
local lastscheme = nil
- for n, char, f in nextglyph, head do
+ local done = nil
+ 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
lastfont = f
lastscheme = fontproperties[f].colorscheme
@@ -156,18 +221,19 @@ function colorschemes.coloring(head)
lastcache = cache[a]
end
if lastscheme then
- local sc = lastscheme[char]
+ 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
+ return head, done
end
function colorschemes.enable()
- nodes.tasks.enableaction("processors","fonts.goodies.colorschemes.coloring")
+ nodes.tasks.appendaction("processors","fonts","fonts.goodies.colorschemes.coloring")
function colorschemes.enable() end
end