summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/grph-inc.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-12-17 18:19:48 +0100
committerContext Git Mirror Bot <phg@phi-gamma.net>2018-12-17 18:19:48 +0100
commit15b67b20aa0d6c508578d0ca8cbdcd9cff9829a8 (patch)
treed656b4161487a8c54d954458084914c7d408aca7 /tex/context/base/mkiv/grph-inc.lua
parent5bb786877a5617fb8fbe3fd0e7b54fbcea3ce002 (diff)
downloadcontext-15b67b20aa0d6c508578d0ca8cbdcd9cff9829a8.tar.gz
2018-12-17 16:49:00
Diffstat (limited to 'tex/context/base/mkiv/grph-inc.lua')
-rw-r--r--tex/context/base/mkiv/grph-inc.lua315
1 files changed, 1 insertions, 314 deletions
diff --git a/tex/context/base/mkiv/grph-inc.lua b/tex/context/base/mkiv/grph-inc.lua
index 334a0b536..ee4ed2a28 100644
--- a/tex/context/base/mkiv/grph-inc.lua
+++ b/tex/context/base/mkiv/grph-inc.lua
@@ -54,8 +54,7 @@ local concat, insert, remove = table.concat, table.insert, table.remove
local todimen = string.todimen
local collapsepath = file.collapsepath
local formatters = string.formatters
-local formatcolumns = utilities.formatters.formatcolumns
-local max, odd = math.max, math.odd
+local odd = math.odd
local P, R, S, Cc, C, Cs, Ct, lpegmatch = lpeg.P, lpeg.R, lpeg.S, lpeg.Cc, lpeg.C, lpeg.Cs, lpeg.Ct, lpeg.match
@@ -2164,315 +2163,3 @@ implement {
end
end
}
-
--- This is an experiment. The following method uses Lua to handle the embedding
--- using the epdf library. This feature will be used when we make the transition
--- from the pre 1.10 epdf library (using an unsuported low level poppler api) to a
--- new (lightweight, small and statically compiled) library. More on that later.
---
--- The method implemented below has the same performance as the hard coded inclusion
--- but opens up some possibilities (like merging fonts) that I will look into some
--- day.
-
-local function pdf_checker(data)
- local request = data.request
- local used = data.used
- if request and used and not request.scanimage then
- local image = lpdf.epdf.image
- local openpdf = image.open
- local closepdf = image.close
- local querypdf = image.query
- local copypage = image.copy
- local pdfdoc = nil
- request.scanimage = function(t)
- pdfdoc = openpdf(t.filename,request.userpassword,request.ownerpassword)
- if pdfdoc then
- --
- pdfdoc.nofcopiedpages = 0
- --
- local info = querypdf(pdfdoc,request.page)
- if info then
- local bbox = info and info.boundingbox or { 0, 0, 0, 0 }
- local height = bbox[4] - bbox[2]
- local width = bbox[3] - bbox[1]
- local rotation = info.rotation or 0
- if rotation == 90 then
- rotation, height, width = 3, width, height
- elseif rotation == 180 then
- rotation = 2
- elseif rotation == 270 then
- rotation, height, width = 1, width, height
- elseif rotation == 1 or rotation == 3 then
- height, width = width, height
- else
- rotation = 0
- end
- return {
- filename = filename,
- -- page = 1,
- pages = pdfdoc.nofpages,
- width = width,
- height = height,
- depth = 0,
- colordepth = 0,
- xres = 0,
- yres = 0,
- xsize = width,
- ysize = height,
- rotation = rotation,
- pdfdoc = pdfdoc,
- }
- end
- end
- end
- request.copyimage = function(t)
- if not pdfdoc then
- pdfdoc = t.pdfdoc
- end
- if pdfdoc then
- local result = copypage(pdfdoc,request.page,nil,request.compact,request.width,request.height,request.attr)
- pdfdoc.nofcopiedpages = pdfdoc.nofcopiedpages + 1
- if pdfdoc.nofcopiedpages >= pdfdoc.nofpages then
- closepdf(pdfdoc)
- pdfdoc = nil
- t.pdfdoc = nil
- end
- return result
- else
- -- message, should not happen as we always first scan so that reopens
- end
- end
- end
- return checkers.generic(data)
-end
-
-local function wrappedidentify(identify,filename)
- local wrapup = function() report_inclusion("fatal error reading %a",filename) end
- local _, result = xpcall(identify,wrapup,filename)
- 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)
- local request = data.request
- local used = data.used
- if request and used and not request.scanimage then
- local identify = graphics.identify
- local inject = lpdf.injectors.jpg
- local found = false
- request.scanimage = function(t)
- local result = wrappedidentify(identify,t.filename)
- found = not result.error
- return {
- filename = result.filename,
- width = result.width,
- height = result.height,
- depth = result.depth,
- colordepth = result.colordepth,
- xres = result.xres,
- yres = result.yres,
- xsize = result.xsize,
- ysize = result.ysize,
- rotation = result.rotation,
- colorspace = result.colorspace,
- }
- end
- request.copyimage = function(t)
- if found then
- found = false
- return inject(t)
- end
- end
- end
- return checkers.generic(data)
-end
-
-local function jp2_checker(data) -- idem as jpg
- local request = data.request
- local used = data.used
- if request and used and not request.scanimage then
- local identify = graphics.identify
- local inject = lpdf.injectors.jp2
- local found = false
- request.scanimage = function(t)
- local result = wrappedidentify(identify,t.filename)
- found = not result.error
- return {
- filename = result.filename,
- width = result.width,
- height = result.height,
- depth = result.depth,
- colordepth = result.colordepth,
- xres = result.xres,
- yres = result.yres,
- xsize = result.xsize,
- ysize = result.ysize,
- rotation = result.rotation,
- colorspace = result.colorspace,
- }
- end
- request.copyimage = function(t)
- if found then
- found = false
- return inject(t)
- end
- end
- end
- return checkers.generic(data)
-end
-
-local function png_checker(data) -- same as jpg (for now)
- local request = data.request
- local used = data.used
- if request and used and not request.scanimage then
- local identify = graphics.identify
- local inject = lpdf.injectors.png
- local found = false
- request.scanimage = function(t)
- local result = wrappedidentify(identify,t.filename)
- found = not result.error
- return {
- filename = result.filename,
- width = result.width,
- height = result.height,
- depth = result.depth,
- colordepth = result.colordepth,
- xres = result.xres,
- yres = result.yres,
- xsize = result.xsize,
- ysize = result.ysize,
- rotation = result.rotation,
- colorspace = result.colorspace,
- tables = result.tables,
- interlace = result.interlace,
- filter = result.filter,
- }
- end
- request.copyimage = function(t)
- if found then
- found = false
- return inject(t)
- end
- end
- end
- return checkers.generic(data)
-end
-
-directives.register("graphics.pdf.uselua",function(v)
- checkers.pdf = v and pdf_checker or nil
- report("%s Lua based PDF inclusion",v and "enabling" or "disabling")
-end)
-
-directives.register("graphics.jpg.uselua",function(v)
- checkers.jpg = v and jpg_checker or nil
- report("%s Lua based JPG inclusion",v and "enabling" or "disabling")
-end)
-
-directives.register("graphics.jp2.uselua",function(v)
- checkers.jp2 = v and jp2_checker or nil
- report("%s Lua based JP2 inclusion",v and "enabling" or "disabling")
-end)
-
-directives.register("graphics.png.uselua",function(v)
- checkers.png = v and png_checker or nil
- report("%s Lua based PNG inclusion",v and "enabling" or "disabling")
-end)
-
-directives.register("graphics.uselua",function(v)
- checkers.pdf = v and pdf_checker or nil
- 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")
-end)
-
--- directives.enable("graphics.pdf.uselua")
---
--- local filename = "luatex.pdf"
---
--- for i=1,240 do
--- context(function()
--- context.startTEXpage()
--- context.externalfigure( { filename }, { page = i } )
--- context.stopTEXpage()
--- end)
--- end
-
--- This is experimental, for the moment here:
-
-local bitmaps = { }
-graphics.bitmaps = bitmaps
-
-local report_bitmap = logs.reporter("graphics","bitmap")
-
-function bitmaps.new(xsize,ysize,colorspace,colordepth,mask)
- if not xsize or not ysize or xsize == 0 or ysize == 0 then
- report_bitmap("provide 'xsize' and 'ysize' larger than zero")
- return
- end
- if not colorspace then
- report_bitmap("provide 'colorspace' (1, 2, 3, 'gray', 'rgb', 'cmyk'")
- return
- end
- if not colordepth then
- report_bitmap("provide 'colordepth' (1, 2)")
- return
- end
- return graphics.identifiers.bitmap {
- colorspace = colorspace,
- colordepth = colordepth,
- xsize = xsize,
- ysize = ysize,
- mask = mask and true or nil,
- }
-end
-
-local function flush(bitmap)
- return wrapimage(lpdf.injectors.bitmap(bitmap))
-end
-
-bitmaps.flush = flush
-
-function bitmaps.tocontext(bitmap,width,height)
- if type(width) == "number" then
- width = width .. "sp"
- end
- if type(height) == "number" then
- height = height .. "sp"
- end
- if width or height then
- context.scale (
- {
- width = width,
- height = height,
- },
- flush(bitmap)
- )
- else
- context(flush(bitmap))
- end
-end
-
-