diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lpdf-xmp.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/lpdf-xmp.lua | 82 |
1 files changed, 60 insertions, 22 deletions
diff --git a/Master/texmf-dist/tex/context/base/lpdf-xmp.lua b/Master/texmf-dist/tex/context/base/lpdf-xmp.lua index c8e7b2b5733..c9bead8a5b3 100644 --- a/Master/texmf-dist/tex/context/base/lpdf-xmp.lua +++ b/Master/texmf-dist/tex/context/base/lpdf-xmp.lua @@ -12,8 +12,16 @@ local xmlfillin = xml.fillin local trace_xmp = false trackers.register("backend.xmp", function(v) trace_xmp = v end) +local report_xmp = logs.reporter("backend","xmp") + +local backends, lpdf = backends, lpdf + +local codeinjections = backends.pdf.codeinjections -- normally it is registered + local pdfdictionary = lpdf.dictionary local pdfconstant = lpdf.constant +local pdfreference = lpdf.reference +local pdfobject = lpdf.object -- i wonder why this begin end is empty / w (no time now to look into it) @@ -69,18 +77,31 @@ local mapping = { -- maybe some day we will load the xmp file at runtime -local xmp, xmpfile, xmpname = nil, nil, "lpdf-xmp.xml" +local xmp, xmpfile, xmpname = nil, nil, "lpdf-pdx.xml" -function lpdf.setxmpfile(name) - xmpfile = resolvers.findctxfile(name) or "" - if xmpfile == "" then - xmpfile = nil +local function setxmpfile(name) + if xmp then + report_xmp("discarding loaded file '%s'",xmpfile) + xmp = nil end + xmpfile = name ~= "" and name end +codeinjections.setxmpfile = setxmpfile +commands.setxmpfile = setxmpfile + local function valid_xmp() if not xmp then - local xmpfile = xmpfile or resolvers.find_file(xmpname) or "" + -- local xmpfile = xmpfile or resolvers.findfile(xmpname) or "" + if xmpfile and xmpfile ~= "" then + xmpfile = resolvers.findfile(xmpfile) or "" + end + if not xmpfile or xmpfile == "" then + xmpfile = resolvers.findfile(xmpname) or "" + end + if xmpfile ~= "" then + report_xmp("using file '%s'",xmpfile) + end local xmpdata = (xmpfile ~= "" and io.loaddata(xmpfile)) or "" xmp = xml.convert(xmpdata) end @@ -119,47 +140,64 @@ end local t = { } for i=1,24 do t[i] = random() end local function flushxmpinfo() - commands.freezerandomseed(os.clock()) -- hack local t = { } for i=1,24 do t[i] = char(96 + random(26)) end local packetid = concat(t) - local time = lpdf.timestamp() - addxmpinfo("Producer",format("LuaTeX-%0.2f.%s",tex.luatexversion/100,tex.luatexrevision)) - addxmpinfo("DocumentID",format("uuid:%s",os.uuid())) - addxmpinfo("InstanceID",format("uuid:%s",os.uuid())) - addxmpinfo("CreatorTool","LuaTeX + ConTeXt MkIV") - addxmpinfo("CreateDate",time) - addxmpinfo("ModifyDate",time) - addxmpinfo("MetadataDate",time) - addxmpinfo("PTEX.Fullbanner", tex.pdftexbanner) + + local documentid = format("uuid:%s",os.uuid()) + local instanceid = format("uuid:%s",os.uuid()) + local producer = format("LuaTeX-%0.2f.%s",tex.luatexversion/100,tex.luatexrevision) + local creator = "LuaTeX + ConTeXt MkIV" + local time = lpdf.timestamp() + local fullbanner = tex.pdftexbanner + -- local fullbanner = gsub(tex.pdftexbanner,"kpse.*","") + + addxmpinfo("DocumentID", documentid) + addxmpinfo("InstanceID", instanceid) + addxmpinfo("Producer", producer) + addxmpinfo("CreatorTool", creator) + addxmpinfo("CreateDate", time) + addxmpinfo("ModifyDate", time) + addxmpinfo("MetadataDate", time) + addxmpinfo("PTEX.Fullbanner", fullbanner) + + addtoinfo("Producer", producer) + addtoinfo("Creator", creator) + addtoinfo("CreationDate", time) + addtoinfo("ModDate", time) +-- addtoinfo("PTEX.Fullbanner", fullbanner) -- no checking done on existence + local blob = xml.tostring(xml.first(xmp or valid_xmp(),"/x:xmpmeta")) local md = pdfdictionary { Subtype = pdfconstant("XML"), Type = pdfconstant("Metadata"), } if trace_xmp then - commands.writestatus("system","xmp data flushed (see log file)") + report_xmp("data flushed (see log file)") texio.write_nl("log","") texio.write("log","\n% ",(gsub(blob,"[\r\n]","\n%% ")),"\n") end blob = format(xpacket,packetid,blob) - if tex.pdfcompresslevel > 0 then + if not verbose and tex.pdfcompresslevel > 0 then blob = gsub(blob,">%s+<","><") end - local r = pdf.obj { + local r = pdfobject { immediate = true, compresslevel = 0, type = "stream", string = blob, attr = md(), } - lpdf.addtocatalog("Metadata",lpdf.reference(r)) + lpdf.addtocatalog("Metadata",pdfreference(r)) commands.defrostrandomseed() -- hack - end -- his will be enabled when we can inhibit compression for a stream at the lua end -lpdf.registerdocumentfinalizer(flushxmpinfo,1) +lpdf.registerdocumentfinalizer(flushxmpinfo,1,"metadata") + +directives.register("backend.verbosexmp", function(v) + verbose = v +end) |