Skip to content

Commit

Permalink
feat: use monochrome emojis if no emoji source available (#2736)
Browse files Browse the repository at this point in the history
Co-authored-by: Diego Muracciole <[email protected]>
  • Loading branch information
siketyan and diegomura authored Nov 14, 2024
1 parent e46fadd commit b242e59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-bags-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-pdf/layout": minor
---

Use monochrome emojis contained in the font family if no emoji source available
10 changes: 2 additions & 8 deletions packages/layout/src/text/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ export const fetchEmojis = (string, source) => {
return promises;
};

const specialCases = ['©️', '®', '™']; // Do not treat these as emojis if emoji not present

export const embedEmojis = (fragments) => {
const result = [];

Expand All @@ -82,8 +80,6 @@ export const embedEmojis = (fragments) => {
Array.from(fragment.string.matchAll(regex)).forEach((match) => {
const { index } = match;
const emoji = match[0];
const isSpecialCase = specialCases.includes(emoji);

const emojiSize = fragment.attributes.fontSize;
const chunk = fragment.string.slice(lastIndex, index + match[0].length);

Expand All @@ -102,12 +98,10 @@ export const embedEmojis = (fragments) => {
},
},
});
} else if (isSpecialCase) {
result.push({ string: chunk, attributes: fragment.attributes });
} else {
// If no emoji data, we just replace the emoji with a nodef char
// If no emoji data, we try to use emojis in the font
result.push({
string: chunk.replace(match, String.fromCharCode(0)),
string: chunk,
attributes: fragment.attributes,
});
}
Expand Down

0 comments on commit b242e59

Please sign in to comment.