Skip to content

Commit 654d9ce

Browse files
authored
Fix SDL_TTF to work with older browser versions. (#25409)
1 parent 0167321 commit 654d9ce

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/lib/libsdl.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,13 +3117,16 @@ var LibrarySDL = {
31173117
try {
31183118
var offscreenCanvas = new OffscreenCanvas(0, 0);
31193119
SDL.ttfContext = offscreenCanvas.getContext('2d');
3120-
// Firefox support for OffscreenCanvas is still experimental, and it seems
3121-
// like CI might be creating a context here but one that is not entirely
3122-
// valid. Check that explicitly and fall back to a plain Canvas if we need
3123-
// to. See https://github.com/emscripten-core/emscripten/issues/16242
3124-
if (typeof SDL.ttfContext.measureText != 'function') {
3125-
abort('bad context');
3120+
#if MIN_FIREFOX_VERSION < 128 // Conservative, not exact
3121+
// According to https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvasRenderingContext2D
3122+
// OffscreenCanvasRenderingContext2D.measureText() appeared in
3123+
// Chrome 69, Firefox 105 and Safari 16.4. Fall back to using regular
3124+
// Canvas2D if OffscreenCanvas2D exists, but does not look workable.
3125+
// https://github.com/emscripten-core/emscripten/issues/16242
3126+
if (!SDL.ttfContext.measureText) {
3127+
throw 1; // no OffscreenCanvasRenderingContext2D.measureText
31263128
}
3129+
#endif
31273130
} catch (ex) {
31283131
var canvas = /** @type {HTMLCanvasElement} */(document.createElement('canvas'));
31293132
SDL.ttfContext = canvas.getContext('2d');

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 246028,
3-
"a.out.nodebug.wasm": 597755,
4-
"total": 843783,
2+
"a.out.js": 246004,
3+
"a.out.nodebug.wasm": 597763,
4+
"total": 843759,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

0 commit comments

Comments
 (0)