< prev index next >

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

Print this page




 930         /* Scale and translate the unit image.
 931          */
 932         mPSStream.println("[" + destWidth + " 0 "
 933                           + "0 " + destHeight
 934                           + " " + destX + " " + destY
 935                           +"]concat");
 936 
 937         /* Color Image invocation.
 938          */
 939         mPSStream.println(intSrcWidth + " " + intSrcHeight + " " + 8 + "["
 940                           + intSrcWidth + " 0 "
 941                           + "0 " + intSrcHeight
 942                           + " 0 " + 0 + "]"
 943                           + "/imageSrc load false 3 colorimage");
 944 
 945         /* Image data.
 946          */
 947         int index = 0;
 948         byte[] rgbData = new byte[intSrcWidth * 3];
 949 
 950         try {
 951             /* Skip the parts of the image that are not part
 952              * of the source rectangle.
 953              */
 954             index = (int) srcY * srcBitMapWidth;
 955 
 956             for(int i = 0; i < intSrcHeight; i++) {
 957 
 958                 /* Skip the left part of the image that is not
 959                  * part of the source rectangle.
 960                  */
 961                 index += (int) srcX;
 962 
 963                 index = swapBGRtoRGB(bgrData, index, rgbData);
 964                 byte[] encodedData = rlEncode(rgbData);
 965                 byte[] asciiData = ascii85Encode(encodedData);
 966                 mPSStream.write(asciiData);
 967                 mPSStream.println("");
 968             }
 969 
 970             /*
 971              * If there is an IOError we subvert it to a PrinterException.
 972              * Fix: There has got to be a better way, maybe define
 973              * a PrinterIOException and then throw that?
 974              */
 975         } catch (IOException e) {
 976             //throw new PrinterException(e.toString());
 977         }
 978 
 979         mPSStream.println(IMAGE_RESTORE);
 980     }
 981 
 982     /**
 983      * Prints the contents of the array of ints, 'data'
 984      * to the current page. The band is placed at the
 985      * location (x, y) in device coordinates on the
 986      * page. The width and height of the band is
 987      * specified by the caller. Currently the data
 988      * is 24 bits per pixel in BGR format.
 989      */
 990     protected void printBand(byte[] bgrData, int x, int y,
 991                              int width, int height)
 992         throws PrinterException
 993     {
 994 
 995         mPSStream.println(IMAGE_SAVE);
 996 
 997         /* Create a PS string big enough to hold a row of pixels.


1006         /* Scale and translate the unit image.
1007          */
1008         mPSStream.println("[" + width + " 0 "
1009                           + "0 " + height
1010                           + " " + x + " " + y
1011                           +"]concat");
1012 
1013         /* Color Image invocation.
1014          */
1015         mPSStream.println(width + " " + height + " " + 8 + "["
1016                           + width + " 0 "
1017                           + "0 " + -height
1018                           + " 0 " + height + "]"
1019                           + "/imageSrc load false 3 colorimage");
1020 
1021         /* Image data.
1022          */
1023         int index = 0;
1024         byte[] rgbData = new byte[width*3];
1025 
1026         try {
1027             for(int i = 0; i < height; i++) {
1028                 index = swapBGRtoRGB(bgrData, index, rgbData);
1029                 byte[] encodedData = rlEncode(rgbData);
1030                 byte[] asciiData = ascii85Encode(encodedData);
1031                 mPSStream.write(asciiData);
1032                 mPSStream.println("");
1033             }
1034 
1035         } catch (IOException e) {
1036             throw new PrinterIOException(e);
1037         }
1038 
1039         mPSStream.println(IMAGE_RESTORE);
1040     }
1041 
1042     /**
1043      * Examine the metrics captured by the
1044      * {@code PeekGraphics} instance and
1045      * if capable of directly converting this
1046      * print job to the printer's control language
1047      * or the native OS's graphics primitives, then
1048      * return a {@code PSPathGraphics} to perform
1049      * that conversion. If there is not an object
1050      * capable of the conversion then return
1051      * {@code null}. Returning {@code null}
1052      * causes the print job to be rasterized.
1053      */
1054 
1055     protected Graphics2D createPathGraphics(PeekGraphics peekGraphics,
1056                                             PrinterJob printerJob,




 930         /* Scale and translate the unit image.
 931          */
 932         mPSStream.println("[" + destWidth + " 0 "
 933                           + "0 " + destHeight
 934                           + " " + destX + " " + destY
 935                           +"]concat");
 936 
 937         /* Color Image invocation.
 938          */
 939         mPSStream.println(intSrcWidth + " " + intSrcHeight + " " + 8 + "["
 940                           + intSrcWidth + " 0 "
 941                           + "0 " + intSrcHeight
 942                           + " 0 " + 0 + "]"
 943                           + "/imageSrc load false 3 colorimage");
 944 
 945         /* Image data.
 946          */
 947         int index = 0;
 948         byte[] rgbData = new byte[intSrcWidth * 3];
 949 

 950         /* Skip the parts of the image that are not part
 951          * of the source rectangle.
 952          */
 953         index = (int) srcY * srcBitMapWidth;
 954 
 955         for(int i = 0; i < intSrcHeight; i++) {
 956 
 957             /* Skip the left part of the image that is not
 958              * part of the source rectangle.
 959              */
 960             index += (int) srcX;
 961 
 962             index = swapBGRtoRGB(bgrData, index, rgbData);
 963             byte[] encodedData = rlEncode(rgbData);
 964             byte[] asciiData = ascii85Encode(encodedData);
 965             mPSStream.write(asciiData);
 966             mPSStream.println("");
 967         }
 968 
 969         /*
 970          * If there is an IOError we subvert it to a PrinterException.
 971          * Fix: There has got to be a better way, maybe define
 972          * a PrinterIOException and then throw that?
 973          */
 974         //if (mPSStream.checkError()) {
 975               //throw new PrinterException(e.toString());
 976         //}
 977 
 978         mPSStream.println(IMAGE_RESTORE);
 979     }
 980 
 981     /**
 982      * Prints the contents of the array of ints, 'data'
 983      * to the current page. The band is placed at the
 984      * location (x, y) in device coordinates on the
 985      * page. The width and height of the band is
 986      * specified by the caller. Currently the data
 987      * is 24 bits per pixel in BGR format.
 988      */
 989     protected void printBand(byte[] bgrData, int x, int y,
 990                              int width, int height)
 991         throws PrinterException
 992     {
 993 
 994         mPSStream.println(IMAGE_SAVE);
 995 
 996         /* Create a PS string big enough to hold a row of pixels.


1005         /* Scale and translate the unit image.
1006          */
1007         mPSStream.println("[" + width + " 0 "
1008                           + "0 " + height
1009                           + " " + x + " " + y
1010                           +"]concat");
1011 
1012         /* Color Image invocation.
1013          */
1014         mPSStream.println(width + " " + height + " " + 8 + "["
1015                           + width + " 0 "
1016                           + "0 " + -height
1017                           + " 0 " + height + "]"
1018                           + "/imageSrc load false 3 colorimage");
1019 
1020         /* Image data.
1021          */
1022         int index = 0;
1023         byte[] rgbData = new byte[width*3];
1024 

1025         for(int i = 0; i < height; i++) {
1026             index = swapBGRtoRGB(bgrData, index, rgbData);
1027             byte[] encodedData = rlEncode(rgbData);
1028             byte[] asciiData = ascii85Encode(encodedData);
1029             mPSStream.write(asciiData);
1030             mPSStream.println("");
1031         }
1032 
1033         if (mPSStream.checkError()) {
1034             throw new PrinterException("Error in PrintStream");
1035         }
1036 
1037         mPSStream.println(IMAGE_RESTORE);
1038     }
1039 
1040     /**
1041      * Examine the metrics captured by the
1042      * {@code PeekGraphics} instance and
1043      * if capable of directly converting this
1044      * print job to the printer's control language
1045      * or the native OS's graphics primitives, then
1046      * return a {@code PSPathGraphics} to perform
1047      * that conversion. If there is not an object
1048      * capable of the conversion then return
1049      * {@code null}. Returning {@code null}
1050      * causes the print job to be rasterized.
1051      */
1052 
1053     protected Graphics2D createPathGraphics(PeekGraphics peekGraphics,
1054                                             PrinterJob printerJob,


< prev index next >