summaryrefslogtreecommitdiff
path: root/tex/context/base/lpdf-pdx.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/lpdf-pdx.lua')
-rw-r--r--tex/context/base/lpdf-pdx.lua75
1 files changed, 51 insertions, 24 deletions
diff --git a/tex/context/base/lpdf-pdx.lua b/tex/context/base/lpdf-pdx.lua
index 43b0b87dc..db1217c53 100644
--- a/tex/context/base/lpdf-pdx.lua
+++ b/tex/context/base/lpdf-pdx.lua
@@ -6,6 +6,10 @@ if not modules then modules = { } end modules ['lpdf-pdx'] = {
license = "see context related readme files",
}
+local trace_colorprofiles = false trackers.register("backend.colorprofiles", function(v) trace_colorprofiles = v end)
+
+local report_backends = logs.new("backends")
+
local codeinjections = backends.codeinjections -- normally it is registered
local variables = interfaces.variables
@@ -16,6 +20,7 @@ local pdfreference = lpdf.reference
local pdfflushobject = lpdf.flushobject
local pdfstring = lpdf.string
local pdfverbose = lpdf.verbose
+local pdfobject = lpdf.object
local lower, gmatch = string.lower, string.gmatch
@@ -47,9 +52,9 @@ function codeinjections.useinternalICCprofile(colorspace,filename)
local channel = channels[colorspace]
if channel and filename ~= "" then
local a = pdfdictionary { N = channel }
- profile = pdf.obj {
+ profile = pdfobject {
compresslevel = 0,
- immediate = true,
+ immediate = true, -- !
type = "stream",
file = filename,
attr = a(),
@@ -85,30 +90,51 @@ function codeinjections.useexternalICCprofile(colorspace,name,urls,checksum,vers
end
end
-local function embedprofile(colorspace,filename)
- local colorspace = lower(colorspace)
- local n = codeinjections.useinternalICCprofile(colorspace,filename)
- if n then
- local a = pdfarray {
- pdfconstant("ICCBased"),
- pdfreference(n),
- }
- lpdf.adddocumentcolorspace(prefixes[colorspace],pdfreference(pdfflushobject(a))) -- part of page /Resources
- defaults[lower(colorspace)] = filename
- end
-end
-
+local loaded = { }
function codeinjections.useICCdefaultprofile(colorspace,filename)
- defaults[lower(colorspace)] = filename
-end
-
-local function flushembeddedprofiles()
- for colorspace, filename in next, defaults do
- embedprofile(colorspace,filename)
+ local colorspace = lower(colorspace)
+ if not loaded[colorspace] then
+ local n = codeinjections.useinternalICCprofile(colorspace,filename)
+ if n then
+ local a = pdfarray {
+ pdfconstant("ICCBased"),
+ pdfreference(n),
+ }
+ -- used in page /Resources, so this must be inserted at runtime
+ lpdf.adddocumentcolorspace(prefixes[colorspace],pdfreference(pdfflushobject(a)))
+ if trace_colorprofiles then
+ report_backends("including color profile '%s' from '%s'",colorspace,filename)
+ end
+ elseif trace_colorprofiles then
+ report_backends("no color profile '%s' in '%s'",colorspace,filename)
+ end
+ loaded = true
+ elseif trace_colorprofiles then
+ report_backends("color profile '%s' is already included",colorspace)
end
end
+--~ The following is somewhat cleaner but then we need to flag that there are
+--~ color spaces set so that the page flusher does not optimize the (at that
+--~ moment) still empty array away. So, next(d_colorspaces) should then become
+--~ a different test, i.e. also on flag. I'll add that when we need more forward
+--~ referencing.
+--~
+--~ local function embedprofile = codeinjections.useICCdefaultprofile
+--~
+--~ local function flushembeddedprofiles()
+--~ for colorspace, filename in next, defaults do
+--~ embedprofile(colorspace,filename)
+--~ end
+--~ end
+--~
+--~ function codeinjections.useICCdefaultprofile(colorspace,filename)
+--~ defaults[lower(colorspace)] = filename
+--~ end
+--~
+--~ lpdf.registerdocumentfinalizer(flushembeddedprofiles,1,"embedded color profiles")
+
function codeinjections.usePDFXoutputintent(id,name,reference,outputcondition,info)
local d = {
Type = pdfconstant("OutputIntent"),
@@ -125,6 +151,9 @@ function codeinjections.usePDFXoutputintent(id,name,reference,outputcondition,in
d["DestOutputProfile"] = pdfreference(icc)
end
intents[#intents+1] = pdfreference(pdfflushobject(pdfdictionary(d)))
+ if trace_colorprofiles then
+ report_backends("adding output intent '%s' with id '%s' (entry %s)",name,id,#intents)
+ end
end
local function flushoutputintents()
@@ -133,6 +162,4 @@ local function flushoutputintents()
end
end
-
-lpdf.registerdocumentfinalizer(flushoutputintents,1)
-lpdf.registerdocumentfinalizer(flushembeddedprofiles,1)
+lpdf.registerdocumentfinalizer(flushoutputintents,2,"output intents")