1if not modules then modules = { } end modules ['luatex-fonts-demo-tt'] = {
2 version = 1.001,
3 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
4 copyright = "PRAGMA ADE / ConTeXt Development Team",
5 license = "see context related readme files",
6}
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40local random, sin = math.random, math.sin
41local formatters = string.formatters
42
43local now = 0
44local max = 2 * math.pi
45local step = max/20
46
47
48
49
50
51
52function fonts.helpers.FuzzyFontStart(exheight,ttgrayness,ttthickness,ttshift,ttstep,ttmax)
53 local grayness = ttgrayness * random(0,5)/10
54 local thickness = ttthickness * random(1,2)/10
55 local shift = 0
56 if ttstep > 0 then
57 if now > max then
58 now = 0
59 else
60 now = now + step * ttstep
61 end
62 shift = ttmax * sin(now) * exheight/5
63 else
64 shift = ttshift * random(-1,1) * exheight/20
65 end
66
67
68 local template = formatters["pdf:page:q %0.2F g %.2F G %0.2F w 2 Tr %.3F Ts"](
69 grayness, grayness, thickness, shift
70 )
71 vf.special(template)
72
73
74
75
76
77end
78
79function fonts.helpers.FuzzyFontStop()
80 vf.special("pdf:page:Q")
81
82
83end
84
85return function(specification)
86 local features = specification.features.normal
87 local list = features.ttfont
88 if list then
89 list = utilities.parsers.settings_to_array(list)
90 else
91 list = {
92 'lmtypewriter10-regular',
93 'almfixed',
94 }
95 end
96 local f = { }
97 local id = { }
98 for i=1,#list do
99 f[i], id[i] = fonts.constructors.readanddefine(list[i],specification.size)
100 end
101 local f1 = f[1]
102 if f1 then
103 f1.name = specification.name
104 f1.properties.name = specification.name
105 f1.properties.virtualized = true
106 f1.fonts = { }
107 local target = f1.characters
108 local exbp = f1.parameters.exheight * number.dimenfactors.bp
109 local stop = {
110 "lua",
111 "fonts.helpers.FuzzyFontStop()",
112 }
113 local start = {
114 "lua",
115 formatters["fonts.helpers.FuzzyFontStart(%.3F,%.2F,%.2F,%.2F,%.2F,%.2F)"](
116 exbp,
117 tonumber(features.ttgrayness) or 1,
118 tonumber(features.ttthickness) or 1,
119 tonumber(features.ttshift) or 1,
120 tonumber(features.ttstep) or 0,
121 tonumber(features.ttmax) or 1
122 ),
123 }
124 for i=1,#list do
125 f1.fonts[i] = { id = id[i] }
126 local characters = f[i].characters
127 for u, v in next, characters do
128 v.commands = { start, { "slot", i, u }, stop }
129 if characters ~= target then
130 target[u] = v
131 end
132 end
133 end
134 end
135 return f1
136end
137 |