Emoji: Make the UN flag test more accurate.

Previously, the UN flag test relied on the image being produced to be quite small. Unfortunately, the Chrome PNG encoder seems to have changed recently, and it now produces a relatively large image.

For a better test, we can compare the rendering of [U] + [N] against [U] + zero width space + [N].

Fixes #40616.



git-svn-id: https://develop.svn.wordpress.org/trunk@40582 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
pento 2017-05-08 05:00:29 +00:00
parent 45b183ea79
commit 491f14540e

View File

@ -39,21 +39,25 @@
switch ( type ) { switch ( type ) {
case 'flag': case 'flag':
/* /*
* This works because the image will be one of three things: * Test for UN flag compatibility. This is the least supported of the letter locale flags,
* - Two empty squares, if the browser doesn't render emoji * so gives us an easy test for full support.
* - Two squares with 'U' and 'N' in them, if the browser doesn't render flag emoji
* - The United Nations flag
* *
* The first two will encode to small images (1-2KB data URLs), the third will encode * To test for support, we try to render it, and compare the rendering to how it would look if
* to a larger image (4-5KB data URL). * the browser doesn't render it correctly ([U] + [N]).
*/ */
context.fillText( stringFromCharCode( 55356, 56826, 55356, 56819 ), 0, 0 ); context.fillText( stringFromCharCode( 55356, 56826, 55356, 56819 ), 0, 0 );
if ( canvas.toDataURL().length < 3000 ) { flag = canvas.toDataURL();
return false;
}
context.clearRect( 0, 0, canvas.width, canvas.height ); context.clearRect( 0, 0, canvas.width, canvas.height );
// Add a zero width space between the characters, to force rendering as characters.
context.fillText( stringFromCharCode( 55356, 57331, 8203, 55356, 57096 ), 0, 0 );
flag2 = canvas.toDataURL();
if ( flag !== flag2 ) {
return false;
}
/* /*
* Test for rainbow flag compatibility. As the rainbow flag was added out of sequence with * Test for rainbow flag compatibility. As the rainbow flag was added out of sequence with
* the usual Unicode release cycle, some browsers support it, and some don't, even if their * the usual Unicode release cycle, some browsers support it, and some don't, even if their