Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2004

Tip: Looking for answers? Try searching our database.

Loading OpenType fonts

Thread view: 
Bjørn Børresen - 20 Apr 2004 13:01 GMT
I'm currently loading TrueType fonts from the server and using them
directly in my application with the Font.createFont(InputStream) method.
This method does only support TrueType fonts.

I need to switch to OpenType, so I was wondering if anyone know about
libraries that support loading OpenType sfnt tables or OpenType fonts
directly. Or if it is possible to do in Java.

Best regards,
Bjørn Børresen
Signature

free phpODP script: http://www.bie.no

Thomas Weidenfeller - 20 Apr 2004 14:21 GMT
> I'm currently loading TrueType fonts from the server and using them
> directly in my application with the Font.createFont(InputStream) method.
[quoted text clipped - 3 lines]
> libraries that support loading OpenType sfnt tables or OpenType fonts
> directly. Or if it is possible to do in Java.

OpenType is an extension of TrueType (with PostScript outlines). There
is a strange interface in the current J2SE:

    java.awt.font.OpenType

Strange, because it is apparently not used anywhere in the API. Maybe
you are lucky, and createFont() can indeed deal with OpenType fonts,
while claiming to handle TrueType only. Or your OpenType fonts include
TrueType outlines, only? Did you try it? Did you check if the returned
Font implements java.awt.font.OpenType?

If all this doesn't work out, I think Apache FOP contains an OpenType
reader of some sort.

/Thomas
Bjørn Børresen - 22 Apr 2004 13:31 GMT
> Strange, because it is apparently not used anywhere in the API. Maybe you
> are lucky, and createFont() can indeed deal with OpenType fonts, while
> claiming to handle TrueType only. Or your OpenType fonts include TrueType
> outlines, only? Did you try it? Did you check if the returned Font
> implements java.awt.font.OpenType?

Font.createFont(int fontFormat, InputStream is) contains this code:

     if ( fontFormat != Font.TRUETYPE_FONT ) {
        throw new IllegalArgumentException ( "font format not recognized" );
     }

Nonetheless I tried to just hand it an .otf file and specify that it was
truetype. I got this exception:

java.awt.FontFormatException: Unable to create font - bad font data
       at java.awt.Font.createFont(Font.java:625)
       at FontTest.getFont(FontTest.java:40)
       at FontTest.<init>(FontTest.java:14)
       at FontTest.main(FontTest.java:70)
Exception in thread "main" java.lang.NullPointerException
       at FontTest.<init>(FontTest.java:18)
       at FontTest.main(FontTest.java:70)

.. so no luck there :(

> If all this doesn't work out, I think Apache FOP contains an OpenType
> reader of some sort.

Hmm, I found a PFMReader and TTFReader there, but no OpenType reader ...

The closest thing I've found to what I need is
gnu.java.awt.Font.OpenTypeFactory; http://www.brawer.ch/software/fonts/

..but it didn't work on any of the fonts I've tested it on.

- Bjørn
Signature

Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.