From 91e1947625f4e33e3dba8f4250a289a08a28e8fe Mon Sep 17 00:00:00 2001 From: duke Date: Thu, 2 Jan 2025 06:57:43 +0000 Subject: [PATCH] Backport b3e63631c735862ba00270636b4ef51c0e48a1af --- .../classes/sun/print/CustomMediaSizeName.java | 17 +++++++++-------- .../java/awt/print/Dialog/PaperSizeError.java | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/java.desktop/share/classes/sun/print/CustomMediaSizeName.java b/src/java.desktop/share/classes/sun/print/CustomMediaSizeName.java index b8d3ec723b8..04772f29858 100644 --- a/src/java.desktop/share/classes/sun/print/CustomMediaSizeName.java +++ b/src/java.desktop/share/classes/sun/print/CustomMediaSizeName.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * 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, if (value == null) { value = new CustomMediaSizeName(name, choice, width, length); customMap.put(key, value); - - // add this new custom media size name to MediaSize array - if ((width > 0.0) && (length > 0.0)) { - try { - new MediaSize(width, length, Size2DSyntax.INCH, value); - } catch (IllegalArgumentException e) { + if (value.getStandardMedia() == null) { + // add this new custom media size name to MediaSize array + if ((width > 0.0) && (length > 0.0)) { + try { + new MediaSize(width, length, Size2DSyntax.INCH, value); + } catch (IllegalArgumentException e) { /* PDF printer in Linux for Ledger paper causes "IllegalArgumentException: X dimension > Y dimension". We rotate based on IPP spec. */ - new MediaSize(length, width, Size2DSyntax.INCH, value); + new MediaSize(length, width, Size2DSyntax.INCH, value); + } } } } diff --git a/test/jdk/java/awt/print/Dialog/PaperSizeError.java b/test/jdk/java/awt/print/Dialog/PaperSizeError.java index fea7bb85af8..18f33704a06 100644 --- a/test/jdk/java/awt/print/Dialog/PaperSizeError.java +++ b/test/jdk/java/awt/print/Dialog/PaperSizeError.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,16 +23,22 @@ /** * @test - * @bug 6360339 + * @bug 6360339 8343224 * @key printer * @summary Test for fp error in paper size calculations. * @run main/manual PaperSizeError */ -import java.awt.print.*; -import javax.print.*; -import javax.print.attribute.*; -import javax.print.attribute.standard.*; +import javax.print.PrintService; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.Size2DSyntax; +import javax.print.attribute.standard.MediaSize; +import javax.print.attribute.standard.MediaSizeName; +import javax.print.attribute.standard.OrientationRequested; +import java.awt.print.PageFormat; +import java.awt.print.Paper; +import java.awt.print.PrinterJob; public class PaperSizeError {