6

For example, I'd like to use the Twemoji font[1]. Fedora provides a TrueType variant[2] built using Google's Noto Emoji tooling[3]. Then there is a COLR/CPAL version provided by Mozilla[4].

I can't use any of the TrueType emoji fonts built in the same manner as the Noto Emoji font. This also includes Android Emoji, EmojiOne and NotoColorEmoji. The error is:

! error:  (file /usr/share/fonts/twemoji/Twemoji.ttf) (ttf): sfnt table not foundmtx-context     | fatal error: return code: 1

I can't use any of the color versions, i.e. the COLR/CPAL Twemoji Mozilla. The competing font color proposals are new, but I was hoping the font would display without color (black). In fact the glyph is present and can be copied from the PDF; it is just transparent.

\definefallbackfamily   [mainface] [serif] [twemoji] [range={miscellaneoussymbolsandpictographs}]
\definefontfamily       [mainface] [serif] [DejaVu Serif]
\definefontfamily       [mainface] [sans]  [DejaVu Sans]
\definefontfamily       [mainface] [mono]  [DejaVu Sans Mono]

\setupbodyfont[mainface]

\definesymbol[link][\utfchar{"1F517}]

\starttext
A\symbol[link]B
\stoptext

follow-up:

As documentation there is also On and On, Chapter 4: Emoji Again which is basically a verbose version of the presentation linked in the answer and explains most of the followup questions I have:

  1. The \emoji command requires the "emoji" font synonym to have been defined. I can confirm this is done by the \define*family commands though you still have to pass features={colr=yes,} or alternatively any name defined via \definefontfeature.

  2. The standalone link emoji requires only colr=yes. The documentation explains (with examples) why the ccmp and dist features should also be enabled for overlay fonts - basically, for combining emojis.

  3. For completion I describe the other emoji fonts in my question, as per mtxrun --script fonts --list --all --pattern='*emoji*':

    • google-android-emoji/AndroidEmoji.ttf

      non-color (no features required)

    • eosrei-emojione/emojione-android.ttf

      bitmap

    • EmojiOne/OpenType.SVG.v3.1.2/emojione-svg.otf

      non-color (no features required) + svg

      Notes: Either works. Although the svg feature causes ConTeXt to generate glyphs using inkscape, these glyphs are positioned exactly like the regular glyphs (as opposed to bitmap glyphs) and are drawn black and white, without color. This leads me to think that ConTeXt is not drawing the converted glyphs. This font is advertised as EmojiOne v3 though the glyphs are clearly from EmojiOne v2.

    • google-noto-emoji/NotoColorEmoji.ttf

      bitmap

    • google-noto-emoji/NotoEmoji-Regular.ttf

      non-color (no features required)

    • Twemoji.ttf

      bitmap

      Notes: The conversion is very ugly for this font.


    I should note that the glyph positioning of bitmap (and probably svg) fonts is sub-par: the bottom of the image is aligned to the baseline. Also, the initial conversion process (bitmap->png->tma->tmc) is very slow and the end result is rasterized: it will look pixelated at high zoom levels.

  4. Consider the signature \definefontfeature [...] [...] [.=.]. The first argument is clearly an arbitrary user-defined feature name that is later selected via a font name, for example, [name:twemojimozilla*default,overlay] with either \definefont or \definefontsynonym. This example enables both the "default" and "overlay" features, "default" being predefined by ConTeXt as:

    default:liga=yes,kern=yes,tlig=yes,trep=yes
    

    According to the documentation I should also be able to use \definefontsynonym[emoji][name:twemojimozilla][features=overlay], but that doesn't work.

    What I don't understand is the second argument to \definefontfeature, i.e. the [default] in \definefontsynonym[emoji][name:twemojimozilla*default,overlay]. What does it do?

  5. When I try to force a greyscale palette, recreating the workflow on page 15 of the online presentation slides mentioned in the answer but substituting the TwemojiMozilla font for seguiemj, I get this error:

    ! error:  (vf command): commands has to be a tablemtx-context     | fatal error: return code: 1
    

    Do you mind updating you answer with the correct approach?

Sources:

  1. https://github.com/twitter/twemoji
  2. https://src.fedoraproject.org/cgit/rpms/twitter-twemoji-fonts.git/
  3. https://github.com/googlei18n/noto-emoji/issues/9
  4. https://github.com/mozilla/twemoji-colr
  • 2
    You don't want to use the Emoji font as fallback. – Henri Menke Dec 18 '18 at 21:06
8

You have to activate the correct font features. I used the Mozilla Twemoji font (I couldn't find a TTF file for the others).

There was also a talk about this stuff at the 2017 ConTeXt meeting. The slides are available online (PDF).

\definefontfeature
  [overlay]
  [default]
  [ccmp=yes,
   colr=yes,
   dist=yes]

\definefontsynonym
  [emoji]
  [file:TwemojiMozilla.ttf*overlay]

\starttext

\emoji{link}

\stoptext

enter image description here


If you want different colors, you have to define a custom color palette to be used with the colr font feature. The problem here is, that the default color palettes of the fonts are fairly complicated so it is definitely not a trivial task to color certain elements of the Emoji the way you want. I you just to switch to “some sort of monochrome”, the solution below should be sufficient.

\usemodule[fonts-emoji]

\definefontcolorpalette
  [emojibw]
  [middlegray]

\definefontfeature
  [overlay]
  [default]
  [ccmp=yes,
   colr=emojibw,
   dist=yes]

\definefontsynonym
  [emoji]
  [file:TwemojiMozilla.ttf*overlay]

\definefont
  [emojifont]
  [emoji]

\starttext

\emoji{man}

\emojifont\ShowEmoji[^man]

\stoptext

enter image description here

  • Very beautiful answer and good output. – Sebastiano Dec 18 '18 at 21:14
  • I updated my answer with some supplementary information to your answer that could have just as easily been posted as (too many) comments here. However my main problem is in point [5]: I can't extend your example with the workflow described in the presentation slides you linked to remove color from the emojis. Perhaps this would be better illustrated with \emoji{man}. – user19087 Dec 20 '18 at 19:12
  • 1
    Thanks. When I realized that chapter 4 was just an expanded version of the presentation slides I mainly just skimmed it. To be fair though I exactly recreated the custom palette example on page 15 of the online slides, substituting TwemojiMozilla for seguiemj. I don't know why that version generates an error whereas your updated answer works perfectly. The only useful extra information from that chapter is that the last color is repeated to fill up the palette. – user19087 Dec 20 '18 at 21:14
  • 1
    @user19087 I understand your frustration. This Emoji stuff is pretty much hit and miss. If you just need logos like link you might be happier using a symbol font like fontawesome (as shown for example in Wolfgang's answer here). – Henri Menke Dec 20 '18 at 21:20
  • 1
    @user19087 All the glyphs in fontawesome are in the private use area of Unicode. Therefore it is impossible to enter them directly as Unicode symbols in the source and they don't map to Emoji either. – Henri Menke Dec 20 '18 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.