diff options
author | Hans Hagen <pragma@wxs.nl> | 2018-11-18 16:12:36 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2018-11-18 16:12:36 +0100 |
commit | 744095aa4676553437db0d71c281a74557a3222f (patch) | |
tree | bfdf5d203b5fbfa44ee7db705d3b3475361ad28f /tex/context/base/mkiv/back-pdf.lua | |
parent | e2ee706a3114129601a30908d6b8cbb57068d32c (diff) | |
download | context-744095aa4676553437db0d71c281a74557a3222f.tar.gz |
2018-11-18 14:16:00
Diffstat (limited to 'tex/context/base/mkiv/back-pdf.lua')
-rw-r--r-- | tex/context/base/mkiv/back-pdf.lua | 214 |
1 files changed, 44 insertions, 170 deletions
diff --git a/tex/context/base/mkiv/back-pdf.lua b/tex/context/base/mkiv/back-pdf.lua index f45783e51..27e9cb69c 100644 --- a/tex/context/base/mkiv/back-pdf.lua +++ b/tex/context/base/mkiv/back-pdf.lua @@ -18,7 +18,6 @@ local context = context local scanners = tokens.scanners local scannumber = scanners.number local scankeyword = scanners.keyword -local scandimen = scanners.dimen local scancount = scanners.count local scanstring = scanners.string @@ -38,14 +37,14 @@ end backends.install("pdf") -local f_matrix = string.formatters["%F %F %F %F"] -- 0.8 is default - -scanners.pdfrotation = function() -- a - -- todo: check for 1 and 0 and flush sparse - local a = scannumber() - local s, c = sind(a), cosd(a) - context(f_matrix(c,s,-s,c)) -end +-- local f_matrix = string.formatters["%F %F %F %F"] -- 0.8 is default +-- +-- scanners.pdfrotation = function() -- a +-- -- todo: check for 1 and 0 and flush sparse +-- local a = scannumber() +-- 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 @@ -53,14 +52,29 @@ end -- -- we could also do the save restore wrapping here + colorhack -local pdfsave = nodes.pool.pdfsave -local pdfrestore = nodes.pool.pdfrestore -local pdfsetmatrix = nodes.pool.pdfsetmatrix +local nodepool = nodes.pool +local pdfsave = nodepool.pdfsave +local pdfrestore = nodepool.pdfrestore +local pdfsetmatrix = nodepool.pdfsetmatrix local stack = { } local restore = true -- false -scanners.pdfstartrotation = function() +local function pdfstopsomething() + local top = remove(stack) + if top == false then + -- not wrapped + elseif top == true then + context(pdfrestore()) + elseif top then + context(pdfsetmatrix(unpack(top))) -- not really needed anymore + context(pdfrestore()) + else + -- nesting error + end +end + +local function pdfstartrotation() local a = scannumber() if a == 0 then insert(stack,false) @@ -72,7 +86,10 @@ scanners.pdfstartrotation = function() end end -scanners.pdfstartscaling = function() -- at the tex end we use sx and sy instead of rx and ry +implement { name = "pdfstartrotation", actions = pdfstartrotation } +implement { name = "pdfstoprotation", actions = pdfstopsomething } + +local function pdfstartscaling() -- at the tex end we use sx and sy instead of rx and ry local rx, ry = 1, 1 while true do if scankeyword("rx") then @@ -107,7 +124,10 @@ scanners.pdfstartscaling = function() -- at the tex end we use sx and sy instead end end -scanners.pdfstartmatrix = function() -- rx sx sy ry -- tx, ty +implement { name = "pdfstartscaling", actions = pdfstartscaling } +implement { name = "pdfstopscaling", actions = pdfstopsomething } + +local function pdfstartmatrix() -- rx sx sy ry -- tx, ty local rx, sx, sy, ry = 1, 0, 0, 1 while true do if scankeyword("rx") then rx = scannumber() @@ -125,46 +145,32 @@ scanners.pdfstartmatrix = function() -- rx sx sy ry -- tx, ty end end -local function pdfstopsomething() - local top = remove(stack) - if top == false then - -- not wrapped - elseif top == true then - context(pdfrestore()) - elseif top then - context(pdfsetmatrix(unpack(top))) -- not really needed anymore - context(pdfrestore()) - else - -- nesting error - end -end +implement { name = "pdfstartmatrix", actions = pdfstartmatrix } +implement { name = "pdfstopmatrix", actions = pdfstopsomething } -scanners.pdfstoprotation = pdfstopsomething -scanners.pdfstopscaling = pdfstopsomething -scanners.pdfstopmatrix = pdfstopsomething - -scanners.pdfstartmirroring = function() +local function pdfstartmirroring() context(pdfsetmatrix(-1,0,0,1)) end +implement { name = "pdfstartmirroring", actions = pdfstartmirroring } +implement { name = "pdfstopmirroring", actions = pdfstopsomething } + if environment.arguments.nocompression then lpdf.setcompression(0,0,true) end -scanners.pdfstopmirroring = scanners.pdfstartmirroring - --- todo, change the above to implement too -- +-- todo: implement { name = "setmapfile", arguments = "string", - actions = pdf.mapfile + actions = lpdf.setmapfile } implement { name = "setmapline", arguments = "string", - actions = pdf.mapline + actions = lpdf.setmapline } implement { @@ -173,135 +179,3 @@ implement { actions = lpdf.setcompression, } -local report = logs.reporter("backend","pdftex primitives") -local trace = false - -scanners.pdfannot = function() - if scankeyword("reserveobjectnum") then - report("\\pdfannot reserveobjectnum is not (yet) supported") - -- if trace then - -- report() - -- report("\\pdfannot: reserved number (not supported yet)") - -- report() - -- end - else - local width = false - local height = false - local depth = false - local data = false - local object = false - local attr = false - -- - if scankeyword("useobjnum") then - object = scancount() - report("\\pdfannot useobjectnum is not (yet) supported") - end - while true do - if scankeyword("width") then - width = scandimen() - elseif scankeyword("height") then - height = scandimen() - elseif scankeyword("depth") then - depth = scandimen() - else - break - end - end - if scankeyword("attr") then - attr = scanstring() - end - data = scanstring() - -- - -- less strict variant: - -- - -- while true do - -- if scankeyword("width") then - -- width = scandimen() - -- elseif scankeyword("height") then - -- height = scandimen() - -- elseif scankeyword("depth") then - -- depth = scandimen() - -- elseif scankeyword("useobjnum") then - -- object = scancount() - -- elseif scankeyword("attr") then - -- attr = scanstring() - -- else - -- data = scanstring() - -- break - -- end - -- end - -- - -- if trace then - -- report() - -- report("\\pdfannot:") - -- report() - -- report(" object: %s",object or "<unset> (not supported yet)") - -- report(" width : %p",width or "<unset>") - -- report(" height: %p",height or "<unset>") - -- report(" depth : %p",depth or "<unset>") - -- report(" attr : %s",attr or "<unset>") - -- report(" data : %s",data or "<unset>") - -- report() - -- end - context(backends.nodeinjections.annotation(width or 0,height or 0,depth or 0,data or "")) - end -end - -scanners.pdfdest = function() - local name = false - local zoom = false - local view = false - local width = false - local height = false - local depth = false - if scankeyword("num") then - report("\\pdfdest num is not (yet) supported") - elseif scankeyword("name") then - name = scanstring() - end - if scankeyword("xyz") then - view = "xyz" - if scankeyword("zoom") then - report("\\pdfdest zoom is ignored") - zoom = scancount() -- will be divided by 1000 in the backend - end - elseif scankeyword("fitbh") then - view = "fitbh" - elseif scankeyword("fitbv") then - view = "fitbv" - elseif scankeyword("fitb") then - view = "fitb" - elseif scankeyword("fith") then - view = "fith" - elseif scankeyword("fitv") then - view = "fitv" - elseif scankeyword("fitr") then - view = "fitr" - while true do - if scankeyword("width") then - width = scandimen() - elseif scankeyword("height") then - height = scandimen() - elseif scankeyword("depth") then - depth = scandimen() - else - break - end - end - elseif scankeyword("fit") then - view = "fit" - end - -- if trace then - -- report() - -- report("\\pdfdest:") - -- report() - -- report(" name : %s",name or "<unset>") - -- report(" view : %s",view or "<unset>") - -- report(" zoom : %s",zoom or "<unset> (not supported)") - -- report(" width : %p",width or "<unset>") - -- report(" height: %p",height or "<unset>") - -- report(" depth : %p",depth or "<unset>") - -- report() - -- end - context(backends.nodeinjections.destination(width or 0,height or 0,depth or 0,{ name or "" },view or "fit")) -end |