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:
parent
45b183ea79
commit
491f14540e
@ -39,21 +39,25 @@
|
||||
switch ( type ) {
|
||||
case 'flag':
|
||||
/*
|
||||
* This works because the image will be one of three things:
|
||||
* - Two empty squares, if the browser doesn't render emoji
|
||||
* - Two squares with 'U' and 'N' in them, if the browser doesn't render flag emoji
|
||||
* - The United Nations flag
|
||||
* Test for UN flag compatibility. This is the least supported of the letter locale flags,
|
||||
* so gives us an easy test for full support.
|
||||
*
|
||||
* The first two will encode to small images (1-2KB data URLs), the third will encode
|
||||
* to a larger image (4-5KB data URL).
|
||||
* To test for support, we try to render it, and compare the rendering to how it would look if
|
||||
* the browser doesn't render it correctly ([U] + [N]).
|
||||
*/
|
||||
context.fillText( stringFromCharCode( 55356, 56826, 55356, 56819 ), 0, 0 );
|
||||
if ( canvas.toDataURL().length < 3000 ) {
|
||||
return false;
|
||||
}
|
||||
flag = canvas.toDataURL();
|
||||
|
||||
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
|
||||
* the usual Unicode release cycle, some browsers support it, and some don't, even if their
|
||||
|
Loading…
Reference in New Issue
Block a user