1
2
3
4
5
6
7
8
9
10
11
12
13
14\startluacode
15moduledata.emoji = moduledata.emoji or { }
16
17local find = string.find
18local sortedhash = table.sortedhash
19local utfvalues = string.utfvalues
20
21local context = context
22
23local traverseid = nodes.traverseid
24
25local glyph_code = nodes.nodecodes.glyph
26
27local descriptions = fonts.hashes.descriptions
28local checkedemoji = fonts.symbols.emoji.checked
29local compactemoji = characters.emoji.compact
30local resolvedemoji = characters.emoji.resolve
31local knownemoji = characters.emoji.known
32
33local function emojisnippets(name)
34 local d = descriptions[true]
35 if d then
36 local e = resolvedemoji(name)
37 local s = { }
38 for b in utfvalues(e) do
39 if not (b == 0x200D or (b >= 0x1F3FB and b <= 0x1F3FF)) then
40 local t = { }
41 s[#s+1] = t
42 local c = d[b]
43 if c then
44 c = c.colors
45 if c then
46 for i=1,#c do
47 t[#t+1] = c[i].slot
48 end
49 else
50 t[#t+1] = b
51 end
52 end
53 end
54 end
55 return #s > 0 and s or nil
56 end
57end
58
59local function emojiglyphs(name)
60 local d = descriptions[true]
61 if d then
62 local e = checkedemoji(name)
63 local s = { }
64 for n in traverseid(glyph_code,e) do
65 local b = n.char
66 if not (b == 0x200D or (b >= 0x1F3FB and b <= 0x1F3FF)) then
67 local t = { }
68 s[#s+1] = t
69 local c = d[b]
70 if c then
71 c = c.colors
72 if c then
73 for i=1,#c do
74 t[#t+1] = c[i].slot
75 end
76 else
77 t[#t+1] = b
78 end
79 end
80 end
81 end
82 nodes.flush_list(e)
83 return #s > 0 and s or nil
84 end
85end
86
87characters.emojisnippets = emojisnippets
88fonts.symbols.emojiglyphs = emojiglyphs
89
90function moduledata.emoji.showsnippets(name)
91 local s = emojisnippets(name)
92 if s then
93 local ni = #s
94 for i=1,ni do
95 local si = s[i]
96 local nj = #si
97 for j=1,nj do
98 context.WrapEmojiSnippet(i,ni,j,nj,si[j])
99 end
100 end
101 end
102end
103
104function moduledata.emoji.showglyphs(name)
105 local s = emojiglyphs(name)
106 if s then
107 local ni = #s
108 for i=1,ni do
109 local si = s[i]
110 local nj = #si
111 for j=1,nj do
112 context.WrapEmojiSnippet(i,ni,j,nj,si[j])
113 end
114 end
115 end
116end
117
118function moduledata.emoji.showknown(list)
119 local hash = knownemoji()
120 local size = 0
121 if list then
122 list = utilities.parsers.settings_to_array(list)
123 size = #list
124 if size == 0 then
125 list = false
126 else
127 for i=1,size do
128 list[i] = string.escapedpattern(list[i])
129 end
130 end
131 end
132 for k, v in sortedhash(hash) do
133 local okay = true
134 if find(compactemoji(k),"%-s%-t") then
135 okay = false
136 elseif list then
137 okay = false
138 for i=1,size do
139 if find(k,list[i]) then
140 okay = true
141 break
142 end
143 end
144 end
145 if okay then
146 context("\\WrapEmojiPlusText{%s}{%!tex!}",k,v)
147 end
148 end
149end
150
151local function convert(t,k)
152 local v = { }
153 for i=1,#k do
154 local p = k[i]
155 end
156 return v
157end
158
159function moduledata.emoji.showpalette(list)
160 local colorpalettes = fonts.hashes.resources[true].colorpalettes
161 if colorpalettes then
162 if list then
163 list = utilities.parsers.settings_to_hash(list)
164 if not next(list) then
165 list = false
166 end
167 end
168 context.starttabulate { "||lp|" }
169 for i=1,#colorpalettes do
170 if not list or list[tostring(i)] then
171 local palette = colorpalettes[i]
172 context.BC()
173 context.type(i)
174 context.NC()
175 for j=1,#palette do
176 local p = palette[j]
177 local r, g, b = p[1]/255, p[2]/255, p[3]/255
178 local s = attributes.colors.rgbtogray(r,g,b)
179 context.WrapEmojiColorEntry(j,s,r,g,b)
180 end
181 context.NC()
182 context.NR()
183 end
184 end
185 context.stoptabulate()
186 end
187end
188
189\stopluacode
190
191\unexpanded\def\WrapEmojiPlusText#1#2
192 {\dontleavehmode\hbox\bgroup
193 \tttf
194 \hpack to 8\emwidth{\setfontid\scratchcounter#2\hss}
195 \hpack to 8\emwidth{\setfontid\scratchcounter\checkedemoji{#1}\hss}
196 #1
197 \egroup\par}
198
199\unexpanded\def\ShowEmoji
200 {\dosingleempty\doShowEmoji}
201
202\unexpanded\def\doShowEmoji[#1]
203 {\begingroup
204 \scratchcounter\fontid\font
205 \ctxlua{moduledata.emoji.showknown([[#1]])}
206 \endgroup}
207
208\unexpanded\def\WrapEmojiSnippet#1#2#3#4#5
209 {\ifnum#3=\plusone
210 \par
211 \dontleavehmode\ruledhbox\bgroup
212 \fi
213 \ruledhbox to 2\emwidth{\hss\char#5\hss}
214 \ifnum#3=#4\relax
215 \egroup
216 \par
217 \fi}
218
219\unexpanded\def\ShowEmojiSnippets[#1]
220 {\ctxlua{moduledata.emoji.showsnippets("#1")}}
221
222\unexpanded\def\ShowEmojiGlyphs[#1]
223 {\ctxlua{moduledata.emoji.showglyphs("#1")}}
224
225\unexpanded\def\OverlayEmojiSnippet#1#2#3#4#5
226 {\setbox\scratchbox\hbox{\color[trace:#3]{\char#5}}
227 \ifnum#3=\plusone
228 \ifnum#1=\plusone
229 \dontleavehmode\ruledhbox\bgroup
230 \fi
231 \hbox\bgroup
232 \else
233 \hskip\wd\scratchbox
234 \fi
235 \box\scratchbox
236 \ifnum#3=#4\relax
237 \egroup
238 \ifnum#1=#2\relax
239 \egroup
240 \fi
241 \fi}
242
243\unexpanded\def\ShowEmojiSnippetsOverlay[#1]
244 {\begingroup
245 \let\WrapEmojiSnippet\OverlayEmojiSnippet
246 \ctxlua{moduledata.emoji.showsnippets("#1")}
247 \endgroup}
248
249\unexpanded\def\WrapEmojiColorEntry#1#2#3#4#5
250 {\dontleavehmode\hpack\bgroup
251 \definecolor
252 [dummy]
253 [r=#3,g=#4,b=#5]
254 \backgroundline
255 [dummy]
256 {\setbox\scratchbox\hpack to 2\emwidth{\hss\ifdim#2pt<.5pt\white\fi\ttx#1\hss}
257 \ht\scratchbox.8\strutht\dp\scratchbox.6\strutdp\box\scratchbox}
258 \egroup
259 \quad}
260
261\unexpanded\def\ShowEmojiPalettes
262 {\dosingleempty\doShowEmojiPalettes}
263
264\unexpanded\def\doShowEmojiPalettes[#1]
265 {\ctxlua{moduledata.emoji.showpalette([[#1]])}}
266
267
268
269
270
271
272
273
274\definefontfeature[seguiemjcl][color:overlay]
275\definefontfeature[seguiemjbw][bandw:overlay]
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290\continueifinputfile{sfontsemoji.mkiv}
291
292\starttext
293
294\start
295
296\definedfont[file:seguiemj.any*default,seguiemjcl]
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314\startTEXpage
315[\char8205\char128104]=\char988828\par
316[\char8205\char128105]=\char988851\par
317[\char8205\char983484]=\char988834\par
318[\char8205\char983485]=\char988835\par
319[\char8205\char983486]=\char988836\par
320[\char8205\char983487]=\char988837\par
321[\char8205\char983488]=\char988838\par
322[\char8205\char983495]=\char988858\par
323[\char8205\char983496]=\char988859\par
324[\char8205\char983497]=\char988860\par
325[\char8205\char983498]=\char988861\par
326[\char8205\char983499]=\char988862\par
327\stopTEXpage
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355\stop
356
357\stoptext
358 |