Changeset 41669
- Timestamp:
- 10/02/2017 03:59:50 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/wp-emoji-loader.js
r41386 r41669 10 10 11 11 /** 12 * Check if two sets of Emoji characters render the same. 13 * 14 * @param set1 array Set of Emoji characters. 15 * @param set2 array Set of Emoji characters. 16 * @returns {boolean} True if the two sets render the same. 17 */ 18 function emojiSetsRenderIdentically( set1, set2 ) { 19 var stringFromCharCode = String.fromCharCode; 20 21 // Cleanup from previous test. 22 context.clearRect( 0, 0, canvas.width, canvas.height ); 23 context.fillText( stringFromCharCode.apply( this, set1 ), 0, 0 ); 24 var rendered1 = canvas.toDataURL(); 25 26 // Cleanup from previous test. 27 context.clearRect( 0, 0, canvas.width, canvas.height ); 28 context.fillText( stringFromCharCode.apply( this, set2 ), 0, 0 ); 29 var rendered2 = canvas.toDataURL(); 30 31 return rendered1 === rendered2; 32 } 33 34 /** 12 35 * Detect if the browser supports rendering emoji or flag emoji. Flag emoji are a single glyph 13 36 * made of two characters, so some browsers (notably, Firefox OS X) don't support them. … … 15 38 * @since 4.2.0 16 39 * 17 * @param type {String} Whether to test for support of "flag" or "emoji 4" emoji.40 * @param type {String} Whether to test for support of "flag" or "emoji". 18 41 * @return {Boolean} True if the browser can render emoji, false if it cannot. 19 42 */ 20 43 function browserSupportsEmoji( type ) { 21 var stringFromCharCode = String.fromCharCode, 22 flag, flag2, emoji41, emoji42; 44 var isIdentical; 23 45 24 46 if ( ! context || ! context.fillText ) { 25 47 return false; 26 48 } 27 28 // Cleanup from previous test.29 context.clearRect( 0, 0, canvas.width, canvas.height );30 49 31 50 /* … … 46 65 * the browser doesn't render it correctly ([U] + [N]). 47 66 */ 48 context.fillText( stringFromCharCode( 55356, 56826, 55356, 56819 ), 0, 0 ); 49 flag = canvas.toDataURL(); 67 isIdentical = emojiSetsRenderIdentically( 68 [ 55356, 56826, 55356, 56819 ], 69 [ 55356, 56826, 8203, 55356, 56819 ] 70 ); 50 71 51 context.clearRect( 0, 0, canvas.width, canvas.height ); 52 53 // Add a zero width space between the characters, to force rendering as characters. 54 context.fillText( stringFromCharCode( 55356, 56826, 8203, 55356, 56819 ), 0, 0 ); 55 flag2 = canvas.toDataURL(); 56 57 if ( flag === flag2 ) { 72 if ( isIdentical ) { 58 73 return false; 59 74 } … … 66 81 * the browser doesn't render it correctly (black flag emoji + [G] + [B] + [E] + [N] + [G]). 67 82 */ 68 // Cleanup from previous test. 69 context.clearRect( 0, 0, canvas.width, canvas.height ); 83 isIdentical = emojiSetsRenderIdentically( 84 [ 55356, 57332, 56128, 56423, 56128, 56418, 56128, 56421, 56128, 56430, 56128, 56423, 56128, 56447 ], 85 [ 55356, 57332, 8203, 56128, 56423, 8203, 56128, 56418, 8203, 56128, 56421, 8203, 56128, 56430, 8203, 56128, 56423, 8203, 56128, 56447 ] 86 ); 70 87 71 context.fillText( stringFromCharCode( 55356, 57332, 56128, 56423, 56128, 56418, 56128, 56421, 56128, 56430, 56128, 56423, 56128, 56447 ), 0, 0 ); 72 flag = canvas.toDataURL(); 73 74 context.clearRect( 0, 0, canvas.width, canvas.height ); 75 76 context.fillText( stringFromCharCode( 55356, 57332, 8203, 56128, 56423, 8203, 56128, 56418, 8203, 56128, 56421, 8203, 56128, 56430, 8203, 56128, 56423, 8203, 56128, 56447 ), 0, 0 ); 77 flag2 = canvas.toDataURL(); 78 79 return flag !== flag2; 80 case 'emoji4': 88 return ! isIdentical; 89 case 'emoji': 81 90 /* 82 91 * Emoji 5 has fairies of all genders. … … 86 95 * (fairy + male sign). 87 96 */ 88 context.fillText( stringFromCharCode( 55358, 56794, 8205, 9794, 65039 ), 0, 0 ); 89 emoji41 = canvas.toDataURL(); 90 91 context.clearRect( 0, 0, canvas.width, canvas.height ); 92 93 context.fillText( stringFromCharCode( 55358, 56794, 8203, 9794, 65039 ), 0, 0 ); 94 emoji42 = canvas.toDataURL(); 95 96 return emoji41 !== emoji42; 97 isIdentical = emojiSetsRenderIdentically( 98 [ 55358, 56794, 8205, 9794, 65039 ], 99 [ 55358, 56794, 8203, 9794, 65039 ] 100 ); 101 return ! isIdentical; 97 102 } 98 103 … … 108 113 } 109 114 110 tests = Array( 'flag', 'emoji 4' );115 tests = Array( 'flag', 'emoji' ); 111 116 112 117 settings.supports = {
Note: See TracChangeset
for help on using the changeset viewer.