1
2
3
4
5
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
if not modules then modules = { } end modules ['meta-fnt'] = {
version = 1.001,
comment = "companion to meta-fnt.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
-- This was one of the demo modules that never was used for real so the \MKIV\
-- variant has been replaced by one using the newer \LMTX\ interface, but only
-- because we want to be (sort of) compatible. Instead of doing the work at the
-- \LUA\ end we do it at the \TEX end.
metapost.fonts = metapost.fonts or { }
function metapost.fonts.define(specification)
local fontname = specification.fontname
local filename = specification.filename
local fontsize = specification.size
context.definemetafont (
{ fontname },
{ filename },
{ size and { "at " .. size .. " sp" } or "" }
)
end
-- metapost.fonts.define {
-- fontname = "bidi",
-- filename = "bidi-symbols.mp",
-- }
-- okay, let's for the moment put this here:
local tonumber = tonumber
local find = string.find
local context = context
local fastserialize = table.fastserialize
local settings_to_hash = utilities.parsers.settings_to_hash
local settings_to_array = utilities.parsers.settings_to_array
local addcharacters = fonts.constructors.addcharacters
local fontdata = fonts.hashes.identifiers
-- This is a prelude to a more advance mechanism: when we are in mp we can construct the
-- whole composed character there.
function fonts.helpers.combineglyphs(fnt, specification)
local hash = fastserialize(specification)
local fontid = fnt or font.current()
local tfmdata = fontdata[fontid]
local combhash = tfmdata.combhash or { }
local unicode = combhash[hash]
if not unicode then
local t = { }
local h = 0
local d = 0
local w = 0
local o = 0
local characters = tfmdata.characters
for i=1,#specification do
local s = specification[i]
local l = find(s,"=") and settings_to_hash(s)
local n = tonumber(l and l.unicode or s) or tonumber(s)
if n then
local data = characters[n]
if data then
local bb = data.boundingbox
if bb then
local llx = bb[1]
local lly = bb[2]
local urx = bb[3]
local ury = bb[4]
if ury > h then
h = ury
elseif - ury > d then
d = - ury
end
if - lly > d then
d = - lly
elseif lly > h then
h = lly
end
if llx < o then
o = llx
end
-- could be an extension to the "offset" command
local c = l and l.color
if c then
t[#t+1] = { "startcolor", c }
end
t[#t+1] = { "offset", 0, 0, n }
if c then
t[#t+1] = { "stopcolor" }
end
-- t[#t+1] = { "push" }
-- if c then
-- t[#t+1] = { "startcolor", c }
-- end
-- t[#t+1] = { "right", 0 }
-- t[#t+1] = { "char", n }
-- if c then
-- t[#t+1] = { "stopcolor" }
-- end
-- t[#t+1] = { "pop" }
if urx > w then
w = urx
end
else
local ht = data.height or 0 if ht > h then h = ht end
local dp = data.depth or 0 if dp > d then d = dp end
local wd = data.width or 0 if wd > w then w = wd end
t[#t+1] = { "char", n }
end
end
end
end
for i=1,#t do
-- if t[i][1] == "right" then
if t[i][1] == "offset" then
t[i][2] = -o
-- t[i][2] = o
end
end
-- cheat one: we get a private slot
unicode = fonts.helpers.addprivate(tfmdata,nil,{
commands = t,
width = w - o,
height = h,
depth = d,
})
-- cheat two: we overload it later
addcharacters(fontid,{ characters = { [unicode] = characters[unicode] } })
tfmdata.combhash = combhash
combhash[hash] = unicode
end
return unicode
end
interfaces.implement {
name = "combineglyphs",
public = true,
arguments = "string",
actions = function(list)
local list = settings_to_array(list)
local unicode = fonts.helpers.combineglyphs(font.current(),list)
context(unicode)
end,
}
|