< prev index next >

src/java.desktop/share/classes/sun/print/PSPrinterJob.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 120      * method this value forces fills to be
 121      * done using the non-zero winding rule.
 122      */
 123     protected static final int FILL_WINDING = 2;
 124 
 125     /* PostScript has a 64K maximum on its strings.
 126      */
 127     private static final int MAX_PSSTR = (1024 * 64 - 1);
 128 
 129     private static final int RED_MASK = 0x00ff0000;
 130     private static final int GREEN_MASK = 0x0000ff00;
 131     private static final int BLUE_MASK = 0x000000ff;
 132 
 133     private static final int RED_SHIFT = 16;
 134     private static final int GREEN_SHIFT = 8;
 135     private static final int BLUE_SHIFT = 0;
 136 
 137     private static final int LOWNIBBLE_MASK = 0x0000000f;
 138     private static final int HINIBBLE_MASK =  0x000000f0;
 139     private static final int HINIBBLE_SHIFT = 4;
 140     private static final byte hexDigits[] = {
 141         (byte)'0', (byte)'1', (byte)'2', (byte)'3',
 142         (byte)'4', (byte)'5', (byte)'6', (byte)'7',
 143         (byte)'8', (byte)'9', (byte)'A', (byte)'B',
 144         (byte)'C', (byte)'D', (byte)'E', (byte)'F'
 145     };
 146 
 147     private static final int PS_XRES = 300;
 148     private static final int PS_YRES = 300;
 149 
 150     private static final String ADOBE_PS_STR =  "%!PS-Adobe-3.0";
 151     private static final String EOF_COMMENT =   "%%EOF";
 152     private static final String PAGE_COMMENT =  "%%Page: ";
 153 
 154     private static final String READIMAGEPROC = "/imStr 0 def /imageSrc " +
 155         "{currentfile /ASCII85Decode filter /RunLengthDecode filter " +
 156         " imStr readstring pop } def";
 157 
 158     private static final String COPIES =        "/#copies exch def";
 159     private static final String PAGE_SAVE =     "/pgSave save def";
 160     private static final String PAGE_RESTORE =  "pgSave restore";


 715                         pw.println();
 716                         pw.append("\t\t").append(br.readLine());
 717                     }
 718                 } finally {
 719                     pw.flush();
 720                 }
 721                 throw new IOException(sw.toString());
 722             }
 723         }
 724 
 725         public Object run() {
 726             if (spoolFile == null || !spoolFile.exists()) {
 727                pex = new PrinterException("No spool file");
 728                return null;
 729             }
 730             try {
 731                 /**
 732                  * Spool to the printer.
 733                  */
 734                 String fileName = spoolFile.getAbsolutePath();
 735                 String execCmd[] = printExecCmd(mDestination, mOptions,
 736                                mNoJobSheet, getJobNameInt(),
 737                                                 1, fileName);
 738 
 739                 Process process = Runtime.getRuntime().exec(execCmd);
 740                 process.waitFor();
 741                 final int result = process.exitValue();
 742                 if (0 != result) {
 743                     handleProcessFailure(process, execCmd, result);
 744                 }
 745             } catch (IOException ex) {
 746                 pex = new PrinterIOException(ex);
 747             } catch (InterruptedException ie) {
 748                 pex = new PrinterException(ie.toString());
 749             } finally {
 750                 spoolFile.delete();
 751             }
 752             return null;
 753         }
 754     }
 755 


