Skip to content

Commit 366c0f9

Browse files
committed
8343224: print/Dialog/PaperSizeError.java fails with MediaSizeName is not A4: A4
Backport-of: b3e63631c735862ba00270636b4ef51c0e48a1af
1 parent f1798aa commit 366c0f9

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -203,16 +203,17 @@ public static CustomMediaSizeName create(String name, String choice,
203203
if (value == null) {
204204
value = new CustomMediaSizeName(name, choice, width, length);
205205
customMap.put(key, value);
206-
207-
// add this new custom media size name to MediaSize array
208-
if ((width > 0.0) && (length > 0.0)) {
209-
try {
210-
new MediaSize(width, length, Size2DSyntax.INCH, value);
211-
} catch (IllegalArgumentException e) {
206+
if (value.getStandardMedia() == null) {
207+
// add this new custom media size name to MediaSize array
208+
if ((width > 0.0) && (length > 0.0)) {
209+
try {
210+
new MediaSize(width, length, Size2DSyntax.INCH, value);
211+
} catch (IllegalArgumentException e) {
212212
/* PDF printer in Linux for Ledger paper causes
213213
"IllegalArgumentException: X dimension > Y dimension".
214214
We rotate based on IPP spec. */
215-
new MediaSize(length, width, Size2DSyntax.INCH, value);
215+
new MediaSize(length, width, Size2DSyntax.INCH, value);
216+
}
216217
}
217218
}
218219
}

test/jdk/java/awt/print/Dialog/PaperSizeError.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,16 +23,22 @@
2323

2424
/**
2525
* @test
26-
* @bug 6360339
26+
* @bug 6360339 8343224
2727
* @key printer
2828
* @summary Test for fp error in paper size calculations.
2929
* @run main/manual PaperSizeError
3030
*/
3131

32-
import java.awt.print.*;
33-
import javax.print.*;
34-
import javax.print.attribute.*;
35-
import javax.print.attribute.standard.*;
32+
import javax.print.PrintService;
33+
import javax.print.attribute.HashPrintRequestAttributeSet;
34+
import javax.print.attribute.PrintRequestAttributeSet;
35+
import javax.print.attribute.Size2DSyntax;
36+
import javax.print.attribute.standard.MediaSize;
37+
import javax.print.attribute.standard.MediaSizeName;
38+
import javax.print.attribute.standard.OrientationRequested;
39+
import java.awt.print.PageFormat;
40+
import java.awt.print.Paper;
41+
import java.awt.print.PrinterJob;
3642

3743
public class PaperSizeError {
3844

0 commit comments

Comments
 (0)