Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4165930

TextAttribute.TRANSFORM is not working

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs
    • 2d
    • x86, sparc
    • solaris_2.5.1, solaris_2.6, windows_95

      TextLayout text is not appearing transformed when the TextLayout is created from an AttributedCharacterIterator of an AttributedString that contains a TextAttribute.TRANSFORM.

      java full version "JDK-1.2fcs-E"


      import java.awt.*;
      import java.awt.font.*;
      import java.awt.geom.AffineTransform;
      import java.text.*;

      public class test5 extends Canvas {

          public test5() {
              setBackground(Color.white);
          }

          public void paint(Graphics g) {
              int w = getSize().width;
              int h = getSize().height;

              Graphics2D g2 = (Graphics2D) g;
              FontRenderContext frc = g2.getFontRenderContext();

              Font f = new Font("serif", Font.PLAIN, w/8);
              String s = "AttributedString";
              AttributedString as = new AttributedString(s);
              as.addAttribute(TextAttribute.FONT, f, 0, s.length() );
              AffineTransform fontAT = new AffineTransform();
              fontAT.shear(+0.3, 0.0);
              fontAT.rotate(Math.toRadians(10));
              fontAT.scale(1.0, 1.5);
              as.addAttribute(TextAttribute.TRANSFORM, fontAT, 0, s.length());
              AttributedCharacterIterator aci = as.getIterator();
              TextLayout tl = new TextLayout ( aci, frc );
              float sw = (float) tl.getBounds().getWidth();
              float sh = (float) tl.getBounds().getHeight();
              g2.setColor(Color.green);
              tl.draw(g2, w/2-sw/2, h*0.5f+sh/2);
          }

          public static void main(String s[]) {
              Frame f = new Frame("test5");
              f.add("Center", new test5());
              f.pack();
              f.setSize(new Dimension(400,400));
              f.show();
          }
      }


      gstone@eng 1998-11-18

      Looks like drawString has the same problem. This code sample shows how the text is fine when there are no attributes besides the transform associated with the attributedString. As soon as an attribute, in this case a Font attribute, is added the rotation doesn't happen. I haven't tried this with other attributes, but I'm not sure John's evaluation is 100% accurate, since he seems to imply the rotation isn't being applied at all. Whereas this test shows that it is, but that the transform is somehow getting lost in the pipeline when other attrs are involved. Anyway, here's another test case to run against any fixes:

      import java.awt.*;
      import java.awt.geom.*;
      import java.text.*;
      import java.awt.font.*;

      public class xformAttr extends Frame {

      public static void main( String[] args ) {
      Frame f = new xformAttr();
      f.setSize(new Dimension(200, 200));
      f.show();
      }

      public void paint( Graphics gr ) {
      AffineTransform af = AffineTransform.getRotateInstance(Math.toRadians(15));
      AttributedString aText = new AttributedString( "RotateMe!" );
      Graphics2D graphics = (Graphics2D)gr;

      gr.setColor(Color.yellow);
      Font defFont = new Font("serif", Font.PLAIN, 24);
      // Commenting out the next line shows the rotate, but with it no rotation occurs.
      aText.addAttribute(TextAttribute.FONT, defFont, 0, 9);
      aText.addAttribute( TextAttribute.TRANSFORM, new TransformAttribute(af), 0, 9);
      graphics.drawString( aText.getIterator(), getSize().width/4, getSize().height/2 );
      graphics.dispose();
      }
      }

            dougfelt Doug Felt (Inactive)
            blichtensunw Brian Lichtenwalter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: