Je suis en train d'afficher des emoji dans les objets swing (JLabel, etc.) ainsi afin de faire, je suis tellement en utilisant this library et la classe suivante pour que emojis affichage juste enGraphics2D drawString ne fonctionne pas avec les polices de couleur
jLabel.setIcon(new EmojiIcon(":poop:"));
fonctionne avec toutes les polices qui ont le soutien de emoji, sauf pour ceux qui sont colorés (c.-à-EmojiOne et Noto Color Emoji)
Quel est le point d'un emoji monochrome?
public class EmojiIcon implements Icon {
private Font font;
private final static int DEFAULT_SIZE = 32;
private int width = DEFAULT_SIZE;
private int height = DEFAULT_SIZE;
private String emoji;
public EmojiIcon (String iconString){
this.emoji = EmojiParser.parseToUnicode(iconString);
setFont("emojione-android");
recalculateIconWidth(emoji);
}
public void setFont(String strFont){
try {
font = Font.createFont(Font.TRUETYPE_FONT, new File("fonts/"+strFont+".ttf")).deriveFont(48f);
} catch (FontFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void recalculateIconWidth(String iconString){
FontRenderContext frc = new FontRenderContext(null, true, true);
Rectangle2D bounds = font.getStringBounds(iconString, frc);
width = (int) bounds.getWidth();
height = (int) bounds.getHeight();
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y){
Graphics2D g2d = (Graphics2D) g;
g2d.setFont(font);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.drawString(emoji, 0, height);
}
}
Je cherchais wether en ligne est-il même légal pour une police d'avoir une couleur si j'ai découvert here qu'il ne soit pas fixées de manière homogène (au moins avec les polices .ttf). Y at-il une solution de contournement pour cela? Je voudrais vraiment utiliser EmojiOne font