27
28
29 import java.awt.*;
30 import java.awt.geom.Rectangle2D;
31 import java.awt.image.BufferedImage;
32 import java.awt.print.*;
33 import java.security.AccessController;
34 import java.security.PrivilegedAction;
35
36 import javax.print.*;
37 import javax.print.attribute.PrintRequestAttributeSet;
38 import javax.print.attribute.HashPrintRequestAttributeSet;
39 import javax.print.attribute.standard.Copies;
40 import javax.print.attribute.standard.Media;
41 import javax.print.attribute.standard.MediaPrintableArea;
42 import javax.print.attribute.standard.MediaSize;
43 import javax.print.attribute.standard.MediaSizeName;
44 import javax.print.attribute.standard.PageRanges;
45
46 import sun.java2d.*;
47 import sun.misc.ManagedLocalsThread;
48 import sun.print.*;
49
50 public final class CPrinterJob extends RasterPrinterJob {
51 // NOTE: This uses RasterPrinterJob as a base, but it doesn't use
52 // all of the RasterPrinterJob functions. RasterPrinterJob will
53 // break down printing to pieces that aren't necessary under MacOSX
54 // printing, such as controlling the # of copies and collating. These
55 // are handled by the native printing. RasterPrinterJob is kept for
56 // future compatibility and the state keeping that it handles.
57
58 private static String sShouldNotReachHere = "Should not reach here.";
59
60 private volatile SecondaryLoop printingLoop;
61
62 private boolean noDefaultPrinter = false;
63
64 private static Font defaultFont;
65
66 // This is the NSPrintInfo for this PrinterJob. Protect multi thread
67 // access to it. It is used by the pageDialog, jobDialog, and printLoop.
758 Runnable r = new Runnable() { public void run() { synchronized(ret) {
759 try {
760 int pageResult = printable.print(graphics, pageFormat, pageIndex);
761 if (pageResult != Printable.NO_SUCH_PAGE) {
762 ret[0] = getPageFormatArea(pageFormat);
763 }
764 } catch (Exception e) {} // Original code bailed on any exception
765 }}};
766
767 if (onEventThread) {
768 try { EventQueue.invokeAndWait(r); } catch (Exception e) { e.printStackTrace(); }
769 } else {
770 r.run();
771 }
772
773 synchronized(ret) { return ret[0]; }
774 }
775
776 // upcall from native
777 private static void detachPrintLoop(final long target, final long arg) {
778 new ManagedLocalsThread(() -> _safePrintLoop(target, arg)).start();
779 }
780 private static native void _safePrintLoop(long target, long arg);
781
782 @Override
783 protected void startPage(PageFormat arg0, Printable arg1, int arg2, boolean arg3) throws PrinterException {
784 // TODO Auto-generated method stub
785 }
786
787 @Override
788 protected MediaSize getMediaSize(Media media, PrintService service,
789 PageFormat page) {
790 if (media == null || !(media instanceof MediaSizeName)) {
791 return getDefaultMediaSize(page);
792 }
793 MediaSize size = MediaSize.getMediaSizeForName((MediaSizeName) media);
794 return size != null ? size : getDefaultMediaSize(page);
795 }
796
797 private MediaSize getDefaultMediaSize(PageFormat page){
798 final int inch = 72;
|
27
28
29 import java.awt.*;
30 import java.awt.geom.Rectangle2D;
31 import java.awt.image.BufferedImage;
32 import java.awt.print.*;
33 import java.security.AccessController;
34 import java.security.PrivilegedAction;
35
36 import javax.print.*;
37 import javax.print.attribute.PrintRequestAttributeSet;
38 import javax.print.attribute.HashPrintRequestAttributeSet;
39 import javax.print.attribute.standard.Copies;
40 import javax.print.attribute.standard.Media;
41 import javax.print.attribute.standard.MediaPrintableArea;
42 import javax.print.attribute.standard.MediaSize;
43 import javax.print.attribute.standard.MediaSizeName;
44 import javax.print.attribute.standard.PageRanges;
45
46 import sun.java2d.*;
47 import sun.print.*;
48
49 public final class CPrinterJob extends RasterPrinterJob {
50 // NOTE: This uses RasterPrinterJob as a base, but it doesn't use
51 // all of the RasterPrinterJob functions. RasterPrinterJob will
52 // break down printing to pieces that aren't necessary under MacOSX
53 // printing, such as controlling the # of copies and collating. These
54 // are handled by the native printing. RasterPrinterJob is kept for
55 // future compatibility and the state keeping that it handles.
56
57 private static String sShouldNotReachHere = "Should not reach here.";
58
59 private volatile SecondaryLoop printingLoop;
60
61 private boolean noDefaultPrinter = false;
62
63 private static Font defaultFont;
64
65 // This is the NSPrintInfo for this PrinterJob. Protect multi thread
66 // access to it. It is used by the pageDialog, jobDialog, and printLoop.
757 Runnable r = new Runnable() { public void run() { synchronized(ret) {
758 try {
759 int pageResult = printable.print(graphics, pageFormat, pageIndex);
760 if (pageResult != Printable.NO_SUCH_PAGE) {
761 ret[0] = getPageFormatArea(pageFormat);
762 }
763 } catch (Exception e) {} // Original code bailed on any exception
764 }}};
765
766 if (onEventThread) {
767 try { EventQueue.invokeAndWait(r); } catch (Exception e) { e.printStackTrace(); }
768 } else {
769 r.run();
770 }
771
772 synchronized(ret) { return ret[0]; }
773 }
774
775 // upcall from native
776 private static void detachPrintLoop(final long target, final long arg) {
777 new Thread(null, () -> _safePrintLoop(target, arg),
778 "PrintLoop", 0, false).start();
779 }
780 private static native void _safePrintLoop(long target, long arg);
781
782 @Override
783 protected void startPage(PageFormat arg0, Printable arg1, int arg2, boolean arg3) throws PrinterException {
784 // TODO Auto-generated method stub
785 }
786
787 @Override
788 protected MediaSize getMediaSize(Media media, PrintService service,
789 PageFormat page) {
790 if (media == null || !(media instanceof MediaSizeName)) {
791 return getDefaultMediaSize(page);
792 }
793 MediaSize size = MediaSize.getMediaSizeForName((MediaSizeName) media);
794 return size != null ? size : getDefaultMediaSize(page);
795 }
796
797 private MediaSize getDefaultMediaSize(PageFormat page){
798 final int inch = 72;
|