author | prr |
Fri, 24 May 2013 09:31:29 -0700 | |
changeset 17674 | 46246fbf98d4 |
child 21224 | 58a31574ac84 |
permissions | -rw-r--r-- |
17674
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
1 |
/* |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
4 |
* |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
8 |
* |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
13 |
* accompanied this code). |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
14 |
* |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
18 |
* |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
21 |
* questions. |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
22 |
*/ |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
23 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
24 |
/** |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
25 |
* @test |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
26 |
* @bug 800535 |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
27 |
* @summary JDK7 Printing: CJK and Latin Text in string overlap |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
28 |
* @run main/manual=yesno PrintLatinCJKTest |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
29 |
*/ |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
30 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
31 |
import java.awt.Font; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
32 |
import java.awt.Graphics; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
33 |
import java.awt.event.ActionEvent; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
34 |
import java.awt.event.ActionListener; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
35 |
import java.awt.print.PageFormat; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
36 |
import java.awt.print.Pageable; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
37 |
import java.awt.print.Printable; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
38 |
import java.awt.print.PrinterException; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
39 |
import java.awt.print.PrinterJob; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
40 |
import javax.swing.JButton; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
41 |
import javax.swing.JFrame; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
42 |
import javax.swing.JTextArea; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
43 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
44 |
import javax.swing.SwingUtilities; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
45 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
46 |
public class PrintLatinCJKTest implements Printable, ActionListener { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
47 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
48 |
static PrintLatinCJKTest testInstance = new PrintLatinCJKTest(); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
49 |
private PageFormat pf; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
50 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
51 |
static String info = |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
52 |
"You need a printer for this test. If you have none, let "+ |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
53 |
"the test pass. If there is a printer, press Print, send "+ |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
54 |
"the output to the printer, and examine it. It should have "+ |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
55 |
"text looking like this : \u4e00\u4e01\u4e02\u4e03\u4e04English."; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
56 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
57 |
public static void showFrame() { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
58 |
JFrame f = new JFrame(); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
59 |
JTextArea jta = new JTextArea(info, 4, 30); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
60 |
jta.setLineWrap(true); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
61 |
jta.setWrapStyleWord(true); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
62 |
f.add("Center", jta); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
63 |
JButton b = new JButton("Print"); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
64 |
b.addActionListener(testInstance); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
65 |
f.add("South", b); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
66 |
f.pack(); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
67 |
f.setVisible(true); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
68 |
} |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
69 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
70 |
public int print(Graphics g, PageFormat pf, int pageIndex) |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
71 |
throws PrinterException { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
72 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
73 |
if (pageIndex > 0) { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
74 |
return Printable.NO_SUCH_PAGE; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
75 |
} |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
76 |
g.translate((int) pf.getImageableX(), (int) pf.getImageableY()); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
77 |
g.setFont(new Font("Dialog", Font.PLAIN, 36)); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
78 |
g.drawString("\u4e00\u4e01\u4e02\u4e03\u4e04English", 20, 100); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
79 |
return Printable.PAGE_EXISTS; |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
80 |
} |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
81 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
82 |
public void actionPerformed(ActionEvent e) { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
83 |
try { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
84 |
PrinterJob job = PrinterJob.getPrinterJob(); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
85 |
job.setPrintable(testInstance); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
86 |
if (job.printDialog()) { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
87 |
job.print(); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
88 |
} |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
89 |
} catch (PrinterException ex) { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
90 |
ex.printStackTrace(); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
91 |
} |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
92 |
} |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
93 |
|
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
94 |
public static void main(String[] args) { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
95 |
SwingUtilities.invokeLater(new Runnable() { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
96 |
@Override |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
97 |
public void run() { |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
98 |
showFrame(); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
99 |
} |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
100 |
}); |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
101 |
} |
46246fbf98d4
8008535: JDK7 Printing : CJK and Latin Text in a string overlap
prr
parents:
diff
changeset
|
102 |
} |