Java implementation of FreeType

(this is not really JOGL related, but i think this forum fits best)

afaik, the most popular way to rasterize fonts for games, is the fine library FreeType
http://www.freetype.org/index2.html

now for my java game, i would be very happy, if i could use this library too.

so, is there already a java port for FreeType, or if not, would you recommend accessing it using JNI, or porting it myself?

Why would you choose freetype over the font apis provided by AWT?

You might if you were using LWJGL.

Cas :slight_smile:

But then he chose the wrong forum :wink:
On a more serious note, does freetype have any advantages over java.awt.Font? Better quality, speed, … ?

thanks!
ok, i was not really aware about awt Font. can it do stuff like kerning, bold, italics, etc… ?

what about LWJGL? does it have a font library too?

Java AWT font rendering is one of the best implementations around. Freetype, in my experience, was much, much inferior. I couldn’t comment on the speed though as I didn’t test that.

LWJGL doesn’t have a font library, it’s just OpenGL+AL+Input plus a few odds and sods. I use AWT font rendering ahead-of-time during development and pack my fonts into textures.

Cas :slight_smile:

I seem to remember you had difficulties extracting kerning information from java.awt.Font though, how did that work out for you?

AFAIK, there’s no way to extract kerning information from AWT fonts. You may want to try Apache FOP, it does its own TTF parsing and gives access to kerning information. I wouldn’t recommend it though, too much hassle for minimal gains and besides, font rendering without kerning adjustments is good enough for games.

You may also want to download my zShapes, there’s a lot of useful code in the gr.zdimensions.zshapes.editor.font package for getting glyphs out of AWT fonts.

Brute force kerning! I draw every glyph next to every other glyph and look at the distance between them. Currently that’s the only way to do it in Java - a bit crap!

Cas :slight_smile:

As per my experience with text, kerning (we’re not talking about “advance” i.e. standard character spacing but rather special inter-spacing, like between the couple WA) is not that vital for good-looking rendering, compared to many other parameters (correct advance, antialiasing, etc…)

In addition, not every font is offering kerning-pairs (e.g. Georgia is a great example of font that don’t have any kerning…)

Anyway, for the purists: I think that the latest version of java (6?) is handling kerning (to be double-checked…)

Just out of interest, how many character pairs have interesting kerning values in a given font? is it unmanageably large, like the O(n2) corner-cases in my mind, or do you simply limit the character set and be damned with those pesky non-ASCII foreign types?

Does it expose kerning information to the programmer? As I understand it, java will already render text with the proper kerning values, there’s just no way to access them outside of rendering and measuring glyphs. This, as artfully described by princec, is a bit crap. Will this change in java 6?

[quote=“bleb,post:11,topic:28642”]
IIRC from the tests I’ve done with FOP, the (few) fonts with kerning information contain up to a few hundred pairs. Of course there’s no way to know beforehand which pairs they are, which sucks if you’ve got an AWT font with thousands of glyphs.

[quote=“bleb,post:11,topic:28642”]
No, you still can’t get to the kerning information. Most of the low-level font data is buried deeply in native code.

As I understand it, until version 6: java was rendering text without taking count kerning, so there was no way to “guess” something that is just not there.

With the latest version, if text is rendered with kerning, and even if there are no official methods to obtain the precious info, it’s then possible to guess things out (i.e. drawing a glyph vector with a pair and use the good-old measuring features, etc…)

Kerning has always been implemented in Java font rendering. Shame they can’t figure out how to actually let us have the information. Bloody encapsulation. OOP’s biggest Achilles’ heel. Grr.

Cas :slight_smile:

Good to know … but, does somebody actually have an example of how to use awt Font with JOGL?

Thanks

yes, has anyone of you guys every written a small class that renders each character to a texture and binds that on a quad?

I’ve only implemented the bitmap font technique described in the red book. It’s pretty straightforward using BufferedImage and Font. Make an image of type BufferedImage.TYPE_BYTE_BINARY, render the character you want to it and read back the contents of the data buffer. That data can then be used as input for glBitmap. This gives you crisp, non-scaling text.

Text2D class in Xith3D.

Enjoy… http://www.xith.org/

http://www.chronotext.org
using jogl since 2005 to make many thousands of letters flying around in real-time 8)

thanks guys, but i dont find the text2D class in the xith package. in which subpackage is it?

as for chronotext, this is very nice, but also i did not find no source code anywhere.

ariel, just out of curiousity, what is the size of the texture for one character?