Skip to content

Commit

Permalink
fix: fix ZWJ detection on windows (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Sep 24, 2020
1 parent 0a9e3bb commit a467685
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/picker/utils/checkZwjSupport.js
Expand Up @@ -13,12 +13,17 @@ export function checkZwjSupport (zwjEmojisToCheck, baselineEmoji, emojiToDomNode
if (typeof baselineEmojiWidth === 'undefined') { // calculate the baseline emoji width only once
baselineEmojiWidth = calculateTextWidth(baselineEmoji)
}
// compare sizes rounded to 1/10 of a pixel to avoid issues with slightly different measurements (e.g. GNOME Web)
const supported = emojiWidth.toFixed(1) === baselineEmojiWidth.toFixed(1)
// On Windows, some supported emoji are ~50% bigger than the baseline emoji, but what we really want to guard
// against are the ones that are 2x the size, because those are truly broken (person with red hair = person with
// floating red wig, black cat = cat with black square, polar bear = bear with snowflake, etc.)
// So here we set the threshold at 1.8 times the size of the baseline emoji.
const supported = emojiWidth / 1.8 < baselineEmojiWidth
supportedZwjEmojis.set(emoji.unicode, supported)
/* istanbul ignore if */
/* istanbul ignore next */
if (!supported) {
log('Filtered unsupported emoji', emoji.unicode)
log('Filtered unsupported emoji', emoji.unicode, emojiWidth, baselineEmojiWidth)
} else if (emojiWidth !== baselineEmojiWidth) {
log('Allowed borderline emoji', emoji.unicode, emojiWidth, baselineEmojiWidth)
}
}
stop('checkZwjSupport')
Expand Down

0 comments on commit a467685

Please sign in to comment.