Skip to content

Commit b3dbfc6

Browse files
committed
4884570: StreamPrintService.isAttributeValueSupported does not work properly for SheetCollate
Reviewed-by: serb
1 parent 8703f14 commit b3dbfc6

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

src/java.desktop/share/classes/sun/print/PSStreamPrintService.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,17 @@ else if (attr.getCategory() == Copies.class) {
427427
if (attr == OrientationRequested.REVERSE_PORTRAIT ||
428428
(flavor != null) &&
429429
!(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
430-
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
430+
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
431+
flavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
432+
flavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
433+
flavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
434+
flavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
435+
flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
436+
flavor.equals(DocFlavor.BYTE_ARRAY.PNG) ||
437+
flavor.equals(DocFlavor.URL.GIF) ||
438+
flavor.equals(DocFlavor.URL.JPEG) ||
439+
flavor.equals(DocFlavor.URL.PNG)))
440+
{
431441
return false;
432442
}
433443
} else if (attr.getCategory() == PageRanges.class) {
@@ -440,7 +450,7 @@ else if (attr.getCategory() == Copies.class) {
440450
if (flavor != null &&
441451
!(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
442452
flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
443-
return false;
453+
return attr == SheetCollate.UNCOLLATED;
444454
}
445455
} else if (attr.getCategory() == Sides.class) {
446456
if (flavor != null &&
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 4884570
27+
* @summary Attribute support reporting should be consistent
28+
*/
29+
30+
import java.io.ByteArrayOutputStream;
31+
import java.io.OutputStream;
32+
33+
import javax.print.DocFlavor;
34+
import javax.print.StreamPrintService;
35+
import javax.print.StreamPrintServiceFactory;
36+
import javax.print.attribute.Attribute;
37+
import javax.print.attribute.standard.Chromaticity;
38+
import javax.print.attribute.standard.Media;
39+
import javax.print.attribute.standard.OrientationRequested;
40+
import javax.print.attribute.standard.SheetCollate;
41+
import javax.print.attribute.standard.Sides;
42+
43+
public class StreamServiceAttributeTest {
44+
45+
private static boolean allSupported = true;
46+
private static Class[] attrClasses = {
47+
Chromaticity.class,
48+
Media.class,
49+
OrientationRequested.class,
50+
SheetCollate.class,
51+
Sides.class,
52+
};
53+
54+
public static void main(String args[]) {
55+
56+
StreamPrintServiceFactory[] fact =
57+
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
58+
null, null);
59+
60+
if (fact.length == 0) {
61+
return;
62+
}
63+
OutputStream out = new ByteArrayOutputStream();
64+
StreamPrintService sps = fact[0].getPrintService(out);
65+
for (Class<? extends Attribute> ac : attrClasses) {
66+
test(sps, ac);
67+
}
68+
69+
if (!allSupported) {
70+
throw new RuntimeException("Inconsistent support reported");
71+
}
72+
}
73+
74+
private static void test(StreamPrintService sps,
75+
Class<? extends Attribute> ac) {
76+
if (!sps.isAttributeCategorySupported(ac)) {
77+
return;
78+
}
79+
DocFlavor[] dfs = sps.getSupportedDocFlavors();
80+
for (DocFlavor f : dfs) {
81+
Attribute[] attrs = (Attribute[])
82+
sps.getSupportedAttributeValues(ac, f, null);
83+
if (attrs == null) {
84+
continue;
85+
}
86+
for (Attribute a : attrs) {
87+
if (!sps.isAttributeValueSupported(a, f, null)) {
88+
allSupported = false;
89+
System.out.println("Unsupported : " + f + " " + a);
90+
}
91+
}
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)