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

Emoji not rendering correctly depending on emoji-source #2466

Closed
JaeSeoKim opened this issue Dec 20, 2023 · 0 comments · Fixed by #2467
Closed

Emoji not rendering correctly depending on emoji-source #2466

JaeSeoKim opened this issue Dec 20, 2023 · 0 comments · Fixed by #2467

Comments

@JaeSeoKim
Copy link
Contributor

Describe the bug

Variation Selectors (U+FE00..U+FE0F) were required depending on the emoji-source, causing emoji to not render correctly.

To Reproduce

example with twemoji

example with npm:emoji-datasource

Expected behavior

// https://github.com/diegomura/react-pdf/blob/9f7a2dffc66294f64ab39b3de68564e0a2e77ed8/packages/layout/src/text/emoji.js#L18-L35

/**
 * When an emoji as no color, it might still have 2 parts,
 * the canonical emoji and an empty string.
 * ex.
 *   (no color) Array.from('❤️') => ["❤", "️"]
 *   (w/ color) Array.from('👍🏿') => ["👍", "🏿"]
 *
 * The empty string needs to be removed otherwise the generated
 * url will be incorect.
 */
const _removeNoColor = x => x !== '️';

const getCodePoints = string =>
  Array.from(string)
    .filter(_removeNoColor)
    .map(char => char.codePointAt(0).toString(16))
    .join('-');

Since the Variation Selectors are being removed via the _removeNoColor function, we need to get additional options for the conditions under which the filter works.

for example

Font.registerEmojiSource({
  format: "png",
  url: "https://cdn.jsdelivr.net/npm/emoji-datasource-apple@15.0.1/img/apple/64/",
  withVariationSelectors: true,
});

Screenshots

Error screenshot

image

fixed with a simple patch Screenshot

image

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: chrome 120.0.6099.71
  • React-pdf version:
    • "@react-pdf/renderer": "^3.1.14"
JaeSeoKim added a commit to JaeSeoKim/react-pdf that referenced this issue Dec 20, 2023
diegomura pushed a commit that referenced this issue Jan 14, 2024
* feat: add withVariationSelectors option to registerEmojiSource

fixed: #2466

* feat: update EmojiSource

* chore: create changeset
mskec pushed a commit to mskec/react-pdf that referenced this issue Feb 26, 2024
…mura#2467)

* feat: add withVariationSelectors option to registerEmojiSource

fixed: diegomura#2466

* feat: update EmojiSource

* chore: create changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant