Q for Trembovetski: Font kerning information

Big and important question (to me!) to the Java2D team:

How the hell can I get font kerning (and glyph) information out of a Font? Currently the only way I can do this is by rendering every bloody character of the font next to every other character of the font and measuring the difference between their positions and the expected advance. This is fine for tiny fonts but just try doing it on a 72pt font with 4000 glyphs.

There must be a way to get this kind of font information directly from Java.

Cas :slight_smile:

It would seem you can’t, yet…
http://forum.java.sun.com/thread.jsp?thread=421610&forum=20&message=1922881

Err… sh*t.
Well, that’s that then :confused:

Cas :slight_smile:

I’m curious as why you wanted the information. I can’t think of an application which would require it .

That’s because you don’t write character generators for TV :wink:

Cas :slight_smile:

Do you ?

Mik

[quote]That’s because you don’t write character generators for TV :wink:
[/quote]
So you want to render for an especially low resolution display and find you need to adjust the kerning. I presume you tried setting the resolution in a FontRenderContext to an appropriate value.

All this has to do with is being able to layout fonts in some unusual ways that Java2D doesn’t do fast enough, so I have to do it manually with sprites in OpenGL. To position the sprites correctly though I need to know how pairs of characters kern together, otherwise some text just looks a bit funny.

Cas :slight_smile:

You’re not the one responsible for the evil Telewest EPG are you? :wink:

Kev

So, Princec, you’re OpenGL’ing to make java2D faster or what ?

Anyway, can you tell me more about your implementation ? Maybe we could team for some project, as I write character generators in java…

For your problem, take a look at the FontMetrics class. It’s not that easy anyway, but I manages something by using gliph visualbounds and logicalbounds.
The book “Java 2D API Graphics” by Vincent Hardy has been of great help for me. It’s simply the best java2d book around…

Cheers,

Mik

Sounds like you are making a fancy animated text generator for video titling that has some cool effects… fly a word on to the screen in 3D one letter at a time. That sort of thing?
You might want to try posting at javadesktop.org as well. There are guys from the Java2D team lurking there every so often.

Well, I’m not really a font person, but I’ve forwarded your question to those unfortunate ones who are…
Doug or Phil are people to ask these questions…

Thanks :slight_smile: Kerning information should be a pretty easy bit of info to add to the existing FontMetrics API:


float getKerning(char a, char b);

returns the kerning between two characters. It’s the only bit of usefuil information about fonts that isn’t available in the current API. You could most likely squeeze it into Tiger with little to no effort.

About the character generators - well, not just characters, but graphics and stuff too. It’s a “slate generator” we’ve got, and it replaces several Astons and Chyrons and of course it runs on standard PC hardware, using Java and LWJGL (with AWT this time). It’s a client/server app that uses RMI. The client GUI can be used to load up slates into a queue where you can stop, start, advance, etc. them like a tape jukebox, and double click to edit them. Not quite a WYSYWIG editor but they didn’t have the budget for that :wink:

If anyone receives bulletins from APTN you’ll be seeing my slates already on an older system installed last year. If you’re really lucky you’ll spot the Windows Update dialog box appearing over the top of it coz some fool forgot to turn it off!

Cas :slight_smile:

[quote]You could most likely squeeze it into Tiger with little to no effort.
[/quote]
I think the cutoff for that has long gone.

Arse! Might get it into 1.5.1 then I suppose.

Cas :slight_smile:

You don’t often here the words ‘dot release’ and ‘api change’ in the same sentence :-/ (well not when talking about Java atleast ^_^)

Princec, your suggestion about kerning is right and welcome.
We also need it for our character generators. Why don’t you post an RFE ?

Princec how can you manage the alpha channel with LWJGL ?

Cheers,

Mik

p.s.
What we’re doing ? Check it out at http://www.classx.it (can you read italian ?)

My RFEs are all voting for Structs unfortunately which I see to be the very biggest problem for games developers as it can’t be worked around (whereas I can get kerning information ahead-of-time if I’m prepared to wait. Or even write a native DLL to go rummaging around in font files - I don’t care at this stage if it’s Win32 only as my CG runs on Windows).

Hm, your character generators are a little cheaper than ours :slight_smile: Ours costs £30,000 and doesn’t look nearly as flashy :o Alpha channel in LWJGL is trivial. Unless you mean the key channel - in which case you’re looking at using a 1600x600 screen, Wildcat dualhead output, and two genlocked scan converters. Not exactly elegant but excellent quality and very cheap compared to the competition! (Our hardware in total costs only £6k)

Abuse - I think we can get new API into a dot release provided that none of the existing API changes behaviour, which in the case it doesn’t.

Cas :slight_smile:

Trust Trembovetski and me… New API never goes into a dot release (well, it might depend on how much influence you wield with Scott…)

Um, I have to admit that the Sun JVM’s don’t do kerning at all… I expect Apple’s does, though I haven’t examined their implementation closely.

What are you trying to do with text that the existing text APIs don’t do or are too slow at? Text on a path? Tightening or loosening the text? Justification?

Text APIs have to be general enough to support Unicode, then optimized underneath for ASCII or Latin-1. So for example the API would have to support surrogates. There’s really no API for getting the pure font table information-- not itself so straightforward if you have to support both Type1 and TrueType/OpenType. You can’t even get the font file (if there is one) there are some security issues that would have to be dealt with. The approach so far has been to just provide higher-level API, and let the real intense folks just pull apart the font data themselves if they have access to it, and have at it.

Sorry for summoning such an old thread :stuck_out_tongue:

Well, Cas… how did you get that kerning information then? (I know you did ;D)

I don’t really need it right now, because my current game will only have about 30-40 words… but it’s good to know how to do that kind of stuff if I ever really need it :slight_smile: