font-imp-unicode.lua /size: 2440 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
font-imp-unicode
'
]
=
{
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
=
next
12 13
local
fonts
=
fonts
14
local
helpers
=
fonts
.
helpers
15
local
constructors
=
fonts
.
constructors
16
local
registerotffeature
=
fonts
.
handlers
.
otf
.
features
.
register
17 18
local
extraprivates
=
helpers
.
extraprivates
19
local
addprivate
=
helpers
.
addprivate
20 21
local
function
initialize
(
tfmdata
)
22
for
i
=
1
,
#
extraprivates
do
23
local
e
=
extraprivates
[
i
]
24
local
c
=
e
[
2
]
(
tfmdata
)
25
if
c
then
26
addprivate
(
tfmdata
,
e
[
1
]
,
c
)
27
end
28
end
29
end
30 31
constructors
.
newfeatures
.
otf
.
register
{
32
name
=
"
extraprivates
"
,
33
description
=
"
extra privates
"
,
34
default
=
true
,
35
manipulators
=
{
36
base
=
initialize
,
37
node
=
initialize
,
38
}
39
}
40 41
local
tounicode
=
fonts
.
mappings
.
tounicode
42 43
local
function
initialize
(
tfmdata
,
key
,
value
)
44
if
value
=
=
"
ligatures
"
then
45
local
private
=
fonts
.
constructors
and
fonts
.
constructors
.
privateoffset
or
0xF0000
46
local
collected
=
fonts
.
handlers
.
otf
.
readers
.
getcomponents
(
tfmdata
.
shared
.
rawdata
)
47
if
collected
and
next
(
collected
)
then
48
for
unicode
,
char
in
next
,
tfmdata
.
characters
do
49
local
u
=
collected
[
unicode
]
50
if
u
then
51
local
n
=
#
u
52
for
i
=
1
,
n
do
53
if
u
[
i
]
>
private
then
54
n
=
0
55
break
56
end
57
end
58
if
n
>
0
then
59
if
n
=
=
1
then
60
u
=
u
[
1
]
61
end
62
char
.
unicode
=
u
63
char
.
tounicode
=
tounicode
(
u
)
64
end
65
end
66
end
67
end
68
end
69
end
70 71
-- forceunicodes=ligatures : aggressive lig resolving (e.g. for emoji)
72
--
73
-- kind of like: \enabletrackers[fonts.mapping.forceligatures]
74 75
registerotffeature
{
76
name
=
"
forceunicodes
"
,
77
description
=
"
forceunicodes
"
,
78
manipulators
=
{
79
base
=
initialize
,
80
node
=
initialize
,
81
}
82
}
83