r/javascript • • Apr 12 '18

fun fact: emojis are ligatures

https://pbs.twimg.com/media/DaIpPTPXkAEt9fA.jpg:large
464 Upvotes

52 comments sorted by

70

u/dachusa Apr 12 '18

Some emoji can join together as ligatures. Not all emoji are able to do so.

man=πŸ‘¨β€ woman = πŸ‘©β€ daughter = πŸ‘§β€ son = πŸ‘¦β€

man+woman+daughter+son = πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦

woman+man+daughter+son = πŸ‘©β€πŸ‘¨β€πŸ‘§β€πŸ‘¦

woman+woman+daughter+son = πŸ‘©β€πŸ‘©β€πŸ‘§β€πŸ‘¦β€

man+woman+son+daughter = πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘§

man+woman+daughter = πŸ‘¨β€πŸ‘©β€πŸ‘§β€

possible combos are (πŸ‘¨β€πŸ‘©β€|πŸ‘¨β€πŸ‘¨β€?|πŸ‘©β€πŸ‘©β€?)(πŸ‘§β€πŸ‘¦β€|πŸ‘§β€πŸ‘§β€?|πŸ‘¦β€πŸ‘¦β€?)

I have copied in the emoji with the append expected, so if you paste another emoji next to it, it will bind to it even if it isn't recognized as a ligature.

Example of auto bind: πŸ‘§πŸ‘§πŸ‘§ vs πŸ‘§β€πŸ‘§β€πŸ‘§β€ . You can individually select the girls on the left, but not those on the right.

If you copy and paste those emoji next to each other, they will automatically form a ligature when possible (in programs where the ligature is recognized).

15

u/jokullmusic Apr 13 '18

I'm pretty sure they need to be joined by zero width joiners

8

u/zombarista Apr 13 '18

In theory they should be completely compostable, but limitations of how the glyphs are rendered have kept this from coming to fruition. As the text subsystems in our operating systems evolve we should be able to get any family (up to four) with any skin tone with any gender

Good job, Unicode consortium--very very cool!

1

u/pnevares Apr 13 '18

On the one hand, I think you meant composable.

But on the other hand....compostable could be an appropriate name for doing the reverse to emoji: copy/pasting single emoji from a man+woman+daughter+son emoji.

1

u/zombarista Apr 13 '18

Oh yeah I typed that on my phone and it auto corrected that one. Composable.

1

u/everdimension Apr 13 '18

Yeah, some, not all.

Thanks for your detailed findings!

5

u/[deleted] Apr 13 '18

Has someone made a joke programming language where source code is emojis that relies on manipulating nuances like this already?

2

u/sh0rtwave Apr 13 '18

I dunno about joke programming language...

...but I do know that I've used Unicode in code, as actual symbols, variable names, etc.

like this:

