diff --git a/src/java.desktop/share/classes/sun/print/PSPrinterJob.java b/src/java.desktop/share/classes/sun/print/PSPrinterJob.java index 7404c6c3948..03fdb532b71 100644 --- a/src/java.desktop/share/classes/sun/print/PSPrinterJob.java +++ b/src/java.desktop/share/classes/sun/print/PSPrinterJob.java @@ -127,24 +127,6 @@ public class PSPrinterJob extends RasterPrinterJob { */ private static final int MAX_PSSTR = (1024 * 64 - 1); - private static final int RED_MASK = 0x00ff0000; - private static final int GREEN_MASK = 0x0000ff00; - private static final int BLUE_MASK = 0x000000ff; - - private static final int RED_SHIFT = 16; - private static final int GREEN_SHIFT = 8; - private static final int BLUE_SHIFT = 0; - - private static final int LOWNIBBLE_MASK = 0x0000000f; - private static final int HINIBBLE_MASK = 0x000000f0; - private static final int HINIBBLE_SHIFT = 4; - private static final byte[] hexDigits = { - (byte)'0', (byte)'1', (byte)'2', (byte)'3', - (byte)'4', (byte)'5', (byte)'6', (byte)'7', - (byte)'8', (byte)'9', (byte)'A', (byte)'B', - (byte)'C', (byte)'D', (byte)'E', (byte)'F' - }; - private static final int PS_XRES = 300; private static final int PS_YRES = 300; @@ -267,14 +249,6 @@ public class PSPrinterJob extends RasterPrinterJob { private double xres = PS_XRES; private double yres = PS_YRES; - /* non-null if printing EPS for Java Plugin */ - private EPSPrinter epsPrinter = null; - - /** - * The metrics for the font currently set. - */ - FontMetrics mCurMetrics; - /** * The output stream to which the generated PostScript * is written. @@ -513,46 +487,43 @@ public class PSPrinterJob extends RasterPrinterJob { OutputStream output = null; - if (epsPrinter == null) { - if (getPrintService() instanceof PSStreamPrintService) { - StreamPrintService sps = (StreamPrintService)getPrintService(); - mDestType = RasterPrinterJob.STREAM; - if (sps.isDisposed()) { - throw new PrinterException("service is disposed"); - } - output = sps.getOutputStream(); - if (output == null) { - throw new PrinterException("Null output stream"); + if (getPrintService() instanceof PSStreamPrintService) { + StreamPrintService sps = (StreamPrintService)getPrintService(); + mDestType = RasterPrinterJob.STREAM; + if (sps.isDisposed()) { + throw new PrinterException("service is disposed"); + } + output = sps.getOutputStream(); + if (output == null) { + throw new PrinterException("Null output stream"); + } + } else { + /* REMIND: This needs to be more maintainable */ + mNoJobSheet = super.noJobSheet; + if (super.destinationAttr != null) { + mDestType = RasterPrinterJob.FILE; + mDestination = super.destinationAttr; + } + if (mDestType == RasterPrinterJob.FILE) { + try { + spoolFile = new File(mDestination); + output = new FileOutputStream(spoolFile); + } catch (IOException ex) { + abortDoc(); + throw new PrinterIOException(ex); } } else { - /* REMIND: This needs to be more maintainable */ - mNoJobSheet = super.noJobSheet; - if (super.destinationAttr != null) { - mDestType = RasterPrinterJob.FILE; - mDestination = super.destinationAttr; - } - if (mDestType == RasterPrinterJob.FILE) { - try { - spoolFile = new File(mDestination); - output = new FileOutputStream(spoolFile); - } catch (IOException ex) { - abortDoc(); - throw new PrinterIOException(ex); - } - } else { - PrinterOpener po = new PrinterOpener(); - po.run(); - if (po.pex != null) { - throw po.pex; - } - output = po.result; + PrinterOpener po = new PrinterOpener(); + po.run(); + if (po.pex != null) { + throw po.pex; } + output = po.result; } - - mPSStream = new PrintStream(new BufferedOutputStream(output)); - mPSStream.println(ADOBE_PS_STR); } + mPSStream = new PrintStream(new BufferedOutputStream(output)); + mPSStream.println(ADOBE_PS_STR); mPSStream.println("%%BeginProlog"); mPSStream.println(READIMAGEPROC); mPSStream.println("/BD {bind def} bind def"); @@ -619,45 +590,43 @@ public class PSPrinterJob extends RasterPrinterJob { mPSStream.println("%%EndProlog"); mPSStream.println("%%BeginSetup"); - if (epsPrinter == null) { - // Set Page Size using first page's format. - PageFormat pageFormat = getPageable().getPageFormat(0); - double paperHeight = pageFormat.getPaper().getHeight(); - double paperWidth = pageFormat.getPaper().getWidth(); + // Set Page Size using first page's format. + PageFormat pageFormat = getPageable().getPageFormat(0); + double paperHeight = pageFormat.getPaper().getHeight(); + double paperWidth = pageFormat.getPaper().getWidth(); - /* PostScript printers can always generate uncollated copies. - */ - mPSStream.print("<< /PageSize [" + - paperWidth + " "+ paperHeight+"]"); + /* PostScript printers can always generate uncollated copies. + */ + mPSStream.print("<< /PageSize [" + + paperWidth + " "+ paperHeight+"]"); - final PrintService pservice = getPrintService(); - Boolean isPS = Boolean.TRUE; - try { - Class psClass = Class.forName("sun.print.IPPPrintService"); - if (psClass.isInstance(pservice)) { - Method isPSMethod = psClass.getMethod("isPostscript", - (Class[])null); - isPS = (Boolean)isPSMethod.invoke(pservice, (Object[])null); - } - } catch (Throwable t) { + final PrintService pservice = getPrintService(); + Boolean isPS = Boolean.TRUE; + try { + Class psClass = Class.forName("sun.print.IPPPrintService"); + if (psClass.isInstance(pservice)) { + Method isPSMethod = psClass.getMethod("isPostscript", + (Class[])null); + isPS = (Boolean)isPSMethod.invoke(pservice, (Object[])null); } - if (isPS) { - mPSStream.print(" /DeferredMediaSelection true"); - } - - mPSStream.print(" /ImagingBBox null /ManualFeed false"); - mPSStream.print(isCollated() ? " /Collate true":""); - mPSStream.print(" /NumCopies " +getCopiesInt()); - - if (sidesAttr != Sides.ONE_SIDED) { - if (sidesAttr == Sides.TWO_SIDED_LONG_EDGE) { - mPSStream.print(" /Duplex true "); - } else if (sidesAttr == Sides.TWO_SIDED_SHORT_EDGE) { - mPSStream.print(" /Duplex true /Tumble true "); - } - } - mPSStream.println(" >> setpagedevice "); + } catch (Throwable t) { } + if (isPS) { + mPSStream.print(" /DeferredMediaSelection true"); + } + + mPSStream.print(" /ImagingBBox null /ManualFeed false"); + mPSStream.print(isCollated() ? " /Collate true":""); + mPSStream.print(" /NumCopies " +getCopiesInt()); + + if (sidesAttr != Sides.ONE_SIDED) { + if (sidesAttr == Sides.TWO_SIDED_LONG_EDGE) { + mPSStream.print(" /Duplex true "); + } else if (sidesAttr == Sides.TWO_SIDED_SHORT_EDGE) { + mPSStream.print(" /Duplex true /Tumble true "); + } + } + mPSStream.println(" >> setpagedevice "); mPSStream.println("%%EndSetup"); } @@ -1175,36 +1144,6 @@ public class PSPrinterJob extends RasterPrinterJob { return psFont; } - - private static String escapeParens(String str) { - if (str.indexOf('(') == -1 && str.indexOf(')') == -1 ) { - return str; - } else { - int count = 0; - int pos = 0; - while ((pos = str.indexOf('(', pos)) != -1) { - count++; - pos++; - } - pos = 0; - while ((pos = str.indexOf(')', pos)) != -1) { - count++; - pos++; - } - char []inArr = str.toCharArray(); - char []outArr = new char[inArr.length+count]; - pos = 0; - for (int i=0;i 0) { - return Printable.NO_SUCH_PAGE; - } else { - // "aware" client code can detect that its been passed a - // PrinterGraphics and could theoretically print - // differently. I think this is more likely useful than - // a problem. - applet.printAll(g); - return Printable.PAGE_EXISTS; - } - } - - } - - /* - * This class can take an application-client supplied printable object - * and send the result to a stream. - * The application does not need to send any postscript to this stream - * unless it needs to specify a translation etc. - * It assumes that its importing application obeys all the conventions - * for importation of EPS. See Appendix H - Encapsulated Postscript File - * Format - of the Adobe Postscript Language Reference Manual, 2nd edition. - * This class could be used as the basis for exposing the ability to - * generate EPSF from 2D graphics as a StreamPrintService. - * In that case a MediaPrintableArea attribute could be used to - * communicate the bounding box. - */ - public static class EPSPrinter implements Pageable { - - private PageFormat pf; - private PSPrinterJob job; - private int llx, lly, urx, ury; - private Printable printable; - private PrintStream stream; - private String epsTitle; - - public EPSPrinter(Printable printable, String title, - PrintStream stream, - int x, int y, int wid, int hgt) { - - this.printable = printable; - this.epsTitle = title; - this.stream = stream; - llx = x; - lly = y; - urx = llx+wid; - ury = lly+hgt; - // construct a PageFormat with zero margins representing the - // exact bounds of the applet. ie construct a theoretical - // paper which happens to exactly match applet panel size. - Paper p = new Paper(); - p.setSize((double)wid, (double)hgt); - p.setImageableArea(0.0,0.0, (double)wid, (double)hgt); - pf = new PageFormat(); - pf.setPaper(p); - } - - public void print() throws PrinterException { - stream.println("%!PS-Adobe-3.0 EPSF-3.0"); - stream.println("%%BoundingBox: " + - llx + " " + lly + " " + urx + " " + ury); - stream.println("%%Title: " + epsTitle); - stream.println("%%Creator: Java Printing"); - stream.println("%%CreationDate: " + new java.util.Date()); - stream.println("%%EndComments"); - stream.println("/pluginSave save def"); - stream.println("mark"); // for restoring stack state on return - - job = new PSPrinterJob(); - job.epsPrinter = this; // modifies the behaviour of PSPrinterJob - job.mPSStream = stream; - job.mDestType = RasterPrinterJob.STREAM; // prevents closure - - job.startDoc(); - try { - job.printPage(this, 0); - } catch (Throwable t) { - if (t instanceof PrinterException) { - throw (PrinterException)t; - } else { - throw new PrinterException(t.toString()); - } - } finally { - stream.println("cleartomark"); // restore stack state - stream.println("pluginSave restore"); - job.endDoc(); - } - stream.flush(); - } - - public int getNumberOfPages() { - return 1; - } - - public PageFormat getPageFormat(int pgIndex) { - if (pgIndex > 0) { - throw new IndexOutOfBoundsException("pgIndex"); - } else { - return pf; - } - } - - public Printable getPrintable(int pgIndex) { - if (pgIndex > 0) { - throw new IndexOutOfBoundsException("pgIndex"); - } else { - return printable; - } - } - - } }