Skip to content

Commit 03fe2dc

Browse files
committed
Fix rendering combined emoji in the PDF
Fixes https://ecamp.sentry.io/issues/6353794860/?project=5602507&query=is%3Aunresolved%20image&referrer=issue-stream The twemoji library strips one code point from the emoji file names in some cases, see twitter/twemoji#419 (comment) Specifically, the male mage emoji consists of [4 code points](https://apps.timwhitlock.info/unicode/inspect?s=%F0%9F%A7%99%E2%80%8D%E2%99%82%EF%B8%8F): - 1f9d9 mage - 200d zero width joiner - 2642 male sign - fe0f variation selector 16 And the correct twemoji filename is: `/twemoji/assets/72x72/1f9d9-200d-2642-fe0f.png` On the other hand, the dove emoji consists of [2 code points](https://apps.timwhitlock.info/unicode/inspect?s=%F0%9F%95%8A%EF%B8%8F): - 1f54a dove - fe0f variation selector 16 And the correct twemoji filename is: `/twemoji/assets/72x72/1f54a.png` (note the omitted variation selector) In the twemoji library, according to the linked comment, the variation selector is removed in simple emoji without a zero width joiner, but preserved in combined emoji with a zero width joiner. Therefore, we need to mirror this transformation. Different emoji libraries can handle this differently, which is why it can't really be fixed on the react-pdf side.
1 parent 27429c8 commit 03fe2dc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pdf/src/CampPrint.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,15 @@ const registerFonts = async () => {
7575
})
7676
7777
Font.registerEmojiSource({
78-
formag: 'png',
79-
url: '/twemoji/assets/72x72/',
78+
withVariationSelectors: true,
79+
builder(code) {
80+
// If the code point does not contain 200d, remove any fe0f
81+
// https://github.com/twitter/twemoji/issues/419#issuecomment-637360325
82+
const filename = code.includes('200d')
83+
? code
84+
: code.replaceAll('fe0f', '').replaceAll(/--|^-|-$/g, '')
85+
return '/twemoji/assets/72x72/' + filename + '.png'
86+
},
8087
})
8188
8289
return await Promise.all([

0 commit comments

Comments
 (0)