onandon-emoji.tex /size: 19 Kb    last modification: 2023-12-21 09:43
1% language=us
2
3\usemodule[fonts-emoji]
4
5\environment onandon-environment
6
7% \definefont[MyEmoji][emojionecolor-svginot*default,svg]
8% \definefont[MyEmoji][seguiemj*seguiemj-bw]
9% \definefont[MyEmoji][emojionemozilla*default,overlay]
10% \definefont[MyEmoji][applecoloremoji*default,bitmap]
11
12\definefontfeature[seguiemj-cl][default][colr=yes,ccmp=yes,dist=yes]
13\definefontfeature[seguiemj-bw][default][ccmp=yes,dist=yes]
14
15\definefont[MyEmoji]     [seguiemj*seguiemj-cl]
16\definefont[MyEmojiLarge][seguiemj*seguiemj-cl @ 100pt]
17
18\definefontsynonym[emoji][seguiemj*seguiemj-cl]
19
20\startcomponent onandon-emoji
21
22\startchapter[title=Emoji again]
23
24Because at the \CONTEXT\ 2016 meeting color fonts \footnote {For that occasion
25the cowfont, a practical joke concerning Dutch \quote {koeieletters}, were turned
26into a color font and presented at the meeting.} were on the agenda, some time
27was spent on emoji (these colorful small picture glyphs). When possible I bring
28kids to the Bacho\TEX\ conference so for the 2017 BachoTUG I decided to do
29something with emoji that, after all, are mostly used by those younger than I am.
30So, I had to take a look at the current state. Here are some observations.
31
32The \UNICODE\ standard defines a whole lot of emoji and if mankind manages to
33survive for a while one can assume that a lot more will be added. After all,
34icons as well as variants keep evolving. There are several ways to organize these
35symbols in groups but I will not give grouping a try. Just visit \type
36{emojipedia.org} and you get served well. For this story I only mention that:
37
38\startitemize
39    \startitem
40        There are quite some shapes and nearly all of them are in color. The
41        yellow ones, smilies and such, are quite prominently present but there
42        are many more.
43    \stopitem
44    \startitem
45        A special subset is fulled by persons: man, woman, girl, boy and recently
46        a baby.
47    \stopitem
48    \startitem
49        The grown ups can be combined in loving couples (either or not kissing)
50        and then can form families, but only upto 2 young kids or gender neutral
51        babies.
52    \stopitem
53    \startitem
54        All persons can be flagged with one of five skin tones so that not all
55        persons (or heads) look bright yellow.
56    \stopitem
57    \startitem
58        Interesting is that girls and boys are still fond of magenta (pinkish)
59        and cyan (blueish) cloths and ornaments. Also haircuts are rather
60        specific to the gender.
61    \stopitem
62\stopitemize
63
64For rendering color emojis we have a few color related \OPENTYPE\ font properties
65available: bitmaps, \SVG\, and stacked glyphs. Now, if you think of the
66combinations that can be made with skin tones, you realize that fonts can become
67pretty large if each combination results in a glyph. In the first half of 2017
68\MICROSOFT\ released an update for its emoji font and the company took the
69challenge to provide not only mixed skin tone couples, but also supported skin
70tones for the kids, including a baby.
71
72This recent addition already adds over 25.000 additional glyphs \footnote {That
73is the amount I counted when I added all combinations runtime but the emojipedia
74mentions twice that amount. Currently in \CONTEXT\ we resolve such combinations
75when requested.} so imagine what will happen in the future. But, instead of
76making a picture for each variant, a different solution has been chosen. For
77coloring this seguiemj font uses the (very flexible) stacking technology: a color
78shape is an overlay of colored symbols. The colors are organized in palettes and
79it's no big deal to add additional palettes if needed. Instead of adding
80pre|-|composed shapes (as is needed with bitmaps and \SVG) snippets are used to
81build alternative glyphs and these can be combined into new shapes by
82substitution and positioning (for that kerns, mark anchoring and distance
83compensation is used).
84
85So, a family can be constructed of composed shapes (man, woman, etc) that each
86are composed of snippets (skull, hair, mouth, eyes). So, effectively a family of
87four is a bunch of maybe 25 small glyphs overlayed and colored. In \in {figure}
88[fig:emojisnippets] we see how a shape is constructed out of separate glyphs. \in
89{Figure} [fig:emojisnippetsoverlay] shows how they can be overlayed with colors
90(we use a dedicated color set).
91
92\startplacefigure[title={Emoji snippets.},reference=fig:emojisnippets]
93    \scale[width=\textwidth]{\framed[frame=off,offset=overlay,align=normal]\bgroup
94        \forgetall
95        \MyEmoji
96        \ShowEmojiSnippets
97          [family man light skin tone
98           woman dark skin tone
99           girl medium skin tone
100           boy medium skin tone]
101    \egroup}
102\stopplacefigure
103
104\startplacefigure[title={Emoji snippets overlayed.},reference=fig:emojisnippetsoverlay]
105    \scale[width=\textwidth]{\framed[frame=off,offset=overlay,align=normal]\bgroup
106        \forgetall
107        \MyEmoji
108        \ShowEmojiSnippetsOverlay
109          [family man light skin tone
110           woman dark skin tone
111           girl medium skin tone
112           boy medium skin tone]
113    \egroup}
114\stopplacefigure
115
116When a font supports it, a sequence of emoji can be turned into a more compact
117representation. In \in {figure} [fig:emojiskintones] we see how skin tones are
118applied in such combinations. \in {Figure} [fig:emojiglyphs] shows the small
119snippets.
120
121\startplacefigure[title={Emoji families and such with skin tones.},reference=fig:emojiskintones,location=page]
122    \startcombination[2*4]
123        {\ruledhbox{\MyEmojiLarge\resolvedemoji
124            {family man woman girl boy}}}
125            {family man woman girl boy}
126        {\ruledhbox{\MyEmojiLarge\resolvedemoji
127            {family woman girl boy}}}
128            {family woman girl boy}
129        {\ruledhbox{\MyEmojiLarge\resolvedemoji
130            {family woman woman girl boy}}}
131            {family woman woman girl boy}
132        {\ruledhbox{\MyEmojiLarge\resolvedemoji
133            {family man girl boy}}}
134            {family man girl boy}
135        {\ruledhbox{\MyEmojiLarge\resolvedemoji
136            {family
137             man dark skin tone
138             woman girl baby}}}
139            {family
140             man dark skin tone
141             woman girl baby}
142        {\ruledhbox{\MyEmojiLarge\resolvedemoji
143            {family
144             man light skin tone
145             woman light skin tone
146             girl dark skin tone}}}
147            {family
148             man light skin tone
149             woman light skin tone
150             girl dark skin tone}
151        {\ruledhbox{\MyEmojiLarge\resolvedemoji
152            {family woman girl boy}}}
153            {family woman girl boy}
154        {\ruledhbox{\MyEmojiLarge\resolvedemoji
155            {family
156             man light skin tone
157             woman dark skin tone
158             girl medium skin tone
159             boy medium skin tone}}}
160            {family
161             man light skin tone
162             woman dark skin tone
163             girl medium skin tone
164             boy medium skin tone}
165    \stopcombination
166\stopplacefigure
167
168\startplacefigure[title={Emoji glyphs.},reference=fig:emojiglyphs]
169    \scale[width=\textwidth]{\framed[frame=off,offset=overlay,align=normal]\bgroup
170        \forgetall
171        \MyEmoji
172        \ShowEmojiGlyphs
173          [family man light skin tone
174           woman dark skin tone
175           girl medium skin tone
176           boy medium skin tone]
177    \egroup}
178\stopplacefigure
179
180When we have to choose a font we need to take the following criteria into
181account:
182
183\startitemize
184\startitem
185    What is the quality of the shapes? For sure, outlines are best if you want to
186    scale too.
187\stopitem
188\startitem
189    How efficiently is a shape constructed? In that respect a bitmap or \SVG\ image
190    is just one entity.
191\stopitem
192\startitem
193    How well can a (semi)arbitrary combinations of emoji be provided? Here the
194    glyph approach wins.
195\stopitem
196\startitem
197    Are all skin colors for all human relates shapes supported? Actually it opens
198    the possibility for racist fonts.
199\stopitem
200\startitem
201    Are all reasonable combinations of persons supported? It looks like (depending
202    on time and version) kissing men or women can be missing, maybe because of
203    social political reasons.
204\stopitem
205\startitem
206    Are black and white shapes provided alongside color shapes?
207\stopitem
208\stopitemize
209
210Maybe an \SVG\ or bitmap image can have a lot of detail compared to a stacked
211glyph but, when we're just using pictographic representations, the latter is the
212best choice.
213
214When I was playing a bit with the skin tone variants and other combinations that
215should result in some composed shape, I used the \UNICODE\ test files but I got
216the impression that there were some errors in the test suite, for instance with
217respect to modifiers. Maybe the fonts are just doing the wrong thing or maybe
218some implement these sequences a bit inconsistent. This will probably improve
219over time but the question is if we should intercept issues. I'm not in favour of
220this because it adds more and more fuzzy code that not only wastes cycles
221(energy) but is also a conceptual horror. So, when testing, imperfection has to
222be accepted for now. This is no big deal as until now no one ever asked for emoji
223support in \CONTEXT.
224
225When no combined shape is provided, the original sequence shows up. A side effect
226can be that zero|-|width|-| joiners and modifiers become visible. This depends on
227the fonts. Users probably don't care that much about it. Now how do we suppose
228that users enter these emoji (sequences) in a document source? One can imagine a
229pop up in the editor but \TEX ies are often using commands for special cases.
230
231We already showed some combined shapes. The reader might appreciate the outcome
232but getting there from the input takes a bit of work. For instance a two person
233\typ {man light skin tone woman medium skin tone girl medium-light skin tone baby
234medium-light skin tone} involves this:
235
236\blank
237\start
238    \setupalign[verytolerant]
239    \showotfcomposition
240      {seguiemj*seguiemj-cl}
241      {1}
242      {\resolvedemoji{family
243            man light skin tone
244            woman medium skin tone
245            girl medium-light skin tone
246            baby medium-light skin tone}}
247\stop
248\blank
249
250A black and white example is the following \type {family woman girl}:
251
252\blank
253\start
254    \setupalign[verytolerant]
255    \showotfcomposition
256      {seguiemj*seguiemj-bw}
257      {1}
258      {\resolvedemoji{family woman girl}}
259\stop
260\blank
261
262I will not show all emoji, just the subset that contains the word \type {woman}
263in the description. As you can see the persons in the sequences are separated by
264a zero|-|width|-|joiner. There are some curious ones, for instance a \typ {woman
265wearing turban} which in terms of \UNICODE\ input is a female combine with a
266turban wearing man becomes a beardless woman wearing a turban. Woman vampires and
267zombies are not supported so these are male properties.
268
269\startpacked
270    \MyEmoji
271    \ShowEmoji[woman]
272\stoppacked
273
274So what if you don't like these colors? Because we're dealing with \TEX\ you can
275assume that if there is some way around the fixed color sets, then it will be
276provided. So, when you use \CONTEXT, here is away to overload them:
277
278\startbuffer
279\definecolor[emoji-red]   [r=.4]
280\definecolor[emoji-green] [g=.4]
281\definecolor[emoji-blue]  [b=.4]
282\definecolor[emoji-yellow][r=.4,g=.4]
283\definecolor[emoji-gray]  [s=1,t=.5,a=1]
284
285\definefontcolorpalette
286  [emoji-s]
287  [black,emoji-gray]
288
289\definefontcolorpalette
290  [emoji-r]
291  [emoji-red,emoji-gray]
292
293\definefontcolorpalette
294  [emoji-g]
295  [emoji-green,emoji-gray]
296
297\definefontcolorpalette
298  [emoji-b]
299  [emoji-blue,emoji-gray]
300
301\definefontcolorpalette
302  [emoji-y]
303  [emoji-yellow,emoji-gray]
304
305\definefontfeature[seguiemj-s][ccmp=yes,dist=yes,colr=emoji-s]
306\definefontfeature[seguiemj-r][ccmp=yes,dist=yes,colr=emoji-r]
307\definefontfeature[seguiemj-g][ccmp=yes,dist=yes,colr=emoji-g]
308\definefontfeature[seguiemj-b][ccmp=yes,dist=yes,colr=emoji-b]
309\definefontfeature[seguiemj-y][ccmp=yes,dist=yes,colr=emoji-y]
310
311\definefont[MyEmojiS][seguiemj*seguiemj-s]
312\definefont[MyEmojiR][seguiemj*seguiemj-r]
313\definefont[MyEmojiG][seguiemj*seguiemj-g]
314\definefont[MyEmojiB][seguiemj*seguiemj-b]
315\definefont[MyEmojiY][seguiemj*seguiemj-y]
316\stopbuffer
317
318\typebuffer \getbuffer
319
320\startplacefigure[title={Overloading colors by plugging in a sequence of alternate colors.},reference=fig:emojioverload,location=page]
321\startcombination[4*6]
322    {\scale[height=.1\textheight]{\MyEmoji \resolvedemoji{triangular ruler}}} {}
323    {\scale[height=.1\textheight]{\MyEmoji \resolvedemoji{rabbit face}}}      {}
324    {\scale[height=.1\textheight]{\MyEmoji \resolvedemoji{man}}}              {}
325    {\scale[height=.1\textheight]{\MyEmoji \resolvedemoji{woman}}}            {}
326    {\scale[height=.1\textheight]{\MyEmojiR\resolvedemoji{triangular ruler}}} {}
327    {\scale[height=.1\textheight]{\MyEmojiR\resolvedemoji{rabbit face}}}      {}
328    {\scale[height=.1\textheight]{\MyEmojiR\resolvedemoji{man}}}              {}
329    {\scale[height=.1\textheight]{\MyEmojiR\resolvedemoji{woman}}}            {}
330    {\scale[height=.1\textheight]{\MyEmojiG\resolvedemoji{triangular ruler}}} {}
331    {\scale[height=.1\textheight]{\MyEmojiG\resolvedemoji{rabbit face}}}      {}
332    {\scale[height=.1\textheight]{\MyEmojiG\resolvedemoji{man}}}              {}
333    {\scale[height=.1\textheight]{\MyEmojiG\resolvedemoji{woman}}}            {}
334    {\scale[height=.1\textheight]{\MyEmojiB\resolvedemoji{triangular ruler}}} {}
335    {\scale[height=.1\textheight]{\MyEmojiB\resolvedemoji{rabbit face}}}      {}
336    {\scale[height=.1\textheight]{\MyEmojiB\resolvedemoji{man}}}              {}
337    {\scale[height=.1\textheight]{\MyEmojiB\resolvedemoji{woman}}}            {}
338    {\scale[height=.1\textheight]{\MyEmojiY\resolvedemoji{triangular ruler}}} {}
339    {\scale[height=.1\textheight]{\MyEmojiY\resolvedemoji{rabbit face}}}      {}
340    {\scale[height=.1\textheight]{\MyEmojiY\resolvedemoji{man}}}              {}
341    {\scale[height=.1\textheight]{\MyEmojiY\resolvedemoji{woman}}}            {}
342    {\scale[height=.1\textheight]{\MyEmojiS\resolvedemoji{triangular ruler}}} {}
343    {\scale[height=.1\textheight]{\MyEmojiS\resolvedemoji{rabbit face}}}      {}
344    {\scale[height=.1\textheight]{\MyEmojiS\resolvedemoji{man}}}              {}
345    {\scale[height=.1\textheight]{\MyEmojiS\resolvedemoji{woman}}}            {}
346\stopcombination
347\vskip2ex % looks nicer
348\stopplacefigure
349
350In \in {figure} [fig:emojioverload] we see how this is applied. You can provide
351as many colors as needed but when you don't provide enough the last one is used.
352This way we get the overlayed transparent colors in the examples. By using
353transparency we don't obscure shapes.
354
355The emojipedia mentions \quotation {Asked about the design, \MICROSOFT\ told
356emojipedia that one of the reasons for the thick stroke was to allow each emoji
357to be easily read on any background color.} The first glyph in the stack seems to
358do the trick, so just make sure that it doesn't become white. And, before I read
359that remark, while preparing a presentation with a colored background, I had
360already noticed that using a background was no problem. This font definitely sets
361the standard.
362
363How do we know what colors are used? The next table shows the first color palette
364of seguiemj. There are quite some colors so defining your own definitely involved
365some studying.
366
367{\MyEmoji\ShowEmojiPalettes[1]}
368
369Normally special symbols are accessed in \CONTEXT\ with the \type {symbol}
370command where symbols are organized in symbol sets. This is a rather old
371mechanism and dates from the time that fonts were limited in coverage and symbols
372were collected in special fonts. The emoji are accessed by their own command:
373\type {\emoji}. The font used has the font synonym \type {emoji} so you need to
374set that one first:
375
376\starttyping
377\definefontsynonym[emoji][seguiemj*seguiemj-cl]
378\stoptyping
379
380Here is an example:
381
382\startbuffer
383\emoji{woman light skin tone}\quad
384\emoji{woman scientist}\quad
385{\bfd bigger \emoji{man health worker}}
386\stopbuffer
387
388\typebuffer
389
390or typeset: \getbuffer
391
392The emoji symbol scales with the normal running font. When you ask for a family
393with skin toned members the lookup can result in another match (or no match)
394because one never knows to what extend a font supports it.
395
396\starttabulate[|l|p|]
397\NC \type{\expandedemoji} \NC the sequence constructed from the given string \NC \NR
398\NC \type{\resolvedemoji} \NC a protected sequence constructed from the given string \NC \NR
399\NC \type{\checkedemoji } \NC an typeset sequence with unresolved modifiers and joiners removed \NC \NR
400\NC \type{\emoji}         \NC a typeset resolved sequence using the \type {emoji} font synonym \NC \NR
401\NC \type{\robustemoji}   \NC a typeset checked sequence using the \type {emoji} font synonym \NC \NR
402\stoptabulate
403
404In case you wonder how some of the details above were typeset, there is a module
405\type {fonts-emoji} that provides some helpers for introspection.
406
407\starttabulate[|l|p|]
408\NC \type {\ShowEmoji}                \NC show all the emoji in the current font \NC \NR
409\NC \type {\ShowEmojiSnippets}        \NC show the snippets of a given emoji \NC \NR
410\NC \type {\ShowEmojiSnippetsOverlay} \NC show the overlayed snippets of a given emoji \NC \NR
411\NC \type {\ShowEmojiGlyphs}          \NC show the snippets of a typeset emoji \NC \NR
412\NC \type {\ShowEmojiPalettes}        \NC show the color palletes in the current font \NC \NR
413\stoptabulate
414
415Examples of usage are:
416
417\starttyping
418\ShowEmojiSnippets[family man woman girl boy]
419\ShowEmojiGlyphs  [family man woman baby girl]
420\ShowEmoji        [^man]
421\ShowEmoji
422\ShowEmojiPalettes
423\ShowEmojiPalettes[1]
424\stoptyping
425
426A good source of information about emoji is the mentioned \type {emojipedia.org}
427website. There you find not only details about all these symbols but also has
428some history. It compares updates in fonts too. It mentions for instance that in
429the creative update of Windows 10, some persons grew beards in the seguiemj font
430and others lost an eye. Now, if you look at the snippets shown before, you can
431wonder if that eye is really gone. Maybe the color is wrong or the order of
432stacking is not right. I decided not to waste time looking into that.
433
434Another quote: \quotation {Support for color emoji presentation on \MSWINDOWS\ is
435limited. Many applications on \MSWINDOWS\ display emojis with a black and white
436text presentation instead of their color version.} Well, we can do better with
437\TEX, but as usual not that many people really cares about that. But it's fun
438anyway.
439
440We end with a warning. When you use \quote {ligatures} like this, you really need
441to check the outcome. For instance, when \MICROSOFT\ updated the font end 2017,
442same gender couples got different hair style for the individuals so that one can
443still distinguish them. However, kissing couples and couples in love (indicated
444by a heart) seem to be removed. Who knows how and when politics creep into fonts:
445is public mixed couple kissing permitted, do we support families with any mix of
446gender, is associating pink with girls okay or not, how do we distinguish male
447and female anyway? In \in {figure} [fig:old-and-new] we see the same combination
448twice, the early 2017 rendering versus the late 2017 rendering. Can you notice
449the differences?
450
451\startplacefigure[title={Incompatible updates.},reference=fig:old-and-new]
452    \externalfigure[onandon-seguiemj.pdf][width=\textwidth]
453\stopplacefigure
454
455\stopchapter
456
457\stopcomponent
458