Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use monochrome emojis contained in the font family if no emoji source available #2736

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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