Make WordPress Core


Ignore:
Timestamp:
08/04/2016 08:50:11 PM (8 years ago)
Author:
ocean90
Message:

Emoji: Update the Twemoji loader to include the rainbow flag.

[38179] added support for the rainbow flag to core, but platform compatibility is a bit strange, because the flag was defined out of sync with the usual Unicode release cycle. For example Android N supports all Unicode 9.0 emoji, but doesn't support the rainbow flag thus the rainbow flag isn't rendered.
The Twemoji loader already has an exception for flags - it'll load if the browser supports everything but flags, and then only replace flag emoji, leaving everything else as native rendering. To provide a seamless experience for all flags the loader now uses the rainbow flag to test flag support.

Props pento.
See #37543.
Fixes #37566.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/wp-emoji-loader.js

    r38087 r38194  
    1515            context = canvas.getContext && canvas.getContext( '2d' ),
    1616            stringFromCharCode = String.fromCharCode,
    17             tonedata, tone, tone2;
     17            flag, flag2, tonedata, tone, tone2;
    1818
    1919        if ( ! context || ! context.fillText ) {
     
    4141                 */
    4242                context.fillText( stringFromCharCode( 55356, 56806, 55356, 56826 ), 0, 0 );
    43                 return canvas.toDataURL().length > 3000;
     43                if ( canvas.toDataURL().length < 3000 ) {
     44                    return false;
     45                }
     46
     47                context.clearRect( 0, 0, canvas.width, canvas.height );
     48
     49                /*
     50                 * Test for rainbow flag compatibility. As the rainbow flag was added out of sequence with
     51                 * the usual Unicode release cycle, some browsers support it, and some don't, even if their
     52                 * Unicode support is up to date.
     53                 *
     54                 * To test for support, we try to render it, and compare the rendering to how it would look if
     55                 * the browser doesn't render it correctly (white flag emoji + rainbow emoji).
     56                 */
     57                context.fillText( stringFromCharCode( 55356, 57331, 65039, 8205, 55356, 57096 ), 0, 0 );
     58                flag = canvas.toDataURL();
     59
     60                context.clearRect( 0, 0, canvas.width, canvas.height );
     61
     62                context.fillText( stringFromCharCode( 55356, 57331, 55356, 57096 ), 0, 0 );
     63                flag2 = canvas.toDataURL();
     64
     65                return flag !== flag2;
    4466            case 'diversity':
    4567                /*
Note: See TracChangeset for help on using the changeset viewer.