1

I need to load font (.otf or .ttf) file from java Resource or InputStream in SWT.

org.eclipse.swt.graphics.Device.loadFont(String path) allows me (example) to load font from font file path (and it works), but there is no corresponding method to load it from any other source.

I was thinking of using java.awt.Font.createFont(int fontFormat, InputStream fontStream) and then building org.eclipse.swt.graphics.FontData and org.eclipse.swt.graphics.Font objects out of AWT java.awt.Font object.

Since I haven't tried that option yet (I don't even know if it works that way) I was just wondering if there are any other options available?

Community
  • 1
  • 1
parxier
  • 3,811
  • 5
  • 42
  • 54

1 Answers1

3

Not great but you can always write the stream to a temporary file, and use the available method.

MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66
  • I haven't thought about such simple solution :-) If nobody else replies with better solution I'll accept this answer. Thanks. – parxier Apr 29 '10 at 04:33
  • This solution works great, thanks! To anyone with the same problem make sure not to delete temp font file until after application terminates. Otherwise you won't be able to use that font in your app. – parxier May 03 '10 at 23:56
  • To make life easier, you can use File.deleteOnExit() for this. – MeBigFatGuy May 08 '10 at 22:03