-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.2.0
-
generic
-
generic
Name: js5519 Date: 02/09/99
TextLayout always uses the default base direction as specified
by the Unicode algorithm (the direction of the first character
that has a strong direction in the string). Setting the direction
explicitly by calling
AttributedString.addAttribute(TextAttribute.RUN_DIRECTION, TextAttribute.RUN_DIRECTION_RTL /*or RUN_DIRECTION_LTR*/)
has no effect. The default direction will always be used.
I tested this on Windows NT 4.0 Arabic Edition.
In the following test case you'll notice that setting the
direction to LTR or RTL has no effect
Listing of BIDITest.java:
=========================
import java.awt.*;
import java.awt.font.*;
import java.awt.event.*;
import java.applet.*;
import java.text.*;
public class BIDITest extends Applet
{
private CheckboxGroup cbg;
private Checkbox cbRTL;
private Checkbox cbLTR;
private String s = "Hello, Hello, \u0623\u0647\u0644\u0627 \u0648\u0633\u0647\u0644\u0627";
private boolean isRTL;
public BIDITest()
{
init();
}
public static void main(String[] args)
{
BIDITest bidiTest = new BIDITest();
Frame f = new Frame("BIDI Test");
f.add(bidiTest);
f.setSize(600, 400);
f.addWindowListener( new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
f.show();
}
public void init()
{
setLayout(new BorderLayout());
cbg = new CheckboxGroup();
cbRTL = new Checkbox("Right to Left", false, cbg);
cbLTR = new Checkbox("Left to Right", true, cbg);
cbRTL.addItemListener( new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
if(cbRTL.getState() == true)
isRTL = true;
repaint();
}
}
);
cbLTR.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
if(cbLTR.getState() == true)
isRTL = false;
repaint();
}
}
);
Panel p = new Panel();
p.setLayout(new FlowLayout(FlowLayout.CENTER));
p.add(cbLTR);
p.add(cbRTL);
p.setBackground(Color.gray);
add(p, BorderLayout.SOUTH);
}
public void paint(Graphics g)
{
AttributedString as = new AttributedString(s);
Boolean runDirection = isRTL ? TextAttribute.RUN_DIRECTION_RTL :
TextAttribute.RUN_DIRECTION_LTR;
as.addAttribute(TextAttribute.RUN_DIRECTION, runDirection);
as.addAttribute(TextAttribute.FONT, new Font("Lucida Sans Regular", Font.PLAIN, 20));
TextLayout tl = new TextLayout(as.getIterator(), ((Graphics2D)g).getFontRenderContext());
tl.draw((Graphics2D)g, 100, 100);
g.drawString("isRTL="+isRTL, 100, 150);
}
}
(Review ID: 53958)
======================================================================