42 BufferedImage bi = |
42 BufferedImage bi = |
43 new BufferedImage(wid, hgt, BufferedImage.TYPE_INT_RGB); |
43 new BufferedImage(wid, hgt, BufferedImage.TYPE_INT_RGB); |
44 |
44 |
45 Graphics2D g2d = bi.createGraphics(); |
45 Graphics2D g2d = bi.createGraphics(); |
46 |
46 |
47 g2d.setColor(Color.white); |
|
48 g2d.fillRect(0, 0, wid, hgt); |
|
49 |
|
50 int x=130, y=130; |
47 int x=130, y=130; |
51 String s = "Text"; |
48 String s = "Text"; |
52 |
49 |
53 int xt=90, yt=50; |
50 int xt=90, yt=50; |
54 for (int angle=0;angle<360;angle+=30) { |
51 for (int angle=0;angle<360;angle+=30) { |
|
52 |
|
53 g2d.setColor(Color.white); |
|
54 g2d.fillRect(0, 0, wid, hgt); |
|
55 |
55 AffineTransform aff = AffineTransform.getTranslateInstance(50,90); |
56 AffineTransform aff = AffineTransform.getTranslateInstance(50,90); |
56 aff.rotate(angle * Math.PI/180.0); |
57 aff.rotate(angle * Math.PI/180.0); |
57 |
58 |
58 Font fnt = new Font("SansSerif", Font.PLAIN, 60); |
59 Font fnt = new Font("SansSerif", Font.PLAIN, 60); |
59 fnt = fnt.deriveFont(Font.PLAIN, aff); |
60 fnt = fnt.deriveFont(Font.PLAIN, aff); |
67 attrMap.put(TextAttribute.STRIKETHROUGH, |
68 attrMap.put(TextAttribute.STRIKETHROUGH, |
68 TextAttribute.STRIKETHROUGH_ON); |
69 TextAttribute.STRIKETHROUGH_ON); |
69 fnt = fnt.deriveFont(attrMap); |
70 fnt = fnt.deriveFont(attrMap); |
70 TextLayout tl = new TextLayout(s, fnt, frc); |
71 TextLayout tl = new TextLayout(s, fnt, frc); |
71 tl.draw(g2d, (float)x, (float)y); |
72 tl.draw(g2d, (float)x, (float)y); |
72 } |
73 |
73 // Test BI: should be no blue: only red and white. |
74 // Test BI: should be minimal blue relative to red. |
74 int red = Color.red.getRGB(); |
75 int redCount = 0; |
75 int blue = Color.blue.getRGB(); |
76 int blueCount = 0; |
76 int white = Color.white.getRGB(); |
77 int red = Color.red.getRGB(); |
77 for (int px=0;px<wid;px++) { |
78 int blue = Color.blue.getRGB(); |
78 for (int py=0;py<hgt;py++) { |
79 for (int px=0;px<wid;px++) { |
79 int rgb = bi.getRGB(px, py); |
80 for (int py=0;py<hgt;py++) { |
80 if (rgb == blue || ( rgb != red && rgb != white)) { |
81 int rgb = bi.getRGB(px, py); |
81 throw new RuntimeException |
82 if (rgb == red) { |
82 ("Unexpected color : " + Integer.toHexString(rgb) + |
83 redCount++; |
83 " at x=" + x + " y="+ y); |
84 } else if (rgb == blue) { |
|
85 blueCount++; |
|
86 } |
84 } |
87 } |
|
88 } |
|
89 if (redCount == 0 || (blueCount/(double)redCount) > 0.1) { |
|
90 throw new |
|
91 RuntimeException("Ratio of blue to red is too great: " + |
|
92 (blueCount/(double)redCount)); |
85 } |
93 } |
86 } |
94 } |
87 } |
95 } |
88 } |
96 } |