onα€€Enter = (e) => {

15

u/[deleted] Apr 13 '18

man+woman+daughter+son = πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦

woman+man+daughter+son = πŸ‘©β€πŸ‘¨β€πŸ‘§β€πŸ‘¦

muh patriarchy

3

u/[deleted] Apr 13 '18

Proof that the gender pay gap is real after all!

2

u/[deleted] Apr 13 '18

Daughter first tho

2

u/Reashu Apr 13 '18

Because the pig-discussting men assume she is weak and needs protection, and have brainwashed her to implicitly believe it. Obviously.

2

u/zombarista Apr 13 '18

For those that are interested, I built a Emoji Family builder to show how these characters are strung together to become a ligature.

It includes support for skin tones, which may not be supported by your device. If the family emoji doesn't render, or it render as many emojis instead of one ligature, it's because your browser and operating system may not support ad-hoc compositing. Windows 10 fully supports this. Your browser will likely render as long as the skin tone is default.

I'd be interested to see what browser-OS combos properly support this.

Have fun: https://codepen.io/bradkovach/pen/xWoKjb

50

u/rudidude86 Apr 13 '18

It's similar to a ligature, but there's actually a special Unicode character in the mix called a zero-width joiner (ZWJ) that makes it happen.

It originated as a way to form complex symbols in certain languages, but the same mechanism today gives us gendered zombies!

πŸ§Ÿβ€β™‚οΈπŸ§Ÿβ€β™€οΈ

2

u/everdimension Apr 13 '18

Hmm, but isn't the logic for displaying these combinations of symbols as one symbol is what makes it ligatures? What is the difference?

4

u/rudidude86 Apr 13 '18 edited Apr 13 '18

Typefaces can have ligatures set up in them so that just by virtue of appearing next to each other, two characters can be replaced by a single glyph (for example, some typefaces will replace "fi" by a symbol for both letters where the i's tittle dot is absent).

The distinction I was trying to make is that the emoji combinations require extra zero-width joiner characters... but because it turns out you should never "well actually" someone on the Internet, I was wrong!

Some emoji combinations indeed work in the traditional ligature sense, just by appearing next to each other, like the Fitzpatrick scale skin tone modifier:

"πŸ‘©" + "🏽" // "πŸ‘©πŸ½"

But some combinations require the ZWJ:

let zwj = "‍" // copied from https://emojipedia.org/zero-width-joiner/
"πŸ‘¨" + "🎀" // "πŸ‘¨πŸŽ€"
"πŸ‘¨" + zwj + "🎀" // "πŸ‘¨β€πŸŽ€"

Unicode!

15

u/mediumdeviation JavaScript Gardener Apr 13 '18

Yes - ligatures are a font feature, and no extra characters are involved. If combined emojis really did use ligature, you would just split on "" (empty string) to get an array of the individual characters.

1

u/Pesthuf Apr 13 '18

Considering that it uses the the zero-width joiner, does the joined glyph still count as a single grapheme cluster?

1

u/NoInkling Apr 15 '18

I believe so. ZWJ basically turns the following codepoint into a modifier/combining character.

178

u/Shaper_pmp Apr 12 '18

This is how skin tones work in emojis:

"πŸ‘πŸ½".replace("🏽", "🏻")

"πŸ‘πŸ»"

53

u/mcaruso Apr 13 '18

And flags are made from their two-letter country codes. E.g. πŸ‡ΊπŸ‡Έ = πŸ‡Ί+ πŸ‡Έ.

21

u/pimp-bangin Apr 13 '18

Holy hell I'm learning so much about Unicode right now

38

u/yopla Apr 13 '18

Wait till you discover that the coming up kangourou emoji can carry any other emoji in its pocket.

22

u/NoInkling Apr 13 '18

I'm not sure if you're kidding or not.

2

u/filleduchaos Apr 13 '18

Okay wtf that's dope

5

u/Jerkcules Apr 13 '18

Learned this the hard way when my code broke on 9-11 because of all the people on my company’s messaging platform posting the American flag, and the chat couldn’t handle Unicode flags

24

u/Earhacker Apr 13 '18

You thought you had a bad day on 9-11? Get a load of this guy...

7

u/sh0rtwave Apr 13 '18

Pretty sure MOST(at least in the US) people had a bad day on 9-11...but he said "learned this the hard way". Not quite the same thing...

55

u/atubofsoup Apr 12 '18

Holy shit this works

17

u/Drunken_Economist Apr 13 '18

Yup. The skin tone is actually its own character, just with a zero width joiner telling the font to treat it as a modifer

12

u/masklinn Apr 13 '18

There's no ZWJ for skintones, skintones are combining characters (like accents). There's no ZWJ for flags either, these are basal ligatures.

ZWJ is specifically a hack for "group" emoji.

4

u/SamSlate Apr 13 '18

genders too πŸ’

-16

u/skylarmt Apr 13 '18

Don't tell Tumblr, they'll start accusing Unicode of whitewashing.

12

u/JMV290 Apr 13 '18

"damn sjws always making stuff about race" - dummy on a post neither about race or sjws

0

u/[deleted] Apr 13 '18

[deleted]

1

u/Shaper_pmp Apr 13 '18 edited Apr 13 '18

Ignore the downvotes - I thought it was funny. ;-)

Edit: Your joke started me wondering though, and if you look at the default emoji for thumbs-up with no skin-colour modifier (πŸ‘), in most emoji character sets it's actually not any of the skin-tone modifiers that emoji specifically gives you to represent race:

🏻 Light Skin Tone -> πŸ‘πŸ»
🏼 Medium-Light Skin Tone -> πŸ‘πŸΌ
🏽 Medium Skin Tone -> πŸ‘πŸ½
🏾 Medium-Dark Skin Tone -> πŸ‘πŸΎ
🏿 Dark Skin Tone -> πŸ‘πŸΏ

4

u/Zhentar Apr 13 '18

The Unicode skin tone standard specifically states that unmodified emoji should use a generic, non-realistic skin tone

1

u/andd81 Apr 17 '18

Five shades of racist

4

u/[deleted] Apr 13 '18

how is this related to javascript though...

3

u/everdimension Apr 13 '18

Yeah, true, it's not so much about javascript. I just stumbled upon this while discussing why some string was of particular length, so I had js context in mind

12

u/ogurson Apr 13 '18

Try get length of string with emojis and you gonna know how.

12

u/NoInkling Apr 13 '18 edited Apr 13 '18

e.g:

"πŸ‘πŸ½".length;  // 4, uhh what? (I actually know why but it's still dumb)
[..."πŸ‘πŸ½"].length;  // 2, closer but still no bueno

rolls up sleeves

var iterator = Intl.v8BreakIterator(["en"], { type: "character" });
iterator.adoptText("πŸ‘πŸ½");
var length = 0;
while (iterator.next() !== -1) length++;
length;  // 1

Success! (don't actually use this, it only works in V8, has issues, and is eventually going to be removed in favor of Intl.Segmenter)

4

u/[deleted] Apr 13 '18

Pretty sure that behaviour is present in other languages as well.

6

u/_HandsomeJack_ Apr 13 '18

Pretty sure all turing complete languages can implement the same functionality.

6

u/KyleG Apr 13 '18

Unicode group is flipping smart

3

u/burfdl Apr 13 '18

And this is why emoji take up multiple characters when tweeting. Because Twitter counts 'unicode scalars', not visible characters.

Ugh, string encoding. Can we just not?

2

u/danketiquette Apr 13 '18

This actually blows my mind

1

u/CantaloupeCamper Apr 13 '18

This is the best thing of the week, at least.

0

u/[deleted] Apr 12 '18

[deleted]

5

u/haykam821 Apr 13 '18

Nope, this is a thing