1573      * If the printer makes copies itself then this
1574      * method should return 1.
1575      */
1576     protected int getNoncollatedCopies() {
1577         return 1;
1578     }
1579 
1580     protected int getCollatedCopies() {
1581         return 1;
1582     }
1583 
1584     private String[] printExecCmd(String printer, String options,
1585                                   boolean noJobSheet,
1586                                   String jobTitle, int copies, String spoolFile) {
1587         int PRINTER = 0x1;
1588         int OPTIONS = 0x2;
1589         int JOBTITLE  = 0x4;
1590         int COPIES  = 0x8;
1591         int NOSHEET = 0x10;
1592         int pFlags = 0;
1593         String execCmd[];
1594         int ncomps = 2; // minimum number of print args
1595         int n = 0;
1596 
1597         if (printer != null && !printer.equals("") && !printer.equals("lp")) {
1598             pFlags |= PRINTER;
1599             ncomps+=1;
1600         }
1601         if (options != null && !options.equals("")) {
1602             pFlags |= OPTIONS;
1603             ncomps+=1;
1604         }
1605         if (jobTitle != null && !jobTitle.equals("")) {
1606             pFlags |= JOBTITLE;
1607             ncomps+=1;
1608         }
1609         if (copies > 1) {
1610             pFlags |= COPIES;
1611             ncomps+=1;
1612         }
1613         if (noJobSheet) {


   1 /*
   2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 120      * method this value forces fills to be
 121      * done using the non-zero winding rule.
 122      */
 123     protected static final int FILL_WINDING = 2;
 124 
 125     /* PostScript has a 64K maximum on its strings.
 126      */
 127     private static final int MAX_PSSTR = (1024 * 64 - 1);
 128 
 129     private static final int RED_MASK = 0x00ff0000;
 130     private static final int GREEN_MASK = 0x0000ff00;
 131     private static final int BLUE_MASK = 0x000000ff;
 132 
 133     private static final int RED_SHIFT = 16;
 134     private static final int GREEN_SHIFT = 8;
 135     private static final int BLUE_SHIFT = 0;
 136 
 137     private static final int LOWNIBBLE_MASK = 0x0000000f;
 138     private static final int HINIBBLE_MASK =  0x000000f0;
 139     private static final int HINIBBLE_SHIFT = 4;
 140     private static final byte[] hexDigits = {
 141         (byte)'0', (byte)'1', (byte)'2', (byte)'3',
 142         (byte)'4', (byte)'5', (byte)'6', (byte)'7',
 143         (byte)'8', (byte)'9', (byte)'A', (byte)'B',
 144         (byte)'C', (byte)'D', (byte)'E', (byte)'F'
 145     };
 146 
 147     private static final int PS_XRES = 300;
 148     private static final int PS_YRES = 300;
 149 
 150     private static final String ADOBE_PS_STR =  "%!PS-Adobe-3.0";
 151     private static final String EOF_COMMENT =   "%%EOF";
 152     private static final String PAGE_COMMENT =  "%%Page: ";
 153 
 154     private static final String READIMAGEPROC = "/imStr 0 def /imageSrc " +
 155         "{currentfile /ASCII85Decode filter /RunLengthDecode filter " +
 156         " imStr readstring pop } def";
 157 
 158     private static final String COPIES =        "/#copies exch def";
 159     private static final String PAGE_SAVE =     "/pgSave save def";
 160     private static final String PAGE_RESTORE =  "pgSave restore";


 715                         pw.println();
 716                         pw.append("\t\t").append(br.readLine());
 717                     }
 718                 } finally {
 719                     pw.flush();
 720                 }
 721                 throw new IOException(sw.toString());
 722             }
 723         }
 724 
 725         public Object run() {
 726             if (spoolFile == null || !spoolFile.exists()) {
 727                pex = new PrinterException("No spool file");
 728                return null;
 729             }
 730             try {
 731                 /**
 732                  * Spool to the printer.
 733                  */
 734                 String fileName = spoolFile.getAbsolutePath();
 735                 String[] execCmd = printExecCmd(mDestination, mOptions,
 736                                mNoJobSheet, getJobNameInt(),
 737                                                 1, fileName);
 738 
 739                 Process process = Runtime.getRuntime().exec(execCmd);
 740                 process.waitFor();
 741                 final int result = process.exitValue();
 742                 if (0 != result) {
 743                     handleProcessFailure(process, execCmd, result);
 744                 }
 745             } catch (IOException ex) {
 746                 pex = new PrinterIOException(ex);
 747             } catch (InterruptedException ie) {
 748                 pex = new PrinterException(ie.toString());
 749             } finally {
 750                 spoolFile.delete();
 751             }
 752             return null;
 753         }
 754     }
 755 


1573      * If the printer makes copies itself then this
1574      * method should return 1.
1575      */
1576     protected int getNoncollatedCopies() {
1577         return 1;
1578     }
1579 
1580     protected int getCollatedCopies() {
1581         return 1;
1582     }
1583 
1584     private String[] printExecCmd(String printer, String options,
1585                                   boolean noJobSheet,
1586                                   String jobTitle, int copies, String spoolFile) {
1587         int PRINTER = 0x1;
1588         int OPTIONS = 0x2;
1589         int JOBTITLE  = 0x4;
1590         int COPIES  = 0x8;
1591         int NOSHEET = 0x10;
1592         int pFlags = 0;
1593         String[] execCmd;
1594         int ncomps = 2; // minimum number of print args
1595         int n = 0;
1596 
1597         if (printer != null && !printer.equals("") && !printer.equals("lp")) {
1598             pFlags |= PRINTER;
1599             ncomps+=1;
1600         }
1601         if (options != null && !options.equals("")) {
1602             pFlags |= OPTIONS;
1603             ncomps+=1;
1604         }
1605         if (jobTitle != null && !jobTitle.equals("")) {
1606             pFlags |= JOBTITLE;
1607             ncomps+=1;
1608         }
1609         if (copies > 1) {
1610             pFlags |= COPIES;
1611             ncomps+=1;
1612         }
1613         if (noJobSheet) {


< prev index next >