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 #427

Closed
otopba opened this issue Jan 17, 2017 · 11 comments
Closed

Emoji support #427

otopba opened this issue Jan 17, 2017 · 11 comments

Comments

@otopba
Copy link

otopba commented Jan 17, 2017

Hi!
I'd love to be able to display emoji.
Because right now, it is not displayed correctly. I will be very thankful for it!

@afester
Copy link
Collaborator

afester commented Jan 17, 2017

You can use the custom segment support introduced with #356. See the RichTextEditor demo for an example how to show images inline.

@JordanMartinez
Copy link
Contributor

@otopba Could you clarify what you mean by "it is not displayed correctly?"

@otopba
Copy link
Author

otopba commented Jan 18, 2017

@afester ok, thx
@JordanMartinez
image

@afester
Copy link
Collaborator

afester commented Jan 18, 2017

How did you add the emojis? Can you share some code (like, the line where you actually add the emojis).
I suppose that you simply tried to add the emojis as UNICODE emojis - in that case, it looks like your font does not contain the necessary glyphs to render those "characters".

@otopba
Copy link
Author

otopba commented Jan 23, 2017

@afester It appears if you copy and paste them into the javaFX window. Yes, there are problems with the font and that's why I wrote this post =)

@JordanMartinez
Copy link
Contributor

@otopba So would this be a clipboard and style codecs issue? Copy and paste is implemented via ClipboardActions.

@otopba
Copy link
Author

otopba commented Jan 29, 2017

@JordanMartinez Emoji do not appear. Whether it's copying or reading from a file , it is simply not displayed.

@afester
Copy link
Collaborator

afester commented Jan 30, 2017

The font you are using does not have the required glyphs to render the UNICODE emojis.

I have verified this with the JavaKeywords demo. I added the following line to JavaKeywords.java to render a Euro character (U+20AC) and an emoji (U+1F600) (note that the UNICODE codepoints for emojis require a surrogate pair since they are encoded with more than 16 bit):

...
"/* T\u20acs\uD83D\uDE00t */",
"public class Foo extends Bar implements Baz {",
...

The result is what you also observed - the emoji is rendered as square:
image

Now, I applied the following modifications to apply a font which contains glyphs for the Unicode Emojis (see also http://stackoverflow.com/a/16866962/1611055):

  • I downloaded an appropriate font (https://github.com/MorbZ/OpenSansEmoji/blob/master/OpenSansEmoji.ttf) and put it in the org.fxmisc.richtext.demo package

  • In the demo's start method, I added code to load the font: Font.loadFont(JavaKeywords.class.getResource("OpenSansEmoji.ttf").toExternalForm(), 10);

  • In the java-keywords.css file, I added

    .paragraph-box {
    	-fx-font-family: "OpenSansEmoji";
    }
    

    so that the font is being applied to the paragraph box nodes.

Now, the text is rendered like this:

image

Note that all characters are now rendered with the OpenSansEmoji font - you might need to put the emojis into a separate segment and apply the font to this segment only, so that the rest of your document is rendered with your default font.

@afester afester changed the title Emoji suppot Emoji support Jan 30, 2017
@JordanMartinez
Copy link
Contributor

@afester Sorry. I thought that was the issue, but since @otopba mentioned copy and paste, I thought I should ask.

In that case, this isn't an issue with RichTextFX. We should still include a note about it in the Developer's guide.

@JordanMartinez
Copy link
Contributor

Ok, I've added an initial page for that.

@JordanMartinez
Copy link
Contributor

Closing this issue as @afester has demonstrated why the glyphs weren't appearing and has written how to add support for them in the wiki.

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