WordPress.org

Make WordPress Core

Changeset 40582


Ignore:
Timestamp:
05/08/17 05:00:29 (8 months ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/wp-emoji-loader.js

    r38869 r40582  
    4040            case 'flag': 
    4141                /* 
    42                  * This works because the image will be one of three things: 
    43                  * - Two empty squares, if the browser doesn't render emoji 
    44                  * - Two squares with 'U' and 'N' in them, if the browser doesn't render flag emoji 
    45                  * - The United Nations flag 
     42                 * Test for UN flag compatibility. This is the least supported of the letter locale flags, 
     43                 * so gives us an easy test for full support. 
    4644                 * 
    47                  * The first two will encode to small images (1-2KB data URLs), the third will encode 
    48                  * to a larger image (4-5KB data URL). 
     45                 * To test for support, we try to render it, and compare the rendering to how it would look if 
     46                 * the browser doesn't render it correctly ([U] + [N]). 
    4947                 */ 
    5048                context.fillText( stringFromCharCode( 55356, 56826, 55356, 56819 ), 0, 0 ); 
    51                 if ( canvas.toDataURL().length < 3000 ) { 
     49                flag = canvas.toDataURL(); 
     50 
     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, 57331, 8203, 55356, 57096 ), 0, 0 ); 
     55                flag2 = canvas.toDataURL(); 
     56 
     57                if ( flag !== flag2 ) { 
    5258                    return false; 
    5359                } 
    54  
    55                 context.clearRect( 0, 0, canvas.width, canvas.height ); 
    5660 
    5761                /* 
Note: See TracChangeset for help on using the changeset viewer.