Hi,

The first of two patches to address a long-standing bug with the text in vertical progress bars... this one lays out glyphs properly in the GlyphVector, and fixes spacing/alignment in the progress bar.

Cheers,
Francis

2007-04-12  Francis Kung  <[EMAIL PROTECTED]>

        PR 23887
        * gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
        (getGlyphLogicalBounds): Fix number of coordinates in transform call.
        (performDefaultLayout): Respect transformation in font attributes.
        * javax/swing/plaf/basic/BasicProgressBarUI.java
        (getStringPlacement): Handle vertical orientations.
        (paintString): Space vertical text properly.
Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.19
diff -u -r1.19 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	3 Apr 2007 19:32:45 -0000	1.19
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	12 Apr 2007 19:22:52 -0000
@@ -43,6 +43,8 @@
 import java.awt.font.GlyphJustificationInfo;
 import java.awt.font.GlyphMetrics;
 import java.awt.font.GlyphVector;
+import java.awt.font.TextAttribute;
+import java.awt.font.TransformAttribute;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.GeneralPath;
 import java.awt.geom.Point2D;
@@ -313,6 +315,24 @@
       }
     glyphPositions[nGlyphs * 2] = x;
     glyphPositions[nGlyphs * 2 + 1] = y;
+    
+    // Apply any transform that may be in the font's attributes
+    TransformAttribute ta;
+    ta = (TransformAttribute)font.getAttributes().get(TextAttribute.TRANSFORM);
+    if (ta != null)
+      {
+        AffineTransform tx = ta.getTransform();
+        
+        // Transform glyph positions
+        tx.transform(glyphPositions, 0, glyphPositions, 0,
+                     glyphPositions.length / 2);
+        
+        // Also store per-glyph scale/shear/rotate (but not translation) 
+        double[] matrix = new double[4];
+        tx.getMatrix(matrix);
+        AffineTransform deltaTx = new AffineTransform(matrix);
+        Arrays.fill(glyphTransforms, deltaTx);
+      }
   }
 
   /**
@@ -375,7 +395,7 @@
                                     p.getY() + r.getY() + r.getHeight()};
     
     if (glyphTransforms[glyphIndex] != null)
-      glyphTransforms[glyphIndex].transform(bounds, 0, bounds, 0, 4);
+      glyphTransforms[glyphIndex].transform(bounds, 0, bounds, 0, 2);
     
     return new Rectangle2D.Double(bounds[0], bounds[1], bounds[2] - bounds[0],
                                   bounds[3] - bounds[1]);
Index: javax/swing/plaf/basic/BasicProgressBarUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicProgressBarUI.java,v
retrieving revision 1.18
diff -u -r1.18 BasicProgressBarUI.java
--- javax/swing/plaf/basic/BasicProgressBarUI.java	13 Jun 2006 09:28:57 -0000	1.18
+++ javax/swing/plaf/basic/BasicProgressBarUI.java	12 Apr 2007 19:22:52 -0000
@@ -600,8 +600,13 @@
                                      int y, int width, int height)
   {
     Rectangle tr = new Rectangle();
-    Rectangle vr = new Rectangle(x, y, width, height);
+    Rectangle vr = new Rectangle();
     Rectangle ir = new Rectangle();
+    
+    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL)
+      vr.setBounds(x, y, width, height);
+    else
+      vr.setBounds(y, x, height, width);
 
     Font f = g.getFont();
     FontMetrics fm = g.getFontMetrics(f);
@@ -611,7 +616,11 @@
                                        SwingConstants.CENTER,
                                        SwingConstants.CENTER,
                                        SwingConstants.CENTER, vr, ir, tr, 0);
-    return new Point(tr.x, tr.y);
+    
+    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL)
+      return new Point(tr.x, tr.y);
+    else
+      return new Point(tr.y, tr.x);
   }
 
   /**
@@ -741,14 +750,19 @@
       {
         AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
         g.setFont(progressBar.getFont().deriveFont(rotate));
+        placement.x = width - placement.x - fm.getAscent();
+      }
+    else
+      {
+        placement.y += fm.getAscent();
       }
     
     g.setColor(getSelectionForeground());
     g.setClip(0, 0, full + b.left, height);
-    g.drawString(str, placement.x, placement.y + fm.getAscent());
+    g.drawString(str, placement.x, placement.y);
     g.setColor(getSelectionBackground());
     g.setClip(full + b.left, 0, width - full, height);
-    g.drawString(str, placement.x, placement.y + fm.getAscent());
+    g.drawString(str, placement.x, placement.y);
     g.setClip(savedClip);
     g.setColor(savedColor);
   }

Reply via email to