summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/grph-inc.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-11-29 20:53:37 +0100
committerContext Git Mirror Bot <phg@phi-gamma.net>2018-11-29 20:53:37 +0100
commit9bd28a3039a458b054459fe1ef80161b107b798f (patch)
treec15bf6aedc4313de999a97bf92dc63b16ca60794 /tex/context/base/mkiv/grph-inc.lua
parent744095aa4676553437db0d71c281a74557a3222f (diff)
downloadcontext-9bd28a3039a458b054459fe1ef80161b107b798f.tar.gz
2018-11-29 19:54:00
Diffstat (limited to 'tex/context/base/mkiv/grph-inc.lua')
-rw-r--r--tex/context/base/mkiv/grph-inc.lua118
1 files changed, 66 insertions, 52 deletions
diff --git a/tex/context/base/mkiv/grph-inc.lua b/tex/context/base/mkiv/grph-inc.lua
index 909df86bc..3ae54adda 100644
--- a/tex/context/base/mkiv/grph-inc.lua
+++ b/tex/context/base/mkiv/grph-inc.lua
@@ -65,7 +65,7 @@ local allocate = utilities.storage.allocate
local setmetatableindex = table.setmetatableindex
local replacetemplate = utilities.templates.replace
--- local bpfactor = number.dimenfactors.bp
+local bpfactor = number.dimenfactors.bp
images = images or { }
local images = images
@@ -131,8 +131,8 @@ function checkimage(figure)
report_inclusion("image %a has bad dimensions (%p,%p), discarding",figure.filename or "?",width,height)
return false, "bad dimensions"
end
- local xres = figure.xres
- local yres = figure.yres
+ -- local xres = figure.xres
+ -- local yres = figure.yres
local changes = false
if height > width then
if height > maxdimen then
@@ -160,14 +160,14 @@ end
--- begin of mapping / this will become graphics & code|nodeinjections but not this year
-local __img__ = img or setmetatableindex(function() report_inclusion("no img lib present") end)
-images.__img__ = img
+local __img__ = type(img) == "table" and img or { }
+images.__img__ =__img__
-local img_new = img.new
-local img_scan = img.scan
-local img_copy = img.copy
-local img_wrap = img.node
-local img_embed = img.immediatewrite
+local img_new = __img__.new
+local img_scan = __img__.scan
+local img_copy = __img__.copy
+local img_wrap = __img__.node
+local img_embed = __img__.immediatewrite
updaters.register("backend.update",function()
local img = images.__img__
@@ -1658,7 +1658,7 @@ function checkers.mov(data)
nodeinjections.insertmovie {
width = width,
height = height,
- factor = number.dimenfactors.bp,
+ factor = bpfactor,
["repeat"] = dr["repeat"],
controls = dr.controls,
preview = dr.preview,
@@ -2240,7 +2240,30 @@ end
local function wrappedidentify(identify,filename)
local wrapup = function() report_inclusion("fatal error reading %a",filename) end
local _, result = xpcall(identify,wrapup,filename)
- return result or { error = "fatal error" }
+ if result then
+ local xsize = result.xsize or 0
+ local ysize = result.ysize or 0
+ local xres = result.xres or 0
+ local yres = result.yres or 0
+ if xres == 0 or yres == 0 then
+ xres = 300
+ yres = 300
+ end
+ result.xsize = xsize
+ result.ysize = ysize
+ result.xres = xres
+ result.yres = yres
+ result.width = result.width or ((72/xres) * xsize / bpfactor)
+ result.height = result.height or ((72/yres) * ysize / bpfactor)
+ result.depth = result.depth or 0
+ result.filename = filename
+ result.colordepth = result.colordepth or 0
+ result.rotation = result.rotation or 0
+ result.colorspace = result.colorspace or 0
+ return result
+ else
+ return { error = "fatal error" }
+ end
end
local function jpg_checker(data)
@@ -2251,23 +2274,20 @@ local function jpg_checker(data)
local inject = lpdf.injectors.jpg
local found = false
request.scanimage = function(t)
- local filename = t.filename
- local result = wrappedidentify(identify,filename)
- local xsize = result.xsize or 0
- local ysize = result.ysize or 0
+ local result = wrappedidentify(identify,t.filename)
found = not result.error
return {
- filename = filename,
- width = xsize * 65536,
- height = ysize * 65536,
- depth = 0,
- colordepth = result.colordepth or 0,
+ filename = result.filename,
+ width = result.width,
+ height = result.height,
+ depth = result.depth,
+ colordepth = result.colordepth,
xres = result.xres,
yres = result.yres,
- xsize = xsize,
- ysize = ysize,
- rotation = result.rotation or 0,
- colorspace = result.colorspace or 0,
+ xsize = result.xsize,
+ ysize = result.ysize,
+ rotation = result.rotation,
+ colorspace = result.colorspace,
}
end
request.copyimage = function(t)
@@ -2288,23 +2308,20 @@ local function jp2_checker(data) -- idem as jpg
local inject = lpdf.injectors.jp2
local found = false
request.scanimage = function(t)
- local filename = t.filename
- local result = wrappedidentify(identify,filename)
- local xsize = result.xsize or 0
- local ysize = result.ysize or 0
+ local result = wrappedidentify(identify,t.filename)
found = not result.error
return {
- filename = filename,
- width = xsize * 65536,
- height = ysize * 65536,
- depth = 0,
- colordepth = result.colordepth or 0,
+ filename = result.filename,
+ width = result.width,
+ height = result.height,
+ depth = result.depth,
+ colordepth = result.colordepth,
xres = result.xres,
yres = result.yres,
- xsize = xsize,
- ysize = ysize,
- rotation = result.rotation or 0,
- colorspace = result.colorspace or 0,
+ xsize = result.xsize,
+ ysize = result.ysize,
+ rotation = result.rotation,
+ colorspace = result.colorspace,
}
end
request.copyimage = function(t)
@@ -2325,23 +2342,20 @@ local function png_checker(data) -- same as jpg (for now)
local inject = lpdf.injectors.png
local found = false
request.scanimage = function(t)
- local filename = t.filename
- local result = wrappedidentify(identify,filename)
- local xsize = result.xsize or 0
- local ysize = result.ysize or 0
+ local result = wrappedidentify(identify,t.filename)
found = not result.error
return {
- filename = filename,
- width = xsize * 65536,
- height = ysize * 65536,
- depth = 0,
- colordepth = result.colordepth or 0,
+ filename = result.filename,
+ width = result.width,
+ height = result.height,
+ depth = result.depth,
+ colordepth = result.colordepth,
xres = result.xres,
yres = result.yres,
- xsize = xsize,
- ysize = ysize,
- rotation = result.rotation or 0,
- colorspace = result.colorspace or 0,
+ xsize = result.xsize,
+ ysize = result.ysize,
+ rotation = result.rotation,
+ colorspace = result.colorspace,
tables = result.tables,
interlace = result.interlace,
filter = result.filter,
@@ -2382,7 +2396,7 @@ directives.register("graphics.uselua",function(v)
checkers.jpg = v and jpg_checker or nil
checkers.jp2 = v and jp2_checker or nil
checkers.png = v and png_checker or nil
- report("%s Lua based PDF, PNG, JPG and JP2 inclusion",v and "enabling" or "disabling")
+ -- report("%s Lua based PDF, PNG, JPG and JP2 inclusion",v and "enabling" or "disabling")
end)
-- directives.enable("graphics.pdf.uselua")