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

Support emojis #73

Closed
oliverpool opened this issue Feb 10, 2021 · 6 comments
Closed

Support emojis #73

oliverpool opened this issue Feb 10, 2021 · 6 comments

Comments

@oliverpool
Copy link
Contributor

I would like to render emojis embedded in the text.

I have made a proof-of-concept that works like this:

  1. get the emojis as png from https://twemoji.twitter.com/ (they are also available as svg, but rendering svg is not trivial)
  2. make a list of all supported emojis (by converting the hex-name of the icons to the string of the emoji : 1f3c3-200d-2640-fe0f.png => 🏃‍♀️)
  3. give a function as a parameter to RichText to recognize the supported emojis from the input text (in RichText.Add)
  4. return the emojis with their coordinates from RichText.ToText (and replace its text with "" to prevent being it renderer as text)
  5. Get the associated png file from the filesystem and draw it as an image on the context.
  6. Example (ignore the strange newlines):
    out

Since the emoji influence the position of the letters (computed in RichText), this requires a modification of the core (and Text has unexported fields, so a 3-rd party package can't work).

However the rendering of the emojis does not have to be in the core (only the identification of the "supported emojis" must be integrated) - so no dependency on twemoji.

Would you consider such an addition to the library or do you think that this is way out of scope?
I can show you in a draft PR if you want to take a closer look at the modifications that I made.


Background: I am using this project for a small german startup (https://www.bilderbrief.de/) and my customers would ❤️ to send emojis 😉

@tdewolff
Copy link
Owner

Hey @oliverpool , that is a great idea! There are two separate things that come to my mind:

  • We should support inline images and paths in RichText
  • We should support SVG glyphs in SFNT fonts (this is where fonts keep their emoticons, see https://docs.microsoft.com/en-us/typography/opentype/spec/svg), however I'm not sure which fonts have them defined and which don't. Surely, you can load a font that has emoticons and add text runs to the RichText with that font (you can combine fonts in RichText)

Both should happen at some point, but the first is far more useful and versatile and can in the meantime be an alternative for the second. Parsing SVGs in SFNT fonts is a lot of work.

However, Text and RichText are being completely revamped in the next release, see the develop branch for a status on that. It has the following implemented: parsing SFNT fonts (TTF, OTF, WOFF, WOFF2, EOT), subsetting SFNT fonts, text shaping using HarfBuzz (ligatures, accents for Devanagari), text direction using FriBidi (combine arabic with latin), vertical text (Chinese, Japanese, ...), font features and variants (ligature and stylistic variants), text justification using Donald Knuth's algorithm as used in TeX, and some other bits. This is working for all output files (SVG, PDF, PNG, ...), however only the NewTextLine is implemented and not yet the RichText interface. The latter should not be a big piece of work though. The Text structure is greatly simplified. Please take a look at the branch to see the results, but adding emoticons would need a bit more work (not much) as well, and realistically that branch might get merged in a month of two.

If you want emoticon support soon, I suggest you create your own branch for now, or wait for the new branch to be merged. You could also push to master now, but there's little gain as the new branch will merge over your changes!

@oliverpool
Copy link
Contributor Author

All right, I will maintain my own branch for now (master...oliverpool:bilderbrief)

Feel free to ping me when the develop branch is finalized, so that I can check if everything still works fine for my usecases and look how I can integrate the emojis back (no hurry - it works fine for now :)

@tdewolff
Copy link
Owner

I've incorporated this issue in the new roadmap from where it will be tracked: #74

@weizhongtan
Copy link

I'm interested in using this package (which is awesome by the way!) for rendering emojis inline with text and came across this issue where it seems that the groundwork has already been started to support this. Is there any appetite to get the changes merged into the upstream? Thanks

@tdewolff
Copy link
Owner

tdewolff commented Sep 2, 2023 via email

@tdewolff
Copy link
Owner

tdewolff commented Sep 11, 2023 via email

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