summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/typo-rep.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-01-12 17:15:07 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-01-12 17:15:07 +0100
commit8d8d528d2ad52599f11250cfc567fea4f37f2a8b (patch)
tree94286bc131ef7d994f9432febaf03fe23d10eef8 /tex/context/base/mkiv/typo-rep.lua
parentf5aed2e51223c36c84c5f25a6cad238b2af59087 (diff)
downloadcontext-8d8d528d2ad52599f11250cfc567fea4f37f2a8b.tar.gz
2016-01-12 16:26:00
Diffstat (limited to 'tex/context/base/mkiv/typo-rep.lua')
-rw-r--r--tex/context/base/mkiv/typo-rep.lua145
1 files changed, 145 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/typo-rep.lua b/tex/context/base/mkiv/typo-rep.lua
new file mode 100644
index 000000000..d95eff68e
--- /dev/null
+++ b/tex/context/base/mkiv/typo-rep.lua
@@ -0,0 +1,145 @@
+if not modules then modules = { } end modules ['typo-rep'] = {
+ version = 1.001,
+ comment = "companion to node-ini.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- This was rather boring to program (more of the same) but I could
+-- endure it by listening to a couple cd's by The Scene and The Lau
+-- on the squeezebox on my desk.
+
+local next, type, tonumber = next, type, tonumber
+
+local trace_stripping = false trackers.register("nodes.stripping", function(v) trace_stripping = v end)
+ trackers.register("fonts.stripping", function(v) trace_stripping = v end)
+
+local report_stripping = logs.reporter("fonts","stripping")
+
+local nodes = nodes
+local tasks = nodes.tasks
+
+local nuts = nodes.nuts
+local tonut = nuts.tonut
+local tonode = nuts.tonode
+
+local getnext = nuts.getnext
+local getchar = nuts.getchar
+local getid = nuts.getid
+
+local getattr = nuts.getattr
+
+local delete_node = nuts.delete
+local replace_node = nuts.replace
+local copy_node = nuts.copy
+
+local nodecodes = nodes.nodecodes
+local glyph_code = nodecodes.glyph
+
+local chardata = characters.data
+local collected = false
+local fontdata = fonts.hashes.identifiers
+
+local a_stripping = attributes.private("stripping")
+local texsetattribute = tex.setattribute
+local unsetvalue = attributes.unsetvalue
+
+local v_reset = interfaces.variables.reset
+
+-- todo: other namespace -> typesetters
+
+nodes.stripping = nodes.stripping or { } local stripping = nodes.stripping
+stripping.glyphs = stripping.glyphs or { } local glyphs = stripping.glyphs
+
+local function initialize()
+ for k,v in next, chardata do
+ if v.category == "cf" and v.visible ~= "yes" then
+ if not glyphs[k] then
+ glyphs[k] = true
+ end
+ end
+ end
+ initialize = nil
+end
+
+local function process(what,head,current,char)
+ if what == true then
+ if trace_stripping then
+ report_stripping("deleting %C from text",char)
+ end
+ head, current = delete_node(head,current)
+ elseif type(what) == "function" then
+ head, current = what(head,current)
+ current = getnext(current)
+ if trace_stripping then
+ report_stripping("processing %C in text",char)
+ end
+ elseif what then -- assume node
+ head, current = replace_node(head,current,copy_node(what))
+ current = getnext(current)
+ if trace_stripping then
+ report_stripping("replacing %C in text",char)
+ end
+ end
+ return head, current
+end
+
+function nodes.handlers.stripping(head)
+ head = tonut(head)
+ local current, done = head, false
+ while current do
+ if getid(current) == glyph_code then
+ -- it's more efficient to keep track of what needs to be kept
+ local todo = getattr(current,a_stripping)
+ if todo == 1 then
+ local char = getchar(current)
+ local what = glyphs[char]
+ if what then
+ head, current = process(what,head,current,char)
+ done = true
+ else -- handling of spacing etc has to be done elsewhere
+ current = getnext(current)
+ end
+ else
+ current = getnext(current)
+ end
+ else
+ current = getnext(current)
+ end
+ end
+ return tonode(head), done
+end
+
+local enabled = false
+
+function stripping.set(n) -- number or 'reset'
+ if n == v_reset then
+ n = unsetvalue
+ else
+ n = tonumber(n)
+ if n then
+ if not enabled then
+ if initialize then initialize() end
+ tasks.enableaction("processors","nodes.handlers.stripping")
+ enabled = true
+ end
+ else
+ n = unsetvalue
+ end
+ end
+ texsetattribute(a_stripping,n)
+end
+
+-- why not in task-ini?
+
+tasks.appendaction("processors","fonts","nodes.handlers.stripping",nil,"nodes.handlers.characters")
+tasks.disableaction("processors","nodes.handlers.stripping")
+
+-- interface
+
+interfaces.implement {
+ name = "setcharacterstripping",
+ actions = stripping.set,
+ arguments = "string"
+}