font-enh.lua /size: 5916 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
font-enh
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to font-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
local
next
=
next
10 11
local
trace_unicoding
=
false
12 13
trackers
.
register
(
"
fonts.defining
"
,
function
(
v
)
trace_unicoding
=
v
end
)
14
trackers
.
register
(
"
fonts.unicoding
"
,
function
(
v
)
trace_unicoding
=
v
end
)
15 16
local
report_unicoding
=
logs
.
reporter
(
"
fonts
"
,
"
unicoding
"
)
17 18
local
fonts
=
fonts
19
local
constructors
=
fonts
.
constructors
20 21
----- tfmfeatures = constructors.features.tfm
22
local
afmfeatures
=
constructors
.
features
.
afm
23
local
otffeatures
=
constructors
.
features
.
otf
24 25
----- registertfmfeature = tfmfeatures.register
26
local
registerafmfeature
=
afmfeatures
.
register
27
local
registerotffeature
=
otffeatures
.
register
28 29
-- -- these will become goodies (when needed at all)
30
--
31
-- local fontencodings = fonts.encodings
32
-- fontencodings.remappings = fontencodings.remappings or { }
33
--
34
-- local function reencode(tfmdata,encoding)
35
-- if encoding and fontencodings.known[encoding] then
36
-- local data = fontencodings.load(encoding)
37
-- if data then
38
-- tfmdata.properties.encoding = encoding
39
-- local characters = tfmdata.characters
40
-- local original = { }
41
-- local vector = data.vector
42
-- for unicode, character in next, characters do
43
-- character.name = vector[unicode]
44
-- character.index = unicode, character
45
-- original[unicode] = character
46
-- end
47
-- for newcode, oldcode in next, data.unicodes do
48
-- if newcode ~= oldcode then
49
-- if trace_unicoding then
50
-- report_unicoding("reencoding %U to %U",oldcode,newcode)
51
-- end
52
-- characters[newcode] = original[oldcode]
53
-- end
54
-- end
55
-- end
56
-- end
57
-- end
58
--
59
-- registertfmfeature {
60
-- name = "reencode",
61
-- description = "reencode",
62
-- manipulators = {
63
-- base = reencode,
64
-- node = reencode,
65
-- }
66
-- }
67
--
68
-- local function remap(tfmdata,remapping)
69
-- local vector = remapping and fontencodings.remappings[remapping]
70
-- if vector then
71
-- local characters, original = tfmdata.characters, { }
72
-- for k, v in next, characters do
73
-- original[k], characters[k] = v, nil
74
-- end
75
-- for k,v in next, vector do
76
-- if k ~= v then
77
-- if trace_unicoding then
78
-- report_unicoding("remapping %U to %U",k,v)
79
-- end
80
-- local c = original[k]
81
-- characters[v] = c
82
-- c.index = k
83
-- end
84
-- end
85
-- local properties = tfmdata.properties
86
-- if not properties then
87
-- properties = { }
88
-- tfmdata.properties = properties
89
-- else
90
-- properties.encodingbytes = 2
91
-- properties.format = properties.format or 'type1'
92
-- end
93
-- end
94
-- end
95
--
96
-- registertfmfeature {
97
-- name = "remap",
98
-- description = "remap",
99
-- manipulators = {
100
-- base = remap,
101
-- node = remap,
102
-- }
103
-- }
104 105
-- \definefontfeature[dingbats][goodies=dingbats,unicoding=yes]
106 107
-- we only add and don't replace
108
-- we could also add kerns but we asssume symbols
109
-- todo: complain if not basemode
110 111
-- remapping = {
112
-- tounicode = true,
113
-- unicodes = {
114
-- a1 = 0x2701,
115 116
----- tosixteen = fonts.mappings.tounicode16
117 118
local
function
initialize
(
tfmdata
)
119
local
goodies
=
tfmdata
.
goodies
120
local
newcoding
=
nil
121
for
i
=
1
,
#
goodies
do
122
local
remapping
=
goodies
[
i
]
.
remapping
123
if
remapping
and
remapping
.
unicodes
then
124
newcoding
=
remapping
.
unicodes
-- names to unicodes
125
end
126
end
127
if
newcoding
then
128
local
characters
=
tfmdata
.
characters
129
local
descriptions
=
tfmdata
.
descriptions
130
local
oldcoding
=
tfmdata
.
resources
.
unicodes
131
local
originals
=
{
}
132
for
name
,
newcode
in
next
,
newcoding
do
133
local
oldcode
=
oldcoding
[
name
]
134
if
characters
[
newcode
]
and
not
originals
[
newcode
]
then
135
originals
[
newcode
]
=
{
136
character
=
characters
[
newcode
]
,
137
description
=
descriptions
[
newcode
]
,
138
}
139
end
140
if
oldcode
then
141
local
original
=
originals
[
oldcode
]
142
local
character
,
description
143
if
original
then
144
character
=
original
.
character
145
description
=
original
.
description
146
else
147
character
=
characters
[
oldcode
]
148
description
=
descriptions
[
oldcode
]
149
end
150
characters
[
newcode
]
=
character
151
descriptions
[
newcode
]
=
description
152
character
.
unicode
=
newcode
153
description
.
unicode
=
newcode
154
else
155
oldcoding
[
name
]
=
newcode
156
end
157
if
trace_unicoding
then
158
if
oldcode
then
159
report_unicoding
(
"
aliasing glyph %a from %U to %U
"
,
name
,
oldcode
,
newcode
)
160
else
161
report_unicoding
(
"
aliasing glyph %a to %U
"
,
name
,
newcode
)
162
end
163
end
164
end
165
end
166
end
167 168
local
specification
=
{
169
name
=
"
unicoding
"
,
170
description
=
"
adapt unicode table
"
,
171
initializers
=
{
172
base
=
initialize
,
173
node
=
initialize
,
174
}
,
175
}
176 177
registerotffeature
(
specification
)
178
registerafmfeature
(
specification
)
179