summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/attr-ini.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/attr-ini.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/attr-ini.lua157
1 files changed, 125 insertions, 32 deletions
diff --git a/Master/texmf-dist/tex/context/base/attr-ini.lua b/Master/texmf-dist/tex/context/base/attr-ini.lua
index 535488c35b1..81c2f4744ca 100644
--- a/Master/texmf-dist/tex/context/base/attr-ini.lua
+++ b/Master/texmf-dist/tex/context/base/attr-ini.lua
@@ -1,6 +1,6 @@
if not modules then modules = { } end modules ['attr-ini'] = {
version = 1.001,
- comment = "companion to attr-ini.tex",
+ comment = "companion to attr-ini.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
@@ -15,8 +15,10 @@ local concat = table.concat
local texsprint = tex.sprint
local ctxcatcodes = tex.ctxcatcodes
+local unsetvalue = attributes.unsetvalue
--- todo: document this
+-- todo: document this but first reimplement this as it reflects the early
+-- days of luatex / mkiv and we have better ways now
-- nb: attributes: color etc is much slower than normal (marks + literals) but ...
-- nb. too many "0 g"s
@@ -60,7 +62,6 @@ colors.data = colors.data or { }
colors.values = colors.values or { }
colors.registered = colors.registered or { }
-colors.enabled = true
colors.weightgray = true
colors.attribute = attributes.private('color')
colors.selector = attributes.private('colormodel')
@@ -79,10 +80,13 @@ local templates = {
}
local models = {
- all = 1,
- gray = 2,
- rgb = 3,
- cmyk = 4,
+ [interfaces.variables.none] = unsetvalue,
+ black = unsetvalue,
+ bw = unsetvalue,
+ all = 1,
+ gray = 2,
+ rgb = 3,
+ cmyk = 4,
}
colors.model = "all"
@@ -94,8 +98,7 @@ local registered = colors.registered
local numbers = attributes.numbers
local list = attributes.list
-local min = math.min
-local max = math.max
+local min, max, floor = math.min, math.max, math.floor
local nodeinjections = backends.nodeinjections
local codeinjections = backends.codeinjections
@@ -121,10 +124,77 @@ local function cmyktogray(c,m,y,k)
return rgbtogray(cmyktorgb(c,m,y,k))
end
+-- http://en.wikipedia.org/wiki/HSI_color_space
+-- http://nl.wikipedia.org/wiki/HSV_(kleurruimte)
+
+
+local function hsvtorgb(h,s,v)
+ -- h = h % 360
+ local hd = h/60
+ local hf = floor(hd)
+ local hi = hf % 6
+ -- local f = hd - hi
+ local f = hd - hf
+ local p = v * (1 - s)
+ local q = v * (1 - f * s)
+ local t = v * (1 - (1 - f) * s)
+ if hi == 0 then
+ return v, t, p
+ elseif hi == 1 then
+ return q, v, p
+ elseif hi == 2 then
+ return p, v, t
+ elseif hi == 3 then
+ return p, q, v
+ elseif hi == 4 then
+ return t, p, v
+ elseif hi == 5 then
+ return v, p, q
+ else
+ print("error in hsv -> rgb",hi,h,s,v)
+ end
+end
+
+function rgbtohsv(r,g,b)
+ local offset, maximum, other_1, other_2
+ if r >= g and r >= b then
+ offset, maximum, other_1, other_2 = 0, r, g, b
+ elseif g >= r and g >= b then
+ offset, maximum, other_1, other_2 = 2, g, b, r
+ else
+ offset, maximum, other_1, other_2 = 4, b, r, g
+ end
+ if maximum == 0 then
+ return 0, 0, 0
+ end
+ local minimum = other_1 < other_2 and other_1 or other_2
+ if maximum == minimum then
+ return 0, 0, maximum
+ end
+ local delta = maximum - minimum
+ return (offset + (other_1-other_2)/delta)*60, delta/maximum, maximum
+end
+
+function graytorgb(s) -- unweighted
+ return 1-s, 1-s, 1-s
+end
+
+function hsvtogray(h,s,v)
+ return rgb_to_gray(hsv_to_rgb(h,s,v))
+end
+
+function grayto_hsv(s)
+ return 0, 0, s
+end
+
colors.rgbtocmyk = rgbtocmyk
colors.rgbtogray = rgbtogray
colors.cmyktorgb = cmyktorgb
colors.cmyktogray = cmyktogray
+colors.rgbtohsv = rgbtohsv
+colors.hsvtorgb = hsvtorgb
+colors.hsvtogray = hsvtogray
+colors.graytohsv = graytohsv
-- we can share some *data by using s, rgb and cmyk hashes, but
-- normally the amount of colors is not that large; storing the
@@ -192,16 +262,20 @@ local function reviver(data,n)
d = { gray, gray, gray, gray }
logs.report("attributes","unable to revive color %s",n or "?")
else
- local kind, gray, rgb, cmyk = v[1], graycolor(v[2]), rgbcolor(v[3],v[4],v[5]), cmykcolor(v[6],v[7],v[8],v[9])
+ local kind = v[1]
if kind == 2 then
+ local gray= graycolor(v[2])
d = { gray, gray, gray, gray }
elseif kind == 3 then
+ local gray, rgb, cmyk = graycolor(v[2]), rgbcolor(v[3],v[4],v[5]), cmykcolor(v[6],v[7],v[8],v[9])
d = { rgb, gray, rgb, cmyk }
elseif kind == 4 then
+ local gray, rgb, cmyk = graycolor(v[2]), rgbcolor(v[3],v[4],v[5]), cmykcolor(v[6],v[7],v[8],v[9])
d = { cmyk, gray, rgb, cmyk }
elseif kind == 5 then
local spot = spotcolor(v[10],v[11],v[12],v[13])
- d = { spot, gray, rgb, cmyk }
+ -- d = { spot, gray, rgb, cmyk }
+ d = { spot, spot, spot, spot }
end
end
data[n] = d
@@ -226,7 +300,7 @@ function colors.register(name, colorspace, ...) -- passing 9 vars is faster (but
local stamp = format(templates[colorspace],...)
local color = registered[stamp]
if not color then
- color = #values+1
+ color = #values + 1
values[color] = colors[colorspace](...)
registered[stamp] = color
-- colors.reviver(color)
@@ -250,13 +324,16 @@ shipouts.handle_color = nodes.install_attribute_handler {
resolver = function() return colors.main end,
}
+function colors.enable()
+ tasks.enableaction("shipouts","shipouts.handle_color")
+end
+
-- transparencies
transparencies = transparencies or { }
transparencies.registered = transparencies.registered or { }
transparencies.data = transparencies.data or { }
transparencies.values = transparencies.values or { }
-transparencies.enabled = false
transparencies.triggering = true
transparencies.attribute = attributes.private('transparency')
@@ -336,24 +413,27 @@ shipouts.handle_transparency = nodes.install_attribute_handler {
processor = states.process,
}
---- overprint / knockout
+function transparencies.enable()
+ tasks.enableaction("shipouts","shipouts.handle_transparency")
+end
+
+--- colorintents: overprint / knockout
-overprints = overprints or { }
-overprints.data = overprints.data or { }
-overprints.enabled = false
-overprints.attribute = attributes.private('overprint')
+colorintents = colorintents or { }
+colorintents.data = colorintents.data or { }
+colorintents.attribute = attributes.private('colorintent')
-overprints.registered = {
+colorintents.registered = {
overprint = 1,
knockout = 2,
}
-local data, registered = overprints.data, overprints.registered
+local data, registered = colorintents.data, colorintents.registered
-local function extender(overprints,key)
+local function extender(colorintents,key)
if key == "none" then
local d = data[2]
- overprints.none = d
+ colorintents.none = d
return d
end
end
@@ -370,26 +450,29 @@ local function reviver(data,n)
end
end
-setmetatable(overprints, { __index = extender })
-setmetatable(overprints.data, { __index = reviver })
+setmetatable(colorintents, { __index = extender })
+setmetatable(colorintents.data, { __index = reviver })
-function overprints.register(stamp)
+function colorintents.register(stamp)
return registered[stamp] or registered.overprint
end
-shipouts.handle_overprint = nodes.install_attribute_handler {
- name = "overprint",
- namespace = overprints,
+shipouts.handle_colorintent = nodes.install_attribute_handler {
+ name = "colorintent",
+ namespace = colorintents,
initializer = states.initialize,
finalizer = states.finalize,
processor = states.process,
}
+function colorintents.enable()
+ tasks.enableaction("shipouts","shipouts.handle_colorintent")
+end
+
--- negative / positive
negatives = negatives or { }
negatives.data = negatives.data or { }
-negatives.enabled = false
negatives.attribute = attributes.private("negative")
negatives.registered = {
@@ -434,13 +517,16 @@ shipouts.handle_negative = nodes.install_attribute_handler {
processor = states.process,
}
+function negatives.enable()
+ tasks.enableaction("shipouts","shipouts.handle_negative")
+end
+
-- effects -- can be optimized (todo: metatables)
effects = effects or { }
effects.data = effects.data or { }
effects.values = effects.values or { }
effects.registered = effects.registered or { }
-effects.enabled = false
effects.stamp = "%s:%s:%s"
effects.attribute = attributes.private("effect")
@@ -463,7 +549,7 @@ end
local function reviver(data,n)
local e = values[n] -- we could nil values[n] now but hardly needed
- local d = effect(v[1],v[2],v[3])
+ local d = effect(e[1],e[2],e[3])
data[n] = d
return d
end
@@ -490,6 +576,10 @@ shipouts.handle_effect = nodes.install_attribute_handler {
processor = states.process,
}
+function effects.enable()
+ tasks.enableaction("shipouts","shipouts.handle_effect")
+end
+
-- layers (ugly code, due to no grouping and such); currently we use exclusive layers
-- but when we need it stacked layers might show up too; the next function based
-- approach can be replaced by static (metatable driven) resolvers
@@ -499,7 +589,6 @@ viewerlayers.data = viewerlayers.data or { }
viewerlayers.registered = viewerlayers.registered or { }
viewerlayers.values = viewerlayers.values or { }
viewerlayers.listwise = viewerlayers.listwise or { }
-viewerlayers.enabled = false
viewerlayers.attribute = attributes.private("viewerlayer")
storage.register("viewerlayers/registered", viewerlayers.registered, "viewerlayers.registered")
@@ -553,3 +642,7 @@ shipouts.handle_viewerlayer = nodes.install_attribute_handler {
finalizer = states.finalize,
processor = states.stacked,
}
+
+function viewerlayers.enable()
+ tasks.enableaction("shipouts","shipouts.handle_viewerlayer")
+end