Skip to main content

How do I turn on kerning?

14 replies [Last post]
qu0ll
Offline
Joined: 2006-12-09
Points: 0

I am trying to use kerning when displaying text using the following code:

<br />
Map textAttributes = new HashMap();<br />
textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);<br />
textAttributes.put(TextAttribute.FONT, font);<br />
g2d.setFont(Font.getFont(textAttributes));<br />
g2d.drawString(text, 100, 150);<br />

but no matter what I use for font or text the output is identical with kerning turned on or off. The font attribute is being picked up but not the kerning attribute.

Why is this? What's the correct way to turn on kerning? I am using JSE 6 on Vista x64.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
qu0ll
Offline
Joined: 2006-12-09
Points: 0

Phil, thank you for looking into this.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Phil Race

Its been a couple of weeks but yesterday finally looked into this.
The problem is indeed specific to the version of the font on Vista
and so affects 32 and 64 bit.

When Microsoft added support for Arabic (etc) to the Times New Roman
font (and others) they added an OpenType 'GPOS' table which is
*supposed* to be the way to do kerning in an OpenType font.
However they did not in fact add kerning information to the table.

On a separate list I received email from Adobe that they also
found the same problem with the Vista fonts.

So really this appears to be a bug in the Vista fonts which
we'll have to see if we can workaround, but really the JDK
is doing just what the font tells it to do.

Anyway I filed bug 6663396 to track it and decide what to do.
It should show up in a day or so on bugs.sun.com

-phil.

java2d@JAVADESKTOP.ORG wrote:
> Hi Phil,
>
> The Vista machine is 64-bit and the XP machine is 32-bit so perhaps that has something to do with it.
>
> Anyway, I have emailed you screen shots of the problem so you can see it.
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Dmitri Trembovetski

And my previous statement that it works on Vista 32-bit
was incorrect..

Thanks,
Dmitri

Phil Race wrote:
> Its been a couple of weeks but yesterday finally looked into this.
> The problem is indeed specific to the version of the font on Vista
> and so affects 32 and 64 bit.
>
> When Microsoft added support for Arabic (etc) to the Times New Roman
> font (and others) they added an OpenType 'GPOS' table which is
> *supposed* to be the way to do kerning in an OpenType font.
> However they did not in fact add kerning information to the table.
>
> On a separate list I received email from Adobe that they also
> found the same problem with the Vista fonts.
>
> So really this appears to be a bug in the Vista fonts which
> we'll have to see if we can workaround, but really the JDK
> is doing just what the font tells it to do.
>
> Anyway I filed bug 6663396 to track it and decide what to do.
> It should show up in a day or so on bugs.sun.com
>
> -phil.
>
> java2d@JAVADESKTOP.ORG wrote:
>> Hi Phil,
>>
>> The Vista machine is 64-bit and the XP machine is 32-bit so perhaps
>> that has something to do with it.
>>
>> Anyway, I have emailed you screen shots of the problem so you can see it.
>>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Phil Race

I didn't get much time today. So I didn't try Vista myself, except that
I dumped
Times New Roman and the Vista and XP versions of the 'kern' table appear
identical,
even though the font itself is about double the size on Vista vs XP.

So perhaps ..
>no kerning on Vista x64

there's a bug in the native code that affects 64 bit ?? Was your XP case
32 or 64 bit?

-phil.

Phil Race wrote:
> Dmitri's pointers are valid.
>
> Vista shouldn't make a difference to 2D since the code isn't OS
> specific and isn't making any OS provided
> calls. Perhaps the fonts just aren't the same. I do believe that Times
> New Roman etc were expanded for Vista.
> Still, that is surprising. Don't have Vista handy right now to look
> how the tables are different. Its possible
> that it now uses more than one subtable, and when we did this work I
> don't think we found kern tables
> like that to test against. But that was pre-vista. I'd need to see a
> test case.
>
> -phil.
>
> java2d@JAVADESKTOP.ORG wrote:
>> That didn't help but I have noticed that the examples on this page:
>>
>>
>>> ttp://java.sun.com/docs/books/tutorial/2d/text/textattributes.html
>>>
>>
>> show no effect with kerning on or off on my Vista machine but do show
>> a difference on XP.
>>
>> Could this be a bug under Vista?
>>
>>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

qu0ll
Offline
Joined: 2006-12-09
Points: 0

Hi Phil,

The Vista machine is 64-bit and the XP machine is 32-bit so perhaps that has something to do with it.

Anyway, I have emailed you screen shots of the problem so you can see it.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Dmitri Trembovetski

I have tried on my 32-bit Vista (with 6u10 b08) and it worked
fine..

