Skip to content

Commit b242e59

Browse files
siketyandiegomura
andauthored
feat: use monochrome emojis if no emoji source available (#2736)
Co-authored-by: Diego Muracciole <[email protected]>
1 parent e46fadd commit b242e59

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

.changeset/nasty-bags-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-pdf/layout": minor
3+
---
4+
5+
Use monochrome emojis contained in the font family if no emoji source available

packages/layout/src/text/emoji.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ export const fetchEmojis = (string, source) => {
6969
return promises;
7070
};
7171

72-
const specialCases = ['©️', '®', '™']; // Do not treat these as emojis if emoji not present
73-
7472
export const embedEmojis = (fragments) => {
7573
const result = [];
7674

@@ -82,8 +80,6 @@ export const embedEmojis = (fragments) => {
8280
Array.from(fragment.string.matchAll(regex)).forEach((match) => {
8381
const { index } = match;
8482
const emoji = match[0];
85-
const isSpecialCase = specialCases.includes(emoji);
86-
8783
const emojiSize = fragment.attributes.fontSize;
8884
const chunk = fragment.string.slice(lastIndex, index + match[0].length);
8985

@@ -102,12 +98,10 @@ export const embedEmojis = (fragments) => {
10298
},
10399
},
104100
});
105-
} else if (isSpecialCase) {
106-
result.push({ string: chunk, attributes: fragment.attributes });
107101
} else {
108-
// If no emoji data, we just replace the emoji with a nodef char
102+
// If no emoji data, we try to use emojis in the font
109103
result.push({
110-
string: chunk.replace(match, String.fromCharCode(0)),
104+
string: chunk,
111105
attributes: fragment.attributes,
112106
});
113107
}

0 commit comments

Comments
 (0)