diff options
author | Marius <mariausol@gmail.com> | 2012-10-19 01:20:13 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2012-10-19 01:20:13 +0300 |
commit | 69d2352af4b60929b37fc49f3bdb263977016244 (patch) | |
tree | db5eb11398e345dfa23b4c4500fb93575d2afb7c /tex/context/base/grph-inc.lua | |
parent | c18f7cbe51449a611ea1819fedd9a4ff18529b7d (diff) | |
download | context-69d2352af4b60929b37fc49f3bdb263977016244.tar.gz |
stable 2012.05.30 11:26
Diffstat (limited to 'tex/context/base/grph-inc.lua')
-rw-r--r-- | tex/context/base/grph-inc.lua | 100 |
1 files changed, 33 insertions, 67 deletions
diff --git a/tex/context/base/grph-inc.lua b/tex/context/base/grph-inc.lua index f8c9a5134..33dd0766d 100644 --- a/tex/context/base/grph-inc.lua +++ b/tex/context/base/grph-inc.lua @@ -15,7 +15,6 @@ if not modules then modules = { } end modules ['grph-inc'] = { -- partly qualified -- dimensions -- consult rlx --- use metatables -- figures.boxnumber can go as we now can use names @@ -69,7 +68,7 @@ local report_inclusion = logs.reporter("graphics","inclusion") local context, img = context, img ---- some extra img functions --- can become luat-img.lua +--- some extra img functions --- local imgkeys = img.keys() @@ -155,16 +154,16 @@ figures.cachepaths = allocate { figures.paths = allocate(table.copy(figures.localpaths)) -local lookuporder = allocate { +figures.order = allocate{ "pdf", "mps", "jpg", "png", "jp2", "jbig", "svg", "eps", "tif", "gif", "mov", "buffer", "tex", "cld", "auto", } -local formats = allocate { -- magic and order will move here +local formats = allocate { ["pdf"] = { list = { "pdf" } }, ["mps"] = { patterns = { "mps", "%d+" } }, ["jpg"] = { list = { "jpg", "jpeg" } }, - ["png"] = { list = { "png" } }, ["jp2"] = { list = { "jp2" } }, + ["png"] = { list = { "png" } }, ["jbig"] = { list = { "jbig", "jbig2", "jb2" } }, ["svg"] = { list = { "svg", "svgz" } }, ["eps"] = { list = { "eps", "ai" } }, @@ -188,44 +187,19 @@ local magics = allocate { figures.formats = formats -- frozen figures.magics = magics -- frozen --- We can set the order but only indirectly so that we can check for support. - -function figures.setorder(list) -- can be table or string - if type(list) == "string" then - list = settings_to_array(list) - end - if list and #list > 0 then - lookuporder = allocate() - figures.order = lookuporder - local done = { } -- just to be sure in case the list is generated - for i=1,#list do - local l = lower(list[i]) - if formats[l] and not done[l] then - lookuporder[#lookuporder+1] = l - done[l] = true - end - end - report_inclusion("lookup order: %s",concat(lookuporder," ")) - else - -- invalid list - end -end - function figures.guess(filename) local f = io.open(filename,'rb') if f then local str = f:read(100) f:close() - if str then - for i=1,#magics do - local pattern = magics[i] - if pattern.pattern:match(str) then - local format = pattern.format - if trace_figures then - report_inclusion("file %q has format %s",filename,format) - end - return format + for i=1,#magics do + local pattern = magics[i] + if pattern.pattern:match(str) then + local format = pattern.format + if trace_figures then + report_inclusion("file %q has format %s",filename,format) end + return format end end end @@ -234,7 +208,7 @@ end function figures.setlookups() -- tobe redone .. just set locals local fs, fp = allocate(), allocate() figures.suffixes, figures.patterns = fs, fp - for _, format in next, lookuporder do + for _, format in next, figures.order do local data = formats[format] local list = data.list if list then @@ -273,8 +247,8 @@ local function register(tag,target,what) else data[tag] = { what } end - if not contains(lookuporder,target) then - lookuporder[#lookuporder+1] = target + if not contains(figures.order,target) then + figures.order[#figures.order+1] = target end figures.setlookups() end @@ -636,7 +610,7 @@ local function locate(request) -- name, format, cache -- we could use the hashed data instead local askedpath= file.is_rootbased_path(askedname) local askedbase = file.basename(askedname) - local askedformat = (request.format ~= "" and request.format ~= "unknown" and request.format) or file.suffix(askedname) or "" + local askedformat = (request.format ~= "" and request.format ~= "unknown" and request.format) or file.extname(askedname) or "" local askedcache = request.cache local askedconversion = request.conversion local askedresolution = request.resolution @@ -725,8 +699,9 @@ local function locate(request) -- name, format, cache if trace_figures then report_inclusion("strategy: rootbased path") end - for i=1,#lookuporder do - local format = lookuporder[i] + local figureorder = figures.order + for i=1,#figureorder do + local format = figureorder[i] local list = formats[format].list or { format } for j=1,#list do local suffix = list[j] @@ -750,8 +725,9 @@ local function locate(request) -- name, format, cache report_inclusion("strategy: unknown format, prefer quality") end local figurepaths = figures.paths - for j=1,#lookuporder do - local format = lookuporder[j] + local figureorder = figures.order + for j=1,#figureorder do + local format = figureorder[j] local list = formats[format].list or { format } for k=1,#list do local suffix = list[k] @@ -786,10 +762,11 @@ local function locate(request) -- name, format, cache report_inclusion("strategy: unknown format, prefer path") end local figurepaths = figures.paths + local figureorder = figures.order for i=1,#figurepaths do local path = figurepaths[i] - for j=1,#lookuporder do - local format = lookuporder[j] + for j=1,#figureorder do + local format = figureorder[j] local list = formats[format].list or { format } for k=1,#list do local suffix = list[k] @@ -813,8 +790,9 @@ local function locate(request) -- name, format, cache if trace_figures then report_inclusion("strategy: default tex path") end - for j=1,#lookuporder do - local format = lookuporder[j] + local figureorder = figures.order + for j=1,#figureorder do + local format = figureorder[j] local list = formats[format].list or { format } for k=1,#list do local suffix = list[k] @@ -1173,8 +1151,6 @@ local function makeoptions(options) return (to == "table" and concat(options," ")) or (to == "string" and options) or "" end --- programs.makeoptions = makeoptions - local function runprogram(template,binary,...) local command = format(template,binary,...) local binary = match(binary,"[%S]+") -- to be sure @@ -1192,7 +1168,6 @@ end local epsconverter = { } converters.eps = epsconverter -converters.ps = epsconverter programs.gs = { resolutions = { @@ -1458,7 +1433,7 @@ function figures.applyratio(width,height,w,h) -- width and height are strings an end end --- example of simple plugins: +-- example of a simple plugin: -- -- figures.converters.png = { -- png = function(oldname,newname,resolution) @@ -1468,18 +1443,9 @@ end -- end, -- } --- figures.converters.bmp = { --- pdf = function(oldname,newname) --- os.execute(string.format("gm convert %s %s",oldname,newname)) --- end --- } - --- local fig = figures.push { name = pdffile } --- figures.identify() --- figures.check() --- local nofpages = fig.used.pages --- figures.pop() - --- interfacing -commands.setfigurelookuporder = figures.setorder +-- local fig = figures.push { name = pdffile } +-- figures.identify() +-- figures.check() +-- local nofpages = fig.used.pages +-- figures.pop() |