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 support #986

Open
nfraprado opened this issue Jan 15, 2021 · 1 comment
Open

Emoji support #986

nfraprado opened this issue Jan 15, 2021 · 1 comment

Comments

@nfraprado
Copy link
Contributor

I'm creating this issue to discuss emoji support in rst2pdf.

First of all, has anyone already tried using emojis in rst2pdf? What was the procedure? In case everything already works, we should at least document it in the manual.

Ideally, (I'm not even sure it is possible), rst2pdf should have a font alias for emojis. Just like there is stdFont, there should be a stdEmoji, which would automatically be used to render emojis throughout the document.

Experimentation

I started experimenting. Took a couple tries:

  1. Just try using an emoji character and see if it works out-of-the-box. Result: Doesn't work, the emoji is rendered as a box with a ?, since the font I'm using for the text ("Carlito") doesn't support emojis.
  2. Use a custom emoji role for the emoji and make it use an emoji font. I used the font I had installed, which was "NotoColorEmoji". Result: [ERROR] findfonts.py:330 Error registering font: NotoColorEmoji from /usr/share/fonts/noto/NotoColorEmoji.ttf. Apparently reportlab doesn't work with this font for some reason... I included the full traceback at the end by re-raising the error, in case anyone wants to take a look, but it most probably is a reportlab bug. PS: It also happened with the "twemoji" font.
  3. After finding a blog post talking about using emojis in reportlab, and seeing that the person used the "Symbola" font, I tried it out. Result: This one did work. So, for reference, using a custom role with the "Symbola" font for the emojis does work.

Now, reading that blog post further, they suggest that in order to support those colorful emojis, one needs to substitute the characters for images, which they do through a python module they wrote. I found this very weird, though. I think that should also be possible using normal ttf fonts (like "NotoColorEmoji"), without using images.

Conclusions

So, from my experimentations, what I think are the open questions for having good emoji support in rst2pdf:

  • How to make rst2pdf use a separate font for unicode characters representing emojis (which would be defined by stdEmoji for example)? This would remove the need for the user to surround each emoji with a custom rst role.
  • Why are some emoji fonts failing with rst2pdf/reportlab? ("NotoColorEmoji" and "twemoji" fonts seem to only have emojis, while "Symbola seems to also have normal characters, maybe that's why? I'm not even sure of these statements, though, but could be a reason).

Traceback when using the "NotoColorEmoji" font:

Traceback (most recent call last):
  File "/usr/bin/rst2pdf", line 33, in <module>
    sys.exit(load_entry_point('rst2pdf', 'console_scripts', 'rst2pdf')())
  File "/home/nfraprado/cur/git/rst2pdf/rst2pdf/createpdf.py", line 1687, in main
    RstToPdf(
  File "/home/nfraprado/cur/git/rst2pdf/rst2pdf/createpdf.py", line 198, in __init__
    self.loadStyles(stylesheets)
  File "/home/nfraprado/cur/git/rst2pdf/rst2pdf/createpdf.py", line 270, in loadStyles
    self.styles = sty.StyleSheet(
  File "/home/nfraprado/cur/git/rst2pdf/rst2pdf/styles.py", line 367, in __init__
    fontList = findfonts.autoEmbed(style[key])
  File "/home/nfraprado/cur/git/rst2pdf/rst2pdf/findfonts.py", line 330, in autoEmbed
    raise e
  File "/home/nfraprado/cur/git/rst2pdf/rst2pdf/findfonts.py", line 326, in autoEmbed
    _font = TTFont(vname, variant)
  File "/usr/lib/python3.9/site-packages/reportlab/pdfbase/ttfonts.py", line 1196, in __init__
    self.face = TTFontFace(filename, validate=validate, subfontIndex=subfontIndex)
  File "/usr/lib/python3.9/site-packages/reportlab/pdfbase/ttfonts.py", line 1090, in __init__
    TTFontFile.__init__(self, filename, validate=validate, subfontIndex=subfontIndex)
  File "/usr/lib/python3.9/site-packages/reportlab/pdfbase/ttfonts.py", line 458, in __init__
    self.extractInfo(charInfo)
  File "/usr/lib/python3.9/site-packages/reportlab/pdfbase/ttfonts.py", line 872, in extractInfo
    if 'loca' not in self.table: raise TTFError('missing location table')
reportlab.pdfbase.ttfonts.TTFError: missing location table
@lornajane
Copy link
Contributor

I'd be happy to receive and review a PR for this, but given the other open issues on the project, I can't imagine us prioritising this within the core team. Issue is very welcome to be open though as emojis would be nice to have!

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