| | 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 | |
| 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 | ); |
| 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 ) { |
| 68 | | // Cleanup from previous test. |
| 69 | | context.clearRect( 0, 0, canvas.width, canvas.height ); |
| 70 | | |
| 71 | | context.fillText( stringFromCharCode( 55356, 57332, 56128, 56423, 56128, 56418, 56128, 56421, 56128, 56430, 56128, 56423, 56128, 56447 ), 0, 0 ); |
| 72 | | flag = canvas.toDataURL(); |
| | 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 | ); |
| 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': |
| 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; |