summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/colo-ini.lua
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2010-05-24 14:05:02 +0000
committerTaco Hoekwater <taco@elvenkind.com>2010-05-24 14:05:02 +0000
commit57ea7dad48fbf2541c04e434c31bde655ada3ac4 (patch)
tree1f8b43bc7cb92939271e1f5bec610710be69097f /Master/texmf-dist/tex/context/base/colo-ini.lua
parent6ee41e1f1822657f7f23231ec56c0272de3855e3 (diff)
here is context 2010.05.24 13:05
git-svn-id: svn://tug.org/texlive/trunk@18445 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/colo-ini.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/colo-ini.lua255
1 files changed, 164 insertions, 91 deletions
diff --git a/Master/texmf-dist/tex/context/base/colo-ini.lua b/Master/texmf-dist/tex/context/base/colo-ini.lua
index a67df6a778e..342d6110dca 100644
--- a/Master/texmf-dist/tex/context/base/colo-ini.lua
+++ b/Master/texmf-dist/tex/context/base/colo-ini.lua
@@ -1,16 +1,19 @@
if not modules then modules = { } end modules ['colo-ini'] = {
version = 1.000,
- comment = "companion to colo-ini.tex",
+ comment = "companion to colo-ini.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
+local type = type
local concat = table.concat
-local format, gmatch, gsub, lower, match = string.format, string.gmatch, string.gsub, string.lower, string.match
+local format, gmatch, gsub, lower, match, find = string.format, string.gmatch, string.gsub, string.lower, string.match, string.find
local texsprint = tex.sprint
local ctxcatcodes = tex.ctxcatcodes
+local trace_define = false trackers.register("colors.define",function(v) trace_define = v end)
+
local settings_to_hash_strict = aux.settings_to_hash_strict
colors = colors or { }
@@ -23,89 +26,93 @@ local a_transparency = attributes.private('transparency')
local a_colorspace = attributes.private('colormodel')
local a_background = attributes.private('background')
-local a_l_c_template = "\\setevalue{(ca:%s)}{%s}" ..
- "\\setevalue{(cs:%s)}{\\dosetattribute{color}{%s}}"
-local a_g_c_template = "\\setxvalue{(ca:%s)}{%s}" ..
- "\\setxvalue{(cs:%s)}{\\dosetattribute{color}{%s}}"
-local f_l_c_template = "\\setvalue {(ca:%s)}{\\doinheritca{%s}}" ..
- "\\setvalue {(cs:%s)}{\\doinheritcs{%s}}"
-local f_g_c_template = "\\setgvalue{(ca:%s)}{\\doinheritca{%s}}" ..
- "\\setgvalue{(cs:%s)}{\\doinheritcs{%s}}"
-local r_l_c_template = "\\localundefine{(ca:%s)}" ..
- "\\localundefine{(cs:%s)}"
-local r_g_c_template = "\\globalundefine{(ca:%s)}" ..
- "\\globalundefine{(cs:%s)}"
-
-local a_l_t_template = "\\setevalue{(ta:%s)}{%s}" ..
- "\\setevalue{(ts:%s)}{\\dosetattribute{transparency}{%s}}"
-local a_g_t_template = "\\setxvalue{(ta:%s)}{%s}" ..
- "\\setxvalue{(ts:%s)}{\\dosetattribute{transparency}{%s}}"
-local f_l_t_template = "\\setvalue {(ta:%s)}{\\doinheritta{%s}}" ..
- "\\setvalue {(ts:%s)}{\\doinheritts{%s}}"
-local f_g_t_template = "\\setgvalue{(ta:%s)}{\\doinheritta{%s}}" ..
- "\\setgvalue{(ts:%s)}{\\doinheritts{%s}}"
-local r_l_t_template = "\\localundefine{(ta:%s)}" ..
- "\\localundefine{(ts:%s)}"
-local r_g_t_template = "\\globalundefine{(ta:%s)}" ..
- "\\globalundefine{(ts:%s)}"
+local register_color = colors.register
+local attributes_list = attributes.list
local function definecolor(name, ca, global)
if ca and ca > 0 then
if global then
- texsprint(ctxcatcodes,format(a_g_c_template, name, ca, name, ca))
+ if trace_define then
+ commands.writestatus("color","define global color '%s' with attribute: %s",name,ca)
+ end
+ context.colordefagc(name,ca)
else
- texsprint(ctxcatcodes,format(a_l_c_template, name, ca, name, ca))
+ if trace_define then
+ commands.writestatus("color","define local color '%s' with attribute: %s",name,ca)
+ end
+ context.colordefalc(name,ca)
end
else
if global then
- texsprint(ctxcatcodes,format(r_g_c_template, name, name))
+ context.colordefrgc(name)
else
- texsprint(ctxcatcodes,format(r_l_c_template, name, name))
+ context.colordefrlc(name)
end
end
end
+
local function inheritcolor(name, ca, global)
if ca and ca ~= "" then
if global then
- texsprint(ctxcatcodes,format(f_g_c_template, name, ca, name, ca))
+ if trace_define then
+ commands.writestatus("color","inherit global color '%s' with attribute: %s",name,ca)
+ end
+ context.colordeffgc(name,ca)
else
- texsprint(ctxcatcodes,format(f_l_c_template, name, ca, name, ca))
+ if trace_define then
+ commands.writestatus("color","inherit local color '%s' with attribute: %s",name,ca)
+ end
+ context.colordefflc(name,ca)
end
else
if global then
- texsprint(ctxcatcodes,format(r_g_c_template, name, name))
+ context.colordefrgc(name)
else
- texsprint(ctxcatcodes,format(r_l_c_template, name, name))
+ context.colordefrlc(name)
end
end
end
+
local function definetransparent(name, ta, global)
if ta and ta > 0 then
if global then
- texsprint(ctxcatcodes,format(a_g_t_template, name, ta, name, ta))
+ if trace_define then
+ commands.writestatus("color","define global transparency '%s' with attribute: %s",name,ta)
+ end
+ context.colordefagt(name,ta)
else
- texsprint(ctxcatcodes,format(a_l_t_template, name, ta, name, ta))
+ if trace_define then
+ commands.writestatus("color","define local transparency '%s' with attribute: %s",name,ta)
+ end
+ context.colordefalt(name,ta)
end
else
if global then
- texsprint(ctxcatcodes,format(r_g_t_template, name, name))
+ context.colordefrgt(name)
else
- texsprint(ctxcatcodes,format(r_l_t_template, name, name))
+ context.colordefrlt(name)
end
end
end
+
local function inherittransparent(name, ta, global)
if ta and ta ~= "" then
if global then
- texsprint(ctxcatcodes,format(f_g_t_template, name, ta, name, ta))
+ if trace_define then
+ commands.writestatus("color","inherit global transparency '%s' with attribute: %s",name,ta)
+ end
+ context.colordeffgt(name,ta)
else
- texsprint(ctxcatcodes,format(f_l_t_template, name, ta, name, ta))
+ if trace_define then
+ commands.writestatus("color","inherit local transparency '%s' with attribute: %s",name,ta)
+ end
+ context.colordefflt(name,ta)
end
else
if global then
- texsprint(ctxcatcodes,format(r_g_t_template, name, name))
+ context.colordefrgt(name)
else
- texsprint(ctxcatcodes,format(r_l_t_template, name, name))
+ context.colordefrlt(name)
end
end
end
@@ -144,6 +151,9 @@ local function do_registerspotcolor(parent,name,parentnumber,e,f,d,p)
if v then
local kind = colors.default -- else problems with shading etc
if kind == 1 then kind = v[1] end
+ if e and e ~= "" then
+ registrations.spotcolorname(parent,e) -- before registration of the color
+ end
if kind == 2 then -- name noffractions names p's r g b
registrations.grayspotcolor(parent,f,d,p,v[2])
elseif kind == 3 then
@@ -151,9 +161,6 @@ local function do_registerspotcolor(parent,name,parentnumber,e,f,d,p)
elseif kind == 4 then
registrations.cmykspotcolor(parent,f,d,p,v[6],v[7],v[8],v[9])
end
- if e and e ~= "" then
- registrations.spotcolorname(parent,e)
- end
end
registered[parentnumber] = true
end
@@ -178,45 +185,64 @@ local function do_registermultitonecolor(parent,name,parentnumber,e,f,d,p) -- sa
end
function colors.definesimplegray(name,s)
- return colors.register(name,'gray',s) -- we still need to get rid of 'color'
+ return register_color(name,'gray',s) -- we still need to get rid of 'color'
end
function colors.defineprocesscolor(name,str,global,freeze) -- still inconsistent color vs transparent
- local r = match(str,"^#(.+)$") -- for old times sake (if we need to feed from xml or so)
- local t = (r and { h = r }) or settings_to_hash_strict(str)
- if t then
- if t.h then
- local r, g, b = match(t.h .. "000000","(..)(..)(..)") -- watch the 255
- definecolor(name, colors.register(name,'rgb',(tonumber(r,16) or 0)/255,(tonumber(g,16) or 0)/255,(tonumber(b,16) or 0)/255 ), global)
- elseif t.r or t.g or t.b then
- definecolor(name, colors.register(name,'rgb', tonumber(t.r) or 0, tonumber(t.g) or 0, tonumber(t.b) or 0 ), global)
- elseif t.c or t.m or t.y or t.k then
- definecolor(name, colors.register(name,'cmyk',tonumber(t.c) or 0, tonumber(t.m) or 0, tonumber(t.y) or 0, tonumber(t.k) or 0), global)
+ local x = match(str,"^#(.+)$") -- for old times sake (if we need to feed from xml or so)
+ if x then
+ local r, g, b = match(x .. "000000","(..)(..)(..)") -- watch the 255
+ definecolor(name, register_color(name,'rgb',(tonumber(r,16) or 0)/255,(tonumber(g,16) or 0)/255,(tonumber(b,16) or 0)/255), global)
+ else
+ local settings = settings_to_hash_strict(str)
+ if settings then
+ local r, g, b = settings.r, settings.g, settings.b
+ if r or g or b then
+ definecolor(name, register_color(name,'rgb', tonumber(r) or 0, tonumber(g) or 0, tonumber(b) or 0), global)
+ else
+ local c, m, y, k = settings.c, settings.m, settings.y, settings.k
+ if c or m or y or b then
+ definecolor(name, register_color(name,'cmyk',tonumber(c) or 0, tonumber(m) or 0, tonumber(y) or 0, tonumber(k) or 0), global)
+ else
+ local h, s, v = settings.h, settings.s, settings.v
+ if v then
+ r, g, b = colors.hsvtorgb(tonumber(h) or 0, tonumber(s) or 1, tonumber(v) or 1) -- maybe later native
+ definecolor(name, register_color(name,'rgb',r,g,b), global)
+ else
+ local x = settings.x or h
+ if x then
+ r, g, b = match(x .. "000000","(..)(..)(..)") -- watch the 255
+ definecolor(name, register_color(name,'rgb',(tonumber(r,16) or 0)/255,(tonumber(g,16) or 0)/255,(tonumber(b,16) or 0)/255), global)
+ else
+ definecolor(name, register_color(name,'gray',tonumber(s) or 0), global)
+ end
+ end
+ end
+ end
+ local a, t = settings.a, settings.t
+ if a and t then
+ definetransparent(name, transparencies.register(name,transparent[a] or tonumber(a) or 1,tonumber(t) or 1), global)
+ elseif colors.couple then
+ -- definetransparent(name, transparencies.register(nil, 1, 1), global) -- can be sped up
+ definetransparent(name, 0, global) -- can be sped up
+ end
+ elseif freeze then
+ local ca = attributes_list[a_color] [str]
+ local ta = attributes_list[a_transparency][str]
+ if ca then
+ definecolor(name, ca, global)
+ end
+ if ta then
+ definetransparent(name, ta, global)
+ end
else
- definecolor(name, colors.register(name,'gray',tonumber(t.s) or 0), global)
- end
- if t.a and t.t then
- definetransparent(name, transparencies.register(name,transparent[t.a] or tonumber(t.a) or 1,tonumber(t.t) or 1), global)
- elseif colors.couple then
- -- definetransparent(name, transparencies.register(nil, 1, 1), global) -- can be sped up
- definetransparent(name, 0, global) -- can be sped up
+ inheritcolor(name, str, global)
+ inherittransparent(name, str, global)
+ -- if global and str ~= "" then -- For Peter Rolf who wants access to the numbers in Lua. (Currently only global is supported.)
+ -- attributes_list[a_color] [name] = attributes_list[a_color] [str] or attributes.unsetvalue -- reset
+ -- attributes_list[a_transparency][name] = attributes_list[a_transparency][str] or attributes.unsetvalue
+ -- end
end
- elseif freeze then
- local ca = attributes.list[a_color] [str]
- local ta = attributes.list[a_transparency][str]
- if ca then
- definecolor(name, ca, global)
- end
- if ta then
- definetransparent(name, ta, global)
- end
- else
- inheritcolor(name, str, global)
- inherittransparent(name, str, global)
- -- if global and str ~= "" then -- For Peter Rolf who wants access to the numbers in Lua. (Currently only global is supported.)
- -- attributes.list[a_color] [name] = attributes.list[a_color] [str] or attributes.unsetvalue -- reset
- -- attributes.list[a_transparency][name] = attributes.list[a_transparency][str] or attributes.unsetvalue
- -- end
end
end
@@ -226,19 +252,20 @@ function colors.isblack(ca) -- maybe commands
end
function colors.definespotcolor(name,parent,str,global)
- if parent == "" or parent:find("=") then
+ if parent == "" or find(parent,"=") then
colors.registerspotcolor(name, parent)
elseif name ~= parent then
- local cp = attributes.list[a_color][parent]
+ local cp = attributes_list[a_color][parent]
if cp then
local t = settings_to_hash_strict(str)
if t then
- t.p = tonumber(t.p) or 1
- do_registerspotcolor(parent, name, cp, t.e, 1, "", t.p) -- p not really needed, only diagnostics
+ local tp = tonumber(t.p) or 1
+ do_registerspotcolor(parent, name, cp, t.e, 1, "", tp) -- p not really needed, only diagnostics
if name and name ~= "" then
- definecolor(name, colors.register(name,'spot', parent, 1, "", t.p), true)
- if t.a and t.t then
- definetransparent(name, transparencies.register(name,transparent[t.a] or tonumber(t.a) or 1,tonumber(t.t) or 1), global)
+ definecolor(name, register_color(name,'spot', parent, 1, "", tp), true)
+ local ta, tt = t.a, t.t
+ if ta and tt then
+ definetransparent(name, transparencies.register(name,transparent[ta] or tonumber(ta) or 1,tonumber(tt) or 1), global)
elseif colors.couple then
--~ definetransparent(name, transparencies.register(nil, 1, 1), global) -- can be sped up
definetransparent(name, 0, global) -- can be sped up
@@ -250,7 +277,7 @@ function colors.definespotcolor(name,parent,str,global)
end
function colors.registerspotcolor(parent, str)
- local cp = attributes.list[a_color][parent]
+ local cp = attributes_list[a_color][parent]
if cp then
local e = ""
if str then
@@ -275,11 +302,11 @@ function colors.definemultitonecolor(name,multispec,colorspec,selfspec)
dd, pp, nn = concat(dd,','), concat(pp,','), concat(nn,'_')
local parent = gsub(lower(nn),"[^%d%a%.]+","_")
colors.defineprocesscolor(parent,colorspec..","..selfspec,true,true)
- local cp = attributes.list[a_color][parent]
+ local cp = attributes_list[a_color][parent]
if cp then
do_registerspotcolor(parent, name, cp, "", nof, dd, pp)
do_registermultitonecolor(parent, name, cp, "", nof, dd, pp)
- definecolor(name, colors.register(name, 'spot', parent, nof, dd, pp), true)
+ definecolor(name, register_color(name, 'spot', parent, nof, dd, pp), true)
local t = settings_to_hash_strict(selfspec)
if t and t.a and t.t then
definetransparent(name, transparencies.register(name,transparent[t.a] or tonumber(t.a) or 1,tonumber(t.t) or 1), global)
@@ -350,7 +377,7 @@ function colors.formatgray(ca,separator)
return format("%0.3f",(cv and cv[2]) or 0)
end
-function colors.colorcomponents(ca)
+function colors.colorcomponents(ca) -- return list
local cv = colors.value(ca)
if cv then
local model = cv[1]
@@ -405,3 +432,49 @@ function colors.spotcolorvalue(ca,default)
end
return tostring(v)
end
+
+-- experiment (a bit of a hack, as we need to get the attribute number)
+
+local min = math.min
+
+-- a[b,c] -> b+a*(c-b)
+
+local function f(one,two,i,fraction)
+ local o, t = one[i], two[i]
+ local otf = o + fraction * (t - o)
+ if otf > 1 then
+ otf = 1
+ end
+ return otf
+end
+
+function colors.defineintermediatecolor(name,fraction,c_one,c_two,a_one,a_two,specs,global,freeze)
+ fraction = tonumber(fraction) or 1
+ local one, two = colors.value(c_one), colors.value(c_two)
+ if one and two then
+ local csone, cstwo = one[1], two[1]
+ if csone == cstwo then
+ -- actually we can set all 8 values at once here but this is cleaner as we avoid
+ -- problems with weighted gray conversions and work with original values
+ local ca
+ if csone == 2 then
+ ca = register_color(name,'gray',f(one,two,2,fraction))
+ elseif csone == 3 then
+ ca = register_color(name,'rgb',f(one,two,3,fraction),f(one,two,4,fraction),f(one,two,5,fraction))
+ elseif csone == 4 then
+ ca = register_color(name,'cmyk',f(one,two,6,fraction),f(one,two,7,fraction),f(one,two,8,fraction),f(one,two,9,fraction))
+ else
+ ca = register_color(name,'gray',f(one,two,2,fraction))
+ end
+ definecolor(name,ca,global,freeze)
+ end
+ end
+ local one, two = transparencies.value(a_one), transparencies.value(a_two)
+ local t = settings_to_hash_strict(specs)
+ local ta = tonumber((t and t.a) or (one and one[1]) or (two and two[1]))
+ local tt = tonumber((t and t.t) or (one and two and f(one,two,2,fraction)))
+ if ta and tt then
+--~ print(ta,tt)
+ definetransparent(name,transparencies.register(name,ta,tt),global)
+ end
+end