diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/node-aux.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/node-aux.lua | 425 |
1 files changed, 21 insertions, 404 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/node-aux.lua b/Master/texmf-dist/tex/context/base/mkiv/node-aux.lua index d13db4bbaf5..d3c537a3bce 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/node-aux.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/node-aux.lua @@ -21,8 +21,7 @@ local glyph_code = nodecodes.glyph local hlist_code = nodecodes.hlist local vlist_code = nodecodes.vlist local attributelist_code = nodecodes.attributelist -- temporary -local localpar_code = nodecodes.localpar -local ligatureglyph_code = nodes.glyphcodes.ligature +local par_code = nodecodes.par local nuts = nodes.nuts local tonut = nuts.tonut @@ -48,7 +47,6 @@ local setlink = nuts.setlink local setlist = nuts.setlist local setnext = nuts.setnext local setprev = nuts.setprev -local setcomponents = nuts.setcomponents local setattrlist = nuts.setattrlist local traversers = nuts.traversers @@ -382,167 +380,11 @@ function nodes.rehpack(n,...) rehpack(tonut(n),...) end -if CONTEXTLMTXMODE > 0 then - - local fastcopy = table.fastcopy - local getprop = nuts.getprop - local setprop = nuts.setprop - - local function set_components(base,list) - local t = { } - local n = 0 - while list do - local char = isglyph(list) - if char then - n = n + 1 - t[n] = char - end - list = getnext(list) - end - setprop(base,"components",n > 0 and t or false) - end - - local function get_components(base) - return getprop(base,"components") - end - - local function copy_no_components(base) - local copy = copy_node(base) - setprop(copy,"components",false) -- no metatable lookup! - return copy - end - - local function copy_only_glyphs(base) - local t = getprop(base,"components") -- also metatable - if t then - return fastcopy(t) - end - end - - local function do_count(t,marks) - local n = 0 - if t then - for i=1,#t do - local c = t[i] - if type(c) == "table" then - n = n + do_count(t,marks) - elseif not marks[c] then - n = n + 1 - else - --marks don't count - end - end - end - return n - end - - -- start is a mark and we need to keep that one - - local done = false - - local function count_components(base,marks) - local char = isglyph(base) - if char then - if getsubtype(base) == ligatureglyph_code then - if not done then - logs.report("fonts","!") - logs.report("fonts","! check count_components with mkiv !") - logs.report("fonts","!") - done = true - end - local t = getprop(base,"components") - if t then - return do_count(t,marks) - end - elseif not marks[char] then - return 1 - end - end - return 0 - end - - nuts.set_components = set_components - nuts.get_components = get_components - nuts.copy_only_glyphs = copy_only_glyphs - nuts.copy_no_components = copy_no_components - nuts.count_components = count_components - -else - - local get_components = node.direct.getcomponents - local set_components = node.direct.setcomponents - - local function copy_no_components(g,copyinjection) - local components = get_components(g) - if components then - set_components(g) - local n = copy_node(g) - if copyinjection then - copyinjection(n,g) - end - set_components(g,components) - -- maybe also upgrade the subtype but we don't use it anyway - return n - else - local n = copy_node(g) - if copyinjection then - copyinjection(n,g) - end - return n - end - end - - local function copy_only_glyphs(current) - local head = nil - local previous = nil - for n in nextglyph, current do - n = copy_node(n) - if head then - setlink(previous,n) - else - head = n - end - previous = n - end - return head - end - - -- start is a mark and we need to keep that one - - local function count_components(start,marks) - local char = isglyph(start) - if char then - if getsubtype(start) == ligatureglyph_code then - local n = 0 - local components = get_components(start) - while components do - n = n + count_components(components,marks) - components = getnext(components) - end - return n - elseif not marks[char] then - return 1 - end - end - return 0 - end - - nuts.set_components = set_components - nuts.get_components = get_components - nuts.copy_only_glyphs = copy_only_glyphs - nuts.copy_no_components = copy_no_components - nuts.count_components = count_components - -end - -nuts.setcomponents = function() report_error("unsupported: %a","setcomponents") end -nuts.getcomponents = function() report_error("unsupported: %a","getcomponents") end - do - local localparcodes = nodes.localparcodes - local hmodepar_code = localparcodes.vmode_par - local vmodepar_code = localparcodes.hmode_par + local parcodes = nodes.parcodes + local hmodepar_code = parcodes.vmode_par + local vmodepar_code = parcodes.hmode_par local getnest = tex.getnest local getsubtype = nuts.getsubtype @@ -550,7 +392,7 @@ do function nuts.setparproperty(action,...) local tail = tonut(getnest().tail) while tail do - if getid(tail) == localpar_code then + if getid(tail) == par_code then local s = getsubtype(tail) if s == hmodepar_code or s == vmodepar_code then return action(tail,...) @@ -571,10 +413,7 @@ do end --- Currently only in luametatex ... experimental anyway .. if it doesn't end --- up in luatex I'll move this to a different module. - -do +if not nuts.getnormalizedline then local nextnode = traversers.glue local findfail = nuts.tail @@ -617,14 +456,12 @@ do nuts.find_node = find_node - nodes.getnormalizeline = node.getnormalizeline or function() return 0 end - nodes.setnormalizeline = node.setnormalizeline or function() end - - nuts.getnormalizedline = direct.getnormalizedline or function(h) + function nuts.getnormalizedline(h) if getid(h) == hlist_code and getsubtype(h) == line_code then local ls, rs = 0, 0 local lh, rh = 0, 0 - local is, ps = 0, 0 + local lp, rp = 0, 0 + local is = 0 local h = getlist(h) local t = findtail(h) for n, subtype in nextglue, h do @@ -633,241 +470,21 @@ do elseif subtype == lefthangskip_code then lh = getwidth(n) elseif subtype == righthangskip_code then rh = getwidth(n) elseif subtype == indentskip_code then is = getwidth(n) - elseif subtype == parfillskip_code then ps = getwidth(n) + elseif subtype == parfillskip_code then rp = getwidth(n) end end - return ls, rs, lh, rh, is, ps, h, t - end - end - -end - -if not nodes.count then - - local type = type - - local direct = node.direct - local todirect = direct.tovaliddirect - local tonode = direct.tonode - - local count = direct.count - local length = direct.length - local slide = direct.slide - - function node.count(id,first,last) - return count(id,first and todirect(first), last and todirect(last) or nil) - end - - function node.length(first,last) - return length(first and todirect(first), last and todirect(last) or nil) - end - - function node.slide(n) - if n then - n = slide(todirect(n)) - if n then - return tonode(n) - end - end - return nil - end - - local hyphenating = direct.hyphenating - local ligaturing = direct.ligaturing - local kerning = direct.kerning - - -- kind of inconsistent - - function node.hyphenating(first,last) - if first then - local h, t = hyphenating(todirect(first), last and todirect(last) or nil) - return h and tonode(h) or nil, t and tonode(t) or nil, true - else - return nil, false - end - end - - function node.ligaturing(first,last) - if first then - local h, t = ligaturing(todirect(first), last and todirect(last) or nil) - return h and tonode(h) or nil, t and tonode(t) or nil, true - else - return nil, false - end - end - - function node.kerning(first,last) - if first then - local h, t = kerning(todirect(first), last and todirect(last) or nil) - return h and tonode(h) or nil, t and tonode(t) or nil, true - else - return nil, false - end - end - - local protect_glyph = direct.protect_glyph - local unprotect_glyph = direct.unprotect_glyph - local protect_glyphs = direct.protect_glyphs - local unprotect_glyphs = direct.unprotect_glyphs - - function node.protect_glyphs(first,last) - protect_glyphs(todirect(first), last and todirect(last) or nil) - end - - function node.unprotect_glyphs(first,last) - unprotect_glyphs(todirect(first), last and todirect(last) or nil) - end - - function node.protect_glyph(first) - protect_glyph(todirect(first)) - end - - function node.unprotect_glyph(first) - unprotect_glyph(todirect(first)) - end - - local flatten_discretionaries = direct.flatten_discretionaries - local check_discretionaries = direct.check_discretionaries - local check_discretionary = direct.check_discretionary - - function node.flatten_discretionaries(first) - local h, count = flatten_discretionaries(todirect(first)) - return tonode(h), count - end - - function node.check_discretionaries(n) - check_discretionaries(todirect(n)) - end - - function node.check_discretionary(n) - check_discretionary(todirect(n)) - end - - local hpack = direct.hpack - local vpack = direct.vpack - local list_to_hlist = direct.mlist_to_hlist - - function node.hpack(head,...) - local h, badness = hpack(head and todirect(head) or nil,...) - return tonode(h), badness - end - - function node.vpack(head,...) - local h, badness = vpack(head and todirect(head) or nil,...) - return tonode(h), badness - end - - function node.mlist_to_hlist(head,...) - return tonode(mlist_to_hlist(head and todirect(head) or nil,...)) - end - - local end_of_math = direct.end_of_math - local find_attribute = direct.find_attribute - local first_glyph = direct.first_glyph - - function node.end_of_math(n) - if n then - n = end_of_math(todirect(n)) - if n then - return tonode(n) - end - end - return nil - end - - function node.find_attribute(n,a) - if n then - local v, n = find_attribute(todirect(n),a) - if n then - return v, tonode(n) - end + return { + leftskip = ls, + rightskip = rs, + lefthangskip = lh, + righthangskip = rh, + indent = is, + parfillrightskip = rp, + parfillleftskip = lp, + head = h, + tail = t, + } end - return nil - end - - function node.first_glyph(first,last) - local n = first_glyph(todirect(first), last and todirect(last) or nil) - return n and tonode(n) or nil - end - - local dimensions = direct.dimensions - local rangedimensions = direct.rangedimensions - local effective_glue = direct.effective_glue - - function node.dimensions(a,b,c,d,e) - if type(a) == "userdata" then - a = todirect(a) - if type(b) == "userdata" then - b = todirect(b) - end - return dimensions(a,b) - else - d = todirect(d) - if type(e) == "userdata" then - e = todirect(e) - end - return dimensions(a,b,c,d,e) - end - return 0, 0, 0 - end - - function node.rangedimensions(parent,first,last) - return rangedimenensions(todirect(parent),todirect(first),last and todirect(last)) - end - - function node.effective_glue(list,parent) - return effective_glue(list and todirect(list) or nil,parent and todirect(parent) or nil) - end - - local uses_font = direct.uses_font - local has_glyph = direct.has_glyph - local protrusion_skippable = direct.protrusion_skippable - local prepend_prevdepth = direct.prepend_prevdepth - local make_extensible = direct.make_extensible - - function node.uses_font(n,f) - return uses_font(todirect(n),f) - end - - function node.has_glyph(n) - return has_glyph(todirect(n)) - end - - function node.protrusion_skippable(n) - return protrusion_skippable(todirect(n)) - end - - function node.prepend_prevdepth(n) - local n, d = prepend_prevdepth(todirect(n)) - return tonode(n), d - end - - function node.make_extensible(...) - local n = make_extensible(...) - return n and tonode(n) or nil - end - - local last_node = direct.last_node - - function node.last_node() - local n = last_node() - return n and tonode(n) or nil - end - - local is_zero_glue = direct.is_zero_glue - local getglue = direct.getglue - local setglue = direct.setglue - - function node.is_zero_glue(n) - return is_zero_glue(todirect(n)) - end - - function node.get_glue(n) - return get_glue(todirect(n)) - end - - function node.set_glue(n) - return set_glue(todirect(n)) end end |