summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/attr-col.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
committerKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
commit824f7b0903de8ad7f6ee3d7656005e4c59155e06 (patch)
treeabfc8673ef9916f3ab7074e811207384c301492b /Master/texmf-dist/tex/context/base/attr-col.lua
parent689aefb0727676ed3cddf331337b4be226495e72 (diff)
context import for TL13, from www.pragma-ade.com/context/beta/cont-tmf.zip
git-svn-id: svn://tug.org/texlive/trunk@29731 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/attr-col.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/attr-col.lua88
1 files changed, 51 insertions, 37 deletions
diff --git a/Master/texmf-dist/tex/context/base/attr-col.lua b/Master/texmf-dist/tex/context/base/attr-col.lua
index c592d1dc1cb..7c6b7909ba2 100644
--- a/Master/texmf-dist/tex/context/base/attr-col.lua
+++ b/Master/texmf-dist/tex/context/base/attr-col.lua
@@ -15,8 +15,11 @@ if not modules then modules = { } end modules ['attr-col'] = {
local type = type
local format = string.format
local concat = table.concat
+local min, max, floor = math.min, math.max, math.floor
-local attributes, nodes = attributes, nodes
+local attributes, nodes, utilities, logs, backends, storage = attributes, nodes, utilities, logs, backends, storage
+local commands, context, interfaces = commands, context, interfaces
+local tex = tex
local allocate = utilities.storage.allocate
local setmetatableindex = table.setmetatableindex
@@ -31,11 +34,14 @@ local report_transparencies = logs.reporter("transparencies","support")
-- nb: attributes: color etc is much slower than normal (marks + literals) but ...
-- nb. too many "0 g"s
-local states = attributes.states
-local tasks = nodes.tasks
-local nodeinjections = backends.nodeinjections
-local registrations = backends.registrations
-local unsetvalue = attributes.unsetvalue
+local states = attributes.states
+local tasks = nodes.tasks
+local nodeinjections = backends.nodeinjections
+local registrations = backends.registrations
+local unsetvalue = attributes.unsetvalue
+
+local registerstorage = storage.register
+local formatters = string.formatters
-- We can distinguish between rules and glyphs but it's not worth the trouble. A
-- first implementation did that and while it saves a bit for glyphs and rules, it
@@ -63,7 +69,7 @@ local unsetvalue = attributes.unsetvalue
-- colors.strings[color] = "return colors." .. colorspace .. "(" .. concat({...},",") .. ")"
-- end
--
--- storage.register("attributes/colors/data", colors.strings, "attributes.colors.data") -- evaluated
+-- registerstorage("attributes/colors/data", colors.strings, "attributes.colors.data") -- evaluated
--
-- We assume that only processcolors are defined in the format.
@@ -83,15 +89,23 @@ colors.default = 1
colors.main = nil
colors.triggering = true
colors.supported = true
+colors.model = "all"
+
+local data = colors.data
+local values = colors.values
+local registered = colors.registered
-storage.register("attributes/colors/values", colors.values, "attributes.colors.values")
-storage.register("attributes/colors/registered", colors.registered, "attributes.colors.registered")
+local numbers = attributes.numbers
+local list = attributes.list
-local templates = {
- rgb = "r:%s:%s:%s",
- cmyk = "c:%s:%s:%s:%s",
- gray = "s:%s",
- spot = "p:%s:%s:%s:%s"
+registerstorage("attributes/colors/values", values, "attributes.colors.values")
+registerstorage("attributes/colors/registered", registered, "attributes.colors.registered")
+
+local f_colors = {
+ rgb = formatters["r:%s:%s:%s"],
+ cmyk = formatters["c:%s:%s:%s:%s"],
+ gray = formatters["s:%s"],
+ spot = formatters["p:%s:%s:%s:%s"],
}
local models = {
@@ -104,17 +118,6 @@ local models = {
cmyk = 4,
}
-colors.model = "all"
-
-local data = colors.data
-local values = colors.values
-local registered = colors.registered
-
-local numbers = attributes.numbers
-local list = attributes.list
-
-local min, max, floor = math.min, math.max, math.floor
-
local function rgbtocmyk(r,g,b) -- we could reduce
return 1-r, 1-g, 1-b, 0
end
@@ -125,9 +128,9 @@ end
local function rgbtogray(r,g,b)
if colors.weightgray then
- return .30*r+.59*g+.11*b
+ return .30*r + .59*g + .11*b
else
- return r/3+g/3+b/3
+ return r/3 + g/3 + b/3
end
end
@@ -135,6 +138,17 @@ local function cmyktogray(c,m,y,k)
return rgbtogray(cmyktorgb(c,m,y,k))
end
+-- not critical so not needed:
+--
+-- local function cmyktogray(c,m,y,k)
+-- local r, g, b = 1.0 - min(1.0,c+k), 1.0 - min(1.0,m+k), 1.0 - min(1.0,y+k)
+-- if colors.weightgray then
+-- return .30*r + .59*g + .11*b
+-- else
+-- return r/3 + g/3 + b/3
+-- end
+-- end
+
-- http://en.wikipedia.org/wiki/HSI_color_space
-- http://nl.wikipedia.org/wiki/HSV_(kleurruimte)
@@ -271,7 +285,7 @@ local function reviver(data,n)
if not v then
local gray = graycolor(0)
d = { gray, gray, gray, gray }
- report_attributes("unable to revive color %s",n or "?")
+ report_attributes("unable to revive color %a",n)
else
local model = colors.forcedmodel(v[1])
if model == 2 then
@@ -309,7 +323,7 @@ function colors.setmodel(name,weightgray)
end
function colors.register(name, colorspace, ...) -- passing 9 vars is faster (but not called that often)
- local stamp = format(templates[colorspace],...)
+ local stamp = f_colors[colorspace](...)
local color = registered[stamp]
if not color then
color = #values + 1
@@ -363,15 +377,15 @@ transparencies.triggering = true
transparencies.attribute = a_transparency
transparencies.supported = true
-storage.register("attributes/transparencies/registered", transparencies.registered, "attributes.transparencies.registered")
-storage.register("attributes/transparencies/values", transparencies.values, "attributes.transparencies.values")
+local registered = transparencies.registered -- we could use a 2 dimensional table instead
+local data = transparencies.data
+local values = transparencies.values
+local f_transparency = formatters["%s:%s"]
-local registered = transparencies.registered -- we could use a 2 dimensional table instead
-local data = transparencies.data
-local values = transparencies.values
-local template = "%s:%s"
+registerstorage("attributes/transparencies/registered", registered, "attributes.transparencies.registered")
+registerstorage("attributes/transparencies/values", values, "attributes.transparencies.values")
-local function inject_transparency (...)
+local function inject_transparency(...)
inject_transparency = nodeinjections.transparency
return inject_transparency(...)
end
@@ -386,7 +400,7 @@ function transparencies.register(name,a,t,force) -- name is irrelevant here (can
-- but then we'd end up with transparencies resources even if we
-- would not use transparencies (but define them only). This is
-- somewhat messy.
- local stamp = format(template,a,t)
+ local stamp = f_transparency(a,t)
local n = registered[stamp]
if not n then
n = #values + 1