grph-pat.lua /size: 2286 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
grph-pat
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to grph-pat.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
-- This is just a proof of concept. Viewers behave different (offsets) and Acrobat doesn't
10
-- show xform based patterns.
11
--
12
-- This module will be cleaned up and use codeinjections and such.
13 14
local
texsetbox
=
tex
.
setbox
15
local
texgetbox
=
tex
.
getbox
16 17
local
nodepool
=
nodes
.
pool
18
local
new_literal
=
nodepool
.
originliteral
-- really ?
19
local
new_hlist
=
nodepool
.
hlist
20 21
local
names
=
{
}
22 23
interfaces
.
implement
{
24
name
=
"
registerpattern
"
,
25
arguments
=
{
{
26
{
"
name
"
}
,
27
{
"
number
"
,
"
integer
"
}
,
28
{
"
width
"
,
"
dimension
"
}
,
29
{
"
height
"
,
"
dimension
"
}
,
30
{
"
hoffset
"
,
"
dimension
"
}
,
31
{
"
voffset
"
,
"
dimension
"
}
,
32
}
}
,
33
actions
=
function
(
specification
)
34
local
number
=
specification
.
number
35
local
name
=
specification
.
name
36
local
box
=
texgetbox
(
number
)
37
if
not
name
or
name
=
=
"
"
then
38
return
39
end
40
nodes
.
handlers
.
finalizebox
(
number
)
41
names
[
name
]
=
lpdf
.
registerpattern
{
42
number
=
number
,
43
width
=
specification
.
width
or
box
.
width
,
44
height
=
specification
.
height
or
(
box
.
height
+
box
.
depth
)
,
45
hoffset
=
specification
.
hoffset
,
46
voffset
=
specification
.
voffset
,
47
}
48
end
49
}
50 51
interfaces
.
implement
{
52
name
=
"
applypattern
"
,
53
arguments
=
{
{
54
{
"
name
"
}
,
55
{
"
number
"
,
"
integer
"
}
,
56
{
"
width
"
,
"
dimension
"
}
,
57
{
"
height
"
,
"
dimension
"
}
,
58
}
}
,
59
actions
=
function
(
specification
)
60
local
number
=
specification
.
number
61
local
name
=
specification
.
name
62
local
width
=
specification
.
width
63
local
height
=
specification
.
height
64
if
not
name
or
name
=
=
"
"
then
65
return
66
end
67
local
p
=
names
[
name
]
68
if
p
then
69
local
l
=
new_literal
(
lpdf
.
patternstream
(
p
,
width
,
height
)
)
70
local
h
=
new_hlist
(
l
,
width
,
height
)
71
texsetbox
(
number
,
h
)
72
end
73
end
74
}
75