Submitted On 24-SEP-1999
dberansky
Looks like this got fixed in 1.3. I'm clearing my vote
Submitted On 13-DEC-1999
mitchg
Looks like <dberansky> is using a version of 1.3 that no one else in the
whole world is using. The problem is that the workaround is awful (using
transformations) because the AttributeString code is a shambles, and there is
no way to provide scaling transformations that super/subscript correctly when
fonts change.
Submitted On 20-JAN-2000
robertpoling
I agree with mitchg - Superscripts and
subscripts now work, but you can not copy and
paste the formatting. The drawing seems bugging. This implementation seems
buggy.
Submitted On 13-SEP-2002
jkwhitfield
Still not working in 1.4.0
Submitted On 14-MAR-2003
gregory_ewing
still not working in 1.4.1
Submitted On 07-JUL-2003
E.Kopp
This bug's got my vote. Yuck.
Submitted On 10-JUL-2003
E.Kopp
Does anybody know how to make superscripting work with
transforms? I've tried using the TextAttributes.TRANSFORM
modifier on my text with absolutely no success. Possibly the
SUPERSCRIPT attribute isn't working because it relies on a
defective TRANSFORM mechanism?
Submitted On 23-SEP-2003
hattons
If this is the kind of thing that is supposed to be working,
it's not. If it is accepted that this will not work, the
API should reflect this. As it stands, the J2SDK violates
the law of least astonishment by not providing the
functionality indicated.
String s = "attributed";
AttributedString as = new AttributedString(s);
as.addAttribute(TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUB, 0, 3);
as.addAttribute(TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUPER, 5,
s.length());
AttributedCharacterIterator aci = as.getIterator();
//Graphics2D g2
g2.drawString(aci, this.location.x, this.location.y +
this.size.height);Í
IMO, this is a bug, and it has not been fixed.
Submitted On 15-NOV-2004
rpdmiranda
It did not work when setting an explicit Font object, at least not with Verdana, in Windows Platform, J2SDK 1.5.0 final.
Submitted On 05-APR-2005
devy
Has anyone been able to make this work with TextLayout? I'm using an AttributedString with LineBreakMeasurer but
addAttribute(TextAttribute.SUPERSCRIPT,TextAttribute.SUPERSCRIPT_SUB);
seems to have no effect.
Submitted On 05-APR-2005
devy
Forgot to mention....I'm using J2SDK 1.5.0_02.
Submitted On 06-APR-2005
dougfelt
This works for me using jdk 1.5 on solaris. - doug
import java.awt.*;
import java.awt.font.*;
import java.text.*;
import javax.swing.*;
public class CheckSSAttr extends JPanel {
AttributedString as;
public static void main(String[] args) {
JFrame jf = new JFrame(CheckSSAttr.class.getName());
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setLayout(new GridLayout(1,0));
jf.add(new CheckSSAttr());
jf.setSize(300, 300);
jf.setVisible(true);
}
CheckSSAttr() {
String s = "attributed string of a length long enough to wrap a few times.";
as = new AttributedString(s);
as.addAttribute(TextAttribute.SIZE,
new Float(24));
as.addAttribute(TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUB, 0, 3);
as.addAttribute(TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUPER, 5, 8);
as.addAttribute(TextAttribute.SUPERSCRIPT,
TextAttribute.SUPERSCRIPT_SUB,
s.length()-5, s.length()-2);
}
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
AttributedCharacterIterator aci = as.getIterator();
g2d.drawString(aci, 10, 100);
FontRenderContext frc = g2d.getFontRenderContext();
LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
final float width = 200;
float y = 150;
for (TextLayout tl = lbm.nextLayout(width); tl != null; tl = lbm.nextLayout(width)) {
y += tl.getAscent();
tl.draw(g2d, 10, y);
g2d.drawLine(0, (int)y, 200, (int)y);
y += tl.getDescent() + tl.getLeading();
}
}
}
Submitted On 03-DEC-2005
jpriddey
Still not working if you set an explicit font. The Solaris code submitted works, but on Windows produces superscripts on the line above and subscripts on the line below -- too much offset, and doesn't work at all if you change the addAttribute(SIZE to an addAttribute(FONT ...) this is still completely broken.
Submitted On 07-DEC-2005
dougfelt
If you set an explicit font, the 'superscript state' in the font overrides the one set in the attributes. The FONT attribute is intended as a fast path through the attribute-based APIs so it takes priority. If you create the font with a superscript it should work.
The size/offset of the superscript is due to it being synthetic rather than using different glyphs in the font. The nominal ascent/descent of the layout with the superscript should be taking this into account. It's just not guaranteed to lie within the original ascent/descent. For that matter, it's not necessarily the case that any glyph lies fully within the ascent/descent. If you want lines to not overlap you need to space them based on the line's (TextLayout's) bounds (or pixel bounds), not the ascent and descent.
I believe swing uses the ascent/descent but I haven't checked lately.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|