summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/grph-pat.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2017-05-14 19:58:50 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2017-05-14 19:58:50 +0200
commitfd0c4577a4b6e85ca2db664906e1a03807ce133f (patch)
treefa23fcc04248d03ff82e34634b8ef1bb9cf28acb /tex/context/base/mkiv/grph-pat.lua
parentdb581096187dc2d3cbdbe4cdc39d247c168b1607 (diff)
downloadcontext-fd0c4577a4b6e85ca2db664906e1a03807ce133f.tar.gz
2017-05-14 19:15:00
Diffstat (limited to 'tex/context/base/mkiv/grph-pat.lua')
-rw-r--r--tex/context/base/mkiv/grph-pat.lua74
1 files changed, 74 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/grph-pat.lua b/tex/context/base/mkiv/grph-pat.lua
new file mode 100644
index 000000000..c5e4b9f64
--- /dev/null
+++ b/tex/context/base/mkiv/grph-pat.lua
@@ -0,0 +1,74 @@
+if not modules then modules = { } end modules ['grph-pat'] = {
+ version = 1.001,
+ comment = "companion to grph-pat.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- This is just a proof of concept. Viewers behave different (offsets) and Acrobat doesn't
+-- show xform based patterns.
+--
+-- This module will be cleaned up and use codeinjections and such.
+
+local texsetbox = tex.setbox
+local texgetbox = tex.getbox
+
+local nodepool = nodes.pool
+local new_literal = nodepool.pdforiginliteral -- really ?
+local new_hlist = nodepool.hlist
+
+local names = { }
+
+interfaces.implement {
+ name = "registerpattern",
+ arguments = { {
+ { "name" },
+ { "number", "integer" },
+ { "width", "dimension" },
+ { "height", "dimension" },
+ { "hoffset", "dimension" },
+ { "voffset", "dimension" },
+ } },
+ actions = function(specification)
+ local number = specification.number
+ local name = specification.name
+ local box = texgetbox(number)
+ if not name or name == "" then
+ return
+ end
+ nodes.handlers.finalize(box)
+ names[name] = lpdf.registerpattern {
+ number = number,
+ width = specification.width or box.width,
+ height = specification.height or (box.height + box.depth) ,
+ hoffset = specification.hoffset,
+ voffset = specification.voffset,
+ }
+ end
+}
+
+interfaces.implement {
+ name = "applypattern",
+ arguments = { {
+ { "name" },
+ { "number", "integer" },
+ { "width", "dimension" },
+ { "height", "dimension" },
+ } },
+ actions = function(specification)
+ local number = specification.number
+ local name = specification.name
+ local width = specification.width
+ local height = specification.height
+ if not name or name == "" then
+ return
+ end
+ local p = names[name]
+ if p then
+ local l = new_literal(lpdf.patternstream(p,width,height))
+ local h = new_hlist(l,width,height)
+ texsetbox(number,h)
+ end
+ end
+}