font-imp-properties.lua /size: 4057 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
font-imp-properties
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to font-ini.mkiv and hand-ini.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
if
not
context
then
return
end
10 11
local
next
,
type
,
tonumber
,
select
=
next
,
type
,
tonumber
,
select
12
local
byte
,
find
,
formatters
=
string
.
byte
,
string
.
find
,
string
.
formatters
13
local
utfchar
=
utf
.
char
14
local
sortedhash
,
sortedkeys
,
sort
=
table
.
sortedhash
,
table
.
sortedkeys
,
table
.
sort
15
local
insert
=
table
.
insert
16 17
local
context
=
context
18
local
fonts
=
fonts
19
local
utilities
=
utilities
20 21
local
helpers
=
fonts
.
helpers
22 23
local
handlers
=
fonts
.
handlers
24
local
hashes
=
fonts
.
hashes
25
local
otf
=
handlers
.
otf
26
local
afm
=
handlers
.
afm
27 28
local
registerotffeature
=
otf
.
features
.
register
29
local
registerafmfeature
=
afm
.
features
.
register
30 31
local
fontdata
=
hashes
.
identifiers
32
local
fontproperties
=
hashes
.
properties
33 34
local
constructors
=
fonts
.
constructors
35
local
getprivate
=
constructors
.
getprivate
36 37
local
allocate
=
utilities
.
storage
.
allocate
38 39
local
setmetatableindex
=
table
.
setmetatableindex
40 41
local
implement
=
interfaces
.
implement
42 43
do
44 45
local
P
,
lpegpatterns
,
lpegmatch
=
lpeg
.
P
,
lpeg
.
patterns
,
lpeg
.
match
46 47
local
amount
,
stretch
,
shrink
,
extra
48 49
local
factor
=
lpegpatterns
.
unsigned
50
local
space
=
lpegpatterns
.
space
51
local
pattern
=
(
52
(
factor
/
function
(
n
)
amount
=
tonumber
(
n
)
or
amount
end
)
53
+
(
P
(
"
+
"
)
+
P
(
"
plus
"
)
)
*
space
^
0
*
(
factor
/
function
(
n
)
stretch
=
tonumber
(
n
)
or
stretch
end
)
54
+
(
P
(
"
-
"
)
+
P
(
"
minus
"
)
)
*
space
^
0
*
(
factor
/
function
(
n
)
shrink
=
tonumber
(
n
)
or
shrink
end
)
55
+
(
P
(
"
extra
"
)
)
*
space
^
0
*
(
factor
/
function
(
n
)
extra
=
tonumber
(
n
)
or
extra
end
)
56
+
space
^
1
57
)
^
1
58 59
local
function
initialize
(
tfmdata
,
key
,
value
)
60
local
characters
=
tfmdata
.
characters
61
local
parameters
=
tfmdata
.
parameters
62
if
type
(
value
)
=
=
"
string
"
then
63
local
emwidth
=
parameters
.
quad
64
amount
,
stretch
,
shrink
,
extra
=
0
,
0
,
0
,
false
65
lpegmatch
(
pattern
,
value
)
66
if
not
extra
then
67
if
shrink
~
=
0
then
68
extra
=
shrink
69
elseif
stretch
~
=
0
then
70
extra
=
stretch
71
else
72
extra
=
amount
73
end
74
end
75
parameters
.
space
=
amount
*
emwidth
76
parameters
.
space_stretch
=
stretch
*
emwidth
77
parameters
.
space_shrink
=
shrink
*
emwidth
78
parameters
.
extra_space
=
extra
*
emwidth
79
end
80
end
81 82
-- 1.1 + 1.2 - 1.3 minus 1.4 plus 1.1 extra 1.4 -- last one wins
83 84
registerotffeature
{
85
name
=
"
spacing
"
,
86
description
=
"
space settings
"
,
87
manipulators
=
{
88
base
=
initialize
,
89
node
=
initialize
,
90
}
91
}
92 93
end
94 95
do
96 97
local
function
initialize
(
tfmdata
,
value
)
98
local
properties
=
tfmdata
.
properties
99
if
properties
then
100
properties
.
identity
=
value
=
=
"
vertical
"
and
"
vertical
"
or
"
horizontal
"
101
end
102
end
103 104
registerotffeature
{
105
name
=
"
identity
"
,
106
description
=
"
set font identity
"
,
107
initializers
=
{
108
base
=
initialize
,
109
node
=
initialize
,
110
}
111
}
112 113
local
function
initialize
(
tfmdata
,
value
)
114
local
properties
=
tfmdata
.
properties
115
if
properties
then
116
properties
.
writingmode
=
value
=
=
"
vertical
"
and
"
vertical
"
or
"
horizontal
"
117
end
118
end
119 120
registerotffeature
{
121
name
=
"
writingmode
"
,
122
description
=
"
set font direction
"
,
123
initializers
=
{
124
base
=
initialize
,
125
node
=
initialize
,
126
}
127
}
128 129
end
130