Git Product home page Git Product logo

Comments (5)

wearhere avatar wearhere commented on May 21, 2024

Ok I deleted my previous comment talking about trial-and-error since I found the spec. In particular, it says:

an emoji modifier must immediately follow [the] base emoji character

and

Emoji presentation selectors are neither needed nor recommended for emoji characters when they are followed by emoji modifiers, and should not be used in newly generated emoji modifier sequences; the emoji modifier automatically implies the emoji presentation style.

I think that suggests processing emojis like this. You're welcome to adopt that implementation for this library if you like, tried to heavily comment and test it both from the perspective of "does this format correctly" and "does this render correctly (on Apple platforms, at least)".

One note about non-Swift implementations is that you'll probably need to look up the scalar (codepoint) properties (isVariationSelector, isEmojiModifier, isEmojiModifierBase) from an external lookup table. I'm pretty sure that unicode.org provides such and I believe that this library already parses some of them.

from gemoji.

wearhere avatar wearhere commented on May 21, 2024

The Gist linked from my previous comment doesn't support applying different modifiers to each person in a multi-person grouping. I'm currently adding support for that and will probably publish the result as a Swift package rather than continue to add to the Gist.

In the meantime, I'd like to call out a limitation of the algorithm in the Gist: it won't work for 👭, 👫, and 👬. That's because those emojis consist of a single scalar, whereas applying different modifiers to each person in the grouping would require representing the groupings as a ZWJ sequence. This means that we have to convert those emojis into a sequence before applying the algorithm:

extension String {
    var modifiableBySkinTone: String {
        switch self {
        case "👭": return "\u{0001F469}\u{200D}\u{0001F91D}\u{200D}\u{0001F469}"
        case "👫": return "\u{0001F469}\u{200D}\u{0001F91D}\u{200D}\u{0001F468}"
        case "👬": return "\u{0001F468}\u{200D}\u{0001F91D}\u{200D}\u{0001F468}"
        default: return self
        }
    }
}

I hoped to submit some sort of PR to add these "sequence forms" to this project's database, the idea being that a capable platform¹ could only ever store and display those versions of 👭, 👫, and 👬 and so avoid having to convert the single-scalar versions in the process of applying skin tones.

Unfortunately, these sequences only render as single characters when they contain modifiers, at least on macOS 10.15.4. Apple probably didn't bother adding code to make the base sequences render given that they can display the single-scalar versions instead.


¹Supporting Emoji 12.0, which I think is when the sequence forms were added, per the spec—whereas the single-scalar emoji date back to Emoji 6.0, says the database.

from gemoji.

wearhere avatar wearhere commented on May 21, 2024

Two more gotchas I've found:

Firstly, the basic algorithm may return results that won't actually render in cases where platforms haven't generally added support for rendering all the different variants. I'm specifically talking about many of the multi-person groupings. In these cases, the database correctly omits skin_tones and so the fix is to simply skip trying to modify such emoji.

More problematic is that skin_tones may be true in cases where only some platforms will render the different variants. This is because "in some circumstances, display of an emoji modifier… should be suppressed", per the spec. As an example, Apple depicts 🏂 without any visible skin whereas Android shows skin. This means that my Swift implementation (for use in iOS) should return no variants for 🏂 whereas implementations for other platforms would need to behave differently.

from gemoji.

mislav avatar mislav commented on May 21, 2024

Thanks for sharing your finding so far!

I am unable to provide advice on how to implement support for skin tone modifiers on top of gemoji since I've never done it. The library does report which emoji supports skin tone modifiers, but intentionally does not yet provide any facilities to generate or parse emoji with skin tones because we haven't figured out proper support for this yet, so the implementation is left to the users.

from gemoji.

mislav avatar mislav commented on May 21, 2024

With #165 merged, you can now call the raw_skin_tone_variants method on an emoji character to get a set of 5 unicode sequences that have each of the skin tone modifiers inserted at the right place.

from gemoji.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.