Bug 508299 - A utility to create an image for an emoji
Summary: A utility to create an image for an emoji
Status: CLOSED INVALID
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-28 09:48 EST by Mickael Istria CLA
Modified: 2020-11-12 08:51 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mickael Istria CLA 2016-11-28 09:48:08 EST
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.
Comment 1 Leo Ufimtsev CLA 2016-11-28 13:21:09 EST
(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?
Comment 2 Mickael Istria CLA 2016-11-28 13:22:34 EST
(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
Comment 3 Mickael Istria CLA 2016-11-29 03:33:24 EST
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;
Comment 4 Mickael Istria CLA 2017-12-12 05:15:55 EST
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.
Comment 5 Mickael Istria CLA 2017-12-12 05:17:00 EST
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.