summaryrefslogtreecommitdiff
path: root/tex/context/base/grph-inc.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/grph-inc.lua')
-rw-r--r--tex/context/base/grph-inc.lua168
1 files changed, 134 insertions, 34 deletions
diff --git a/tex/context/base/grph-inc.lua b/tex/context/base/grph-inc.lua
index a32773ecb..9ee5c6199 100644
--- a/tex/context/base/grph-inc.lua
+++ b/tex/context/base/grph-inc.lua
@@ -47,7 +47,7 @@ local formatters = string.formatters
local longtostring = string.longtostring
local expandfilename = dir.expandname
-local P, lpegmatch = lpeg.P, lpeg.match
+local P, R, S, Cc, lpegmatch = lpeg.P, lpeg.R, lpeg.S, lpeg.Cc, lpeg.match
local settings_to_array = utilities.parsers.settings_to_array
local settings_to_hash = utilities.parsers.settings_to_hash
@@ -57,6 +57,9 @@ local replacetemplate = utilities.templates.replace
local images = img
+local hasscheme = url.hasscheme
+local urlhashed = url.hashed
+
local texgetbox = tex.getbox
local texsetbox = tex.setbox
@@ -75,6 +78,8 @@ local trace_conversion = false trackers.register("graphics.conversion", functi
local trace_inclusion = false trackers.register("graphics.inclusion", function(v) trace_inclusion = v end)
local report_inclusion = logs.reporter("graphics","inclusion")
+local report_figures = logs.reporter("system","graphics")
+local report_figure = logs.reporter("used graphic")
local f_hash_part = formatters["%s->%s->%s"]
local f_hash_full = formatters["%s->%s->%s->%s->%s->%s->%s"]
@@ -86,6 +91,7 @@ local v_high = variables.high
local v_global = variables["global"]
local v_local = variables["local"]
local v_default = variables.default
+local v_auto = variables.auto
local maxdimen = 2^30-1
@@ -233,6 +239,61 @@ figures.formats = figures_formats -- frozen
figures.magics = figures_magics -- frozen
figures.order = figures_order -- frozen
+-- name checker
+
+local pattern = (R("az","AZ") * P(":"))^-1 * ( -- a-z : | A-Z :
+ (R("az","09") + S("_/") - P("_")^2)^1 * P(".") * R("az")^1 + -- a-z | single _ | /
+ (R("az","09") + S("-/") - P("-")^2)^1 * P(".") * R("az")^1 + -- a-z | single - | /
+ (R("AZ","09") + S("_/") - P("_")^2)^1 * P(".") * R("AZ")^1 + -- A-Z | single _ | /
+ (R("AZ","09") + S("-/") - P("-")^2)^1 * P(".") * R("AZ")^1 -- A-Z | single - | /
+) * P(-1) * Cc(false) + Cc(true)
+
+function figures.badname(name)
+ if not name then
+ -- bad anyway
+ elseif not hasscheme(name) then
+ return lpegmatch(pattern,name)
+ else
+ return lpegmatch(pattern,file.basename(name))
+ end
+end
+
+local trace_names = false
+
+trackers.register("graphics.lognames", function(v)
+ if v and not trace_names then
+ luatex.registerstopactions(function()
+ if figures.nofprocessed > 0 then
+ local report_newline = logs.newline
+ logs.pushtarget("logfile")
+ report_newline()
+ report_figures("start names")
+ for _, data in table.sortedhash(figures_found) do
+ report_newline()
+ report_figure("asked : %s",data.askedname)
+ if data.found then
+ report_figure("format : %s",data.format)
+ report_figure("found : %s",data.foundname)
+ report_figure("used : %s",data.fullname)
+ if data.badname then
+ report_figure("comment : %s","bad name")
+ elseif data.comment then
+ report_figure("comment : %s",data.comment)
+ end
+ else
+ report_figure("comment : %s","not found")
+ end
+ end
+ report_newline()
+ report_figures("stop names")
+ report_newline()
+ logs.poptarget()
+ end
+ end)
+ trace_names = true
+ end
+end)
+
-- We can set the order but only indirectly so that we can check for support.
function figures.setorder(list) -- can be table or string
@@ -453,7 +514,7 @@ end
function figures.push(request)
statistics.starttiming(figures)
- local figuredata = figures.initialize(request)
+ local figuredata = figures.initialize(request) -- we could use table.sparse but we set them later anyway
insert(callstack,figuredata)
lastfiguredata = figuredata
return figuredata
@@ -513,9 +574,9 @@ end
local function register(askedname,specification)
if not specification then
- specification = { }
+ specification = { askedname = askedname, comment = "invalid specification" }
elseif forbiddenname(specification.fullname) then
- specification = { }
+ specification = { askedname = askedname, comment = "forbidden name" }
else
local format = specification.format
if format then
@@ -630,7 +691,7 @@ local function register(askedname,specification)
format = newformat
if not figures_suffixes[format] then
-- maybe the new format is lowres.png (saves entry in suffixes)
- -- so let's do thsi extra check
+ -- so let's do this extra check
local suffix = file.suffix(newformat)
if figures_suffixes[suffix] then
if trace_figures then
@@ -640,8 +701,12 @@ local function register(askedname,specification)
end
end
elseif io.exists(oldname) then
- specification.fullname = oldname -- was newname
+ report_inclusion("file %a is bugged",oldname)
+ if format and validtypes[format] then
+ specification.fullname = oldname
+ end
specification.converted = false
+ specification.bugged = true
end
end
end
@@ -652,19 +717,24 @@ local function register(askedname,specification)
if trace_figures then
report_inclusion("format %a is not supported",format)
end
- else
+ elseif validtypes[format] then
specification.found = true
if trace_figures then
- if validtypes[format] then -- format?
- report_inclusion("format %a natively supported by backend",format)
- else
- report_inclusion("format %a supported by output file format",format)
- end
+ report_inclusion("format %a natively supported by backend",format)
+ end
+ else
+ specification.found = false
+ if trace_figures then
+ report_inclusion("format %a supported by output file format",format)
end
end
+ else
+ specification.askedname = askedname
+ specification.found = false
end
end
specification.foundname = specification.foundname or specification.fullname
+ specification.badname = figures.badname(askedname)
local askedhash = f_hash_part(askedname,specification.conversion or "default",specification.resolution or "default")
figures_found[askedhash] = specification
return specification
@@ -673,7 +743,10 @@ end
local resolve_too = false -- true
local internalschemes = {
- file = true,
+ file = true,
+ tree = true,
+ dirfile = true,
+ dirtree = true,
}
local function locate(request) -- name, format, cache
@@ -690,11 +763,18 @@ local function locate(request) -- name, format, cache
local askedconversion = request.conversion
local askedresolution = request.resolution
--
- if request.format == "" or request.format == "unknown" then
- request.format = nil
+ local askedformat = request.format
+ if not askedformat or askedformat == "" or askedformat == "unknown" then
+ askedformat = file.suffix(askedname) or ""
+ elseif askedformat == v_auto then
+ if trace_figures then
+ report_inclusion("ignoring suffix of %a",askedname)
+ end
+ askedformat = ""
+ askedname = file.removesuffix(askedname)
end
-- protocol check
- local hashed = url.hashed(askedname)
+ local hashed = urlhashed(askedname)
if not hashed then
-- go on
elseif internalschemes[hashed.scheme] then
@@ -703,7 +783,7 @@ local function locate(request) -- name, format, cache
askedname = path
end
else
--- local fname = methodhandler('finders',pathname .. "/" .. wantedfiles[k])
+ -- local fname = methodhandler('finders',pathname .. "/" .. wantedfiles[k])
local foundname = resolvers.findbinfile(askedname)
if not foundname or not lfs.isfile(foundname) then -- foundname can be dummy
if trace_figures then
@@ -712,7 +792,6 @@ local function locate(request) -- name, format, cache
-- url not found
return register(askedname)
end
- local askedformat = request.format or file.suffix(askedname) or ""
local guessedformat = figures.guess(foundname)
if askedformat ~= guessedformat then
if trace_figures then
@@ -737,7 +816,6 @@ 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 or file.suffix(askedname) or ""
if askedformat ~= "" then
askedformat = lower(askedformat)
if trace_figures then
@@ -799,7 +877,7 @@ local function locate(request) -- name, format, cache
if foundname then
return register(check, {
askedname = askedname,
- fullname = check,
+ fullname = foundname, -- check,
format = askedformat,
cache = askedcache,
conversion = askedconversion,
@@ -859,7 +937,7 @@ local function locate(request) -- name, format, cache
for i=1,#figure_paths do
local path = figure_paths[i]
local check = path .. "/" .. name
- local isfile = url.hashed(check).scheme == "file"
+ local isfile = internalschemes[urlhashed(check).scheme]
if not isfile then
if trace_figures then
report_inclusion("warning: skipping path %a",path)
@@ -1018,7 +1096,7 @@ end
function existers.generic(askedname,resolve)
-- not findbinfile
local result
- if url.hasscheme(askedname) then
+ if hasscheme(askedname) then
result = resolvers.findbinfile(askedname)
elseif lfs.isfile(askedname) then
result = askedname
@@ -1281,16 +1359,30 @@ end
-- programs.makeoptions = makeoptions
local function runprogram(binary,argument,variables)
- local binary = match(binary,"[%S]+") -- to be sure
+ -- os.which remembers found programs
+ local found = nil
+ if type(binary) == "table" then
+ for i=1,#binary do
+ found = os.which(binary[i])
+ if found then
+ break
+ end
+ end
+ if not found then
+ binary = concat(binary, " | ")
+ end
+ elseif binary then
+ found = os.which(match(binary,"[%S]+"))
+ end
if type(argument) == "table" then
argument = concat(argument," ") -- for old times sake
end
- if not os.which(binary) then
- report_inclusion("program %a is not installed, not running command: %s",binary,command)
+ if not found then
+ report_inclusion("program %a is not installed",binary or "?")
elseif not argument or argument == "" then
- report_inclusion("nothing to run, unknown program %a",binary)
+ report_inclusion("nothing to run, no arguments for program %a",binary)
else
- local command = format([["%s" %s]],binary,replacetemplate(longtostring(argument),variables))
+ local command = format([["%s" %s]],found,replacetemplate(longtostring(argument),variables))
if trace_conversion or trace_programs then
report_inclusion("running command: %s",command)
end
@@ -1315,7 +1407,7 @@ local epstopdf = {
[v_medium] = "ebook",
[v_high] = "prepress",
},
- command = os.type == "windows" and "gswin32c" or "gs",
+ command = os.type == "windows" and { "gswin64c", "gswin32c" } or "gs",
-- -dProcessDSCComments=false
argument = [[
-q
@@ -1326,8 +1418,8 @@ local epstopdf = {
-dAutoRotatePages=/None
-dPDFSETTINGS=/%presets%
-dEPSCrop
- -sOutputFile=%newname%
- %oldname%
+ -sOutputFile="%newname%"
+ "%oldname%"
-c quit
]],
}
@@ -1447,9 +1539,9 @@ bmpconverter.default = converter
local bases = allocate()
figures.bases = bases
-local bases_list = nil -- index => { basename, fullname, xmlroot }
-local bases_used = nil -- [basename] => { basename, fullname, xmlroot } -- pointer to list
-local bases_found = nil
+local bases_list = nil -- index => { basename, fullname, xmlroot }
+local bases_used = nil -- [basename] => { basename, fullname, xmlroot } -- pointer to list
+local bases_found = nil
local bases_enabled = false
local function reset()
@@ -1577,7 +1669,15 @@ identifiers.list = {
statistics.register("graphics processing time", function()
local nofprocessed = figures.nofprocessed
if nofprocessed > 0 then
- return format("%s seconds including tex, %s processed images", statistics.elapsedtime(figures),nofprocessed)
+ local nofnames, nofbadnames = 0, 0
+ for hash, data in next, figures_found do
+ nofnames = nofnames + 1
+ if data.badname then
+ nofbadnames = nofbadnames + 1
+ end
+ end
+ return format("%s seconds including tex, %s processed images, %s unique asked, %s bad names",
+ statistics.elapsedtime(figures),nofprocessed,nofnames,nofbadnames)
else
return nil
end