summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/libs-imp-zint.lmt
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkxl/libs-imp-zint.lmt')
-rw-r--r--tex/context/base/mkxl/libs-imp-zint.lmt64
1 files changed, 49 insertions, 15 deletions
diff --git a/tex/context/base/mkxl/libs-imp-zint.lmt b/tex/context/base/mkxl/libs-imp-zint.lmt
index 2c346ae7d..a3ac97584 100644
--- a/tex/context/base/mkxl/libs-imp-zint.lmt
+++ b/tex/context/base/mkxl/libs-imp-zint.lmt
@@ -28,8 +28,9 @@ utilities.zint = zint
local zintlib_execute = zintlib.execute
-local next, type, unpack = next, type, unpack
+local next, type, unpack, rawget = next, type, unpack, rawget
local lower, gsub = string.lower, string.gsub
+local formatters = string.formatters
local mapping = {
["code 11"] = 1, ["pharma one-track"] = 51, ["aztec code"] = 92,
@@ -65,6 +66,12 @@ local mapping = {
["logmars"] = 50, ["kix code"] = 90, ["rmqr"] = 145,
}
+for k, v in table.sortedhash(mapping) do
+ mapping[gsub(lower(k),"[^a-z0-9]","")]= v
+end
+
+mapping.qr = mapping.qrcode
+
table.setmetatableindex(mapping,function(t,k)
local s = gsub(lower(k),"[^a-z0-9]","")
local v = rawget(t,s) or false
@@ -76,7 +83,22 @@ local report = logs.reporter("zint")
local context = context
local shown = false
------ f_rectangle = string.formatters["%sofill unitsquare xysized (%N,%N) shifted (%N,%N);"]
+-- Same performance as just context(fmt,...): 113pps (On 2013 i7 laptop.)
+
+----- f_rectangle = formatters["%sofill unitsquare xysized (%N,%N) shifted (%N,%N);"]
+local f_hexagon = formatters["%sofill (%N,%N)--(%N,%N)--(%N,%N)--(%N,%N)--(%N,%N)--(%N,%N)--cycle;"]
+local f_circle = formatters["%sofill unitcircle scaled %N shifted (%N,%N);"]
+local f_string = formatters['draw textext("%s") scaled (%N/10) shifted (%N,%N);']
+
+-- A bit faster: 130pps (When I see hexagons I'll do that too but MP takes way more time.)
+
+local s_preamble = [[
+ save ns; def ns (expr a, b) = nofill unitsquare xyscaled a shifted b ; enddef;
+ save ds; def ds (expr a, b) = dofill unitsquare xyscaled a shifted b ; enddef;
+]]
+
+----- f_rectangle = formatters["%ss((%N,%N),(%N,%N));"]
+local f_rectangle = formatters["%ss((%i,%i),(%i,%i));"]
local function execute(specification)
if okay() then
@@ -90,6 +112,7 @@ local function execute(specification)
if result then
-- not that fast but if needed we can speed it up
context.startMPcode()
+ context(s_preamble)
local rectangles = result.rectangles
local hexagons = result.hexagons
local circles = result.circles
@@ -98,34 +121,45 @@ local function execute(specification)
local n = #rectangles
for i=1,n do
local r = rectangles[i]
- context("%sofill unitsquare xysized (%N,%N) shifted (%N,%N);",
- i == n and "d" or "n",r[3],r[4],r[1],r[2])
- -- rectangles[i] = f_rectangle(i == n and "d" or "n",r[3],r[4],r[1],r[2])
+ -- context("%sofill unitsquare xysized (%N,%N) shifted (%N,%N);",
+ rectangles[i] = f_rectangle(
+ i == n and "d" or "n",r[3],r[4],r[1],r[2]
+ )
end
- -- context("% t",rectangles)
+ context("% t",rectangles)
end
if hexagons then
local n = #hexagons
- for i=1,#hexagons do
- context("%sofill (%N,%N)--(%N,%N)--(%N,%N)--(%N,%N)--(%N,%N)--(%N,%N)--cycle;",
- i == n and "d" or "n",unpack(hexagons[i]))
+ for i=1,n do
+ -- context("%sofill (%N,%N)--(%N,%N)--(%N,%N)--(%N,%N)--(%N,%N)--(%N,%N)--cycle;",
+ hexagons[i] = f_hexagon(
+ i == n and "d" or "n",unpack(hexagons[i])
+ )
end
+ context("% t",hexagons)
end
if circles then
local n = #circles
- for i=1,#circles do
+ for i=1,n do
local c = circles[i]
- context("%sofill unitcircle scaled %N shifted (%N,%N);",
- i == n and "d" or "n",c[3],c[1],c[2])
+ -- context("%sofill unitcircle scaled %N shifted (%N,%N);",
+ circles[i] = f_circle(
+ i == n and "d" or "n",c[3],c[1],c[2]
+ )
end
+ context("% t",circles)
end
if strings then
-- We set the font at the encapsulating level.
- for i=1,#strings do
+ local n = #strings
+ for i=1,n do
local s = strings[i]
- context('draw textext("%s") scaled (%N/10) shifted (%N,%N);',
- s[4],s[3],s[1],s[2])
+ -- context('draw textext("%s") scaled (%N/10) shifted (%N,%N);',
+ strings[i] = f_string(
+ s[4],s[3],s[1],s[2]
+ )
end
+ context("% t",strings)
end
context.stopMPcode()
end