Skip to content

Commit f5fa527

Browse files
committed
Merge branch 'main' into dev/1.5
2 parents 4bc2469 + 35a4832 commit f5fa527

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/core/src/Polyfill.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export class Polyfill {
77
static registerPolyfill(): void {
88
Polyfill._registerMatchAll();
99
Polyfill._registerAudioContext();
10+
Polyfill._registerTextMetrics();
1011
}
1112

1213
private static _registerMatchAll(): void {
@@ -69,4 +70,24 @@ export class Polyfill {
6970
};
7071
}
7172
}
73+
74+
private static _registerTextMetrics(): void {
75+
// Based on the specific version of the engine implementation, when actualBoundingBoxLeft is not supported, width is used to represent the rendering width, and `textAlign` uses the default value `start` and direction is left to right.
76+
// Some devices do not support actualBoundingBoxLeft and actualBoundingBoxRight in TextMetrics.
77+
// Examples: Google Pixel 2 XL (Android 11), Honor 6X (Android 8).
78+
if (!("actualBoundingBoxLeft" in TextMetrics.prototype)) {
79+
Object.defineProperties(TextMetrics.prototype, {
80+
actualBoundingBoxLeft: {
81+
get: function () {
82+
return 0;
83+
}
84+
},
85+
actualBoundingBoxRight: {
86+
get: function () {
87+
return this.width;
88+
}
89+
}
90+
});
91+
}
92+
}
7293
}

0 commit comments

Comments
 (0)