changeset 9738:86160b07b1db

8048583: CustomMediaSizeName class matching to standard media is too loose Reviewed-by: bae, jgodinez
author prr
date Mon, 14 Jul 2014 13:54:46 -0700
parents 8d1f9e8d02b1
children baec3649f6c0
files src/share/classes/sun/print/CustomMediaSizeName.java
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/print/CustomMediaSizeName.java	Mon Jul 14 11:09:31 2014 -0700
+++ b/src/share/classes/sun/print/CustomMediaSizeName.java	Mon Jul 14 13:54:46 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;
+                }
+            }
+        }
     }
 
     /**