author | weijun |
Thu, 08 Sep 2011 09:04:28 +0800 | |
changeset 10435 | e9df9d264894 |
parent 9035 | 1255eb81cc2f |
child 32427 | c22b7e41adf3 |
permissions | -rw-r--r-- |
7938
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
7938
diff
changeset
|
2 |
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
7938
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
4 |
* |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
8 |
* |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
13 |
* accompanied this code). |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
14 |
* |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
18 |
* |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
21 |
* questions. |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
22 |
*/ |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
23 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
24 |
/* |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
25 |
* |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
26 |
* @bug 6925760 |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
27 |
* @summary Scaled graphics causes overlapped LCD glyphs on Windows |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
28 |
*/ |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
29 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
30 |
import java.awt.*; |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
31 |
import java.awt.font.*; |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
32 |
import java.awt.geom.*; |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
33 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
34 |
public class LCDScale extends Component { |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
35 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
36 |
public static void main(String args[]) { |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
37 |
Frame f = new Frame("TL TEST"); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
38 |
LCDScale td = new LCDScale(); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
39 |
f.add("Center", td); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
40 |
f.pack(); f.setVisible(true); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
41 |
} |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
42 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
43 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
44 |
public LCDScale() { |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
45 |
super(); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
46 |
} |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
47 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
48 |
public Dimension getPreferredSize() { |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
49 |
return new Dimension(500,500); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
50 |
} |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
51 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
52 |
public void paint(Graphics g) { |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
53 |
Graphics2D g2d = (Graphics2D)g; |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
54 |
g2d.setRenderingHint( |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
55 |
RenderingHints.KEY_TEXT_ANTIALIASING, |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
56 |
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
57 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
58 |
Font f = new Font("Dialog", Font.PLAIN, 40); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
59 |
g.setFont(f); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
60 |
FontRenderContext frc = g2d.getFontRenderContext(); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
61 |
GlyphVector gv = f.createGlyphVector(frc, "Help"); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
62 |
g2d.drawGlyphVector(gv, 10f, 50f); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
63 |
Rectangle2D bds1 = gv.getLogicalBounds(); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
64 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
65 |
f = new Font("Arial", Font.PLAIN, 25); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
66 |
g.setFont(f); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
67 |
double s = 2.0; |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
68 |
AffineTransform tx = AffineTransform.getScaleInstance(s,s); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
69 |
g2d.transform(tx); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
70 |
frc = g2d.getFontRenderContext(); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
71 |
gv = f.createGlyphVector(frc, "Help"); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
72 |
g2d.drawGlyphVector(gv, 10f, 100f); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
73 |
Rectangle2D bds2 = gv.getLogicalBounds(); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
74 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
75 |
System.out.println(bds1); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
76 |
System.out.println(bds2); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
77 |
if (bds2.getWidth()*s < bds1.getWidth()) { |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
78 |
throw new RuntimeException("Bounds too small"); |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
79 |
} |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
80 |
} |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
81 |
} |
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
82 |
|
970d0e025e57
6925760: Scaled graphics can cause overlapped LCD mode strings on Windows for pixel size > 48
prr
parents:
diff
changeset
|
83 |