typo-pnc.lua /size: 6961 b    last modification: 2021-10-28 13:50
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
typo-pnc
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to typo-pnc.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
local
nodes
=
nodes
10
local
fonts
=
fonts
11 12
local
enableaction
=
nodes
.
tasks
.
enableaction
13 14
local
nuts
=
nodes
.
nuts
15
local
tonut
=
nodes
.
tonut
16 17
local
nodecodes
=
nodes
.
nodecodes
18
local
gluecodes
=
nodes
.
gluecodes
19
local
glyph_code
=
nodecodes
.
glyph
20
local
glue_code
=
nodecodes
.
glue
21
local
spaceskip_code
=
gluecodes
.
spaceskip
22 23
local
new_kern
=
nuts
.
pool
.
kern
24
local
insertafter
=
nuts
.
insertafter
25 26
local
nextglyph
=
nuts
.
traversers
.
glyph
27 28
local
getchar
=
nuts
.
getchar
29
local
getfont
=
nuts
.
getfont
30
local
getboth
=
nuts
.
getboth
31
local
getnext
=
nuts
.
getnext
32
local
getattr
=
nuts
.
getattr
33
local
getid
=
nuts
.
getid
34
local
getsubtype
=
nuts
.
getsubtype
35
local
getwidth
=
nuts
.
getwidth
36
local
setwidth
=
nuts
.
setwidth
37 38
local
parameters
=
fonts
.
hashes
.
parameters
39
local
categories
=
characters
.
categories
40 41
local
texsetattribute
=
tex
.
setattribute
42
local
unsetvalue
=
attributes
.
unsetvalue
43 44
local
period
=
0x2E
45
local
factor
=
0
.
5
46 47
-- alternative: tex.getlccode and tex.getuccode
48 49
typesetters
=
typesetters
or
{
}
50
local
typesetters
=
typesetters
51 52
local
periodkerns
=
typesetters
.
periodkerns
or
{
}
53
typesetters
.
periodkerns
=
periodkerns
54 55
local
report
=
logs
.
reporter
(
"
period kerns
"
)
56
local
trace
=
false
57 58
trackers
.
register
(
"
typesetters.periodkerns
"
,
function
(
v
)
trace
=
v
end
)
59 60
periodkerns
.
mapping
=
periodkerns
.
mapping
or
{
}
61
periodkerns
.
factors
=
periodkerns
.
factors
or
{
}
62
local
a_periodkern
=
attributes
.
private
(
"
periodkern
"
)
63 64
storage
.
register
(
"
typesetters/periodkerns/mapping
"
,
periodkerns
.
mapping
,
"
typesetters.periodkerns.mapping
"
)
65
storage
.
register
(
"
typesetters/periodkerns/factors
"
,
periodkerns
.
factors
,
"
typesetters.periodkerns.factors
"
)
66 67
local
mapping
=
periodkerns
.
mapping
68
local
factors
=
periodkerns
.
factors
69 70
function
periodkerns
.
handler
(
head
)
71
for
current
,
char
,
font
in
nextglyph
,
head
do
72
if
char
=
=
period
then
73
local
a
=
getattr
(
current
,
a_periodkern
)
74
if
a
then
75
local
factor
=
mapping
[
a
]
76
if
factor
then
77
local
prev
,
next
=
getboth
(
current
)
78
if
prev
and
next
and
getid
(
prev
)
=
=
glyph_code
and
getid
(
next
)
=
=
glyph_code
then
79
local
pchar
=
getchar
(
prev
)
80
local
pcode
=
categories
[
pchar
]
81
if
pcode
=
=
"
lu
"
or
pcode
=
=
"
ll
"
then
82
local
nchar
=
getchar
(
next
)
83
local
ncode
=
categories
[
nchar
]
84
if
ncode
=
=
"
lu
"
or
ncode
=
=
"
ll
"
then
85
local
next
2
=
getnext
(
next
)
86
if
next
2
and
getid
(
next
2
)
=
=
glyph_code
and
getchar
(
next
2
)
=
=
period
then
87
-- A.B.
88
local
fontspace
,
inserted
89
if
factor
~
=
0
then
90
fontspace
=
parameters
[
getfont
(
current
)
]
.
space
-- can be sped up
91
inserted
=
factor
*
fontspace
92
insertafter
(
head
,
current
,
new_kern
(
inserted
)
)
93
if
trace
then
94
report
(
"
inserting space at %C . [%p] %C .
"
,
pchar
,
inserted
,
nchar
)
95
end
96
end
97
local
next
3
=
getnext
(
next
2
)
98
if
next
3
and
getid
(
next
3
)
=
=
glue_code
and
getsubtype
(
next
3
)
=
=
spaceskip_code
then
99
local
width
=
getwidth
(
next
3
)
100
local
space
=
fontspace
or
parameters
[
getfont
(
current
)
]
.
space
-- can be sped up
101
if
width
>
space
then
-- space + extraspace
102
local
next
4
=
getnext
(
next
3
)
103
if
next
4
and
getid
(
next
4
)
=
=
glyph_code
then
104
local
fchar
=
getchar
(
next
4
)
105
if
categories
[
fchar
]
~
=
"
lu
"
then
106
-- A.B.<glue>X
107
if
trace
then
108
if
inserted
then
109
report
(
"
reverting space at %C . [%p] %C . [%p->%p] %C
"
,
pchar
,
inserted
,
nchar
,
width
,
space
,
fchar
)
110
else
111
report
(
"
reverting space at %C . %C . [%p->%p] %C
"
,
pchar
,
nchar
,
width
,
space
,
fchar
)
112
end
113
end
114
setwidth
(
next
3
,
space
)
115
else
116
if
trace
then
117
if
inserted
then
118
report
(
"
keeping space at %C . [%p] %C . [%p] %C
"
,
pchar
,
inserted
,
nchar
,
width
,
fchar
)
119
else
120
report
(
"
keeping space at %C . %C . [%p] %C
"
,
pchar
,
nchar
,
width
,
fchar
)
121
end
122
end
123
end
124
end
125
end
126
end
127
end
128
end
129
end
130
end
131
end
132
end
133
end
134
end
135
return
head
136
end
137 138
local
enabled
=
false
139 140
function
periodkerns
.
set
(
factor
)
141
factor
=
tonumber
(
factor
)
or
0
142
if
not
enabled
then
143
enableaction
(
"
processors
"
,
"
typesetters.periodkerns.handler
"
)
144
enabled
=
true
145
end
146
local
a
=
factors
[
factor
]
147
if
not
a
then
148
a
=
#
mapping
+
1
149
factors
[
factors
]
,
mapping
[
a
]
=
a
,
factor
150
end
151
factor
=
a
152
texsetattribute
(
a_periodkern
,
factor
)
153
return
factor
154
end
155 156
-- interface
157 158
interfaces
.
implement
{
159
name
=
"
setperiodkerning
"
,
160
actions
=
periodkerns
.
set
,
161
arguments
=
"
string
"
162
}
163 164 165