Skip to main content

Handling of sub/superscripts

2 replies [Last post]
Anonymous

How are sub- and super-scripts handled by TextMeasurer and TextLayout?
My requirement is to use Java2D to perform layout, then to render in,
for example, PDF.

The first question would be: is sub/super handling performed. Does
Java2D rely on the font to handle sub and super?

The API docs (1.5) for TextLayout.getAscent() mention
"The ascent is the distance from the top (right) of the TextLayout to
the baseline. It is always either positive or zero. The ascent is
sufficient to accommodate super-scripted text and is the maximum of the
sum of the ascent, offset, and baseline of each glyph."

Note that ascent includes "offset", which is presumably non-zero for a
super-scripted character. However, there seems to be no way to access
this information. If I am not to render using Java2, I need to be able
to extract such information in order to correctly place a superscript,
given the reported ascent of the TextLayout. Any ideas?

Peter

===========================================================================
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".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Peter B. West

On Fri, 2006-10-06 at 08:51 +0100, Peter B. West wrote:
> How are sub- and super-scripts handled by TextMeasurer and TextLayout?
> My requirement is to use Java2D to perform layout, then to render in,
> for example, PDF.
>
> The first question would be: is sub/super handling performed. Does
> Java2D rely on the font to handle sub and super?
>
First answer - RTFM.

Description
Requests that the font display the characters with glyphs at a
particular superscript level: 0 = none, 1 = superscript, 2 = superscript
of superscript,...-1 = subscript, -2 = subscript of subscript,...
Requests that the font display text using default superscript (or
subscript) glyphs and/or scaling.

Fallback
Use transform with translation of +/-1/2 and scale of 2/3, progressively
for each level. That is, for the transform at level N (with N != 0):
offset = sign(N)*1/2*(2/3)^(abs(N)-1)
scale = (2/3)^abs(N)

This creates a problem of predictability. If I cannot find out what the
layout process actually did, I cannot reproduce it in another rendering
context. Hmmm.

Peter

===========================================================================
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".

Peter B. West

On Fri, 2006-10-06 at 10:25 +0100, Peter B. West wrote:
> On Fri, 2006-10-06 at 08:51 +0100, Peter B. West wrote:
> > How are sub- and super-scripts handled by TextMeasurer and TextLayout?
> > My requirement is to use Java2D to perform layout, then to render in,
> > for example, PDF.
> >
> > The first question would be: is sub/super handling performed. Does
> > Java2D rely on the font to handle sub and super?
> >
> First answer - RTFM.
>
> Description
> Requests that the font display the characters with glyphs at a
> particular superscript level: 0 = none, 1 = superscript, 2 = superscript
> of superscript,...-1 = subscript, -2 = subscript of subscript,...
> Requests that the font display text using default superscript (or
> subscript) glyphs and/or scaling.
>
> Fallback
> Use transform with translation of +/-1/2 and scale of 2/3, progressively
> for each level. That is, for the transform at level N (with N != 0):
> offset = sign(N)*1/2*(2/3)^(abs(N)-1)
> scale = (2/3)^abs(N)
>

>
> This creates a problem of predictability. If I cannot find out what the
> layout process actually did, I cannot reproduce it in another rendering
> context. Hmmm.
>
> Peter

Maybe the reason I didn't spot the above description details is that
they have been removed in the Java6 API docs. So it looks as though the
question stands with respect to Java6. In any case, some guidance here
would be very useful.

The approach I am investigating at the moment is to define my own
SUPERSCRIPT attribute, so that super/sub processing is not performed. I
can then layout the shifted text against its normal baseline, and make
my own calculation as to the impact of the shifted text on the vertical
metrics of the line.

My aim is to rely on Java2D for layout to the greatest extent possible,
but it looks as though this may be one of the situations in which I have
to roll my own.

Peter

===========================================================================
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".