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

How to use DejaVuSans Font with color emoji #1341

Closed
simkessy opened this issue Jan 9, 2025 · 6 comments
Closed

How to use DejaVuSans Font with color emoji #1341

simkessy opened this issue Jan 9, 2025 · 6 comments
Assignees

Comments

@simkessy
Copy link

simkessy commented Jan 9, 2025

It's not clear to me how we're supposed to get emojis in the PDF.

For example. I have DejaVuSans has my font and emojis are just rendering using that instead of the colored emojis from TwitterEmoji.ttf.

Is that expected?

For example this is my setup:

            fpdf.add_font('TwitterEmoji', '', 'TwitterColorEmoji-SVGinOT.ttf')
            fpdf.add_font('OpenMoji', '', 'OpenMoji-color-colr1_svg.ttf')
            fpdf.add_font('DejaVuSans', '', 'DejaVuSans.ttf')
            fpdf.set_fallback_fonts(['TwitterEmoji', 'OpenMoji'])

When I try to render text with emojis, I just get the ones from DejaVuSans or Roboto and not the fallbacks.

image image
@simkessy simkessy added the bug label Jan 9, 2025
@Lucas-C
Copy link
Member

Lucas-C commented Jan 9, 2025

Hi @simkessy! 🙂

I checked you have read our documentation page about emojis?
https://py-pdf.github.io/fpdf2/EmojisSymbolsDingbats.html

I'm a bit in a hurry right now, but I'll try to test your code asap 🙂

@Lucas-C Lucas-C self-assigned this Jan 9, 2025
@simkessy
Copy link
Author

simkessy commented Jan 9, 2025

Hey @Lucas-C I have but yea I can't figure out how or if it's possible to have both a font for text and one for emojis in color

I don't think the examples in the docs cover this and when I use a unicode font, like roboto or devajusans, it just uses the black and white version of those fonts and not the fallback with the emoji in color

@Lucas-C
Copy link
Member

Lucas-C commented Jan 9, 2025

I don't think the examples in the docs cover this and when I use a unicode font, like roboto or devajusans, it just uses the black and white version of those fonts and not the fallback with the emoji in color.

👍
Yeah, we should definitely add a mention about this in our documentation on this page 🙂

I'm testing your code now...

Reference links for the fonts:

@Lucas-C
Copy link
Member

Lucas-C commented Jan 9, 2025

Oh, I just realized: we do not support color emojis yet!
cf. #224

However @andersonhc, another maintainer of fpdf2, is currently working on this 🙂
cf. #1305


For reference, a minimal autonomous test script for testing:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.add_font(fname="fonts/DejaVuSans.ttf")
pdf.add_font(fname="OpenMoji-color-colr1_svg.ttf")
pdf.add_font(fname="TwitterColorEmoji-SVGinOT.ttf")
pdf.set_font("DejaVuSans", size=14)
pdf.set_fallback_fonts(["TwitterColorEmoji-SVGinOT", "OpenMoji-color-colr1_svg"])
pdf.multi_cell(0, text="".join([chr(0x1F600 + x) for x in range(68)]))
pdf.write(text="text with an emoji 🌭")
pdf.output("issue_1341.pdf")

@Lucas-C
Copy link
Member

Lucas-C commented Jan 9, 2025

For now, I suggest to add a warning about this in our documentation:
#1342

@simkessy: do you have any question regarding this?
Else I'll close this issue, and we can track the subject of the color emojis in #224 🙂

@simkessy
Copy link
Author

simkessy commented Jan 9, 2025

No questions, now that know it's not supported I can move on. Thanks for the quick response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants