Ticket #57301: 57301-2.diff
File 57301-2.diff, 4.8 KB (added by , 3 years ago) |
---|
-
wp-includes/js/wp-emoji-loader.js
diff --git a/wp-includes/js/wp-emoji-loader.js b/wp-includes/js/wp-emoji-loader.js index 0b5f3c7749..9fd5440616 100644
a b 16 16 * 17 17 * @private 18 18 * 19 * @param { number[]} set1 Set of Emoji character codes.20 * @param { number[]} set2 Set of Emoji character codes.19 * @param {string} set1 Set of Emoji to test. 20 * @param {string} set2 Set of Emoji to test. 21 21 * 22 22 * @return {boolean} True if the two sets render the same. 23 23 */ 24 24 function emojiSetsRenderIdentically( set1, set2 ) { 25 var stringFromCharCode = String.fromCharCode;26 27 25 // Cleanup from previous test. 28 26 context.clearRect( 0, 0, canvas.width, canvas.height ); 29 context.fillText( s tringFromCharCode.apply( this, set1 ), 0, 0 );27 context.fillText( set1, 0, 0 ); 30 28 var rendered1 = canvas.toDataURL(); 31 29 32 30 // Cleanup from previous test. 33 31 context.clearRect( 0, 0, canvas.width, canvas.height ); 34 context.fillText( s tringFromCharCode.apply( this, set2 ), 0, 0 );32 context.fillText( set2, 0, 0 ); 35 33 var rendered2 = canvas.toDataURL(); 36 34 37 35 return rendered1 === rendered2; 38 36 } 39 37 40 38 /** 41 * Dete cts if the browser supports rendering emoji or flag emoji.39 * Determines if the browser properly renders Emoji that Twemoji can supplement. 42 40 * 43 * Flag emoji are a single glyph made of two characters, so some browsers 44 * (notably, Firefox OS X) don't support them. 41 * Input strings in this function should split supplementary plane code points 42 * into their constituent UTF-16 code units to avoid browser compatability issues. 43 * These are code points above U+FFFF. For example, the character 🅰 is U+1F170, 44 * and while on newer browsers we can write that as '\u{1f170}', on older browsers 45 * we need the code unit sequence '\uD83C\uDD70' instead (Edge < 12, Firefox < 40). 45 46 * 46 47 * @since 4.2.0 47 48 * … … 69 70 switch ( type ) { 70 71 case 'flag': 71 72 /* 72 * Test for Transgender flag compatibility. This flag is shortlisted for the Emoji 13 spec, 73 * but has landed in Twemoji early, so we can add support for it, too. 73 * Test for Transgender flag compatibility. Added in Unicode 13. 74 74 * 75 75 * To test for support, we try to render it, and compare the rendering to how it would look if 76 76 * the browser doesn't render it correctly (white flag emoji + transgender symbol). 77 77 */ 78 78 isIdentical = emojiSetsRenderIdentically( 79 [ 0x1F3F3, 0xFE0F, 0x200D, 0x26A7, 0xFE0F ],80 [ 0x1F3F3, 0xFE0F, 0x200B, 0x26A7, 0xFE0F ]79 '\uD83C\uDFF3\uFE0F\u200D\u26A7\uFE0F', // as a zero-width joiner sequence 80 '\uD83C\uDFF3\uFE0F\u200B\u26A7\uFE0F', // separated by a zero-width space 81 81 ); 82 82 83 83 if ( isIdentical ) { … … 92 92 * the browser doesn't render it correctly ([U] + [N]). 93 93 */ 94 94 isIdentical = emojiSetsRenderIdentically( 95 [ 0xD83C, 0xDDFA, 0xD83C, 0xDDF3 ],96 [ 0xD83C, 0xDDFA, 0x200B, 0xD83C, 0xDDF3 ]95 '\uD83C\uDDFA\uD83C\uDDF3', // as the sequence of two code points 96 '\uD83C\uDDFA\u200B\uD83C\uDDF3', // as the two code points separated by a zero-width space 97 97 ); 98 98 99 99 if ( isIdentical ) { … … 102 102 103 103 /* 104 104 * Test for English flag compatibility. England is a country in the United Kingdom, it 105 * does not have a two letter locale code but rather a nfive letter sub-division code.105 * does not have a two letter locale code but rather a five letter sub-division code. 106 106 * 107 107 * To test for support, we try to render it, and compare the rendering to how it would look if 108 108 * the browser doesn't render it correctly (black flag emoji + [G] + [B] + [E] + [N] + [G]). 109 109 */ 110 110 isIdentical = emojiSetsRenderIdentically( 111 [ 0xD83C, 0xDFF4, 0xDB40, 0xDC67, 0xDB40, 0xDC62, 0xDB40, 0xDC65, 0xDB40, 0xDC6E, 0xDB40, 0xDC67, 0xDB40, 0xDC7F ], 112 [ 0xD83C, 0xDFF4, 0x200B, 0xDB40, 0xDC67, 0x200B, 0xDB40, 0xDC62, 0x200B, 0xDB40, 0xDC65, 0x200B, 0xDB40, 0xDC6E, 0x200B, 0xDB40, 0xDC67, 0x200B, 0xDB40, 0xDC7F ] 111 // as the flag sequence 112 '\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67\uDB40\uDC7F', 113 // with each code point separated by a zero-width space 114 '\uD83C\uDFF4\u200B\uDB40\uDC67\u200B\uDB40\uDC62\u200B\uDB40\uDC65\u200B\uDB40\uDC6E\u200B\uDB40\uDC67\u200B\uDB40\uDC7F', 113 115 ); 114 116 115 117 return ! isIdentical; … … 133 135 * sequence come from older emoji standards. 134 136 */ 135 137 isIdentical = emojiSetsRenderIdentically( 136 [0x1FAF1, 0x1F3FB, 0x200D, 0x1FAF2, 0x1F3FF],137 [0x1FAF1, 0x1F3FB, 0x200B, 0x1FAF2, 0x1F3FF]138 '\uD83E\uDEF1\uD83C\uDFFB\u200D\uD83E\uDEF2\uD83C\uDFFF', // as the zero-width joiner sequence 139 '\uD83E\uDEF1\uD83C\uDFFB\u200B\uD83E\uDEF2\uD83C\uDFFF', // separated by a zero-width space 138 140 ); 139 141 140 142 return ! isIdentical;