1if 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
10
11
12
13
14local texsetbox = tex . setbox
15local texgetbox = tex . getbox
16
17local nodepool = nodes . pool
18local new_literal = nodepool . originliteral
19local new_hlist = nodepool . hlist
20
21local names = { }
22
23interfaces . 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
51interfaces . 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 |