summaryrefslogtreecommitdiff
path: root/tex/context/base/node-tra.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/node-tra.lua')
-rw-r--r--tex/context/base/node-tra.lua216
1 files changed, 155 insertions, 61 deletions
diff --git a/tex/context/base/node-tra.lua b/tex/context/base/node-tra.lua
index 5f060e4f3..4d5ae5aca 100644
--- a/tex/context/base/node-tra.lua
+++ b/tex/context/base/node-tra.lua
@@ -78,6 +78,7 @@ local localpar_code = whatcodes.localpar
local dir_code = whatcodes.dir
local dimenfactors = number.dimenfactors
+local fillorders = nodes.fillcodes
local formatters = string.formatters
-- this will be reorganized:
@@ -358,82 +359,175 @@ local stripper = lpeg.patterns.stripzeros
--
-- redefined:
-local dimenfactors = number.dimenfactors
+-- local function nodetodimen(d,unit,fmt,strip)
+-- d = tonut(d) -- tricky: direct nuts are an issue
+-- if unit == true then
+-- unit = "pt"
+-- fmt = "%0.5f%s"
+-- else
+-- unit = unit or 'pt'
+-- if not fmt then
+-- fmt = "%s%s"
+-- elseif fmt == true then
+-- fmt = "%0.5f%s"
+-- end
+-- end
+-- local id = getid(d)
+-- if id == kern_code then
+-- local str = formatters[fmt](getfield(d,"width")*dimenfactors[unit],unit)
+-- return strip and lpegmatch(stripper,str) or str
+-- end
+-- if id == glue_code then
+-- d = getfield(d,"spec")
+-- end
+-- if not d or not getid(d) == gluespec_code then
+-- local str = formatters[fmt](0,unit)
+-- return strip and lpegmatch(stripper,str) or str
+-- end
+-- local width = getfield(d,"width")
+-- local plus = getfield(d,"stretch_order")
+-- local minus = getfield(d,"shrink_order")
+-- local stretch = getfield(d,"stretch")
+-- local shrink = getfield(d,"shrink")
+-- if plus ~= 0 then
+-- plus = " plus " .. stretch/65536 .. fillcodes[plus]
+-- elseif stretch ~= 0 then
+-- plus = formatters[fmt](stretch*dimenfactors[unit],unit)
+-- plus = " plus " .. (strip and lpegmatch(stripper,plus) or plus)
+-- else
+-- plus = ""
+-- end
+-- if minus ~= 0 then
+-- minus = " minus " .. shrink/65536 .. fillcodes[minus]
+-- elseif shrink ~= 0 then
+-- minus = formatters[fmt](shrink*dimenfactors[unit],unit)
+-- minus = " minus " .. (strip and lpegmatch(stripper,minus) or minus)
+-- else
+-- minus = ""
+-- end
+-- local str = formatters[fmt](getfield(d,"width")*dimenfactors[unit],unit)
+-- return (strip and lpegmatch(stripper,str) or str) .. plus .. minus
+-- end
+--
+-- local function numbertodimen(d,unit,fmt,strip)
+-- if not d then
+-- local str = formatters[fmt](0,unit)
+-- return strip and lpegmatch(stripper,str) or str
+-- end
+-- local t = type(d)
+-- if t == 'string' then
+-- return d
+-- elseif t == "number" then
+-- if unit == true then
+-- unit = "pt"
+-- fmt = "%0.5f%s"
+-- else
+-- unit = unit or 'pt'
+-- if not fmt then
+-- fmt = "%s%s"
+-- elseif fmt == true then
+-- fmt = "%0.5f%s"
+-- end
+-- end
+-- local str = formatters[fmt](d*dimenfactors[unit],unit)
+-- return strip and lpegmatch(stripper,str) or str
+-- else
+-- return nodetodimen(d,unit,fmt,strip) -- real node
+-- end
+-- end
-local function nodetodimen(d,unit,fmt,strip)
- d = tonut(d) -- tricky: direct nuts are an issue
- if unit == true then
- unit = "pt"
- fmt = "%0.5f%s"
- else
- unit = unit or 'pt'
- if not fmt then
- fmt = "%s%s"
- elseif fmt == true then
- fmt = "%0.5f%s"
- end
- end
- local id = getid(d)
+local f_f_f = formatters["%0.5Fpt plus %0.5F%s minus %0.5F%s"]
+local f_f_m = formatters["%0.5Fpt plus %0.5F%s minus %0.5Fpt"]
+local f_p_f = formatters["%0.5Fpt plus %0.5Fpt minus %0.5F%s"]
+local f_p_m = formatters["%0.5Fpt plus %0.5Fpt minus %0.5Fpt"]
+local f_f_z = formatters["%0.5Fpt plus %0.5F%s"]
+local f_p_z = formatters["%0.5Fpt plus %0.5Fpt"]
+local f_z_f = formatters["%0.5Fpt minus %0.5F%s"]
+local f_z_m = formatters["%0.5Fpt minus %0.5Fpt"]
+local f_z_z = formatters["%0.5Fpt"]
+
+local tonut = nodes.tonut
+local getfield = nodes.nuts.getfield
+
+local function nodetodimen(n)
+ n = tonut(n)
+ local id = getid(n)
if id == kern_code then
- local str = formatters[fmt](getfield(d,"width")*dimenfactors[unit],unit)
- return strip and lpegmatch(stripper,str) or str
+ local width = getfield(n,"width")
+ if width == 0 then
+ return "0pt"
+ else
+ return f_z_z(width)
+ end
end
if id == glue_code then
- d = getfield(d,"spec")
+ n = getfield(n,"spec")
end
- if not d or not getid(d) == gluespec_code then
- local str = formatters[fmt](0,unit)
- return strip and lpegmatch(stripper,str) or str
+ if not n or not getid(n) == gluespec_code then
+ return "0pt"
end
- local width = getfield(d,"width")
- local plus = getfield(d,"stretch_order")
- local minus = getfield(d,"shrink_order")
- local stretch = getfield(d,"stretch")
- local shrink = getfield(d,"shrink")
- if plus ~= 0 then
- plus = " plus " .. stretch/65536 .. fillcodes[plus]
+ local stretch_order = getfield(n,"stretch_order")
+ local shrink_order = getfield(n,"shrink_order")
+ local stretch = getfield(n,"stretch") / 65536
+ local shrink = getfield(n,"shrink") / 65536
+ local width = getfield(n,"width") / 65536
+ if stretch_order ~= 0 then
+ if shrink_order ~= 0 then
+ return f_f_f(width,stretch,fillorders[stretch_order],shrink,fillorders[shrink_order])
+ elseif shrink ~= 0 then
+ return f_f_m(width,stretch,fillorders[stretch_order],shrink)
+ else
+ return f_f_z(width,stretch,fillorders[stretch_order])
+ end
+ elseif shrink_order ~= 0 then
+ if stretch ~= 0 then
+ return f_p_f(width,stretch,shrink,fillorders[shrink_order])
+ else
+ return f_z_f(width,shrink,fillorders[shrink_order])
+ end
elseif stretch ~= 0 then
- plus = formatters[fmt](stretch*dimenfactors[unit],unit)
- plus = " plus " .. (strip and lpegmatch(stripper,plus) or plus)
- else
- plus = ""
- end
- if minus ~= 0 then
- minus = " minus " .. shrink/65536 .. fillcodes[minus]
+ if shrink ~= 0 then
+ return f_p_m(width,stretch,shrink)
+ else
+ return f_p_z(width,stretch)
+ end
elseif shrink ~= 0 then
- minus = formatters[fmt](shrink*dimenfactors[unit],unit)
- minus = " minus " .. (strip and lpegmatch(stripper,minus) or minus)
+ return f_z_m(width,shrink)
+ elseif width == 0 then
+ return "0pt"
else
- minus = ""
+ return f_z_z(width)
end
- local str = formatters[fmt](getfield(d,"width")*dimenfactors[unit],unit)
- return (strip and lpegmatch(stripper,str) or str) .. plus .. minus
end
-local function numbertodimen(d,unit,fmt,strip)
- if not d then
- local str = formatters[fmt](0,unit)
- return strip and lpegmatch(stripper,str) or str
- end
- local t = type(d)
- if t == 'string' then
- return d
- elseif t == "number" then
- if unit == true then
- unit = "pt"
- fmt = "%0.5f%s"
+
+-- number.todimen(123)
+-- number.todimen(123,"cm")
+-- number.todimen(123,false,"%F))
+
+local f_pt = formatters["%p"]
+local f_un = formatters["%F%s"]
+
+dimenfactors[""] = dimenfactors.pt
+
+local function numbertodimen(d,unit,fmt)
+ if not d or d == 0 then
+ if not unit or unit == "pt" then
+ return "0pt"
+ elseif fmt then
+ return formatters[fmt](0,unit)
else
- unit = unit or 'pt'
- if not fmt then
- fmt = "%s%s"
- elseif fmt == true then
- fmt = "%0.5f%s"
- end
+ return 0 .. unit
+ end
+ elseif fmt then
+ if not unit then
+ unit = "pt"
end
- local str = formatters[fmt](d*dimenfactors[unit],unit)
- return strip and lpegmatch(stripper,str) or str
+ return formatters[fmt](d*dimenfactors[unit],unit)
+ elseif not unit or unit == "pt" then
+ return f_pt(d)
else
- return nodetodimen(d,unit,fmt,strip) -- real node
+ return f_un(d*dimenfactors[unit],unit)
end
end