Merge pull request #262 from github/skin-tones-couple

Support skin tones for 🧑‍🤝‍🧑 emoji
This commit is contained in:
Mislav Marohnić
2023-03-29 14:50:39 +02:00
committed by GitHub
3 changed files with 27 additions and 7 deletions

View File

@@ -6478,7 +6478,7 @@
]
, "unicode_version": "12.0"
, "ios_version": "13.0"
, "skin_tones": false
, "skin_tones": true
}
, {
"emoji": "👭"

View File

@@ -43,13 +43,20 @@ module Emoji
# Raw Unicode string for an emoji. Nil if emoji is non-standard.
def raw() unicode_aliases.first end
# Raw Unicode strings for each skin tone variant of this emoji.
# Raw Unicode strings for each skin tone variant of this emoji. The result is an empty array
# unless the emoji supports skin tones.
#
# Note: for emojis that depict multiple people (e.g. couples or families), this will not produce
# every possible permutation of skin tone per person.
def raw_skin_tone_variants
return [] if custom? || !skin_tones?
raw_normalized = raw.sub("\u{fe0f}", "") # strip VARIATION_SELECTOR_16
idx = raw_normalized.index("\u{200d}") # detect zero-width joiner
raw_normalized = raw.sub(VARIATION_SELECTOR_16, "")
idx = raw_normalized.index(ZERO_WIDTH_JOINER)
SKIN_TONES.map do |modifier|
if idx
if raw_normalized == PEOPLE_HOLDING_HANDS
# special case to apply the modifier to both persons
raw_normalized[0...idx] + modifier + raw_normalized[idx..nil] + modifier
elsif idx
# insert modifier before zero-width joiner
raw_normalized[0...idx] + modifier + raw_normalized[idx..nil]
else
@@ -97,7 +104,11 @@ module Emoji
end
private
VARIATION_SELECTOR_16 = "\u{fe0f}".freeze
ZERO_WIDTH_JOINER = "\u{200d}".freeze
PEOPLE_HOLDING_HANDS = "\u{1f9d1}\u{200d}\u{1f91d}\u{200d}\u{1f9d1}".freeze
SKIN_TONES = [
"\u{1F3FB}", # light skin tone
"\u{1F3FC}", # medium-light skin tone
@@ -106,7 +117,7 @@ module Emoji
"\u{1F3FF}", # dark skin tone
]
private_constant :SKIN_TONES
private_constant :VARIATION_SELECTOR_16, :ZERO_WIDTH_JOINER, :PEOPLE_HOLDING_HANDS, :SKIN_TONES
def default_image_filename
if custom?

View File

@@ -176,6 +176,15 @@ class EmojiTest < TestCase
"1f9d4-1f3fe-200d-2640",
"1f9d4-1f3ff-200d-2640",
], woman_with_beard.raw_skin_tone_variants.map { |u| Emoji::Character.hex_inspect(u) }
people_holding_hands = Emoji.find_by_alias("people_holding_hands")
assert_equal [
"1f9d1-1f3fb-200d-1f91d-200d-1f9d1-1f3fb",
"1f9d1-1f3fc-200d-1f91d-200d-1f9d1-1f3fc",
"1f9d1-1f3fd-200d-1f91d-200d-1f9d1-1f3fd",
"1f9d1-1f3fe-200d-1f91d-200d-1f9d1-1f3fe",
"1f9d1-1f3ff-200d-1f91d-200d-1f9d1-1f3ff",
], people_holding_hands.raw_skin_tone_variants.map { |u| Emoji::Character.hex_inspect(u) }
end
test "no custom emojis" do