8048583: CustomMediaSizeName class matching to standard media is too loose
authorprr
Mon, 14 Jul 2014 11:11:13 -0700
changeset 25779 86b8de4f7d09
parent 25778 998b49cac7e9
child 25780 9ece64e7ca1a
8048583: CustomMediaSizeName class matching to standard media is too loose Reviewed-by: bae, jgodinez
jdk/src/share/classes/sun/print/CustomMediaSizeName.java
--- a/jdk/src/share/classes/sun/print/CustomMediaSizeName.java	Mon Jul 14 10:29:23 2014 -0700
+++ b/jdk/src/share/classes/sun/print/CustomMediaSizeName.java	Mon Jul 14 11:11:13 2014 -0700
@@ -67,6 +67,22 @@
                                             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;
+                }
+            }
+        }
     }
 
     /**