-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
x86
-
windows_98
Name: gsC80088 Date: 02/15/99
When painting an AttributedString to a canvas the characters with superscript and subscript attributes are not displayed correctly. All superscript characters are displayed as normal text. Here is an example of the problem:
import java.awt.*;
import java.awt.font.*;
import java.awt.event.*;
import java.text.AttributedString;
import java.text.AttributedCharacterIterator;
public class styledText extends Canvas {
TextLayout tl;
public styledText() {
setBackground(Color.white);
}
public void paint(Graphics g) {
Graphics2D g2;
g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
Font f = new Font("Serif", Font.PLAIN, 24);
AttributedString ats = new AttributedString("E=mc2 is Einstein's Equation");
ats.addAttribute(TextAttribute.FONT, f);
//the following line should make the "2" superscript
ats.addAttribute(TextAttribute.SUPERSCRIPT ,TextAttribute.SUPERSCRIPT_SUPER, 4, 5);
ats.addAttribute(TextAttribute.UNDERLINE ,TextAttribute.UNDERLINE_ON, 9, 19);
AttributedCharacterIterator iter = ats.getIterator();
FontRenderContext frc = g2.getFontRenderContext();
tl = new TextLayout(iter, frc);
g2.setColor(Color.blue);
tl.draw(g2, (float)50, (float)50);
}
public static void main(String s[]) {
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
public void windowClosed(WindowEvent e) {System.exit(0);}
};
Frame f = new Frame("2D Text");
f.addWindowListener(l);
f.add("Center", new styledText());
f.pack();
f.setSize(new Dimension(400, 300));
f.show();
}
}
(Review ID: 53696)
======================================================================
- duplicates
-
JDK-4156394 TextAttribute.SUPERSCRIPT not super or sub scripting
- Resolved