1if not modules then modules = { } end modules ['grph-rul'] = {
2 version = 1.001,
3 comment = "companion to grph-rul.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
9local attributes = attributes
10local nodes = nodes
11local context = context
12
13local nuts = nodes.nuts
14local nodepool = nuts.pool
15local userrule = nuts.rules.userrule
16local outlinerule = nuts.pool.outlinerule
17local ruleactions = nuts.rules.ruleactions
18
19local setattrlist = nuts.setattrlist
20local setattr = nuts.setattr
21local tonode = nuts.tonode
22
23local getattribute = tex.getattribute
24
25local direct_value = tokens.values.direct
26
27local a_color = attributes.private('color')
28local a_transparency = attributes.private('transparency')
29local a_colormodel = attributes.private('colormodel')
30
31local floor = math.floor
32local getrandom = utilities.randomizer.get
33
34updaters.register("backends.injections.latebindings",function()
35 local codeinjections = backends.codeinjections
36 ruleactions.mp = codeinjections.ruleactionmp
37 ruleactions.fill = codeinjections.ruleactionfill
38 ruleactions.draw = codeinjections.ruleactiondraw
39 ruleactions.stroke = codeinjections.ruleactionstroke
40 ruleactions.box = codeinjections.ruleactionbox
41end)
42
43interfaces.implement {
44 name = "frule",
45 public = true,
46 protected = true,
47 arguments = { {
48 { "width", "dimension" },
49 { "height", "dimension" },
50 { "depth", "dimension" },
51 { "radius", "dimension" },
52 { "line", "dimension" },
53 { "type", "string" },
54 { "data", "string" },
55 { "name", "string" },
56 { "radius", "dimension" },
57 { "corner", "string" },
58 } } ,
59 actions = function(t)
60 local rule = userrule(t)
61 if t.type == "mp" then
62 t.ma = getattribute(a_colormodel) or 1
63 t.ca = getattribute(a_color)
64 t.ta = getattribute(a_transparency)
65 else
66 setattrlist(rule,true)
67 end
68 context(tonode(rule))
69 end
70}
71
72interfaces.implement {
73 name = "roundedoutline",
74 protected = true,
75 arguments = { "dimension", "dimension", "dimension", "dimension", "dimension", "string" },
76 actions = function(w,h,d,l,r,c)
77 local rule = userrule {
78 width = w,
79 height = h,
80 depth = d,
81 line = l,
82 radius = r,
83 corner = c,
84 }
85 setattrlist(rule,true)
86 context(tonode(rule))
87 end
88}
89
90interfaces.implement {
91 name = "framedoutline",
92
93
94 arguments = { "dimension", "dimension", "dimension", "dimension" },
95 actions = function(w,h,d,l)
96 local rule = outlinerule(w,h,d,l)
97 setattrlist(rule,true)
98 context(tonode(rule))
99 end
100}
101
102interfaces.implement {
103 name = "fakeword",
104 arguments = { {
105 { "factor", "dimension" },
106 { "name", "string" },
107 { "min", "dimension" },
108 { "max", "dimension" },
109 { "n", "integer" },
110 } } ,
111 actions = function(t)
112 local factor = t.factor or 0
113 local amount = getrandom("fakeword",t.min,t.max)
114 local rule = userrule {
115 height = 1.25*factor,
116 depth = 0.25*factor,
117 width = floor(amount/10000) * 10000,
118 line = 0.10*factor,
119 ma = getattribute(a_colormodel) or 1,
120 ca = getattribute(a_color),
121 ta = getattribute(a_transparency),
122 type = "mp",
123 name = t.name,
124 }
125 setattrlist(rule,true)
126 context(tonode(rule))
127 end
128}
129 |