From f8d3835211dbbac2ed31376d655642571db52f4e Mon Sep 17 00:00:00 2001 From: Marius Date: Sat, 29 Dec 2012 00:00:16 +0200 Subject: beta 2012.12.28 20:30 --- tex/context/base/lpdf-col.lua | 49 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'tex/context/base/lpdf-col.lua') diff --git a/tex/context/base/lpdf-col.lua b/tex/context/base/lpdf-col.lua index db9d3268b..4936b37c9 100644 --- a/tex/context/base/lpdf-col.lua +++ b/tex/context/base/lpdf-col.lua @@ -14,6 +14,7 @@ local round = math.round local backends, lpdf, nodes = backends, lpdf, nodes local allocate = utilities.storage.allocate +local formatters = string.formatters local nodeinjections = backends.pdf.nodeinjections local codeinjections = backends.pdf.codeinjections @@ -42,6 +43,11 @@ local forcedmodel = colors.forcedmodel local c_transparency = pdfconstant("Transparency") +local f_gray = formatters["%.3f g %.3f G"] +local f_rgb = formatters["%.3f %.3f %.3f rg %.3f %.3f %.3f RG"] +local f_cmyk = formatters["%.3f %.3f %.3f %.3f k %.3f %.3f %.3f %.3f K"] +local f_cm = formatters["q %f %f %f %f %f %f cm"] + local report_color = logs.reporter("colors","backend") -- page groups (might move to lpdf-ini.lua) @@ -99,15 +105,15 @@ commands.synchronizecolormodel = synchronizecolormodel -- color injection function nodeinjections.rgbcolor(r,g,b) - return register(pdfliteral(format("%s %s %s rg %s %s %s RG",r,g,b,r,g,b))) + return register(pdfliteral(f_rgb(r,g,b,r,g,b))) end function nodeinjections.cmykcolor(c,m,y,k) - return register(pdfliteral(format("%s %s %s %s k %s %s %s %s K",c,m,y,k,c,m,y,k))) + return register(pdfliteral(f_cmyk(c,m,y,k,c,m,y,k))) end function nodeinjections.graycolor(s) -- caching 0/1 does not pay off - return register(pdfliteral(format("%s g %s G",s,s))) + return register(pdfliteral(f_gray(s,s))) end function nodeinjections.spotcolor(n,f,d,p) @@ -154,9 +160,9 @@ local pdf_rbg_range = pdfarray { 0, 1, 0, 1, 0, 1 } local pdf_cmyk_range = pdfarray { 0, 1, 0, 1, 0, 1, 0, 1 } local pdf_gray_range = pdfarray { 0, 1 } -local rgb_function = "dup %s mul exch dup %s mul exch %s mul" -local cmyk_function = "dup %s mul exch dup %s mul exch dup %s mul exch %s mul" -local gray_function = "%s mul" +local f_rgb_function = formatters["dup %s mul exch dup %s mul exch %s mul"] +local f_cmyk_function = formatters["dup %s mul exch dup %s mul exch dup %s mul exch %s mul"] +local f_gray_function = formatters["%s mul"] local documentcolorspaces = pdfdictionary() @@ -345,47 +351,47 @@ end function registrations.rgbspotcolor(name,noffractions,names,p,r,g,b) if noffractions == 1 then - registersomespotcolor(name,noffractions,names,p,pdf_device_rgb,pdf_rbg_range,format(rgb_function,r,g,b)) + registersomespotcolor(name,noffractions,names,p,pdf_device_rgb,pdf_rbg_range,f_rgb_function(r,g,b)) else registersomespotcolor(name,noffractions,names,p,pdf_device_rgb,pdf_rbg_range,format("%s %s %s",r,g,b)) end delayindexcolor(name,names,function() - return registersomeindexcolor(name,noffractions,names,p,pdf_device_rgb,pdf_rgb_range,format(rgb_function,r,g,b)) + return registersomeindexcolor(name,noffractions,names,p,pdf_device_rgb,pdf_rgb_range,f_rgb_function(r,g,b)) end) end function registrations.cmykspotcolor(name,noffractions,names,p,c,m,y,k) if noffractions == 1 then - registersomespotcolor(name,noffractions,names,p,pdf_device_cmyk,pdf_cmyk_range,format(cmyk_function,c,m,y,k)) + registersomespotcolor(name,noffractions,names,p,pdf_device_cmyk,pdf_cmyk_range,f_cmyk_function(c,m,y,k)) else registersomespotcolor(name,noffractions,names,p,pdf_device_cmyk,pdf_cmyk_range,format("%s %s %s %s",c,m,y,k)) end delayindexcolor(name,names,function() - return registersomeindexcolor(name,noffractions,names,p,pdf_device_cmyk,pdf_cmyk_range,format(cmyk_function,c,m,y,k)) + return registersomeindexcolor(name,noffractions,names,p,pdf_device_cmyk,pdf_cmyk_range,f_cmyk_function(c,m,y,k)) end) end function registrations.grayspotcolor(name,noffractions,names,p,s) if noffractions == 1 then - registersomespotcolor(name,noffractions,names,p,pdf_device_gray,pdf_gray_range,format(gray_function,s)) + registersomespotcolor(name,noffractions,names,p,pdf_device_gray,pdf_gray_range,f_gray_function(s)) else registersomespotcolor(name,noffractions,names,p,pdf_device_gray,pdf_gray_range,s) end delayindexcolor(name,names,function() - return registersomeindexcolor(name,noffractions,names,p,pdf_device_gray,pdf_gray_range,format(gray_function,s)) + return registersomeindexcolor(name,noffractions,names,p,pdf_device_gray,pdf_gray_range,f_gray_function(s)) end) end function registrations.rgbindexcolor(name,noffractions,names,p,r,g,b) - registersomeindexcolor(name,noffractions,names,p,pdf_device_rgb,pdf_rgb_range,format(rgb_function,r,g,b)) + registersomeindexcolor(name,noffractions,names,p,pdf_device_rgb,pdf_rgb_range,f_rgb_function(r,g,b)) end function registrations.cmykindexcolor(name,noffractions,names,p,c,m,y,k) - registersomeindexcolor(name,noffractions,names,p,pdf_device_cmyk,pdf_cmyk_range,format(cmyk_function,c,m,y,k)) + registersomeindexcolor(name,noffractions,names,p,pdf_device_cmyk,pdf_cmyk_range,f_cmyk_function(c,m,y,k)) end function registrations.grayindexcolor(name,noffractions,names,p,s) - registersomeindexcolor(name,noffractions,names,p,pdf_device_gray,pdf_gray_range,gray_function) + registersomeindexcolor(name,noffractions,names,p,pdf_device_gray,pdf_gray_range,f_gray_function(s)) end function codeinjections.setfigurecolorspace(data,figure) @@ -461,11 +467,10 @@ end statistics.register("page group warning", function() if done and not transparencygroups[currentgroupcolormodel] then - return format("transparencies are used but no pagecolormodel is set") + return "transparencies are used but no pagecolormodel is set" end end) - -- Literals needed to inject code in the mp stream, we cannot use attributes there -- since literals may have qQ's, much may go away once we have mplib code in place. -- @@ -482,13 +487,13 @@ local function lpdfcolor(model,ca,default) -- todo: use gray when no color model = forcedmodel(model) if model == 2 then local s = cv[2] - return format("%s g %s G",s,s) + return f_gray(s,s) elseif model == 3 then local r, g, b = cv[3], cv[4], cv[5] - return format("%s %s %s rg %s %s %s RG",r,g,b,r,g,b) + return f_rgb(r,g,b,r,g,b) elseif model == 4 then local c, m, y, k = cv[6],cv[7],cv[8],cv[9] - return format("%s %s %s %s k %s %s %s %s K",c,m,y,k,c,m,y,k) + return f_cmyk(c,m,y,k,c,m,y,k) else local n,f,d,p = cv[10],cv[11],cv[12],cv[13] if type(p) == "string" then @@ -497,7 +502,7 @@ local function lpdfcolor(model,ca,default) -- todo: use gray when no color return format("/%s cs /%s CS %s SCN %s scn",n,n,p,p) end else - return format("%s g %s G",default or 0,default or 0) + return f_gray(default or 0,default or 0) end else return "" @@ -716,7 +721,7 @@ backends.pdf.tables.vfspecials = allocate { -- todo: distinguish between glyph a palegray = { "special", 'pdf: .75 g' }, }, - startslant = function(a) return { "special", format("pdf: q 1 0 %s 1 0 0 cm",a) } end, + startslant = function(a) return { "special", format("pdf: q 1 0 %f 1 0 0 cm",a) } end, stopslant = { "special", "pdf: Q" }, } -- cgit v1.2.3