Thanks,
Dmitri

java2d@JAVADESKTOP.ORG wrote:
> Hi Phil,
>
> The Vista machine is 64-bit and the XP machine is 32-bit so perhaps that has something to do with it.
>
> Anyway, I have emailed you screen shots of the problem so you can see it.
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

frank_costanza
Offline
Joined: 2007-07-24
Points: 0

qu0ll

I see the same problem on Linux (Ubuntu Gutsy 32-bit) -

Java(TM) SE Runtime Environment (build 1.6.0_03-b05)

The kerning applet example on the Java 2D tutorial shows no difference between kerning and no kerning.

Phil Race

But you aren't using the same font as the previous reporter.
"Serif" on Linux uses Lucida Bright, which has no 'kern' table,
so that is expected.

-phil.

java2d@JAVADESKTOP.ORG wrote:
> qu0ll
>
> I see the same problem on Linux (Ubuntu Gutsy 32-bit) -
>
> Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
>
> The kerning applet example on the Java 2D tutorial shows no difference between kerning and no kerning.
> [Message sent by forum member 'frank_costanza' (frank_costanza)]
>
> http://forums.java.net/jive/thread.jspa?messageID=256393
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

qu0ll
Offline
Joined: 2006-12-09
Points: 0

I see that the font attribute overrides other attributes so I have now tried this:

[code]
Map textAttributes = new HashMap();
textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
textAttributes.put(TextAttribute.FAMILY, "Serif");
textAttributes.put(TextAttribute.SIZE, 13);
g2d.setFont(Font.getFont(textAttributes));
g2d.drawString(text, 100, 150);
[/code]

but the results are identical no matter what family I use.

How do I turn on kerning?

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Dmitri Trembovetski

Take a look at this preso if you haven't already:
http://gceclub.sun.com.cn/java_one_online/2005/TS-3214/ts-3214.pdf
Slides 42-43.

And, of course:
http://java.sun.com/docs/books/tutorial/2d/text/textattributes.html

Dmitri

java2d@JAVADESKTOP.ORG wrote:
> I see that the font attribute overrides other attributes so I have now tried this:
>
> [code]
> Map textAttributes = new HashMap();
> textAttributes.put(TextAttribute.KERNING, TextAttribute.KERNING_ON);
> textAttributes.put(TextAttribute.FAMILY, "Serif");
> textAttributes.put(TextAttribute.SIZE, 13);
> g2d.setFont(Font.getFont(textAttributes));
> g2d.drawString(text, 100, 150);
> [/code]
>
> but the results are identical no matter what family I use.
>
> How do I turn on kerning?
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

qu0ll
Offline
Joined: 2006-12-09
Points: 0

That didn't help but I have noticed that the examples on this page:

> ttp://java.sun.com/docs/books/tutorial/2d/text/textattributes.html

show no effect with kerning on or off on my Vista machine but do show a difference on XP.

Could this be a bug under Vista?

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Phil Race

Dmitri's pointers are valid.

Vista shouldn't make a difference to 2D since the code isn't OS specific
and isn't making any OS provided
calls. Perhaps the fonts just aren't the same. I do believe that Times
New Roman etc were expanded for Vista.
Still, that is surprising. Don't have Vista handy right now to look how
the tables are different. Its possible
that it now uses more than one subtable, and when we did this work I
don't think we found kern tables
like that to test against. But that was pre-vista. I'd need to see a
test case.

-phil.

java2d@JAVADESKTOP.ORG wrote:
> That didn't help but I have noticed that the examples on this page:
>
>
>> ttp://java.sun.com/docs/books/tutorial/2d/text/textattributes.html
>>
>
> show no effect with kerning on or off on my Vista machine but do show a difference on XP.
>
> Could this be a bug under Vista?
>
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

qu0ll
Offline
Joined: 2006-12-09
Points: 0

I didn't mean to come across as ungrateful and I tried to say that Dmitri's suggestion/fix worked but only on my XP machine. Sorry for any misunderstanding :-)

Well it's pretty easy to get a test case as the example given in the tutorial doesn't apply kerning visually on my Vista machine so perhaps you can try that yourself. And this is supported by my own code where I have run the exact same app on both Vista and XP with different results. So something must be happening on the Vista front.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

qu0ll
Offline
Joined: 2006-12-09
Points: 0

I have done a bit more testing by adding setting of ligature attributes and the results are the same: no kerning on Vista x64 but kerning working on XP.

Actually, I am using JSE 6 Update 10 (b11) so perhaps it has something to do with that? I'll post in the appropriate forum for that release too.

--
And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)