Skip to content

Commit 3eb83b7

Browse files
committed
Emoji: Update Twemoji to version 16.0.1.
Introduces support for Emoji 16: - replaces emoji support test with splatter 🫟, - replaces two letter coded flag support test with Sark 🇨🇶, - introduces the function `emojiRendersEmptyCenterPoint()` to the emoji loader to enable testing of emoji with a single data point. Not to harp 🪉 on about it, but Emoji 16 is perfect for tiring yourself out 🫩 digging 🪏 up root vegetables 🫜 while visiting Sark 🇨🇶. Reviewed by audrasjb. Merges [60227] to the 6.8 branch. Props westonruter, kraftbj, pento, JeffPaul, abcd95, SergeyBiryukov, dd32, peterwilsoncc. Fixes #63324. git-svn-id: https://develop.svn.wordpress.org/branches/6.8@60317 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 07801ac commit 3eb83b7

File tree

5 files changed

+73
-39
lines changed

5 files changed

+73
-39
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ module.exports = function(grunt) {
11411141
}
11421142

11431143
// Fetch a list of the files that Twemoji supplies.
1144-
query = 'query={repository(owner: "jdecked", name: "twemoji") {object(expression: "v15.1.0:assets/svg") {... on Tree {entries {name}}}}}';
1144+
query = 'query={repository(owner: "jdecked", name: "twemoji") {object(expression: "v16.0.1:assets/svg") {... on Tree {entries {name}}}}}';
11451145
files = spawn( 'gh', [ 'api', 'graphql', '-f', query] );
11461146

