From 698f4867ae55da08a0512bea3d241ceebe48e83a Mon Sep 17 00:00:00 2001 From: Phil Race Date: Mon, 14 Jul 2014 11:11:13 -0700 Subject: [PATCH] 8048583: CustomMediaSizeName class matching to standard media is too loose Reviewed-by: bae, jgodinez --- .../classes/sun/print/CustomMediaSizeName.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jdk/src/share/classes/sun/print/CustomMediaSizeName.java b/jdk/src/share/classes/sun/print/CustomMediaSizeName.java index 2390495a703..5b9b4b19883 100644 --- a/jdk/src/share/classes/sun/print/CustomMediaSizeName.java +++ b/jdk/src/share/classes/sun/print/CustomMediaSizeName.java @@ -67,6 +67,22 @@ class CustomMediaSizeName extends MediaSizeName { MediaSize.INCH); } catch (IllegalArgumentException iae) { } + // The public API method finds a closest match even if it not + // all that close. Here we want to be sure its *really* close. + if (mediaName != null) { + MediaSize sz = MediaSize.getMediaSizeForName(mediaName); + if (sz == null) { + mediaName = null; + } else { + float w = sz.getX(MediaSize.INCH); + float h = sz.getY(MediaSize.INCH); + float dw = Math.abs(w - width); + float dh = Math.abs(h - length); + if (dw > 0.1 || dh > 0.1) { + mediaName = null; + } + } + } } /**