[OpenJDK 2D-Dev] Dashed line bug

Hiroshi Yamauchi yamauchi at google.com
Wed Feb 18 00:04:26 UTC 2009


Hi,

I think I found a bug in the dashed line rendering (i.e., an
incompatibility with Sun JDK) and a fix with a test.
The problem was the difference in the interpretation of the float
array which defines the pattern of dashed lines.
I confirmed that this bug exists in openjdk6 b11 and openjdk7 b47.

Thanks,
Hiroshi

---- fix ----
+++ jdk/src/share/classes/sun/java2d/pisces/Dasher.java	2009-02-17
15:05:18.000000000 -0800
@@ -120,7 +120,7 @@

         // Normalize so 0 <= phase < dash[0]
         int idx = 0;
-        dashOn = false;
+        dashOn = true;
         int d;
         while (phase >= (d = dash[idx])) {
             phase -= d;


---- test ----
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;

public class DashTest {
  public static void main(String[] argv) throws Exception {
    BufferedImage image =new BufferedImage(100, 100,
                                           BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setColor(Color.WHITE);
    graphics.fillRect(0, 0, 100, 100);
    graphics.setColor(Color.BLACK);
    graphics.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT,
                                       BasicStroke.JOIN_MITER,
                                       10f, new float[] {1f, 4f}, 0f));
    graphics.drawRect(10, 10, 80, 80);
    ImageIO.write(image, "PNG", new File(argv[0]));
  }
}



More information about the 2d-dev mailing list