changeset 25555:b70a66b5b942

7067052: Default printer media is ignored Reviewed-by: bae, prr
author jgodinez
date Thu, 26 Jun 2014 13:46:27 -0700
parents 8376663d83d7
children 1246bc23416f
files jdk/src/solaris/classes/sun/print/CUPSPrinter.java jdk/src/solaris/classes/sun/print/IPPPrintService.java jdk/src/solaris/native/sun/awt/CUPSfuncs.c
diffstat 3 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/solaris/classes/sun/print/CUPSPrinter.java	Thu Jun 26 13:38:38 2014 +0400
+++ b/jdk/src/solaris/classes/sun/print/CUPSPrinter.java	Thu Jun 26 13:46:27 2014 -0700
@@ -140,6 +140,9 @@
         return cupsCustomMediaSNames;
     }
 
+    public int getDefaultMediaIndex() {
+        return ((pageSizes.length >1) ? (int)(pageSizes[pageSizes.length -1]) : 0);
+    }
 
     /**
      * Returns array of MediaPrintableArea derived from PPD.
@@ -201,8 +204,15 @@
 
                 // add this new custom msn to MediaSize array
                 if ((width > 0.0) && (length > 0.0)) {
+                    try {
                     new MediaSize(width, length,
                                   Size2DSyntax.INCH, msn);
+                    } 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, msn);
+                    }
                 }
             }
 
--- a/jdk/src/solaris/classes/sun/print/IPPPrintService.java	Thu Jun 26 13:38:38 2014 +0400
+++ b/jdk/src/solaris/classes/sun/print/IPPPrintService.java	Thu Jun 26 13:46:27 2014 -0700
@@ -413,6 +413,7 @@
                     mediaSizeNames = cps.getMediaSizeNames();
                     mediaTrays = cps.getMediaTrays();
                     customMediaSizeNames = cps.getCustomMediaSizeNames();
+                    defaultMediaIndex = cps.getDefaultMediaIndex();
                     urlConnection.disconnect();
                     init = true;
                     return;
@@ -1427,7 +1428,9 @@
                 return JobSheets.STANDARD;
             }
         } else if (category == Media.class) {
-            defaultMediaIndex = 0;
+            if (defaultMediaIndex == -1) {
+                defaultMediaIndex = 0;
+            }
             if (mediaSizeNames.length == 0) {
                 String defaultCountry = Locale.getDefault().getCountry();
                 if (defaultCountry != null &&
@@ -1443,17 +1446,7 @@
             if (attribClass != null) {
                 String name = attribClass.getStringValue();
                 if (isCupsPrinter) {
-                    for (int i=0; i< customMediaSizeNames.length; i++) {
-                        //REMIND:  get default from PPD. In native _getMedia,
-                        // move default (ppd_option_t->defchoice) to index 0.
-                        // In the meantime, use indexOf because PPD name
-                        // may be different from the IPP attribute name.
-                        if (customMediaSizeNames[i].toString().indexOf(name)
-                            != -1) {
-                            defaultMediaIndex = i;
-                            return mediaSizeNames[defaultMediaIndex];
-                        }
-                    }
+                    return mediaSizeNames[defaultMediaIndex];
                 } else {
                     for (int i=0; i< mediaSizeNames.length; i++) {
                         if (mediaSizeNames[i].toString().indexOf(name) != -1) {
--- a/jdk/src/solaris/native/sun/awt/CUPSfuncs.c	Thu Jun 26 13:38:38 2014 +0400
+++ b/jdk/src/solaris/native/sun/awt/CUPSfuncs.c	Thu Jun 26 13:46:27 2014 -0700
@@ -349,7 +349,8 @@
         // create array of dimensions - (num_choices * 6)
         //to cover length & height
         DPRINTF( "CUPSfuncs::option->num_choices %d\n", option->num_choices)
-        sizeArray = (*env)->NewFloatArray(env, option->num_choices*6);
+        // +1 is for storing the default media index
+        sizeArray = (*env)->NewFloatArray(env, option->num_choices*6+1);
         if (sizeArray == NULL) {
             unlink(filename);
             j2d_ppdClose(ppd);
@@ -369,6 +370,10 @@
         }
         for (i = 0; i<option->num_choices; i++) {
             choice = (option->choices)+i;
+            // get the index of the default page
+            if (!strcmp(choice->choice, option->defchoice)) {
+                dims[option->num_choices*6] = (float)i;
+            }
             size = j2d_ppdPageSize(ppd, choice->choice);
             if (size != NULL) {
                 // paper width and height