diff options
author | Mojca Miklavec <mojca.miklavec@gmail.com> | 2012-05-14 17:38:55 +0000 |
---|---|---|
committer | Mojca Miklavec <mojca.miklavec@gmail.com> | 2012-05-14 17:38:55 +0000 |
commit | 15995e10bfc68edf79970c4ea4fbb6678566c46e (patch) | |
tree | 2de7ca2a83f2d37ef043ad7429a5cb945bb79ddb /Master/texmf-dist/tex/context/base/lpdf-ini.lua | |
parent | c9a39f716f1e5ec820ed3aab2c9aef25c5a9d730 (diff) |
ConTeXt 2012.05.14 16:00
git-svn-id: svn://tug.org/texlive/trunk@26371 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lpdf-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/lpdf-ini.lua | 80 |
1 files changed, 49 insertions, 31 deletions
diff --git a/Master/texmf-dist/tex/context/base/lpdf-ini.lua b/Master/texmf-dist/tex/context/base/lpdf-ini.lua index 74ecb36de74..88999358ce1 100644 --- a/Master/texmf-dist/tex/context/base/lpdf-ini.lua +++ b/Master/texmf-dist/tex/context/base/lpdf-ini.lua @@ -9,12 +9,9 @@ if not modules then modules = { } end modules ['lpdf-ini'] = { local setmetatable, getmetatable, type, next, tostring, tonumber, rawset = setmetatable, getmetatable, type, next, tostring, tonumber, rawset local char, byte, format, gsub, concat, match, sub, gmatch = string.char, string.byte, string.format, string.gsub, table.concat, string.match, string.sub, string.gmatch local utfvalues = string.utfvalues -local texset = tex.set +local utfchar = utf.char local sind, cosd = math.sind, math.cosd -local lpegmatch = lpeg.match - ---~ local pdfreserveobject = pdf and pdf.reserveobj or function() return 1 end -- for testing ---~ local pdfimmediateobject = pdf and pdf.immediateobj or function() return 2 end -- for testing +local lpegmatch, P, C, R, S, Cc, Cs = lpeg.match, lpeg.P, lpeg.C, lpeg.R, lpeg.S, lpeg.Cc, lpeg.Cs local pdfreserveobject = pdf.reserveobj local pdfimmediateobject = pdf.immediateobj @@ -29,7 +26,7 @@ local trace_detail = false trackers.register("backend.detail", function local report_objects = logs.reporter("backend","objects") local report_finalizing = logs.reporter("backend","finalizing") -local backends, context = backends, context +local backends = backends backends.pdf = backends.pdf or { comment = "backend for directly generating pdf output", @@ -42,7 +39,7 @@ backends.pdf = backends.pdf or { lpdf = lpdf or { } local lpdf = lpdf -local function tosixteen(str) +local function tosixteen(str) -- an lpeg might be faster if not str or str == "" then return "<feff>" -- not () as we want an indication that it's unicode else @@ -61,7 +58,7 @@ local function tosixteen(str) end end -lpdf.tosixteen = tosixteen +lpdf.tosixteen = tosixteen -- lpeg is some 5 times faster than gsub (in test) on escaping @@ -73,7 +70,7 @@ lpdf.tosixteen = tosixteen -- ["("] = "\\(", [")"] = "\\)", -- } -- --- local escaped = lpeg.Cs(lpeg.Cc("(") * (lpeg.S("\\/#<>[]()")/escapes + lpeg.P(1))^0 * lpeg.Cc(")")) +-- local escaped = Cs(Cc("(") * (S("\\/#<>[]()")/escapes + P(1))^0 * Cc(")")) -- -- local function toeight(str) -- if not str or str == "" then @@ -237,7 +234,7 @@ local mt_f = { __lpdftype = "false", __tostring = tostring_f, __call = valu local mt_r = { __lpdftype = "reference", __tostring = tostring_r, __call = value_r } local mt_v = { __lpdftype = "verbose", __tostring = tostring_v, __call = value_v } -local function pdfstream(t) -- we need to add attrbutes +local function pdfstream(t) -- we need to add attributes if t then for i=1,#t do t[i] = tostring(t[i]) @@ -288,7 +285,7 @@ for s in gmatch(forbidden,".") do replacements[s] = format("#%02x",byte(s)) end -local escaped = lpeg.Cs(lpeg.Cc("/") * (lpeg.S(forbidden)/replacements + lpeg.P(1))^0) +local escaped = Cs(Cc("/") * (S(forbidden)/replacements + P(1))^0) local function pdfconstant(str,default) str = str or default or "" @@ -374,14 +371,15 @@ function lpdf.reserveannotation() return pdfreserveobject("annot") end -lpdf.immediateobject = pdfimmediateobject -lpdf.object = pdfdeferredobject -- the table interface, todo: auto attr() and so -lpdf.deferredobject = pdfdeferredobject -lpdf.referenceobject = pdfreferenceobject +-- lpdf.immediateobject = pdfimmediateobject +-- lpdf.deferredobject = pdfdeferredobject +-- lpdf.object = pdfdeferredobject +-- lpdf.referenceobject = pdfreferenceobject + lpdf.pagereference = pdf.pageref or tex.pdfpageref lpdf.registerannotation = pdf.registerannot -function lpdf.delayedobject(data) +function lpdf.delayedobject(data) -- we will get rid of this one local n = pdfdeferredobject(data) pdfreferenceobject(n) return n @@ -415,6 +413,35 @@ function lpdf.flushobject(name,data) end end + +function lpdf.flushstreamobject(data,dict,compressed) -- default compressed + if trace_objects then + report_objects("flushing stream object of %s bytes",#data) + end + local dtype = type(dict) + return pdfdeferredobject { + immediate = true, + compresslevel = compressed == false and 0 or nil, + type = "stream", + string = data, + attr = (dtype == "string" and dict) or (dtype == "table" and dict()) or nil, + } +end + +function lpdf.flushstreamfileobject(filename,dict,compressed) -- default compressed + if trace_objects then + report_objects("flushing stream file object '%s'",filename) + end + local dtype = type(dict) + return pdfdeferredobject { + immediate = true, + compresslevel = compressed == false and 0 or nil, + type = "stream", + file = filename, + attr = (dtype == "string" and dict) or (dtype == "table" and dict()) or nil, + } +end + local shareobjectcache, shareobjectreferencecache = { }, { } function lpdf.shareobject(content) @@ -634,17 +661,6 @@ local function flushcolorspaces() if next(d_colorspaces) then trace_flush("color local function flushpatterns () if next(d_patterns ) then trace_flush("patterns") pdfimmediateobject(r_patterns, tostring(d_patterns )) end end local function flushshades () if next(d_shades ) then trace_flush("shades") pdfimmediateobject(r_shades, tostring(d_shades )) end end ---~ local collected = pdfdictionary { ---~ ExtGState = p_extgstates, ---~ ColorSpace = p_colorspaces, ---~ Pattern = p_patterns, ---~ Shading = p_shades, ---~ } ; collected = collected() - ---~ function lpdf.collectedresources() ---~ context(collected) ---~ end - function lpdf.collectedresources() local ExtGState = next(d_extgstates ) and p_extgstates local ColorSpace = next(d_colorspaces) and p_colorspaces @@ -658,7 +674,9 @@ function lpdf.collectedresources() Shading = Shading, -- ProcSet = pdfarray { pdfconstant("PDF") }, } - context(collected()) + return collected() + else + return "" end end @@ -685,7 +703,7 @@ registerpagefinalizer(checkshades,3,"shades") function lpdf.rotationcm(a) local s, c = sind(a), cosd(a) - context("%s %s %s %s 0 0 cm",c,s,-s,c) + return format("%s %s %s %s 0 0 cm",c,s,-s,c) end -- ! -> universaltime @@ -706,7 +724,7 @@ function lpdf.id() end function lpdf.checkedkey(t,key,variant) - local pn = t[key] + local pn = t and t[key] if pn then local tn = type(pn) if tn == variant then @@ -759,7 +777,7 @@ end -- lpdf.addtoinfo("ConTeXt.Version", tex.contextversiontoks) -- lpdf.addtoinfo("ConTeXt.Time", os.date("%Y.%m.%d %H:%M")) -- :%S --- lpdf.addtoinfo("ConTeXt.Jobname", tex.jobname) +-- lpdf.addtoinfo("ConTeXt.Jobname", environment.jobname) -- lpdf.addtoinfo("ConTeXt.Url", "www.pragma-ade.com") if not pdfreferenceobject then |