Community
Participate
Working Groups
In order to easily reuse icons provided by unicode fonts as emojis, it would be interesting to get a SWT util class/methods to easily retrieve an image from a given character/font/size/color.
(In reply to Mickael Istria from comment #0) > In order to easily reuse icons provided by unicode fonts as emojis, it would > be interesting to get a SWT util class/methods to easily retrieve an image > from a given character/font/size/color. Do you mean given some characters, retrieve the appropriate image from the OS?
(In reply to Leo Ufimtsev from comment #1) > (In reply to Mickael Istria from comment #0) > > In order to easily reuse icons provided by unicode fonts as emojis, it would > > be interesting to get a SWT util class/methods to easily retrieve an image > > from a given character/font/size/color. > > Do you mean given some characters, retrieve the appropriate image from the > OS? Yes. Something like http://stackoverflow.com/questions/11653212/font-to-image-in-swt
I managed to write some code doing this, would be great to have it in SWT TextLayout textLayout = new TextLayout(font.getDevice()); textLayout.setText(emojiString); textLayout.setFont(font); Rectangle bounds = textLayout.getBounds(); PaletteData palette = new PaletteData(0xFF, 0xFF00, 0xFF0000); ImageData imageData = new ImageData(bounds.width, bounds.height, 32, palette); imageData.transparentPixel = palette.getPixel(font.getDevice().getSystemColor(SWT.COLOR_TRANSPARENT).getRGB()); for (int column = 0; column < imageData.width; column++) { for (int line = 0; line < imageData.height; line++) { imageData.setPixel(column, line, imageData.transparentPixel); } } Image image = new Image(font.getDevice(), imageData); GC gc = new GC(image); textLayout.draw(gc, 0, 0); return image;
This doesn't make a lot of sense: if one wants to use an emoji here and there, one can simply include it in a string as part of a Label or wherever. Emojis don't need to be turned into image by adopters, they can be used as plain text, that's where the magic it.
Note for example that it's entirely possible to place an icon emoji in a menu just by adding the emoji to the label: "\u2764\uFE0F Preferences" for instance would show a red heart icon without need for more transformation.