author | tschatzl |
Mon, 24 Aug 2015 16:32:50 +0200 | |
changeset 32390 | b0f6868d46ee |
parent 28983 | 432867ba1a45 |
child 32281 | 99ae1f6dd69b |
permissions | -rw-r--r-- |
28983
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
1 |
/* |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
4 |
* |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
10 |
* |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
15 |
* accompanied this code). |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
16 |
* |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
20 |
* |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
23 |
* questions. |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
24 |
*/ |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
25 |
import java.awt.Graphics; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
26 |
import java.awt.GraphicsEnvironment; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
27 |
import java.awt.print.PageFormat; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
28 |
import java.awt.print.Printable; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
29 |
import java.io.File; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
30 |
import java.io.FileInputStream; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
31 |
import java.io.FileOutputStream; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
32 |
import java.io.IOException; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
33 |
import java.nio.charset.StandardCharsets; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
34 |
import javax.print.DocFlavor; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
35 |
import javax.print.DocPrintJob; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
36 |
import javax.print.SimpleDoc; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
37 |
import javax.print.StreamPrintService; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
38 |
import javax.print.StreamPrintServiceFactory; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
39 |
import javax.print.attribute.HashDocAttributeSet; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
40 |
import javax.print.attribute.HashPrintRequestAttributeSet; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
41 |
import javax.print.event.PrintJobAdapter; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
42 |
import javax.print.event.PrintJobEvent; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
43 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
44 |
/* |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
45 |
* @test |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
46 |
* @bug 8067364 |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
47 |
* @summary Printing to Postscript doesn't support dieresis |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
48 |
* @build PrintSEUmlauts |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
49 |
* @run main/othervm PrintSEUmlauts |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
50 |
*/ |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
51 |
public class PrintSEUmlauts implements Printable { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
52 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
53 |
public static void main(String[] args) throws Exception { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
54 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
55 |
GraphicsEnvironment.getLocalGraphicsEnvironment(); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
56 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
57 |
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
58 |
String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType(); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
59 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
60 |
StreamPrintServiceFactory[] factories = |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
61 |
StreamPrintServiceFactory. |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
62 |
lookupStreamPrintServiceFactories(flavor, mime); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
63 |
if (factories.length == 0) { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
64 |
System.out.println("No print service found."); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
65 |
return; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
66 |
} |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
67 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
68 |
FileOutputStream output = new FileOutputStream("out.ps"); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
69 |
StreamPrintService service = factories[0].getPrintService(output); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
70 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
71 |
SimpleDoc doc = |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
72 |
new SimpleDoc(new PrintSEUmlauts(), |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
73 |
DocFlavor.SERVICE_FORMATTED.PRINTABLE, |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
74 |
new HashDocAttributeSet()); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
75 |
DocPrintJob job = service.createPrintJob(); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
76 |
job.addPrintJobListener(new PrintJobAdapter() { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
77 |
@Override |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
78 |
public void printJobCompleted(PrintJobEvent pje) { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
79 |
testPrintAndExit(); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
80 |
} |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
81 |
}); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
82 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
83 |
job.print(doc, new HashPrintRequestAttributeSet()); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
84 |
} |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
85 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
86 |
private static final boolean DEBUG = false; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
87 |
private static void testPrintAndExit() { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
88 |
String expected = "<e4> 7.44 100.0 100.0 S"; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
89 |
String content = ""; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
90 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
91 |
File file = new File("out.ps"); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
92 |
if (!DEBUG) { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
93 |
file.deleteOnExit(); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
94 |
} |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
95 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
96 |
try (FileInputStream stream = new FileInputStream(file)) { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
97 |
byte[] data = new byte[(int) file.length()]; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
98 |
stream.read(data); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
99 |
content = new String(data, StandardCharsets.ISO_8859_1); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
100 |
} catch (IOException ex) { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
101 |
ex.printStackTrace(); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
102 |
} |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
103 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
104 |
if (!content.contains(expected)) { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
105 |
System.err.println("FAIL"); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
106 |
if (DEBUG) { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
107 |
System.err.println("printing content"); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
108 |
System.err.println(content); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
109 |
} |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
110 |
throw new RuntimeException("Expected <e4> to represent 'ä' but not found!"); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
111 |
} |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
112 |
System.err.println("SUCCESS"); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
113 |
} |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
114 |
|
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
115 |
public int print(Graphics g, PageFormat pf, int pg) { |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
116 |
if (pg > 0) return NO_SUCH_PAGE; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
117 |
g.drawString("ä", 100, 100); |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
118 |
return PAGE_EXISTS; |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
119 |
} |
432867ba1a45
8067364: Printing to Postscript doesn't support dieresis
neugens
parents:
diff
changeset
|
120 |
} |