Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Render Problem of AWT loaded TTF file on MacOS(AWT rendered font from TTF file sometimes renders bad glyphs)
Render Problem of AWT loaded TTF file on MacOS [message #648369] Wed, 12 January 2011 15:43 Go to next message
Thomas Fletcher is currently offline Thomas Fletcher
Messages: 6
Registered: July 2009
Junior Member
I'm writing an application that needs to display text with custom TTF fonts. Since until recently there was no SWT support for loading custom TTF we were using AWT to load the font and draw into an image and then transfer that to the display.

The code looks like:

java.awt.Font f =
java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, fis);
.. set attributes for font ..
java.awt.Font f2 = f.deriveFont(<new attributes>);
BufferedImage img = new BufferedImage(..)
java.awt.Graphics gc = img.getGraphics()
gc.setFont(f2);
gc.drawString(<mytext>)
gc.dispose();

This works great on Windows and Linux, but occasionally on Mac (carbon and cocoa) the text will render with a funny A character that looks like a missing glyph to me (with the same font/text combination as on Windows/Linux). Out of a 100 runs of the same app/font/text, this might happen 5 or so times.

Is there some sort of synchronization that I'm missing in using this AWT functionality from SWT on Mac? All of the work is being done in the SWT main thread.

Any insight is welcome, this is a stop ship issue for us on the Mac right now.

Thanks,
Thomas
http://www.cranksoftware.com
Re: Render Problem of AWT loaded TTF file on MacOS [message #648429 is a reply to message #648369] Wed, 12 January 2011 21:30 Go to previous messageGo to next message
Scott Kovatch is currently offline Scott Kovatch
Messages: 6
Registered: July 2009
Junior Member
Since you need to do AWT work, you should always try to perform it from an AWT context whenever possible. In general this is just a good practice, but on Mac OS X it's pretty much mandatory, as many AWT operations have unpredictable results when run from the main thread where the SWT operates.

The best way to do this depends on the context, but a good pattern to follow is to put the AWT code into a Runnable and run it with SwingUtilities.invokeLater(). Then, at the end of the Runnable, call Display.asyncExec to pass the data back to the SWT.

Hope that helps,
Scott K.

----------------
Scott Kovatch
Eclipse SWT Team
IBM
Pleasanton, CA
Re: Render Problem of AWT loaded TTF file on MacOS [message #648664 is a reply to message #648429] Thu, 13 January 2011 21:04 Go to previous message
Thomas Fletcher is currently offline Thomas Fletcher
Messages: 6
Registered: July 2009
Junior Member
OK so I've wrapped the code in a runnable, then I do the AWT work as:
if(EventQueue.isDispatchThread()) {
runnable.run();
} else {
EventQueue.invokeAndWait(runnable);
}

Then once that is finished I have an AWT BufferedImage that I need to convert to an SWT image. Since I can't be in both context's at once I have to sync with the SWT thread to finish the transform.

It seems to work.

Thanks,
Thomas
Previous Topic:How to Crop/Trim Image/ImageData
Next Topic:DragSourceListener.dragSetData() is never called
Goto Forum:
  


Current Time: Wed Sep 17 09:52:42 GMT 2014

Powered by FUDForum. Page generated in 0.07608 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software