From 1af3de21e3d70133c5c9b1898256b41c3515b66a Mon Sep 17 00:00:00 2001 From: Marius Date: Fri, 2 Aug 2013 23:01:03 +0300 Subject: beta 2013.08.02 21:57 --- tex/context/base/back-pdf.lua | 47 +++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) (limited to 'tex/context/base/back-pdf.lua') diff --git a/tex/context/base/back-pdf.lua b/tex/context/base/back-pdf.lua index f9115375c..a4c0d4b00 100644 --- a/tex/context/base/back-pdf.lua +++ b/tex/context/base/back-pdf.lua @@ -26,23 +26,13 @@ local context = context local sind, cosd = math.sind, math.cosd local insert, remove = table.insert, table.remove --- function commands.pdfrotation(a) -- somewhat weird here --- local s, c = sind(a), cosd(a) --- context("%0.6f %0.6f %0.6f %0.6f",c,s,-s,c) --- end - -local stack = { } -local f_rotation = string.formatters["%0.8f %0.8f %0.8f %0.8f"] -local f_scaling = string.formatters["%0.8f 0 0 %0.8f"] -local s_mirroring = "-1 0 0 1" -local f_matrix = string.formatters["%0.8f %0.8f %0.8f %0.8f"] - local pdfsetmatrix = nodes.pool.pdfsetmatrix +local stack = { } -local function pop() +local function popmatrix() local top = remove(stack) if top then - context(pdfsetmatrix(top)) + context(pdfsetmatrix(unpack(top))) end end @@ -52,7 +42,7 @@ function commands.pdfstartrotation(a) else local s, c = sind(a), cosd(a) context(pdfsetmatrix(f_rotation(c,s,-s,c))) - insert(stack,f_rotation(-c,-s,s,-c)) + insert(stack,{ -c, -s, s, -c }) end end @@ -60,30 +50,31 @@ function commands.pdfstartscaling(sx,sy) if sx == 1 and sy == 1 then insert(stack,false) else - if sx == 0 then sx = 0.0001 end -- prevent acrobat crash - if sy == 0 then sy = 0.0001 end -- prevent acrobat crash - context(pdfsetmatrix(f_scaling(sx,sy))) - insert(stack,f_scaling(1/sx,1/sy)) + if sx == 0 then + sx = 0.0001 + end + if sy == 0 then + sy = 0.0001 + end + context(pdfsetmatrix(sx,0,0,sy)) + insert(stack,{ 1/sx, 0, 0, 1/sy }) end end -function commands.pdfstartmirroring(sx,sy) - context(pdfsetmatrix(s_mirroring)) - insert(stack,s_mirroring) +function commands.pdfstartmirroring() + context(pdfsetmatrix(-1,0,0,1)) end function commands.pdfstartmatrix(sx,rx,ry,sy) - if sx ==1 and rx == 0 and ry == 0 and sy == 1 then + if sx == 1 and rx == 0 and ry == 0 and sy == 1 then insert(stack,false) else - if sx == 0 then sx = 0.0001 end -- prevent acrobat crash - if sy == 0 then sy = 0.0001 end -- prevent acrobat crash context(pdfsetmatrix(f_matrix(rx,sx,sy,ry))) insert(stack,f_matrix(-rx,-sx,-sy,-ry)) end end -commands.pdfstoprotation = pop -commands.pdfstopscaling = pop -commands.pdfstopmirroring = pop -commands.pdfstopmatrix = pop +commands.pdfstoprotation = popmatrix +commands.pdfstopscaling = popmatrix +commands.pdfstopmirroring = commands.pdfstartmirroring +commands.pdfstopmatrix = popmatrix -- cgit v1.2.3