summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/node-aux.lua
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2011-06-01 08:54:21 +0000
committerTaco Hoekwater <taco@elvenkind.com>2011-06-01 08:54:21 +0000
commitd7ccb42582f85acf30568913610ccf4d602023fb (patch)
tree7292e3545a420676878e7451b68892d360c62cb6 /Master/texmf-dist/tex/context/base/node-aux.lua
parent2d62a6fe9b80def59c392268022f1f9a2d6e358f (diff)
commit context 2011.05.18
git-svn-id: svn://tug.org/texlive/trunk@22719 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/node-aux.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/node-aux.lua248
1 files changed, 211 insertions, 37 deletions
diff --git a/Master/texmf-dist/tex/context/base/node-aux.lua b/Master/texmf-dist/tex/context/base/node-aux.lua
index 9ed71fd728c..0b44f77248d 100644
--- a/Master/texmf-dist/tex/context/base/node-aux.lua
+++ b/Master/texmf-dist/tex/context/base/node-aux.lua
@@ -1,18 +1,46 @@
if not modules then modules = { } end modules ['node-aux'] = {
version = 1.001,
- comment = "companion to node-spl.mkiv",
+ 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"
}
-local gsub, format = string.gsub, string.format
+local type, tostring = type, tostring
-local free_node = node.free
-local hpack_nodes = node.hpack
-local node_fields = node.fields
+local nodes, node = nodes, node
-function nodes.repack_hlist(list,...)
+local utfvalues = string.utfvalues
+
+local nodecodes = nodes.nodecodes
+
+local glyph_code = nodecodes.glyph
+local hlist_code = nodecodes.hlist
+local vlist_code = nodecodes.vlist
+
+local nodepool = nodes.pool
+
+local new_glue = nodepool.glue
+local new_glyph = nodepool.glyph
+
+local traverse_nodes = node.traverse
+local traverse_id = node.traverse_id
+local free_node = node.free
+local hpack_nodes = node.hpack
+local has_attribute = node.has_attribute
+local set_attribute = node.set_attribute
+local get_attribute = node.get_attribute
+local unset_attribute = node.unset_attribute
+local first_glyph = node.first_glyph or node.first_character
+local copy_node = node.copy
+local slide_nodes = node.slide
+local insert_node_after = node.insert_after
+local isnode = node.is_node
+
+local texbox = tex.box
+
+function nodes.repackhlist(list,...)
+--~ nodes.showsimplelist(list)
local temp, b = hpack_nodes(list,...)
list = temp.list
temp.list = nil
@@ -20,47 +48,49 @@ function nodes.repack_hlist(list,...)
return list, b
end
-function nodes.merge(a,b)
- if a and b then
- local t = node.fields(a.id)
- for i=3,#t do
- local name = t[i]
- a[name] = b[name]
+local function set_attributes(head,attr,value)
+ for n in traverse_nodes(head) do
+ set_attribute(n,attr,value)
+ local id = n.id
+ if id == hlist_node or id == vlist_node then
+ set_attributes(n.list,attr,value)
end
end
- return a, b
end
-local fields, whatsitfields = { }, { }
-
-for k, v in next, node.types() do
- if v == "whatsit" then
- fields[k], fields[v] = { }, { }
- for kk, vv in next, node.whatsits() do
- local f = node_fields(k,kk)
- whatsitfields[kk], whatsitfields[vv] = f, f
+local function set_unset_attributes(head,attr,value)
+ for n in traverse_nodes(head) do
+ if not has_attribute(n,attr) then
+ set_attribute(n,attr,value)
+ end
+ local id = n.id
+ if id == hlist_code or id == vlist_code then
+ set_unset_attributes(n.list,attr,value)
end
- else
- local f = node_fields(k)
- fields[k], fields[v] = f, f
end
end
-nodes.fields, nodes.whatsitfields = fields, whatsitfields
-
-function nodes.info(n)
- local id = n.id
- local tp = node.type(id)
- local list = (tp == "whatsit" and whatsitfields[n.subtype]) or fields[id]
- logs.report(format("%14s","type"),tp)
- for k,v in next, list do
- logs.report(format("%14s",v),gsub(gsub(tostring(n[v]),"%s+"," "),"node ",""))
+local function unset_attributes(head,attr)
+ for n in traverse_nodes(head) do
+ unset_attribute(n,attr)
+ local id = n.id
+ if id == hlist_code or id == vlist_code then
+ unset_attributes(n.list,attr)
+ end
end
end
--- history:
---
--- local function cp_skipable(a,id) -- skipable nodes at the margins during character protrusion
+nodes.firstglyph = first_glyph
+nodes.setattribute = set_attribute
+nodes.getattribute = has_attribute
+nodes.unsetattribute = unset_attribute
+nodes.setattributes = set_attributes
+nodes.setunsetattributes = set_unset_attributes
+nodes.unsetattributes = unset_attributes
+
+nodes.has_attribute = has_attribute
+
+-- function nodes.is_skipable(a,id) -- skipable nodes at the margins during character protrusion
-- return (
-- id ~= glyph_node
-- or id == ins_node
@@ -75,6 +105,9 @@ end
-- or (id == whatsit_node and a.subtype ~= pdf_refximage_node and a.subtype ~= pdf_refxform_node)
-- )
-- end
+
+-- history:
+--
--
-- local function glyph_width(a)
-- local ch = chardata[a.font][a.char]
@@ -128,7 +161,7 @@ end
-- local u = floor(x / 0x8000) * n + f -- 0100000
-- local v = floor(u % d) * 0x8000 + f -- 0100000
-- if floor(u / d) >= 0x8000 then -- 0100000
--- logs.error("parbuilder",'arith_error')
+-- report_parbuilders('arith_error')
-- else
-- u = 0x8000 * floor(u / d) + floor(v / d) -- 0100000
-- end
@@ -143,3 +176,144 @@ end
-- end
-- end
+function nodes.firstcharacter(n,untagged) -- tagged == subtype > 255
+ if untagged then
+ return first_glyph(n)
+ else
+ for g in traverse_id(glyph_code,n) do
+ return g
+ end
+ end
+end
+
+function nodes.firstcharinbox(n)
+ local l = texbox[n].list
+ if l then
+ for g in traverse_id(glyph_code,l) do
+ return g.char
+ end
+ end
+ return 0
+end
+
+--~ local function firstline(n)
+--~ while n do
+--~ local id = n.id
+--~ if id == hlist_code then
+--~ if n.subtype == line_code then
+--~ return n
+--~ else
+--~ return firstline(n.list)
+--~ end
+--~ elseif id == vlist_code then
+--~ return firstline(n.list)
+--~ end
+--~ n = n.next
+--~ end
+--~ end
+
+--~ nodes.firstline = firstline
+
+-- this depends on fonts, so we have a funny dependency ... will be
+-- sorted out .. we could make tonodes a plugin into this
+
+local function tonodes(str,fnt,attr) -- (str,template_glyph) -- moved from blob-ini
+ if not str or str == "" then
+ return
+ end
+ local head, tail, space, fnt, template = nil, nil, nil, nil, nil
+ if not fnt then
+ fnt = current_font()
+ elseif type(fnt) ~= "number" and fnt.id == "glyph" then
+ fnt, template = nil, fnt
+ -- else
+ -- already a number
+ end
+ for s in utfvalues(str) do
+ local n
+ if s == 32 then
+ if space then
+ n = copy_node(space)
+ elseif fonts then -- depedency
+ local parameters = fonts.hashes.identifiers[fnt].parameters
+ space = new_glue(parameters.space,parameters.space_stretch,parameters.space_shrink)
+ n = space
+ end
+ elseif template then
+ n = copy_node(template)
+ n.char = s
+ else
+ n = new_glyph(fnt,s)
+ end
+ if attr then -- normally false when template
+ n.attr = copy_node_list(attr)
+ end
+ if head then
+ insert_node_after(head,tail,n)
+ else
+ head = n
+ end
+ tail = n
+ end
+ return head, tail
+end
+
+nodes.tonodes = tonodes
+
+local function link(head,tail,list,currentfont,currentattr)
+ for i=1,#list do
+ local n = list[i]
+ if n then
+ local tn = isnode(n)
+ if not tn then
+ local tn = type(n)
+ if tn == "number" then
+ local h, t = tonodes(tostring(n),currentfont,currentattr)
+ if not h then
+ -- skip
+ elseif not head then
+ head, tail = h, t
+ else
+ tail.next, h.prev, tail = h, t, t
+ end
+ elseif tn == "string" then
+ if #tn > 0 then
+ local h, t = tonodes(n,font.current(),currentattr)
+ if not h then
+ -- skip
+ elseif not head then
+ head, tail = h, t
+ else
+ tail.next, h.prev, tail = h, t, t
+ end
+ end
+ elseif tn == "table" then
+ if #tn > 0 then
+ head, tail = link(head,tail,n,currentfont,currentattr)
+ end
+ end
+ elseif not head then
+ head = n
+ if n.next then
+ tail = slide_nodes(n)
+ else
+ tail = n
+ end
+ else
+ tail.next = n
+ n.prev = tail
+ if n.next then
+ tail = slide_nodes(n)
+ else
+ tail = n
+ end
+ end
+ end
+ end
+ return head, tail
+end
+
+function nodes.link(...)
+ local currentfont = font.current
+ return link(nil,nil,{...},currentfont,currentattr)
+end