summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/back-pdf.lua
diff options
context:
space:
mode:
authorMojca Miklavec <mojca.miklavec@gmail.com>2014-05-05 20:29:55 +0000
committerMojca Miklavec <mojca.miklavec@gmail.com>2014-05-05 20:29:55 +0000
commitba9a57343987f1c2c72396e7c38f1fa30352c24c (patch)
tree66a8b12cdf67427ce96770fd0e9e581759aade1c /Master/texmf-dist/tex/context/base/back-pdf.lua
parent15242121b8ddf7d4a041fb3998d295dd8232e1eb (diff)
ConTeXt 2014.04.28 23:24
git-svn-id: svn://tug.org/texlive/trunk@33856 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/back-pdf.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/back-pdf.lua72
1 files changed, 72 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/context/base/back-pdf.lua b/Master/texmf-dist/tex/context/base/back-pdf.lua
index 63261aa3b8e..34a28e3f79f 100644
--- a/Master/texmf-dist/tex/context/base/back-pdf.lua
+++ b/Master/texmf-dist/tex/context/base/back-pdf.lua
@@ -18,3 +18,75 @@ function codeinjections.getoutputfilename()
end
backends.install("pdf")
+
+local context = context
+
+local sind, cosd = math.sind, math.cosd
+local insert, remove = table.insert, table.remove
+
+local f_matrix = string.formatters["%0.8F %0.8F %0.8F %0.8F"]
+
+function commands.pdfrotation(a)
+ -- todo: check for 1 and 0 and flush sparse
+ local s, c = sind(a), cosd(a)
+ context(f_matrix(c,s,-s,c))
+end
+
+-- experimental code (somewhat weird here) .. todo: nodeinjections .. this will only work
+-- out well if we also calculate the accumulated cm and wrap inclusions / annotations in
+-- the accumulated ... it's a mess
+--
+-- we could also do the save restore wrapping here + colorhack
+
+local pdfsetmatrix = nodes.pool.pdfsetmatrix
+local stack = { }
+
+local function popmatrix()
+ local top = remove(stack)
+ if top then
+ context(pdfsetmatrix(unpack(top)))
+ end
+end
+
+function commands.pdfstartrotation(a)
+ if a == 0 then
+ insert(stack,false)
+ else
+ local s, c = sind(a), cosd(a)
+ context(pdfsetmatrix(c,s,-s,c))
+ insert(stack,{ c, -s, s, c })
+ end
+end
+
+function commands.pdfstartscaling(sx,sy)
+ if sx == 1 and sy == 1 then
+ insert(stack,false)
+ else
+ 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()
+ context(pdfsetmatrix(-1,0,0,1))
+end
+
+function commands.pdfstartmatrix(sx,rx,ry,sy) -- tx, ty
+ if sx == 1 and rx == 0 and ry == 0 and sy == 1 then
+ insert(stack,false)
+ else
+ context(pdfsetmatrix(sx,rx,ry,sy))
+ insert(stack,{ -sx, -rx, -ry, -sy })
+ end
+end
+
+commands.pdfstoprotation = popmatrix
+commands.pdfstopscaling = popmatrix
+commands.pdfstopmirroring = commands.pdfstartmirroring
+commands.pdfstopmatrix = popmatrix