diff --git a/fixtures/debug.html b/fixtures/debug.html
new file mode 100644
index 0000000..b4a7bf7
--- /dev/null
+++ b/fixtures/debug.html
@@ -0,0 +1,204 @@
+
+
+
+
+
+ Debug emoji confetti
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/confetti.js b/src/confetti.js
index a67a345..d92a11a 100644
--- a/src/confetti.js
+++ b/src/confetti.js
@@ -808,7 +808,7 @@
scalar = 1,
color = '#000000',
// see https://nolanlawson.com/2022/04/08/the-struggle-of-using-native-emoji-on-the-web/
- fontFamily = '"Twemoji Mozilla", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "EmojiOne Color", "Android Emoji", "system emoji", sans-serif';
+ fontFamily = '"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "EmojiOne Color", "Android Emoji", "Twemoji Mozilla", "system emoji", sans-serif';
if (typeof textData === 'string') {
text = textData;
@@ -829,15 +829,21 @@
ctx.font = font;
var size = ctx.measureText(text);
- var width = Math.floor(size.width);
- var height = Math.floor(size.fontBoundingBoxAscent + size.fontBoundingBoxDescent);
+ var width = Math.ceil(size.actualBoundingBoxRight + size.actualBoundingBoxLeft);
+ var height = Math.ceil(size.actualBoundingBoxAscent + size.actualBoundingBoxDescent);
+
+ var padding = 2;
+ var x = size.actualBoundingBoxLeft + padding;
+ var y = size.actualBoundingBoxAscent + padding;
+ width += padding + padding;
+ height += padding + padding;
canvas = new OffscreenCanvas(width, height);
ctx = canvas.getContext('2d');
ctx.font = font;
ctx.fillStyle = color;
- ctx.fillText(text, 0, fontSize);
+ ctx.fillText(text, x, y);
var scale = 1 / scalar;
diff --git a/test/index.test.js b/test/index.test.js
index 564b860..9da20ee 100644
--- a/test/index.test.js
+++ b/test/index.test.js
@@ -739,8 +739,8 @@ test('[text] shapeFromText renders an emoji', async t => {
...shape
}, {
type: 'bitmap',
- matrix: [ 0.1, 0, 0, 0.1, -6.25, -5.8500000000000005 ],
- hash: '8647FpWTCBH'
+ matrix: [ 0.1, 0, 0, 0.1, -5.7, -5.550000000000001 ],
+ hash: 'c4y5z8b83AC'
});
});