summaryrefslogtreecommitdiff
path: root/tex/context/base/lpdf-col.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-04-25 19:00:14 +0300
committerMarius <mariausol@gmail.com>2012-04-25 19:00:14 +0300
commitc7921b422428aa7845f2f88ec5f1b70a676d1e06 (patch)
treeddf909ec0ed91114c0719c32432d8879e5fd807a /tex/context/base/lpdf-col.lua
parentb83d7a9ca8e8efc730390d17ee07fec98397cb70 (diff)
downloadcontext-c7921b422428aa7845f2f88ec5f1b70a676d1e06.tar.gz
beta 2012.04.25 17:29
Diffstat (limited to 'tex/context/base/lpdf-col.lua')
-rw-r--r--tex/context/base/lpdf-col.lua59
1 files changed, 58 insertions, 1 deletions
diff --git a/tex/context/base/lpdf-col.lua b/tex/context/base/lpdf-col.lua
index 85f719c40..227878b5b 100644
--- a/tex/context/base/lpdf-col.lua
+++ b/tex/context/base/lpdf-col.lua
@@ -38,6 +38,56 @@ local colorsvalue = colors.value
local transparenciesvalue = transparencies.value
local forcedmodel = colors.forcedmodel
+-- page groups (might move to lpdf-ini.lua)
+
+local colorspaceconstants = { -- v_none is ignored
+ gray = pdfconstant("DeviceGray"),
+ rgb = pdfconstant("DeviceRGB"),
+ cmyk = pdfconstant("DeviceCMYK"),
+ all = pdfconstant("DeviceRGB"), -- brr
+}
+
+local transparencygroups = { }
+
+lpdf.colorspaceconstants = colorspaceconstants
+lpdf.transparencygroups = transparencygroups
+
+table.setmetatableindex(transparencygroups, function(transparencygroups,colormodel)
+ local cs = colorspaceconstants[colormodel]
+ if cs then
+ local g = pdfreference(pdfflushobject(pdfdictionary {
+ S = pdfconstant("Transparency"),
+ CS = cs,
+ I = true,
+ }))
+ transparencygroups[colormodel] = g
+ return g
+ else
+ transparencygroups[colormodel] = false
+ return false
+ end
+end)
+
+local currentgroupcolormodel
+
+local function addpagegroup()
+ if currentgroupcolormodel then
+ local g = transparencygroups[currentgroupcolormodel]
+ if g then
+ lpdf.addtopageattributes("Group",g)
+ end
+ end
+end
+
+lpdf.registerpagefinalizer(addpagegroup,3,"pagegroup")
+
+local function synchronizecolormodel(model)
+ currentgroupcolormodel = model
+end
+
+backends.codeinjections.synchronizecolormodel = synchronizecolormodel
+commands.synchronizecolormodel = synchronizecolormodel
+
-- injection code (needs a bit reordering)
-- color injection
@@ -363,7 +413,7 @@ local transparencies = { [0] =
local documenttransparencies = { }
local transparencyhash = { } -- share objects
-local done = false
+local done, signaled = false, false
function registrations.transparency(n,a,t)
if not done then
@@ -397,6 +447,13 @@ function registrations.transparency(n,a,t)
end
end
+statistics.register("page group warning", function()
+ if done and not transparencygroups[currentgroupcolormodel] then
+ return format("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.
--