diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/util-dim.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/util-dim.lua | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/Master/texmf-dist/tex/context/base/util-dim.lua b/Master/texmf-dist/tex/context/base/util-dim.lua index 47e43c386e4..47b2706b736 100644 --- a/Master/texmf-dist/tex/context/base/util-dim.lua +++ b/Master/texmf-dist/tex/context/base/util-dim.lua @@ -16,10 +16,11 @@ table.</p> --ldx]]-- local format, match, gsub, type, setmetatable = string.format, string.match, string.gsub, type, setmetatable -local P, S, R, Cc, lpegmatch = lpeg.P, lpeg.S, lpeg.R, lpeg.Cc, lpeg.match +local P, S, R, Cc, C, lpegmatch = lpeg.P, lpeg.S, lpeg.R, lpeg.Cc, lpeg.C, lpeg.match local allocate = utilities.storage.allocate local setmetatableindex = table.setmetatableindex +local formatters = string.formatters --this might become another namespace @@ -86,6 +87,7 @@ local dimenfactors = allocate { format (string) is implemented using this table.</p> --ldx]]-- + local function numbertodimen(n,unit,fmt) if type(n) == 'string' then return n @@ -141,6 +143,12 @@ local dimenpair = amount/tonumber * (unit^1/dimenfactors + Cc(1)) -- tonumber is lpeg.patterns.dimenpair = dimenpair +local splitter = amount/tonumber * C(unit^1) + +function number.splitdimen(str) + return lpegmatch(splitter,str) +end + --[[ldx-- <p>We use a metatable to intercept errors. When no key is found in the table with factors, the metatable will be consulted for an @@ -430,12 +438,12 @@ probably use a hash instead of a one-element table.</p> <p>Goodie:s</p> --ldx]]-- -function number.percent(n) -- will be cleaned up once luatex 0.30 is out - local hsize = tex.hsize - if type(hsize) == "string" then - hsize = stringtodimen(hsize) +function number.percent(n,d) -- will be cleaned up once luatex 0.30 is out + d = d or tex.hsize + if type(d) == "string" then + d = stringtodimen(d) end - return (n/100) * hsize + return (n/100) * d end number["%"] = number.percent |