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

Rendering emoji? #286

Open
deeplook opened this issue May 26, 2021 · 3 comments
Open

Rendering emoji? #286

deeplook opened this issue May 26, 2021 · 3 comments

Comments

@deeplook
Copy link
Owner

This is mainly a question for @replabrobin, but I put it here because there is no issue management for reportlab on github. ;)

So I would like to render emoji in SVG and came up with this initial attempt giving me the much expected black squares. Is there any way reportlab could make this work as expected?

# pip install emoji reportlab svglib

from io import StringIO
from textwrap import dedent

from emoji import emojize
from reportlab.graphics.renderPM import drawToPIL
from svglib.svglib import svg2rlg

drawing = svg2rlg(StringIO(dedent(emojize('''\
    <?xml version="1.0"?>
    <svg width="500" height="100">
      <text style="fill:#000000; stroke:none; font-size:28; font-family:monospace;">
        <tspan x="0" y="28">Übertitle</tspan>
        <tspan x="0" y="56">👍 (should be "thumbs up")</tspan>
        <tspan x="0" y="84">:thumbs_down: (should be "thumbs down")</tspan>
      </text>
    </svg>
'''))))
drawToPIL(drawing)

Screenshot 2021-05-26 at 08 41 31

@claudep
Copy link
Collaborator

claudep commented May 26, 2021

Interesting... I tried myself with setting a specific emoji font, NotoColorEmoji.ttf, however reportlab unfortunately doesn't support the font (reportlab.pdfbase.ttfonts.TTFError: missing location table).

@411A
Copy link

411A commented Mar 7, 2023

Hi, is there any workaround to deal with Unicode characters? I'm using Cascadia Code font, but I don't know how can I pass a font... or will it work or not. I really need this but apparently, it's very hard to achieve!

@deeplook
Copy link
Owner Author

deeplook commented Mar 8, 2023

FWIW, I just found this article from 2015, so I'm not sure this is still relevant... https://kaviraj.me/generating-pdf-containing-emoji-python/

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

No branches or pull requests

3 participants