11471147
if ( 0 !== files.status ) {

src/js/_enqueues/lib/emoji-loader.js

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@
117117
/**
118118
* Checks if two sets of Emoji characters render the same visually.
119119
*
120+
* This is used to determine if the browser is rendering an emoji with multiple data points
121+
* correctly. set1 is the emoji in the correct form, using a zero-width joiner. set2 is the emoji
122+
* in the incorrect form, using a zero-width space. If the two sets render the same, then the browser
123+
* does not support the emoji correctly.
124+
*
120125
* This function may be serialized to run in a Worker. Therefore, it cannot refer to variables from the containing
121126
* scope. Everything must be passed by parameters.
122127
*
@@ -160,6 +165,42 @@
160165
} );
161166
}
162167

168+
/**
169+
* Checks if the center point of a single emoji is empty.
170+
*
171+
* This is used to determine if the browser is rendering an emoji with a single data point
172+
* correctly. The center point of an incorrectly rendered emoji will be empty. A correctly
173+
* rendered emoji will have a non-zero value at the center point.
174+
*
175+
* This function may be serialized to run in a Worker. Therefore, it cannot refer to variables from the containing
176+
* scope. Everything must be passed by parameters.
177+
*
178+
* @since 6.8.2
179+
*
180+
* @private
181+
*
182+
* @param {CanvasRenderingContext2D} context 2D Context.
183+
* @param {string} emoji Emoji to test.
184+
*
185+
* @return {boolean} True if the center point is empty.
186+
*/
187+
function emojiRendersEmptyCenterPoint( context, emoji ) {
188+
// Cleanup from previous test.
189+
context.clearRect( 0, 0, context.canvas.width, context.canvas.height );
190+
context.fillText( emoji, 0, 0 );
191+
192+
// Test if the center point (16, 16) is empty (0,0,0,0).
193+
var centerPoint = context.getImageData(16, 16, 1, 1);
194+
for ( var i = 0; i < centerPoint.data.length; i++ ) {
195+
if ( centerPoint.data[ i ] !== 0 ) {
196+
// Stop checking the moment it's known not to be empty.
197+
return false;
198+
}
199+
}
200+
201+
return true;
202+
}
203+
163204
/**
164205
* Determines if the browser properly renders Emoji that Twemoji can supplement.
165206
*
@@ -173,10 +214,11 @@
173214
* @param {CanvasRenderingContext2D} context 2D Context.
174215
* @param {string} type Whether to test for support of "flag" or "emoji".
175216
* @param {Function} emojiSetsRenderIdentically Reference to emojiSetsRenderIdentically function, needed due to minification.
217+
* @param {Function} emojiRendersEmptyCenterPoint Reference to emojiRendersEmptyCenterPoint function, needed due to minification.
176218
*
177219
* @return {boolean} True if the browser can render emoji, false if it cannot.
178220
*/
179-
function browserSupportsEmoji( context, type, emojiSetsRenderIdentically ) {
221+
function browserSupportsEmoji( context, type, emojiSetsRenderIdentically, emojiRendersEmptyCenterPoint ) {
180222
var isIdentical;
181223

182224
switch ( type ) {
@@ -198,16 +240,16 @@
198240
}
199241

200242
/*
201-
* Test for UN flag compatibility. This is the least supported of the letter locale flags,
243+
* Test for Sark flag compatibility. This is the least supported of the letter locale flags,
202244
* so gives us an easy test for full support.
203245
*
204246
* To test for support, we try to render it, and compare the rendering to how it would look if
205-
* the browser doesn't render it correctly ([U] + [N]).
247+
* the browser doesn't render it correctly ([C] + [Q]).
206248
*/
207249
isIdentical = emojiSetsRenderIdentically(
208250
context,
209-
'\uD83C\uDDFA\uD83C\uDDF3', // as the sequence of two code points
210-
'\uD83C\uDDFA\u200B\uD83C\uDDF3' // as the two code points separated by a zero-width space
251+
'\uD83C\uDDE8\uD83C\uDDF6', // as the sequence of two code points
252+
'\uD83C\uDDE8\u200B\uD83C\uDDF6' // as the two code points separated by a zero-width space
211253
);
212254

213255
if ( isIdentical ) {
@@ -232,31 +274,21 @@
232274
return ! isIdentical;
233275
case 'emoji':
234276
/*
235-
* Rise Like a Phoenix.
277+
* Does Emoji 16.0 cause the browser to go splat?
236278
*
237-
* To test for Emoji 15.1 support, try to render a new emoji: Phoenix.
279+
* To test for Emoji 16.0 support, try to render a new emoji: Splatter.
238280
*
239-
* A phoenix, a mythical immortal bird with flame-like feathers found in the folklore of many global
240-
* cultures. Often used to symbolize renewal or rebirth.
281+
* The splatter emoji is a single code point emoji. Testing for browser support
282+
* required testing the center point of the emoji to see if it is empty.
241283
*
242-
* The Phoenix emoji is a ZWJ sequence combining 🐦 Bird, Zero Width Joiner and 🔥 Fire.
243-
* These display as a single emoji on supported platforms.
284+
* 0xD83E 0xDEDF (\uD83E\uDEDF) == 🫟 Splatter.
244285
*
245-
* 0xD83D 0xDC26 (\uD83D\uDC26) == 🐦 Bird
246-
* 0x200D == Zero-Width Joiner (ZWJ) that links the code points for the new emoji or
247-
* 0x200B == Zero-Width Space (ZWS) that is rendered for clients not supporting the new emoji.
248-
* 0xD83D 0xDD25 (\uD83D\uDD25) == 🔥 Fire
249-
*
250-
* When updating this test for future Emoji releases, ensure that individual emoji that make up the
251-
* sequence come from older emoji standards.
286+
* When updating this test, please ensure that the emoji is either a single code point
287+
* or switch to using the emojiSetsRenderIdentically function and testing with a zero-width
288+
* joiner vs a zero-width space.
252289
*/
253-
isIdentical = emojiSetsRenderIdentically(
254-
context,
255-
'\uD83D\uDC26\u200D\uD83D\uDD25', // as the zero-width joiner sequence
256-
'\uD83D\uDC26\u200B\uD83D\uDD25' // separated by a zero-width space
257-
);
258-
259-
return ! isIdentical;
290+
var notSupported = emojiRendersEmptyCenterPoint( context, '\uD83E\uDEDF' );
291+
return ! notSupported;
260292
}
261293

262294
return false;
@@ -275,10 +307,11 @@
275307
* @param {string[]} tests Tests.
276308
* @param {Function} browserSupportsEmoji Reference to browserSupportsEmoji function, needed due to minification.
277309
* @param {Function} emojiSetsRenderIdentically Reference to emojiSetsRenderIdentically function, needed due to minification.
310+
* @param {Function} emojiRendersEmptyCenterPoint Reference to emojiRendersEmptyCenterPoint function, needed due to minification.
278311
*
279312
* @return {SupportTests} Support tests.
280313
*/
281-
function testEmojiSupports( tests, browserSupportsEmoji, emojiSetsRenderIdentically ) {
314+
function testEmojiSupports( tests, browserSupportsEmoji, emojiSetsRenderIdentically, emojiRendersEmptyCenterPoint ) {
282315
var canvas;
283316
if (
284317
typeof WorkerGlobalScope !== 'undefined' &&
@@ -301,7 +334,7 @@
301334

302335
var supports = {};
303336
tests.forEach( function ( test ) {
304-
supports[ test ] = browserSupportsEmoji( context, test, emojiSetsRenderIdentically );
337+
supports[ test ] = browserSupportsEmoji( context, test, emojiSetsRenderIdentically, emojiRendersEmptyCenterPoint );
305338
} );
306339
return supports;
307340
}
@@ -354,7 +387,8 @@
354387
[
355388
JSON.stringify( tests ),
356389
browserSupportsEmoji.toString(),
357-
emojiSetsRenderIdentically.toString()
390+
emojiSetsRenderIdentically.toString(),
391+
emojiRendersEmptyCenterPoint.toString()
358392
].join( ',' ) +
359393
'));';
360394
var blob = new Blob( [ workerScript ], {
@@ -371,7 +405,7 @@
371405
} catch ( e ) {}
372406
}
373407

374-
supportTests = testEmojiSupports( tests, browserSupportsEmoji, emojiSetsRenderIdentically );
408+
supportTests = testEmojiSupports( tests, browserSupportsEmoji, emojiSetsRenderIdentically, emojiRendersEmptyCenterPoint );
375409
setSessionSupportTests( supportTests );
376410
resolve( supportTests );
377411
} )

0 commit comments

Comments
 (0)