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

Colored emoji support #1109

Open
hainautjb opened this issue Mar 21, 2024 · 2 comments
Open

Colored emoji support #1109

hainautjb opened this issue Mar 21, 2024 · 2 comments

Comments

@hainautjb
Copy link

Is your feature request related to a problem? Please describe.
We use openpdf through flying saucer and we would like to be able to render UTF-8 colored emoji. Until now we are juste able to render them in black and white (or the unique color chosen for the font).

We tried with :

  • Roboto One Color -> nothing is rendered
  • Roboto One B&W -> rendered in b&w (normal)
  • Emoji One Color -> rendered in b&w

I assume that currently openpdf don't take into account the color info in the emoji font. Is it right or am I just doing something wrong ?

Here is the code used to create the pdf from the html

final var processedHtml = templateProcessor.process(templateName, parameters);
try (var os = new ByteArrayOutputStream()) {
    final var renderer = new ITextRenderer();
    renderer.setDocumentFromString(addTagWhenDetectingEmoji(processedHtml.replaceAll(xml10pattern, "")));
    renderer.getFontResolver().addFont("templates/fonts/Roboto-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    renderer.getFontResolver().addFont("templates/fonts/EmojiOneColor.otf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    renderer.layout();
    renderer.createPDF(os, true);
    renderer.finishPDF();
    return os.toByteArray();
} catch (IOException e) {
    throw new PDFGenerationException("Cannot open FileOutputStream", e);
}

A simplified html given as input

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <title>Bulletins</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>

<body>
    <table class="w100">
    	<tr>
    		<td class="smallerBottomTableBorder"><h2>Avis du conseil de classe</h2></td>
        </tr>
        <tr>
        	<td class="text-justify line-return"><span >salut <span style="font-family: 'EmojiOne', sans-serif;">😃</span></span></td>
        </tr>
    </table>
</body>
</html>

Describe the solution you'd like
Adding the ability to render UTF-8 colored emoji in openpdf

Describe alternatives you've considered
Keeping the emoji in black and white

Additional context
/

@asturio
Copy link
Member

asturio commented Mar 27, 2024

I think you are correct. As in the code the declared color is used for the whole font, and not for individual characters/emojis.

This would be a nice feature, to support Fonts with different colors for different characters. As I understand each "character" in the font is a simple image (like an SVG?).

@asturio
Copy link
Member

asturio commented Apr 14, 2024

I searched a little for open/free fonts, and many of them come with the SVGs used to create them. Maybe using these SVG instead of the font could be a workaround.

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