< prev index next >

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

Print this page




  55  * This class converts paths into PostScript
  56  * by breaking all graphics into fills and
  57  * clips of paths.
  58  */
  59 
  60 class PSPathGraphics extends PathGraphics {
  61 
  62     /**
  63      * For a drawing application the initial user space
  64      * resolution is 72dpi.
  65      */
  66     private static final int DEFAULT_USER_RES = 72;
  67 
  68     PSPathGraphics(Graphics2D graphics, PrinterJob printerJob,
  69                    Printable painter, PageFormat pageFormat, int pageIndex,
  70                    boolean canRedraw) {
  71         super(graphics, printerJob, painter, pageFormat, pageIndex, canRedraw);
  72     }
  73 
  74     /**
  75      * Creates a new <code>Graphics</code> object that is
  76      * a copy of this <code>Graphics</code> object.
  77      * @return     a new graphics context that is a copy of
  78      *                       this graphics context.
  79      * @since      1.0
  80      */
  81     public Graphics create() {
  82 
  83         return new PSPathGraphics((Graphics2D) getDelegate().create(),
  84                                   getPrinterJob(),
  85                                   getPrintable(),
  86                                   getPageFormat(),
  87                                   getPageIndex(),
  88                                   canDoRedraws());
  89     }
  90 
  91 
  92     /**
  93      * Override the inherited implementation of fill
  94      * so that we can generate PostScript in user space
  95      * rather than device space.
  96      */


  98         deviceFill(s.getPathIterator(new AffineTransform()), color);
  99     }
 100 
 101     /**
 102      * Draws the text given by the specified string, using this
 103      * graphics context's current font and color. The baseline of the
 104      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 105      * graphics context's coordinate system.
 106      * @param       str      the string to be drawn.
 107      * @param       x        the <i>x</i> coordinate.
 108      * @param       y        the <i>y</i> coordinate.
 109      * @see         java.awt.Graphics#drawBytes
 110      * @see         java.awt.Graphics#drawChars
 111      * @since       1.0
 112      */
 113     public void drawString(String str, int x, int y) {
 114         drawString(str, (float) x, (float) y);
 115     }
 116 
 117     /**
 118      * Renders the text specified by the specified <code>String</code>,
 119      * using the current <code>Font</code> and <code>Paint</code> attributes
 120      * in the <code>Graphics2D</code> context.
 121      * The baseline of the first character is at position
 122      * (<i>x</i>,&nbsp;<i>y</i>) in the User Space.
 123      * The rendering attributes applied include the <code>Clip</code>,
 124      * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
 125      * <code>Composite</code> attributes. For characters in script systems
 126      * such as Hebrew and Arabic, the glyphs can be rendered from right to
 127      * left, in which case the coordinate supplied is the location of the
 128      * leftmost character on the baseline.
 129      * @param str the <code>String</code> to be rendered
 130      * @param x,&nbsp;y the coordinates where the <code>String</code>
 131      * should be rendered
 132      * @see #setPaint
 133      * @see java.awt.Graphics#setColor
 134      * @see java.awt.Graphics#setFont
 135      * @see #setTransform
 136      * @see #setComposite
 137      * @see #setClip
 138      */
 139      public void drawString(String str, float x, float y) {
 140          drawString(str, x, y, getFont(), getFontRenderContext(), 0f);
 141      }
 142 
 143 
 144     protected boolean canDrawStringToWidth() {
 145         return true;
 146     }
 147 
 148     protected int platformFontCount(Font font, String str) {
 149         PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob();
 150         return psPrinterJob.platformFontCount(font,  str);


 231             }
 232         }
 233 
 234         /* The text could not be converted directly to PS text
 235          * calls so decompose the text into a shape.
 236          */
 237         if (drawnWithPS == false) {
 238             if (oldFont != null) {
 239                 setFont(oldFont);
 240                 oldFont = null;
 241             }
 242             super.drawString(str, x, y, font, frc, w);
 243         }
 244 
 245         if (oldFont != null) {
 246             setFont(oldFont);
 247         }
 248     }
 249 
 250     /**
 251      * The various <code>drawImage()</code> methods for
 252      * <code>WPathGraphics</code> are all decomposed
 253      * into an invocation of <code>drawImageToPlatform</code>.
 254      * The portion of the passed in image defined by
 255      * <code>srcX, srcY, srcWidth, and srcHeight</code>
 256      * is transformed by the supplied AffineTransform and
 257      * drawn using PS to the printer context.
 258      *
 259      * @param   image   The image to be drawn.
 260      *                  This method does nothing if <code>img</code> is null.
 261      * @param   xform   Used to transform the image before drawing.
 262      *                  This can be null.
 263      * @param   bgcolor This color is drawn where the image has transparent
 264      *                  pixels. If this parameter is null then the
 265      *                  pixels already in the destination should show
 266      *                  through.
 267      * @param   srcX    With srcY this defines the upper-left corner
 268      *                  of the portion of the image to be drawn.
 269      *
 270      * @param   srcY    With srcX this defines the upper-left corner
 271      *                  of the portion of the image to be drawn.
 272      * @param   srcWidth    The width of the portion of the image to
 273      *                      be drawn.
 274      * @param   srcHeight   The height of the portion of the image to
 275      *                      be drawn.
 276      * @param   handlingTransparency if being recursively called to
 277      *                    print opaque region of transparent image
 278      */
 279     protected boolean drawImageToPlatform(Image image, AffineTransform xform,
 280                                           Color bgcolor,


 713 
 714 
 715         /* Pull the raster data from the buffered image
 716          * and pass it along to PS.
 717          */
 718         ByteComponentRaster tile = (ByteComponentRaster)deepImage.getRaster();
 719 
 720         psPrinterJob.drawImageBGR(tile.getDataStorage(),
 721                             scaledBounds.x, scaledBounds.y,
 722                             scaledBounds.width,
 723                             scaledBounds.height,
 724                             0f, 0f,
 725                             deepImage.getWidth(), deepImage.getHeight(),
 726                             deepImage.getWidth(), deepImage.getHeight());
 727 
 728 
 729     }
 730 
 731 
 732     /*
 733      * Fill the path defined by <code>pathIter</code>
 734      * with the specified color.
 735      * The path is provided in current user space.
 736      */
 737     protected void deviceFill(PathIterator pathIter, Color color) {
 738 
 739         PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob();
 740         psPrinterJob.deviceFill(pathIter, color, getTransform(), getClip());
 741     }
 742 
 743     /*
 744      * Draw the bounding rectangle using path by calling draw()
 745      * function and passing a rectangle shape.
 746      */
 747     protected void deviceFrameRect(int x, int y, int width, int height,
 748                                    Color color) {
 749 
 750         draw(new Rectangle2D.Float(x, y, width, height));
 751     }
 752 
 753     /*




  55  * This class converts paths into PostScript
  56  * by breaking all graphics into fills and
  57  * clips of paths.
  58  */
  59 
  60 class PSPathGraphics extends PathGraphics {
  61 
  62     /**
  63      * For a drawing application the initial user space
  64      * resolution is 72dpi.
  65      */
  66     private static final int DEFAULT_USER_RES = 72;
  67 
  68     PSPathGraphics(Graphics2D graphics, PrinterJob printerJob,
  69                    Printable painter, PageFormat pageFormat, int pageIndex,
  70                    boolean canRedraw) {
  71         super(graphics, printerJob, painter, pageFormat, pageIndex, canRedraw);
  72     }
  73 
  74     /**
  75      * Creates a new {@code Graphics} object that is
  76      * a copy of this {@code Graphics} object.
  77      * @return     a new graphics context that is a copy of
  78      *                       this graphics context.
  79      * @since      1.0
  80      */
  81     public Graphics create() {
  82 
  83         return new PSPathGraphics((Graphics2D) getDelegate().create(),
  84                                   getPrinterJob(),
  85                                   getPrintable(),
  86                                   getPageFormat(),
  87                                   getPageIndex(),
  88                                   canDoRedraws());
  89     }
  90 
  91 
  92     /**
  93      * Override the inherited implementation of fill
  94      * so that we can generate PostScript in user space
  95      * rather than device space.
  96      */


  98         deviceFill(s.getPathIterator(new AffineTransform()), color);
  99     }
 100 
 101     /**
 102      * Draws the text given by the specified string, using this
 103      * graphics context's current font and color. The baseline of the
 104      * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 105      * graphics context's coordinate system.
 106      * @param       str      the string to be drawn.
 107      * @param       x        the <i>x</i> coordinate.
 108      * @param       y        the <i>y</i> coordinate.
 109      * @see         java.awt.Graphics#drawBytes
 110      * @see         java.awt.Graphics#drawChars
 111      * @since       1.0
 112      */
 113     public void drawString(String str, int x, int y) {
 114         drawString(str, (float) x, (float) y);
 115     }
 116 
 117     /**
 118      * Renders the text specified by the specified {@code String},
 119      * using the current {@code Font} and {@code Paint} attributes
 120      * in the {@code Graphics2D} context.
 121      * The baseline of the first character is at position
 122      * (<i>x</i>,&nbsp;<i>y</i>) in the User Space.
 123      * The rendering attributes applied include the {@code Clip},
 124      * {@code Transform}, {@code Paint}, {@code Font} and
 125      * {@code Composite} attributes. For characters in script systems
 126      * such as Hebrew and Arabic, the glyphs can be rendered from right to
 127      * left, in which case the coordinate supplied is the location of the
 128      * leftmost character on the baseline.
 129      * @param str the {@code String} to be rendered
 130      * @param x,&nbsp;y the coordinates where the {@code String}
 131      * should be rendered
 132      * @see #setPaint
 133      * @see java.awt.Graphics#setColor
 134      * @see java.awt.Graphics#setFont
 135      * @see #setTransform
 136      * @see #setComposite
 137      * @see #setClip
 138      */
 139      public void drawString(String str, float x, float y) {
 140          drawString(str, x, y, getFont(), getFontRenderContext(), 0f);
 141      }
 142 
 143 
 144     protected boolean canDrawStringToWidth() {
 145         return true;
 146     }
 147 
 148     protected int platformFontCount(Font font, String str) {
 149         PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob();
 150         return psPrinterJob.platformFontCount(font,  str);


 231             }
 232         }
 233 
 234         /* The text could not be converted directly to PS text
 235          * calls so decompose the text into a shape.
 236          */
 237         if (drawnWithPS == false) {
 238             if (oldFont != null) {
 239                 setFont(oldFont);
 240                 oldFont = null;
 241             }
 242             super.drawString(str, x, y, font, frc, w);
 243         }
 244 
 245         if (oldFont != null) {
 246             setFont(oldFont);
 247         }
 248     }
 249 
 250     /**
 251      * The various {@code drawImage()} methods for
 252      * {@code WPathGraphics} are all decomposed
 253      * into an invocation of {@code drawImageToPlatform}.
 254      * The portion of the passed in image defined by
 255      * {@code srcX, srcY, srcWidth, and srcHeight}
 256      * is transformed by the supplied AffineTransform and
 257      * drawn using PS to the printer context.
 258      *
 259      * @param   image   The image to be drawn.
 260      *                  This method does nothing if {@code img} is null.
 261      * @param   xform   Used to transform the image before drawing.
 262      *                  This can be null.
 263      * @param   bgcolor This color is drawn where the image has transparent
 264      *                  pixels. If this parameter is null then the
 265      *                  pixels already in the destination should show
 266      *                  through.
 267      * @param   srcX    With srcY this defines the upper-left corner
 268      *                  of the portion of the image to be drawn.
 269      *
 270      * @param   srcY    With srcX this defines the upper-left corner
 271      *                  of the portion of the image to be drawn.
 272      * @param   srcWidth    The width of the portion of the image to
 273      *                      be drawn.
 274      * @param   srcHeight   The height of the portion of the image to
 275      *                      be drawn.
 276      * @param   handlingTransparency if being recursively called to
 277      *                    print opaque region of transparent image
 278      */
 279     protected boolean drawImageToPlatform(Image image, AffineTransform xform,
 280                                           Color bgcolor,


 713 
 714 
 715         /* Pull the raster data from the buffered image
 716          * and pass it along to PS.
 717          */
 718         ByteComponentRaster tile = (ByteComponentRaster)deepImage.getRaster();
 719 
 720         psPrinterJob.drawImageBGR(tile.getDataStorage(),
 721                             scaledBounds.x, scaledBounds.y,
 722                             scaledBounds.width,
 723                             scaledBounds.height,
 724                             0f, 0f,
 725                             deepImage.getWidth(), deepImage.getHeight(),
 726                             deepImage.getWidth(), deepImage.getHeight());
 727 
 728 
 729     }
 730 
 731 
 732     /*
 733      * Fill the path defined by {@code pathIter}
 734      * with the specified color.
 735      * The path is provided in current user space.
 736      */
 737     protected void deviceFill(PathIterator pathIter, Color color) {
 738 
 739         PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob();
 740         psPrinterJob.deviceFill(pathIter, color, getTransform(), getClip());
 741     }
 742 
 743     /*
 744      * Draw the bounding rectangle using path by calling draw()
 745      * function and passing a rectangle shape.
 746      */
 747     protected void deviceFrameRect(int x, int y, int width, int height,
 748                                    Color color) {
 749 
 750         draw(new Rectangle2D.Float(x, y, width, height));
 751     }
 752 
 753     /*


< prev index next >