From c10ee230c83a5dfcda077652c2b16bc8f8a9d221 Mon Sep 17 00:00:00 2001
From: Khaled Hosny
We use a metatable to intercept errors. When no key is found in @@ -149,7 +149,7 @@ function string:todimen() if type(self) == "number" then return self else - local value, unit = lpegmatch(pattern,self) + local value, unit = lpegmatch(dimenpair,self) return value/unit end end @@ -158,7 +158,7 @@ local amount = S("+-")^0 * R("09")^0 * S(".,")^0 * R("09")^0 local unit = P("pt") + P("cm") + P("mm") + P("sp") + P("bp") + P("in") + P("pc") + P("dd") + P("cc") + P("nd") + P("nc") -local pattern = amount * unit +local validdimen = amount * unit lpeg.patterns.validdimen = pattern @@ -166,12 +166,12 @@ lpeg.patterns.validdimen = pattern
This converter accepts calls like:
And of course the often more efficient:
@@ -371,7 +371,7 @@ function dimen(a) if k then a = k else - local value, unit = lpegmatch(pattern,a) + local value, unit = lpegmatch(dimenpair,a) if type(unit) == "function" then k = value/unit() else @@ -395,7 +395,7 @@ function string:todimen() else local k = known[self] if not k then - local value, unit = lpegmatch(pattern,self) + local value, unit = lpegmatch(dimenpair,self) if value and unit then k = value/unit else @@ -408,6 +408,10 @@ function string:todimen() end end +function number.toscaled(d) + return format("0.5f",d/2^16) +end + --[[ldx--In a similar fashion we can define a glue datatype. In that case we probably use a hash instead of a one-element table.
-- cgit v1.2.3