0N/A/*
2362N/A * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.print;
0N/A
0N/Aimport java.lang.ref.SoftReference;
0N/Aimport java.util.Hashtable;
0N/Aimport sun.font.CharToGlyphMapper;
0N/Aimport sun.font.CompositeFont;
0N/Aimport sun.font.Font2D;
0N/Aimport sun.font.Font2DHandle;
0N/Aimport sun.font.FontManager;
1686N/Aimport sun.font.FontManagerFactory;
1686N/Aimport sun.font.FontUtilities;
0N/A
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Font;
0N/Aimport java.awt.Graphics2D;
0N/Aimport java.awt.Image;
0N/Aimport java.awt.Paint;
0N/Aimport java.awt.Polygon;
0N/Aimport java.awt.Shape;
0N/A
0N/Aimport java.text.AttributedCharacterIterator;
0N/A
0N/Aimport java.awt.font.FontRenderContext;
0N/Aimport java.awt.font.GlyphVector;
0N/Aimport java.awt.font.TextAttribute;
0N/Aimport java.awt.font.TextLayout;
0N/A
0N/Aimport java.awt.geom.AffineTransform;
0N/Aimport java.awt.geom.Arc2D;
0N/Aimport java.awt.geom.Ellipse2D;
0N/Aimport java.awt.geom.Line2D;
0N/Aimport java.awt.geom.Point2D;
0N/Aimport java.awt.geom.Rectangle2D;
0N/Aimport java.awt.geom.RoundRectangle2D;
0N/Aimport java.awt.geom.PathIterator;
0N/A
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.BufferedImageOp;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.DataBuffer;
0N/Aimport java.awt.image.DataBufferInt;
0N/Aimport java.awt.image.ImageObserver;
0N/Aimport java.awt.image.IndexColorModel;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.RenderedImage;
0N/Aimport java.awt.image.SampleModel;
0N/Aimport java.awt.image.SinglePixelPackedSampleModel;
0N/Aimport java.awt.image.VolatileImage;
0N/Aimport sun.awt.image.ByteComponentRaster;
0N/Aimport sun.awt.image.ToolkitImage;
0N/Aimport sun.awt.image.SunWritableRaster;
0N/A
0N/Aimport java.awt.print.PageFormat;
0N/Aimport java.awt.print.Printable;
0N/Aimport java.awt.print.PrinterException;
0N/Aimport java.awt.print.PrinterGraphics;
0N/Aimport java.awt.print.PrinterJob;
0N/A
0N/Aimport java.util.Map;
0N/A
0N/Apublic abstract class PathGraphics extends ProxyGraphics2D {
0N/A
0N/A private Printable mPainter;
0N/A private PageFormat mPageFormat;
0N/A private int mPageIndex;
0N/A private boolean mCanRedraw;
0N/A protected boolean printingGlyphVector;
0N/A
0N/A protected PathGraphics(Graphics2D graphics, PrinterJob printerJob,
0N/A Printable painter, PageFormat pageFormat,
0N/A int pageIndex, boolean canRedraw) {
0N/A super(graphics, printerJob);
0N/A
0N/A mPainter = painter;
0N/A mPageFormat = pageFormat;
0N/A mPageIndex = pageIndex;
0N/A mCanRedraw = canRedraw;
0N/A }
0N/A
0N/A /**
0N/A * Return the Printable instance responsible for drawing
0N/A * into this Graphics.
0N/A */
0N/A protected Printable getPrintable() {
0N/A return mPainter;
0N/A }
0N/A
0N/A /**
0N/A * Return the PageFormat associated with this page of
0N/A * Graphics.
0N/A */
0N/A protected PageFormat getPageFormat() {
0N/A return mPageFormat;
0N/A }
0N/A
0N/A /**
0N/A * Return the page index associated with this Graphics.
0N/A */
0N/A protected int getPageIndex() {
0N/A return mPageIndex;
0N/A }
0N/A
0N/A /**
0N/A * Return true if we are allowed to ask the application
0N/A * to redraw portions of the page. In general, with the
0N/A * PrinterJob API, the application can be asked to do a
0N/A * redraw. When PrinterJob is emulating PrintJob then we
0N/A * can not.
0N/A */
0N/A public boolean canDoRedraws() {
0N/A return mCanRedraw;
0N/A }
0N/A
0N/A /**
0N/A * Redraw a rectanglular area using a proxy graphics
0N/A */
0N/A public abstract void redrawRegion(Rectangle2D region,
0N/A double scaleX, double scaleY,
0N/A Shape clip,
0N/A AffineTransform devTransform)
0N/A
0N/A throws PrinterException ;
0N/A
0N/A /**
0N/A * Draws a line, using the current color, between the points
0N/A * <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
0N/A * in this graphics context's coordinate system.
0N/A * @param x1 the first point's <i>x</i> coordinate.
0N/A * @param y1 the first point's <i>y</i> coordinate.
0N/A * @param x2 the second point's <i>x</i> coordinate.
0N/A * @param y2 the second point's <i>y</i> coordinate.
0N/A */
0N/A public void drawLine(int x1, int y1, int x2, int y2) {
0N/A
0N/A Paint paint = getPaint();
0N/A
0N/A try {
0N/A AffineTransform deviceTransform = getTransform();
0N/A if (getClip() != null) {
0N/A deviceClip(getClip().getPathIterator(deviceTransform));
0N/A }
0N/A
0N/A deviceDrawLine(x1, y1, x2, y2, (Color) paint);
0N/A
0N/A } catch (ClassCastException e) {
0N/A throw new IllegalArgumentException("Expected a Color instance");
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws the outline of the specified rectangle.
0N/A * The left and right edges of the rectangle are at
0N/A * <code>x</code> and <code>x&nbsp;+&nbsp;width</code>.
0N/A * The top and bottom edges are at
0N/A * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
0N/A * The rectangle is drawn using the graphics context's current color.
0N/A * @param x the <i>x</i> coordinate
0N/A * of the rectangle to be drawn.
0N/A * @param y the <i>y</i> coordinate
0N/A * of the rectangle to be drawn.
0N/A * @param width the width of the rectangle to be drawn.
0N/A * @param height the height of the rectangle to be drawn.
0N/A * @see java.awt.Graphics#fillRect
0N/A * @see java.awt.Graphics#clearRect
0N/A */
0N/A public void drawRect(int x, int y, int width, int height) {
0N/A
0N/A Paint paint = getPaint();
0N/A
0N/A try {
0N/A AffineTransform deviceTransform = getTransform();
0N/A if (getClip() != null) {
0N/A deviceClip(getClip().getPathIterator(deviceTransform));
0N/A }
0N/A
0N/A deviceFrameRect(x, y, width, height, (Color) paint);
0N/A
0N/A } catch (ClassCastException e) {
0N/A throw new IllegalArgumentException("Expected a Color instance");
0N/A }
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Fills the specified rectangle.
0N/A * The left and right edges of the rectangle are at
0N/A * <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>.
0N/A * The top and bottom edges are at
0N/A * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
0N/A * The resulting rectangle covers an area
0N/A * <code>width</code> pixels wide by
0N/A * <code>height</code> pixels tall.
0N/A * The rectangle is filled using the graphics context's current color.
0N/A * @param x the <i>x</i> coordinate
0N/A * of the rectangle to be filled.
0N/A * @param y the <i>y</i> coordinate
0N/A * of the rectangle to be filled.
0N/A * @param width the width of the rectangle to be filled.
0N/A * @param height the height of the rectangle to be filled.
0N/A * @see java.awt.Graphics#clearRect
0N/A * @see java.awt.Graphics#drawRect
0N/A */
0N/A public void fillRect(int x, int y, int width, int height){
0N/A
0N/A Paint paint = getPaint();
0N/A
0N/A try {
0N/A AffineTransform deviceTransform = getTransform();
0N/A if (getClip() != null) {
0N/A deviceClip(getClip().getPathIterator(deviceTransform));
0N/A }
0N/A
0N/A deviceFillRect(x, y, width, height, (Color) paint);
0N/A
0N/A } catch (ClassCastException e) {
0N/A throw new IllegalArgumentException("Expected a Color instance");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Clears the specified rectangle by filling it with the background
0N/A * color of the current drawing surface. This operation does not
0N/A * use the current paint mode.
0N/A * <p>
0N/A * Beginning with Java&nbsp;1.1, the background color
0N/A * of offscreen images may be system dependent. Applications should
0N/A * use <code>setColor</code> followed by <code>fillRect</code> to
0N/A * ensure that an offscreen image is cleared to a specific color.
0N/A * @param x the <i>x</i> coordinate of the rectangle to clear.
0N/A * @param y the <i>y</i> coordinate of the rectangle to clear.
0N/A * @param width the width of the rectangle to clear.
0N/A * @param height the height of the rectangle to clear.
0N/A * @see java.awt.Graphics#fillRect(int, int, int, int)
0N/A * @see java.awt.Graphics#drawRect
0N/A * @see java.awt.Graphics#setColor(java.awt.Color)
0N/A * @see java.awt.Graphics#setPaintMode
0N/A * @see java.awt.Graphics#setXORMode(java.awt.Color)
0N/A */
0N/A public void clearRect(int x, int y, int width, int height) {
0N/A
0N/A fill(new Rectangle2D.Float(x, y, width, height), getBackground());
0N/A }
0N/A
0N/A /**
0N/A * Draws an outlined round-cornered rectangle using this graphics
0N/A * context's current color. The left and right edges of the rectangle
0N/A * are at <code>x</code> and <code>x&nbsp;+&nbsp;width</code>,
0N/A * respectively. The top and bottom edges of the rectangle are at
0N/A * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
0N/A * @param x the <i>x</i> coordinate of the rectangle to be drawn.
0N/A * @param y the <i>y</i> coordinate of the rectangle to be drawn.
0N/A * @param width the width of the rectangle to be drawn.
0N/A * @param height the height of the rectangle to be drawn.
0N/A * @param arcWidth the horizontal diameter of the arc
0N/A * at the four corners.
0N/A * @param arcHeight the vertical diameter of the arc
0N/A * at the four corners.
0N/A * @see java.awt.Graphics#fillRoundRect
0N/A */
0N/A public void drawRoundRect(int x, int y, int width, int height,
0N/A int arcWidth, int arcHeight) {
0N/A
0N/A draw(new RoundRectangle2D.Float(x, y,
0N/A width, height,
0N/A arcWidth, arcHeight));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Fills the specified rounded corner rectangle with the current color.
0N/A * The left and right edges of the rectangle
0N/A * are at <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>,
0N/A * respectively. The top and bottom edges of the rectangle are at
0N/A * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
0N/A * @param x the <i>x</i> coordinate of the rectangle to be filled.
0N/A * @param y the <i>y</i> coordinate of the rectangle to be filled.
0N/A * @param width the width of the rectangle to be filled.
0N/A * @param height the height of the rectangle to be filled.
0N/A * @param arcWidth the horizontal diameter
0N/A * of the arc at the four corners.
0N/A * @param arcHeight the vertical diameter
0N/A * of the arc at the four corners.
0N/A * @see java.awt.Graphics#drawRoundRect
0N/A */
0N/A public void fillRoundRect(int x, int y, int width, int height,
0N/A int arcWidth, int arcHeight) {
0N/A
0N/A fill(new RoundRectangle2D.Float(x, y,
0N/A width, height,
0N/A arcWidth, arcHeight));
0N/A }
0N/A
0N/A /**
0N/A * Draws the outline of an oval.
0N/A * The result is a circle or ellipse that fits within the
0N/A * rectangle specified by the <code>x</code>, <code>y</code>,
0N/A * <code>width</code>, and <code>height</code> arguments.
0N/A * <p>
0N/A * The oval covers an area that is
0N/A * <code>width&nbsp;+&nbsp;1</code> pixels wide
0N/A * and <code>height&nbsp;+&nbsp;1</code> pixels tall.
0N/A * @param x the <i>x</i> coordinate of the upper left
0N/A * corner of the oval to be drawn.
0N/A * @param y the <i>y</i> coordinate of the upper left
0N/A * corner of the oval to be drawn.
0N/A * @param width the width of the oval to be drawn.
0N/A * @param height the height of the oval to be drawn.
0N/A * @see java.awt.Graphics#fillOval
0N/A * @since JDK1.0
0N/A */
0N/A public void drawOval(int x, int y, int width, int height) {
0N/A draw(new Ellipse2D.Float(x, y, width, height));
0N/A }
0N/A
0N/A /**
0N/A * Fills an oval bounded by the specified rectangle with the
0N/A * current color.
0N/A * @param x the <i>x</i> coordinate of the upper left corner
0N/A * of the oval to be filled.
0N/A * @param y the <i>y</i> coordinate of the upper left corner
0N/A * of the oval to be filled.
0N/A * @param width the width of the oval to be filled.
0N/A * @param height the height of the oval to be filled.
0N/A * @see java.awt.Graphics#drawOval
0N/A */
0N/A public void fillOval(int x, int y, int width, int height){
0N/A
0N/A fill(new Ellipse2D.Float(x, y, width, height));
0N/A }
0N/A
0N/A /**
0N/A * Draws the outline of a circular or elliptical arc
0N/A * covering the specified rectangle.
0N/A * <p>
0N/A * The resulting arc begins at <code>startAngle</code> and extends
0N/A * for <code>arcAngle</code> degrees, using the current color.
0N/A * Angles are interpreted such that 0&nbsp;degrees
0N/A * is at the 3&nbsp;o'clock position.
0N/A * A positive value indicates a counter-clockwise rotation
0N/A * while a negative value indicates a clockwise rotation.
0N/A * <p>
0N/A * The center of the arc is the center of the rectangle whose origin
0N/A * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
0N/A * <code>width</code> and <code>height</code> arguments.
0N/A * <p>
0N/A * The resulting arc covers an area
0N/A * <code>width&nbsp;+&nbsp;1</code> pixels wide
0N/A * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
0N/A * <p>
0N/A * The angles are specified relative to the non-square extents of
0N/A * the bounding rectangle such that 45 degrees always falls on the
0N/A * line from the center of the ellipse to the upper right corner of
0N/A * the bounding rectangle. As a result, if the bounding rectangle is
0N/A * noticeably longer in one axis than the other, the angles to the
0N/A * start and end of the arc segment will be skewed farther along the
0N/A * longer axis of the bounds.
0N/A * @param x the <i>x</i> coordinate of the
0N/A * upper-left corner of the arc to be drawn.
0N/A * @param y the <i>y</i> coordinate of the
0N/A * upper-left corner of the arc to be drawn.
0N/A * @param width the width of the arc to be drawn.
0N/A * @param height the height of the arc to be drawn.
0N/A * @param startAngle the beginning angle.
0N/A * @param arcAngle the angular extent of the arc,
0N/A * relative to the start angle.
0N/A * @see java.awt.Graphics#fillArc
0N/A */
0N/A public void drawArc(int x, int y, int width, int height,
0N/A int startAngle, int arcAngle) {
0N/A draw(new Arc2D.Float(x, y, width, height,
0N/A startAngle, arcAngle,
0N/A Arc2D.OPEN));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Fills a circular or elliptical arc covering the specified rectangle.
0N/A * <p>
0N/A * The resulting arc begins at <code>startAngle</code> and extends
0N/A * for <code>arcAngle</code> degrees.
0N/A * Angles are interpreted such that 0&nbsp;degrees
0N/A * is at the 3&nbsp;o'clock position.
0N/A * A positive value indicates a counter-clockwise rotation
0N/A * while a negative value indicates a clockwise rotation.
0N/A * <p>
0N/A * The center of the arc is the center of the rectangle whose origin
0N/A * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
0N/A * <code>width</code> and <code>height</code> arguments.
0N/A * <p>
0N/A * The resulting arc covers an area
0N/A * <code>width&nbsp;+&nbsp;1</code> pixels wide
0N/A * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
0N/A * <p>
0N/A * The angles are specified relative to the non-square extents of
0N/A * the bounding rectangle such that 45 degrees always falls on the
0N/A * line from the center of the ellipse to the upper right corner of
0N/A * the bounding rectangle. As a result, if the bounding rectangle is
0N/A * noticeably longer in one axis than the other, the angles to the
0N/A * start and end of the arc segment will be skewed farther along the
0N/A * longer axis of the bounds.
0N/A * @param x the <i>x</i> coordinate of the
0N/A * upper-left corner of the arc to be filled.
0N/A * @param y the <i>y</i> coordinate of the
0N/A * upper-left corner of the arc to be filled.
0N/A * @param width the width of the arc to be filled.
0N/A * @param height the height of the arc to be filled.
0N/A * @param startAngle the beginning angle.
0N/A * @param arcAngle the angular extent of the arc,
0N/A * relative to the start angle.
0N/A * @see java.awt.Graphics#drawArc
0N/A */
0N/A public void fillArc(int x, int y, int width, int height,
0N/A int startAngle, int arcAngle) {
0N/A
0N/A fill(new Arc2D.Float(x, y, width, height,
0N/A startAngle, arcAngle,
0N/A Arc2D.PIE));
0N/A }
0N/A
0N/A /**
0N/A * Draws a sequence of connected lines defined by
0N/A * arrays of <i>x</i> and <i>y</i> coordinates.
0N/A * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
0N/A * The figure is not closed if the first point
0N/A * differs from the last point.
0N/A * @param xPoints an array of <i>x</i> points
0N/A * @param yPoints an array of <i>y</i> points
0N/A * @param nPoints the total number of points
0N/A * @see java.awt.Graphics#drawPolygon(int[], int[], int)
0N/A * @since JDK1.1
0N/A */
0N/A public void drawPolyline(int xPoints[], int yPoints[],
0N/A int nPoints) {
0N/A float fromX;
0N/A float fromY;
0N/A float toX;
0N/A float toY;
0N/A
0N/A if (nPoints > 0) {
0N/A fromX = xPoints[0];
0N/A fromY = yPoints[0];
0N/A for(int i = 1; i < nPoints; i++) {
0N/A toX = xPoints[i];
0N/A toY = yPoints[i];
0N/A draw(new Line2D.Float(fromX, fromY, toX, toY));
0N/A fromX = toX;
0N/A fromY = toY;
0N/A }
0N/A }
0N/A
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Draws a closed polygon defined by
0N/A * arrays of <i>x</i> and <i>y</i> coordinates.
0N/A * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
0N/A * <p>
0N/A * This method draws the polygon defined by <code>nPoint</code> line
0N/A * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
0N/A * line segments are line segments from
0N/A * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
0N/A * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
0N/A * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
0N/A * The figure is automatically closed by drawing a line connecting
0N/A * the final point to the first point, if those points are different.
0N/A * @param xPoints a an array of <code>x</code> coordinates.
0N/A * @param yPoints a an array of <code>y</code> coordinates.
0N/A * @param nPoints a the total number of points.
0N/A * @see java.awt.Graphics#fillPolygon
0N/A * @see java.awt.Graphics#drawPolyline
0N/A */
0N/A public void drawPolygon(int xPoints[], int yPoints[],
0N/A int nPoints) {
0N/A
0N/A draw(new Polygon(xPoints, yPoints, nPoints));
0N/A }
0N/A
0N/A /**
0N/A * Draws the outline of a polygon defined by the specified
0N/A * <code>Polygon</code> object.
0N/A * @param p the polygon to draw.
0N/A * @see java.awt.Graphics#fillPolygon
0N/A * @see java.awt.Graphics#drawPolyline
0N/A */
0N/A public void drawPolygon(Polygon p) {
0N/A draw(p);
0N/A }
0N/A
0N/A /**
0N/A * Fills a closed polygon defined by
0N/A * arrays of <i>x</i> and <i>y</i> coordinates.
0N/A * <p>
0N/A * This method draws the polygon defined by <code>nPoint</code> line
0N/A * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
0N/A * line segments are line segments from
0N/A * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
0N/A * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
0N/A * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
0N/A * The figure is automatically closed by drawing a line connecting
0N/A * the final point to the first point, if those points are different.
0N/A * <p>
0N/A * The area inside the polygon is defined using an
0N/A * even-odd fill rule, also known as the alternating rule.
0N/A * @param xPoints a an array of <code>x</code> coordinates.
0N/A * @param yPoints a an array of <code>y</code> coordinates.
0N/A * @param nPoints a the total number of points.
0N/A * @see java.awt.Graphics#drawPolygon(int[], int[], int)
0N/A */
0N/A public void fillPolygon(int xPoints[], int yPoints[],
0N/A int nPoints) {
0N/A
0N/A fill(new Polygon(xPoints, yPoints, nPoints));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Fills the polygon defined by the specified Polygon object with
0N/A * the graphics context's current color.
0N/A * <p>
0N/A * The area inside the polygon is defined using an
0N/A * even-odd fill rule, also known as the alternating rule.
0N/A * @param p the polygon to fill.
0N/A * @see java.awt.Graphics#drawPolygon(int[], int[], int)
0N/A */
0N/A public void fillPolygon(Polygon p) {
0N/A
0N/A fill(p);
0N/A }
0N/A
0N/A /**
0N/A * Draws the text given by the specified string, using this
0N/A * graphics context's current font and color. The baseline of the
0N/A * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
0N/A * graphics context's coordinate system.
0N/A * @param str the string to be drawn.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @see java.awt.Graphics#drawBytes
0N/A * @see java.awt.Graphics#drawChars
0N/A * @since JDK1.0
0N/A */
0N/A public void drawString(String str, int x, int y) {
0N/A drawString(str, (float) x, (float) y);
0N/A }
0N/A
0N/A public void drawString(String str, float x, float y) {
0N/A if (str.length() == 0) {
0N/A return;
0N/A }
0N/A TextLayout layout =
0N/A new TextLayout(str, getFont(), getFontRenderContext());
0N/A layout.draw(this, x, y);
0N/A }
0N/A
0N/A protected void drawString(String str, float x, float y,
0N/A Font font, FontRenderContext frc, float w) {
0N/A TextLayout layout =
0N/A new TextLayout(str, font, frc);
0N/A Shape textShape =
0N/A layout.getOutline(AffineTransform.getTranslateInstance(x, y));
0N/A fill(textShape);
0N/A }
0N/A
0N/A /**
0N/A * Draws the text given by the specified iterator, using this
0N/A * graphics context's current color. The iterator has to specify a font
0N/A * for each character. The baseline of the
0N/A * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
0N/A * graphics context's coordinate system.
0N/A * @param iterator the iterator whose text is to be drawn
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @see java.awt.Graphics#drawBytes
0N/A * @see java.awt.Graphics#drawChars
0N/A */
0N/A public void drawString(AttributedCharacterIterator iterator,
0N/A int x, int y) {
0N/A drawString(iterator, (float) x, (float) y);
0N/A }
0N/A public void drawString(AttributedCharacterIterator iterator,
0N/A float x, float y) {
0N/A if (iterator == null) {
0N/A throw
0N/A new NullPointerException("attributedcharacteriterator is null");
0N/A }
0N/A TextLayout layout =
0N/A new TextLayout(iterator, getFontRenderContext());
0N/A layout.draw(this, x, y);
0N/A }
0N/A
0N/A /**
0N/A * Draws a GlyphVector.
0N/A * The rendering attributes applied include the clip, transform,
0N/A * paint or color, and composite attributes. The GlyphVector specifies
0N/A * individual glyphs from a Font.
0N/A * @param g The GlyphVector to be drawn.
0N/A * @param x,y The coordinates where the glyphs should be drawn.
0N/A * @see #setPaint
0N/A * @see java.awt.Graphics#setColor
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public void drawGlyphVector(GlyphVector g,
0N/A float x,
0N/A float y) {
0N/A
0N/A /* We should not reach here if printingGlyphVector is already true.
0N/A * Add an assert so this can be tested if need be.
0N/A * But also ensure that we do at least render properly by filling
0N/A * the outline.
0N/A */
0N/A if (printingGlyphVector) {
0N/A assert !printingGlyphVector; // ie false.
0N/A fill(g.getOutline(x, y));
0N/A return;
0N/A }
0N/A
0N/A try {
0N/A printingGlyphVector = true;
0N/A if (RasterPrinterJob.shapeTextProp ||
0N/A !printedSimpleGlyphVector(g, x, y)) {
0N/A fill(g.getOutline(x, y));
0N/A }
0N/A } finally {
0N/A printingGlyphVector = false;
0N/A }
0N/A }
0N/A
0N/A protected static SoftReference<Hashtable<Font2DHandle,Object>>
0N/A fontMapRef = new SoftReference<Hashtable<Font2DHandle,Object>>(null);
0N/A
0N/A protected int platformFontCount(Font font, String str) {
0N/A return 0;
0N/A }
0N/A
0N/A /**
0N/A * Default implementation returns false.
0N/A * Callers of this method must always be prepared for this,
0N/A * and delegate to outlines or some other solution.
0N/A */
0N/A protected boolean printGlyphVector(GlyphVector gv, float x, float y) {
0N/A return false;
0N/A }
0N/A
0N/A /* GlyphVectors are usually encountered because TextLayout is in use.
0N/A * Some times TextLayout is needed to handle complex text or some
0N/A * rendering attributes trigger it.
0N/A * We try to print GlyphVectors by reconstituting into a String,
0N/A * as that is most recoverable for applications that export to formats
0N/A * such as Postscript or PDF. In some cases (eg where its not complex
0N/A * text and its just that positions aren't what we'd expect) we print
0N/A * one character at a time. positioning individually.
0N/A * Failing that, if we can directly send glyph codes to the printer
0N/A * then we do that (printGlyphVector).
0N/A * As a last resort we return false and let the caller print as filled
0N/A * shapes.
0N/A */
0N/A boolean printedSimpleGlyphVector(GlyphVector g, float x, float y) {
0N/A
0N/A int flags = g.getLayoutFlags();
0N/A
0N/A /* We can't handle RTL, re-ordering, complex glyphs etc by
0N/A * reconstituting glyphs into a String. So if any flags besides
0N/A * position adjustments are set, see if we can directly
0N/A * print the GlyphVector as glyph codes, using the positions
0N/A * layout has assigned. If that fails return false;
0N/A */
0N/A if (flags != 0 && flags != GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS) {
0N/A return printGlyphVector(g, x, y);
0N/A }
0N/A
0N/A Font font = g.getFont();
1686N/A Font2D font2D = FontUtilities.getFont2D(font);
0N/A if (font2D.handle.font2D != font2D) {
0N/A /* suspicious, may be a bad font. lets bail */
0N/A return false;
0N/A }
0N/A Hashtable<Font2DHandle,Object> fontMap;
0N/A synchronized (PathGraphics.class) {
0N/A fontMap = fontMapRef.get();
0N/A if (fontMap == null) {
0N/A fontMap = new Hashtable<Font2DHandle,Object>();
0N/A fontMapRef =
0N/A new SoftReference<Hashtable<Font2DHandle,Object>>(fontMap);
0N/A }
0N/A }
0N/A
0N/A int numGlyphs = g.getNumGlyphs();
0N/A int[] glyphCodes = g.getGlyphCodes(0, numGlyphs, null);
0N/A
0N/A char[] glyphToCharMap = null;
0N/A char[][] mapArray = null;
0N/A CompositeFont cf = null;
0N/A
0N/A /* Build the needed maps for this font in a synchronized block */
0N/A synchronized (fontMap) {
0N/A if (font2D instanceof CompositeFont) {
0N/A cf = (CompositeFont)font2D;
0N/A int numSlots = cf.getNumSlots();
0N/A mapArray = (char[][])fontMap.get(font2D.handle);
0N/A if (mapArray == null) {
0N/A mapArray = new char[numSlots][];
0N/A fontMap.put(font2D.handle, mapArray);
0N/A }
0N/A for (int i=0; i<numGlyphs;i++) {
0N/A int slot = glyphCodes[i] >>> 24;
0N/A if (slot >= numSlots) { /* shouldn't happen */
0N/A return false;
0N/A }
0N/A if (mapArray[slot] == null) {
0N/A Font2D slotFont = cf.getSlotFont(slot);
0N/A char[] map = (char[])fontMap.get(slotFont.handle);
0N/A if (map == null) {
0N/A map = getGlyphToCharMapForFont(slotFont);
0N/A }
0N/A mapArray[slot] = map;
0N/A }
0N/A }
0N/A } else {
0N/A glyphToCharMap = (char[])fontMap.get(font2D.handle);
0N/A if (glyphToCharMap == null) {
0N/A glyphToCharMap = getGlyphToCharMapForFont(font2D);
0N/A fontMap.put(font2D.handle, glyphToCharMap);
0N/A }
0N/A }
0N/A }
0N/A
0N/A char[] chars = new char[numGlyphs];
0N/A if (cf != null) {
0N/A for (int i=0; i<numGlyphs; i++) {
0N/A int gc = glyphCodes[i];
0N/A char[] map = mapArray[gc >>> 24];
0N/A gc = gc & 0xffffff;
0N/A if (map == null) {
0N/A return false;
0N/A }
0N/A /* X11 symbol & dingbats fonts used only for global metrics,
0N/A * so the glyph codes we have really refer to Lucida Sans
0N/A * Regular.
0N/A * So its possible the glyph code may appear out of range.
0N/A * Note that later on we double-check the glyph codes that
0N/A * we get from re-creating the GV from the string are the
0N/A * same as those we started with.
0N/A *
0N/A * If the glyphcode is INVISIBLE_GLYPH_ID then this may
0N/A * be \t, \n or \r which are mapped to that by layout.
0N/A * This is a case we can handle. It doesn't matter what
0N/A * character we use (we use \n) so long as layout maps it
0N/A * back to this in the verification, since the invisible
0N/A * glyph isn't visible :)
0N/A */
0N/A char ch;
0N/A if (gc == CharToGlyphMapper.INVISIBLE_GLYPH_ID) {
0N/A ch = '\n';
0N/A } else if (gc < 0 || gc >= map.length) {
0N/A return false;
0N/A } else {
0N/A ch = map[gc];
0N/A }
0N/A if (ch != CharToGlyphMapper.INVISIBLE_GLYPH_ID) {
0N/A chars[i] = ch;
0N/A } else {
0N/A return false;
0N/A }
0N/A }
0N/A } else {
0N/A for (int i=0; i<numGlyphs; i++) {
0N/A int gc = glyphCodes[i];
0N/A char ch;
0N/A if (gc == CharToGlyphMapper.INVISIBLE_GLYPH_ID) {
0N/A ch = '\n';
0N/A } else if (gc < 0 || gc >= glyphToCharMap.length) {
0N/A return false;
0N/A } else {
0N/A ch = glyphToCharMap[gc];
0N/A }
0N/A if (ch != CharToGlyphMapper.INVISIBLE_GLYPH_ID) {
0N/A chars[i] = ch;
0N/A } else {
0N/A return false;
0N/A }
0N/A }
0N/A }
0N/A
0N/A FontRenderContext gvFrc = g.getFontRenderContext();
0N/A GlyphVector gv2 = font.createGlyphVector(gvFrc, chars);
0N/A if (gv2.getNumGlyphs() != numGlyphs) {
0N/A return printGlyphVector(g, x, y);
0N/A }
0N/A int[] glyphCodes2 = gv2.getGlyphCodes(0, numGlyphs, null);
0N/A /*
0N/A * Needed to double-check remapping of X11 symbol & dingbats.
0N/A */
0N/A for (int i=0; i<numGlyphs; i++) {
0N/A if (glyphCodes[i] != glyphCodes2[i]) {
0N/A return printGlyphVector(g, x, y);
0N/A }
0N/A }
0N/A
0N/A FontRenderContext g2dFrc = getFontRenderContext();
0N/A boolean compatibleFRC = gvFrc.equals(g2dFrc);
0N/A /* If differ only in specifying A-A or a translation, these are
0N/A * also compatible FRC's, and we can do one drawString call.
0N/A */
0N/A if (!compatibleFRC &&
0N/A gvFrc.usesFractionalMetrics() == g2dFrc.usesFractionalMetrics()) {
0N/A AffineTransform gvAT = gvFrc.getTransform();
0N/A AffineTransform g2dAT = getTransform();
0N/A double[] gvMatrix = new double[4];
0N/A double[] g2dMatrix = new double[4];
0N/A gvAT.getMatrix(gvMatrix);
0N/A g2dAT.getMatrix(g2dMatrix);
0N/A compatibleFRC = true;
0N/A for (int i=0;i<4;i++) {
0N/A if (gvMatrix[i] != g2dMatrix[i]) {
0N/A compatibleFRC = false;
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A String str = new String(chars, 0, numGlyphs);
0N/A int numFonts = platformFontCount(font, str);
0N/A if (numFonts == 0) {
0N/A return false;
0N/A }
0N/A
0N/A float[] positions = g.getGlyphPositions(0, numGlyphs, null);
0N/A boolean noPositionAdjustments =
0N/A ((flags & GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS) == 0) ||
0N/A samePositions(gv2, glyphCodes2, glyphCodes, positions);
0N/A
0N/A /* We have to consider that the application may be directly
0N/A * creating a GlyphVector, rather than one being created by
0N/A * TextLayout or indirectly from drawString. In such a case, if the
0N/A * font has layout attributes, the text may measure differently
0N/A * when we reconstitute it into a String and ask for the length that
0N/A * drawString would use. For example, KERNING will be applied in such
0N/A * a case but that Font attribute is not applied when the application
0N/A * directly created a GlyphVector. So in this case we need to verify
0N/A * that the text measures the same in both cases - ie that the
0N/A * layout attribute has no effect. If it does we can't always
0N/A * use the drawString call unless we can coerce the drawString call
0N/A * into measuring and displaying the string to the same length.
0N/A * That is the case where there is only one font used and we can
0N/A * specify the overall advance of the string. (See below).
0N/A */
0N/A
0N/A Point2D gvAdvancePt = g.getGlyphPosition(numGlyphs);
0N/A float gvAdvanceX = (float)gvAdvancePt.getX();
0N/A boolean layoutAffectsAdvance = false;
0N/A if (font.hasLayoutAttributes() && printingGlyphVector &&
0N/A noPositionAdjustments) {
0N/A
0N/A /* If TRACKING is in use then the glyph vector will report
0N/A * position adjustments, then that ought to be sufficient to
0N/A * tell us we can't just ask native to do "drawString". But layout
0N/A * always sets the position adjustment flag, so we don't believe
0N/A * it and verify the positions are really different than
0N/A * createGlyphVector() (with no layout) would create. However
0N/A * inconsistently, TRACKING is applied when creating a GlyphVector,
0N/A * since it doesn't actually require "layout" (even though its
0N/A * considered a layout attribute), it just requires a fractional
0N/A * tweak to the[default]advances. So we need to specifically
0N/A * check for tracking until such time as as we can trust
0N/A * the GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS bit.
0N/A */
0N/A Map<TextAttribute, ?> map = font.getAttributes();
0N/A Object o = map.get(TextAttribute.TRACKING);
0N/A boolean tracking = o != null && (o instanceof Number) &&
0N/A (((Number)o).floatValue() != 0f);
0N/A
0N/A if (tracking) {
0N/A noPositionAdjustments = false;
0N/A } else {
0N/A Rectangle2D bounds = font.getStringBounds(str, gvFrc);
0N/A float strAdvanceX = (float)bounds.getWidth();
0N/A if (Math.abs(strAdvanceX - gvAdvanceX) > 0.00001) {
0N/A layoutAffectsAdvance = true;
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (compatibleFRC && noPositionAdjustments && !layoutAffectsAdvance) {
0N/A drawString(str, x, y, font, gvFrc, 0f);
0N/A return true;
0N/A }
0N/A
0N/A /* If positions have not been explicitly assigned, we can
0N/A * ask the string to be drawn adjusted to this width.
0N/A * This call is supported only in the PS generator.
0N/A * GDI has API to specify the advance for each glyph in a
0N/A * string which could be used here too, but that is not yet
0N/A * implemented, and we'd need to update the signature of the
0N/A * drawString method to take the advances (ie relative positions)
0N/A * and use that instead of the width.
0N/A */
0N/A if (numFonts == 1 && canDrawStringToWidth() && noPositionAdjustments) {
0N/A drawString(str, x, y, font, gvFrc, gvAdvanceX);
0N/A return true;
0N/A }
0N/A
0N/A /* In some scripts chars drawn individually do not have the
0N/A * same representation (glyphs) as when combined with other chars.
0N/A * The logic here is erring on the side of caution, in particular
0N/A * in including supplementary characters.
0N/A */
1686N/A if (FontUtilities.isComplexText(chars, 0, chars.length)) {
0N/A return printGlyphVector(g, x, y);
0N/A }
0N/A
0N/A /* If we reach here we have mapped all the glyphs back
0N/A * one-to-one to simple unicode chars that we know are in the font.
0N/A * We can call "drawChars" on each one of them in turn, setting
0N/A * the position based on the glyph positions.
0N/A * There's typically overhead in this. If numGlyphs is 'large',
0N/A * it may even be better to try printGlyphVector() in this case.
0N/A * This may be less recoverable for apps, but sophisticated apps
0N/A * should be able to recover the text from simple glyph vectors
0N/A * and we can avoid penalising the more common case - although
0N/A * this is already a minority case.
0N/A */
0N/A if (numGlyphs > 10 && printGlyphVector(g, x, y)) {
0N/A return true;
0N/A }
0N/A
0N/A for (int i=0; i<numGlyphs; i++) {
0N/A String s = new String(chars, i, 1);
0N/A drawString(s, x+positions[i*2], y+positions[i*2+1],
0N/A font, gvFrc, 0f);
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A /* The same codes must be in the same positions for this to return true.
0N/A * This would look cleaner if it took the original GV as a parameter but
0N/A * we already have the codes and will need to get the positions array
0N/A * too in most cases anyway. So its cheaper to pass them in.
0N/A * This call wouldn't be necessary if layout didn't always set the
0N/A * FLAG_HAS_POSITION_ADJUSTMENTS even if the default advances are used
0N/A * and there was no re-ordering (this should be fixed some day).
0N/A */
0N/A private boolean samePositions(GlyphVector gv, int[] gvcodes,
0N/A int[] origCodes, float[] origPositions) {
0N/A
0N/A int numGlyphs = gv.getNumGlyphs();
0N/A float[] gvpos = gv.getGlyphPositions(0, numGlyphs, null);
0N/A
0N/A /* this shouldn't happen here, but just in case */
0N/A if (numGlyphs != gvcodes.length || /* real paranoia here */
0N/A origCodes.length != gvcodes.length ||
0N/A origPositions.length != gvpos.length) {
0N/A return false;
0N/A }
0N/A
0N/A for (int i=0; i<numGlyphs; i++) {
0N/A if (gvcodes[i] != origCodes[i] || gvpos[i] != origPositions[i]) {
0N/A return false;
0N/A }
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A protected boolean canDrawStringToWidth() {
0N/A return false;
0N/A }
0N/A
0N/A /* return an array which can map glyphs back to char codes.
0N/A * Glyphs which aren't mapped from a simple unicode code point
0N/A * will have no mapping in this array, and will be assumed to be
0N/A * because of some substitution that we can't handle.
0N/A */
0N/A private static char[] getGlyphToCharMapForFont(Font2D font2D) {
0N/A /* NB Composites report the number of glyphs in slot 0.
0N/A * So if a string uses a char from a later slot, or a fallback slot,
0N/A * it will not be able to use this faster path.
0N/A */
0N/A int numGlyphs = font2D.getNumGlyphs();
0N/A int missingGlyph = font2D.getMissingGlyphCode();
0N/A char[] glyphToCharMap = new char[numGlyphs];
0N/A int glyph;
0N/A
0N/A for (int i=0;i<numGlyphs; i++) {
0N/A glyphToCharMap[i] = CharToGlyphMapper.INVISIBLE_GLYPH_ID;
0N/A }
0N/A
0N/A /* Consider refining the ranges to try to map by asking the font
0N/A * what ranges it supports.
0N/A * Since a glyph may be mapped by multiple code points, and this
0N/A * code can't handle that, we always prefer the earlier code point.
0N/A */
0N/A for (char c=0; c<0xFFFF; c++) {
0N/A if (c >= CharToGlyphMapper.HI_SURROGATE_START &&
0N/A c <= CharToGlyphMapper.LO_SURROGATE_END) {
0N/A continue;
0N/A }
0N/A glyph = font2D.charToGlyph(c);
4798N/A if (glyph != missingGlyph &&
4798N/A glyph >= 0 && glyph < numGlyphs &&
0N/A (glyphToCharMap[glyph] ==
0N/A CharToGlyphMapper.INVISIBLE_GLYPH_ID)) {
0N/A glyphToCharMap[glyph] = c;
0N/A }
0N/A }
0N/A return glyphToCharMap;
0N/A }
0N/A
0N/A /**
0N/A * Strokes the outline of a Shape using the settings of the current
0N/A * graphics state. The rendering attributes applied include the
0N/A * clip, transform, paint or color, composite and stroke attributes.
0N/A * @param s The shape to be drawn.
0N/A * @see #setStroke
0N/A * @see #setPaint
0N/A * @see java.awt.Graphics#setColor
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #clip
0N/A * @see #setClip
0N/A * @see #setComposite
0N/A */
0N/A public void draw(Shape s) {
0N/A
0N/A fill(getStroke().createStrokedShape(s));
0N/A }
0N/A
0N/A /**
0N/A * Fills the interior of a Shape using the settings of the current
0N/A * graphics state. The rendering attributes applied include the
0N/A * clip, transform, paint or color, and composite.
0N/A * @see #setPaint
0N/A * @see java.awt.Graphics#setColor
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public void fill(Shape s) {
0N/A Paint paint = getPaint();
0N/A
0N/A try {
0N/A fill(s, (Color) paint);
0N/A
0N/A /* The PathGraphics class only supports filling with
0N/A * solid colors and so we do not expect the cast of Paint
0N/A * to Color to fail. If it does fail then something went
0N/A * wrong, like the app draw a page with a solid color but
0N/A * then redrew it with a Gradient.
0N/A */
0N/A } catch (ClassCastException e) {
0N/A throw new IllegalArgumentException("Expected a Color instance");
0N/A }
0N/A }
0N/A
0N/A public void fill(Shape s, Color color) {
0N/A AffineTransform deviceTransform = getTransform();
0N/A
0N/A if (getClip() != null) {
0N/A deviceClip(getClip().getPathIterator(deviceTransform));
0N/A }
0N/A deviceFill(s.getPathIterator(deviceTransform), color);
0N/A }
0N/A
0N/A /**
0N/A * Fill the path defined by <code>pathIter</code>
0N/A * with the specified color.
0N/A * The path is provided in device coordinates.
0N/A */
0N/A protected abstract void deviceFill(PathIterator pathIter, Color color);
0N/A
0N/A /*
0N/A * Set the clipping path to that defined by
0N/A * the passed in <code>PathIterator</code>.
0N/A */
0N/A protected abstract void deviceClip(PathIterator pathIter);
0N/A
0N/A /*
0N/A * Draw the outline of the rectangle without using path
0N/A * if supported by platform.
0N/A */
0N/A protected abstract void deviceFrameRect(int x, int y,
0N/A int width, int height,
0N/A Color color);
0N/A
0N/A /*
0N/A * Draw a line without using path if supported by platform.
0N/A */
0N/A protected abstract void deviceDrawLine(int xBegin, int yBegin,
0N/A int xEnd, int yEnd, Color color);
0N/A
0N/A /*
0N/A * Fill a rectangle using specified color.
0N/A */
0N/A protected abstract void deviceFillRect(int x, int y,
0N/A int width, int height, Color color);
0N/A
0N/A /* Obtain a BI from known implementations of java.awt.Image
0N/A */
0N/A protected BufferedImage getBufferedImage(Image img) {
0N/A if (img instanceof BufferedImage) {
0N/A // Otherwise we expect a BufferedImage to behave as a standard BI
0N/A return (BufferedImage)img;
0N/A } else if (img instanceof ToolkitImage) {
0N/A // This can be null if the image isn't loaded yet.
0N/A // This is fine as in that case our caller will return
0N/A // as it will only draw a fully loaded image
0N/A return ((ToolkitImage)img).getBufferedImage();
0N/A } else if (img instanceof VolatileImage) {
0N/A // VI needs to make a new BI: this is unavoidable but
0N/A // I don't expect VI's to be "huge" in any case.
0N/A return ((VolatileImage)img).getSnapshot();
0N/A } else {
0N/A // may be null or may be some non-standard Image which
0N/A // shouldn't happen as Image is implemented by the platform
0N/A // not by applications
0N/A // If you add a new Image implementation to the platform you
0N/A // will need to support it here similarly to VI.
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Return true if the BufferedImage argument has non-opaque
0N/A * bits in it and therefore can not be directly rendered by
0N/A * GDI. Return false if the image is opaque. If this function
0N/A * can not tell for sure whether the image has transparent
0N/A * pixels then it assumes that it does.
0N/A */
0N/A protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
0N/A ColorModel colorModel = bufferedImage.getColorModel();
0N/A boolean hasTransparency = colorModel == null
0N/A ? true
0N/A : colorModel.getTransparency() != ColorModel.OPAQUE;
0N/A
0N/A /*
0N/A * For the default INT ARGB check the image to see if any pixels are
0N/A * really transparent. If there are no transparent pixels then the
0N/A * transparency of the color model can be ignored.
0N/A * We assume that IndexColorModel images have already been
0N/A * checked for transparency and will be OPAQUE unless they actually
0N/A * have transparent pixels present.
0N/A */
0N/A if (hasTransparency && bufferedImage != null) {
0N/A if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
0N/A bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
0N/A DataBuffer db = bufferedImage.getRaster().getDataBuffer();
0N/A SampleModel sm = bufferedImage.getRaster().getSampleModel();
0N/A if (db instanceof DataBufferInt &&
0N/A sm instanceof SinglePixelPackedSampleModel) {
0N/A SinglePixelPackedSampleModel psm =
0N/A (SinglePixelPackedSampleModel)sm;
0N/A // Stealing the data array for reading only...
0N/A int[] int_data =
0N/A SunWritableRaster.stealData((DataBufferInt) db, 0);
0N/A int x = bufferedImage.getMinX();
0N/A int y = bufferedImage.getMinY();
0N/A int w = bufferedImage.getWidth();
0N/A int h = bufferedImage.getHeight();
0N/A int stride = psm.getScanlineStride();
0N/A boolean hastranspixel = false;
0N/A for (int j = y; j < y+h; j++) {
0N/A int yoff = j * stride;
0N/A for (int i = x; i < x+w; i++) {
0N/A if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
0N/A hastranspixel = true;
0N/A break;
0N/A }
0N/A }
0N/A if (hastranspixel) {
0N/A break;
0N/A }
0N/A }
0N/A if (hastranspixel == false) {
0N/A hasTransparency = false;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A return hasTransparency;
0N/A }
0N/A
0N/A protected boolean isBitmaskTransparency(BufferedImage bufferedImage) {
0N/A ColorModel colorModel = bufferedImage.getColorModel();
0N/A return (colorModel != null &&
0N/A colorModel.getTransparency() == ColorModel.BITMASK);
0N/A }
0N/A
0N/A
0N/A /* An optimisation for the special case of ICM images which have
0N/A * bitmask transparency.
0N/A */
0N/A protected boolean drawBitmaskImage(BufferedImage bufferedImage,
0N/A AffineTransform xform,
0N/A Color bgcolor,
0N/A int srcX, int srcY,
0N/A int srcWidth, int srcHeight) {
0N/A
0N/A ColorModel colorModel = bufferedImage.getColorModel();
0N/A IndexColorModel icm;
0N/A int [] pixels;
0N/A
0N/A if (!(colorModel instanceof IndexColorModel)) {
0N/A return false;
0N/A } else {
0N/A icm = (IndexColorModel)colorModel;
0N/A }
0N/A
0N/A if (colorModel.getTransparency() != ColorModel.BITMASK) {
0N/A return false;
0N/A }
0N/A
0N/A // to be compatible with 1.1 printing which treated b/g colors
0N/A // with alpha 128 as opaque
0N/A if (bgcolor != null && bgcolor.getAlpha() < 128) {
0N/A return false;
0N/A }
0N/A
0N/A if ((xform.getType()
0N/A & ~( AffineTransform.TYPE_UNIFORM_SCALE
0N/A | AffineTransform.TYPE_TRANSLATION
0N/A | AffineTransform.TYPE_QUADRANT_ROTATION
0N/A )) != 0) {
0N/A return false;
0N/A }
0N/A
0N/A if ((getTransform().getType()
0N/A & ~( AffineTransform.TYPE_UNIFORM_SCALE
0N/A | AffineTransform.TYPE_TRANSLATION
0N/A | AffineTransform.TYPE_QUADRANT_ROTATION
0N/A )) != 0) {
0N/A return false;
0N/A }
0N/A
0N/A BufferedImage subImage = null;
0N/A Raster raster = bufferedImage.getRaster();
0N/A int transpixel = icm.getTransparentPixel();
0N/A byte[] alphas = new byte[icm.getMapSize()];
0N/A icm.getAlphas(alphas);
0N/A if (transpixel >= 0) {
0N/A alphas[transpixel] = 0;
0N/A }
0N/A
0N/A /* don't just use srcWidth & srcHeight from application - they
0N/A * may exceed the extent of the image - may need to clip.
0N/A * The image xform will ensure that points are still mapped properly.
0N/A */
0N/A int rw = raster.getWidth();
0N/A int rh = raster.getHeight();
0N/A if (srcX > rw || srcY > rh) {
0N/A return false;
0N/A }
0N/A int right, bottom, wid, hgt;
0N/A if (srcX+srcWidth > rw) {
0N/A right = rw;
0N/A wid = right - srcX;
0N/A } else {
0N/A right = srcX+srcWidth;
0N/A wid = srcWidth;
0N/A }
0N/A if (srcY+srcHeight > rh) {
0N/A bottom = rh;
0N/A hgt = bottom - srcY;
0N/A } else {
0N/A bottom = srcY+srcHeight;
0N/A hgt = srcHeight;
0N/A }
0N/A pixels = new int[wid];
0N/A for (int j=srcY; j<bottom; j++) {
0N/A int startx = -1;
0N/A raster.getPixels(srcX, j, wid, 1, pixels);
0N/A for (int i=srcX; i<right; i++) {
0N/A if (alphas[pixels[i-srcX]] == 0) {
0N/A if (startx >=0) {
0N/A subImage = bufferedImage.getSubimage(startx, j,
0N/A i-startx, 1);
0N/A xform.translate(startx, j);
0N/A drawImageToPlatform(subImage, xform, bgcolor,
0N/A 0, 0, i-startx, 1, true);
0N/A xform.translate(-startx, -j);
0N/A startx = -1;
0N/A }
0N/A } else if (startx < 0) {
0N/A startx = i;
0N/A }
0N/A }
0N/A if (startx >= 0) {
0N/A subImage = bufferedImage.getSubimage(startx, j,
0N/A right - startx, 1);
0N/A xform.translate(startx, j);
0N/A drawImageToPlatform(subImage, xform, bgcolor,
0N/A 0, 0, right - startx, 1, true);
0N/A xform.translate(-startx, -j);
0N/A }
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A
0N/A
0N/A /**
0N/A * The various <code>drawImage()</code> methods for
0N/A * <code>PathGraphics</code> are all decomposed
0N/A * into an invocation of <code>drawImageToPlatform</code>.
0N/A * The portion of the passed in image defined by
0N/A * <code>srcX, srcY, srcWidth, and srcHeight</code>
0N/A * is transformed by the supplied AffineTransform and
0N/A * drawn using PS to the printer context.
0N/A *
0N/A * @param img The image to be drawn.
0N/A * This method does nothing if <code>img</code> is null.
0N/A * @param xform Used to tranform the image before drawing.
0N/A * This can be null.
0N/A * @param bgcolor This color is drawn where the image has transparent
0N/A * pixels. If this parameter is null then the
0N/A * pixels already in the destination should show
0N/A * through.
0N/A * @param srcX With srcY this defines the upper-left corner
0N/A * of the portion of the image to be drawn.
0N/A *
0N/A * @param srcY With srcX this defines the upper-left corner
0N/A * of the portion of the image to be drawn.
0N/A * @param srcWidth The width of the portion of the image to
0N/A * be drawn.
0N/A * @param srcHeight The height of the portion of the image to
0N/A * be drawn.
0N/A * @param handlingTransparency if being recursively called to
0N/A * print opaque region of transparent image
0N/A */
0N/A protected abstract boolean
0N/A drawImageToPlatform(Image img, AffineTransform xform,
0N/A Color bgcolor,
0N/A int srcX, int srcY,
0N/A int srcWidth, int srcHeight,
0N/A boolean handlingTransparency);
0N/A
0N/A /**
0N/A * Draws as much of the specified image as is currently available.
0N/A * The image is drawn with its top-left corner at
0N/A * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
0N/A * space. Transparent pixels in the image do not affect whatever
0N/A * pixels are already there.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * complete image has not yet been loaded, and it has not been dithered
0N/A * and converted for the current output device.
0N/A * <p>
0N/A * If the image has not yet been completely loaded, then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the specified image observer.
0N/A * @param img the specified image to be drawn.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @param observer object to be notified as more of
0N/A * the image is converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public boolean drawImage(Image img, int x, int y,
0N/A ImageObserver observer) {
0N/A
0N/A return drawImage(img, x, y, null, observer);
0N/A }
0N/A
0N/A /**
0N/A * Draws as much of the specified image as has already been scaled
0N/A * to fit inside the specified rectangle.
0N/A * <p>
0N/A * The image is drawn inside the specified rectangle of this
0N/A * graphics context's coordinate space, and is scaled if
0N/A * necessary. Transparent pixels do not affect whatever pixels
0N/A * are already there.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * entire image has not yet been scaled, dithered, and converted
0N/A * for the current output device.
0N/A * If the current output representation is not yet complete, then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the image observer by calling its <code>imageUpdate</code> method.
0N/A * <p>
0N/A * A scaled version of an image will not necessarily be
0N/A * available immediately just because an unscaled version of the
0N/A * image has been constructed for this output device. Each size of
0N/A * the image may be cached separately and generated from the original
0N/A * data in a separate image production sequence.
0N/A * @param img the specified image to be drawn.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @param width the width of the rectangle.
0N/A * @param height the height of the rectangle.
0N/A * @param observer object to be notified as more of
0N/A * the image is converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public boolean drawImage(Image img, int x, int y,
0N/A int width, int height,
0N/A ImageObserver observer) {
0N/A
0N/A return drawImage(img, x, y, width, height, null, observer);
0N/A
0N/A }
0N/A
0N/A /*
0N/A * Draws as much of the specified image as is currently available.
0N/A * The image is drawn with its top-left corner at
0N/A * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
0N/A * space. Transparent pixels are drawn in the specified
0N/A * background color.
0N/A * <p>
0N/A * This operation is equivalent to filling a rectangle of the
0N/A * width and height of the specified image with the given color and then
0N/A * drawing the image on top of it, but possibly more efficient.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * complete image has not yet been loaded, and it has not been dithered
0N/A * and converted for the current output device.
0N/A * <p>
0N/A * If the image has not yet been completely loaded, then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the specified image observer.
0N/A * @param img the specified image to be drawn.
0N/A * This method does nothing if <code>img</code> is null.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @param bgcolor the background color to paint under the
0N/A * non-opaque portions of the image.
0N/A * In this WPathGraphics implementation,
0N/A * this parameter can be null in which
0N/A * case that background is made a transparent
0N/A * white.
0N/A * @param observer object to be notified as more of
0N/A * the image is converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public boolean drawImage(Image img, int x, int y,
0N/A Color bgcolor,
0N/A ImageObserver observer) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A
0N/A boolean result;
0N/A int srcWidth = img.getWidth(null);
0N/A int srcHeight = img.getHeight(null);
0N/A
0N/A if (srcWidth < 0 || srcHeight < 0) {
0N/A result = false;
0N/A } else {
0N/A result = drawImage(img, x, y, srcWidth, srcHeight, bgcolor, observer);
0N/A }
0N/A
0N/A return result;
0N/A }
0N/A
0N/A /**
0N/A * Draws as much of the specified image as has already been scaled
0N/A * to fit inside the specified rectangle.
0N/A * <p>
0N/A * The image is drawn inside the specified rectangle of this
0N/A * graphics context's coordinate space, and is scaled if
0N/A * necessary. Transparent pixels are drawn in the specified
0N/A * background color.
0N/A * This operation is equivalent to filling a rectangle of the
0N/A * width and height of the specified image with the given color and then
0N/A * drawing the image on top of it, but possibly more efficient.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * entire image has not yet been scaled, dithered, and converted
0N/A * for the current output device.
0N/A * If the current output representation is not yet complete then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the specified image observer.
0N/A * <p>
0N/A * A scaled version of an image will not necessarily be
0N/A * available immediately just because an unscaled version of the
0N/A * image has been constructed for this output device. Each size of
0N/A * the image may be cached separately and generated from the original
0N/A * data in a separate image production sequence.
0N/A * @param img the specified image to be drawn.
0N/A * This method does nothing if <code>img</code> is null.
0N/A * @param x the <i>x</i> coordinate.
0N/A * @param y the <i>y</i> coordinate.
0N/A * @param width the width of the rectangle.
0N/A * @param height the height of the rectangle.
0N/A * @param bgcolor the background color to paint under the
0N/A * non-opaque portions of the image.
0N/A * @param observer object to be notified as more of
0N/A * the image is converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.0
0N/A */
0N/A public boolean drawImage(Image img, int x, int y,
0N/A int width, int height,
0N/A Color bgcolor,
0N/A ImageObserver observer) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A
0N/A boolean result;
0N/A int srcWidth = img.getWidth(null);
0N/A int srcHeight = img.getHeight(null);
0N/A
0N/A if (srcWidth < 0 || srcHeight < 0) {
0N/A result = false;
0N/A } else {
0N/A result = drawImage(img,
0N/A x, y, x + width, y + height,
0N/A 0, 0, srcWidth, srcHeight,
0N/A observer);
0N/A }
0N/A
0N/A return result;
0N/A }
0N/A
0N/A /**
0N/A * Draws as much of the specified area of the specified image as is
0N/A * currently available, scaling it on the fly to fit inside the
0N/A * specified area of the destination drawable surface. Transparent pixels
0N/A * do not affect whatever pixels are already there.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * image area to be drawn has not yet been scaled, dithered, and converted
0N/A * for the current output device.
0N/A * If the current output representation is not yet complete then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the specified image observer.
0N/A * <p>
0N/A * This method always uses the unscaled version of the image
0N/A * to render the scaled rectangle and performs the required
0N/A * scaling on the fly. It does not use a cached, scaled version
0N/A * of the image for this operation. Scaling of the image from source
0N/A * to destination is performed such that the first coordinate
0N/A * of the source rectangle is mapped to the first coordinate of
0N/A * the destination rectangle, and the second source coordinate is
0N/A * mapped to the second destination coordinate. The subimage is
0N/A * scaled and flipped as needed to preserve those mappings.
0N/A * @param img the specified image to be drawn
0N/A * @param dx1 the <i>x</i> coordinate of the first corner of the
0N/A * destination rectangle.
0N/A * @param dy1 the <i>y</i> coordinate of the first corner of the
0N/A * destination rectangle.
0N/A * @param dx2 the <i>x</i> coordinate of the second corner of the
0N/A * destination rectangle.
0N/A * @param dy2 the <i>y</i> coordinate of the second corner of the
0N/A * destination rectangle.
0N/A * @param sx1 the <i>x</i> coordinate of the first corner of the
0N/A * source rectangle.
0N/A * @param sy1 the <i>y</i> coordinate of the first corner of the
0N/A * source rectangle.
0N/A * @param sx2 the <i>x</i> coordinate of the second corner of the
0N/A * source rectangle.
0N/A * @param sy2 the <i>y</i> coordinate of the second corner of the
0N/A * source rectangle.
0N/A * @param observer object to be notified as more of the image is
0N/A * scaled and converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.1
0N/A */
0N/A public boolean drawImage(Image img,
0N/A int dx1, int dy1, int dx2, int dy2,
0N/A int sx1, int sy1, int sx2, int sy2,
0N/A ImageObserver observer) {
0N/A
0N/A return drawImage(img,
0N/A dx1, dy1, dx2, dy2,
0N/A sx1, sy1, sx2, sy2,
0N/A null, observer);
0N/A }
0N/A
0N/A /**
0N/A * Draws as much of the specified area of the specified image as is
0N/A * currently available, scaling it on the fly to fit inside the
0N/A * specified area of the destination drawable surface.
0N/A * <p>
0N/A * Transparent pixels are drawn in the specified background color.
0N/A * This operation is equivalent to filling a rectangle of the
0N/A * width and height of the specified image with the given color and then
0N/A * drawing the image on top of it, but possibly more efficient.
0N/A * <p>
0N/A * This method returns immediately in all cases, even if the
0N/A * image area to be drawn has not yet been scaled, dithered, and converted
0N/A * for the current output device.
0N/A * If the current output representation is not yet complete then
0N/A * <code>drawImage</code> returns <code>false</code>. As more of
0N/A * the image becomes available, the process that draws the image notifies
0N/A * the specified image observer.
0N/A * <p>
0N/A * This method always uses the unscaled version of the image
0N/A * to render the scaled rectangle and performs the required
0N/A * scaling on the fly. It does not use a cached, scaled version
0N/A * of the image for this operation. Scaling of the image from source
0N/A * to destination is performed such that the first coordinate
0N/A * of the source rectangle is mapped to the first coordinate of
0N/A * the destination rectangle, and the second source coordinate is
0N/A * mapped to the second destination coordinate. The subimage is
0N/A * scaled and flipped as needed to preserve those mappings.
0N/A * @param img the specified image to be drawn
0N/A * This method does nothing if <code>img</code> is null.
0N/A * @param dx1 the <i>x</i> coordinate of the first corner of the
0N/A * destination rectangle.
0N/A * @param dy1 the <i>y</i> coordinate of the first corner of the
0N/A * destination rectangle.
0N/A * @param dx2 the <i>x</i> coordinate of the second corner of the
0N/A * destination rectangle.
0N/A * @param dy2 the <i>y</i> coordinate of the second corner of the
0N/A * destination rectangle.
0N/A * @param sx1 the <i>x</i> coordinate of the first corner of the
0N/A * source rectangle.
0N/A * @param sy1 the <i>y</i> coordinate of the first corner of the
0N/A * source rectangle.
0N/A * @param sx2 the <i>x</i> coordinate of the second corner of the
0N/A * source rectangle.
0N/A * @param sy2 the <i>y</i> coordinate of the second corner of the
0N/A * source rectangle.
0N/A * @param bgcolor the background color to paint under the
0N/A * non-opaque portions of the image.
0N/A * @param observer object to be notified as more of the image is
0N/A * scaled and converted.
0N/A * @see java.awt.Image
0N/A * @see java.awt.image.ImageObserver
0N/A * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
0N/A * @since JDK1.1
0N/A */
0N/A public boolean drawImage(Image img,
0N/A int dx1, int dy1, int dx2, int dy2,
0N/A int sx1, int sy1, int sx2, int sy2,
0N/A Color bgcolor,
0N/A ImageObserver observer) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A int imgWidth = img.getWidth(null);
0N/A int imgHeight = img.getHeight(null);
0N/A
0N/A if (imgWidth < 0 || imgHeight < 0) {
0N/A return true;
0N/A }
0N/A
0N/A int srcWidth = sx2 - sx1;
0N/A int srcHeight = sy2 - sy1;
0N/A
0N/A /* Create a transform which describes the changes
0N/A * from the source coordinates to the destination
0N/A * coordinates. The scaling is determined by the
0N/A * ratio of the two rectangles, while the translation
0N/A * comes from the difference of their origins.
0N/A */
0N/A float scalex = (float) (dx2 - dx1) / srcWidth;
0N/A float scaley = (float) (dy2 - dy1) / srcHeight;
0N/A AffineTransform xForm
0N/A = new AffineTransform(scalex,
0N/A 0,
0N/A 0,
0N/A scaley,
0N/A dx1 - (sx1 * scalex),
0N/A dy1 - (sy1 * scaley));
0N/A
0N/A /* drawImageToPlatform needs the top-left of the source area and
0N/A * a positive width and height. The xform describes how to map
0N/A * src->dest, so that information is not lost.
0N/A */
0N/A int tmp=0;
0N/A if (sx2 < sx1) {
0N/A tmp = sx1;
0N/A sx1 = sx2;
0N/A sx2 = tmp;
0N/A }
0N/A if (sy2 < sy1) {
0N/A tmp = sy1;
0N/A sy1 = sy2;
0N/A sy2 = tmp;
0N/A }
0N/A
0N/A /* if src area is beyond the bounds of the image, we must clip it.
0N/A * The transform is based on the specified area, not the clipped one.
0N/A */
0N/A if (sx1 < 0) {
0N/A sx1 = 0;
0N/A } else if (sx1 > imgWidth) { // empty srcArea, nothing to draw
0N/A sx1 = imgWidth;
0N/A }
0N/A if (sx2 < 0) { // empty srcArea, nothing to draw
0N/A sx2 = 0;
0N/A } else if (sx2 > imgWidth) {
0N/A sx2 = imgWidth;
0N/A }
0N/A if (sy1 < 0) {
0N/A sy1 = 0;
0N/A } else if (sy1 > imgHeight) { // empty srcArea
0N/A sy1 = imgHeight;
0N/A }
0N/A if (sy2 < 0) { // empty srcArea
0N/A sy2 = 0;
0N/A } else if (sy2 > imgHeight) {
0N/A sy2 = imgHeight;
0N/A }
0N/A
0N/A srcWidth = sx2 - sx1;
0N/A srcHeight = sy2 - sy1;
0N/A
0N/A if (srcWidth <= 0 || srcHeight <= 0) {
0N/A return true;
0N/A }
0N/A
0N/A return drawImageToPlatform(img, xForm, bgcolor,
0N/A sx1, sy1, srcWidth, srcHeight, false);
0N/A
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Draws an image, applying a transform from image space into user space
0N/A * before drawing.
0N/A * The transformation from user space into device space is done with
0N/A * the current transform in the Graphics2D.
0N/A * The given transformation is applied to the image before the
0N/A * transform attribute in the Graphics2D state is applied.
0N/A * The rendering attributes applied include the clip, transform,
0N/A * and composite attributes. Note that the result is
0N/A * undefined, if the given transform is noninvertible.
0N/A * @param img The image to be drawn.
0N/A * This method does nothing if <code>img</code> is null.
0N/A * @param xform The transformation from image space into user space.
0N/A * @param obs The image observer to be notified as more of the image
0N/A * is converted.
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public boolean drawImage(Image img,
0N/A AffineTransform xform,
0N/A ImageObserver obs) {
0N/A
0N/A if (img == null) {
0N/A return true;
0N/A }
0N/A
0N/A boolean result;
0N/A int srcWidth = img.getWidth(null);
0N/A int srcHeight = img.getHeight(null);
0N/A
0N/A if (srcWidth < 0 || srcHeight < 0) {
0N/A result = false;
0N/A } else {
0N/A result = drawImageToPlatform(img, xform, null,
0N/A 0, 0, srcWidth, srcHeight, false);
0N/A }
0N/A
0N/A return result;
0N/A }
0N/A
0N/A /**
0N/A * Draws a BufferedImage that is filtered with a BufferedImageOp.
0N/A * The rendering attributes applied include the clip, transform
0N/A * and composite attributes. This is equivalent to:
0N/A * <pre>
0N/A * img1 = op.filter(img, null);
0N/A * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
0N/A * </pre>
0N/A * @param op The filter to be applied to the image before drawing.
0N/A * @param img The BufferedImage to be drawn.
0N/A * This method does nothing if <code>img</code> is null.
0N/A * @param x,y The location in user space where the image should be drawn.
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public void drawImage(BufferedImage img,
0N/A BufferedImageOp op,
0N/A int x,
0N/A int y) {
0N/A
0N/A if (img == null) {
0N/A return;
0N/A }
0N/A
0N/A int srcWidth = img.getWidth(null);
0N/A int srcHeight = img.getHeight(null);
0N/A
0N/A if (op != null) {
0N/A img = op.filter(img, null);
0N/A }
0N/A if (srcWidth <= 0 || srcHeight <= 0) {
0N/A return;
0N/A } else {
0N/A AffineTransform xform = new AffineTransform(1f,0f,0f,1f,x,y);
0N/A drawImageToPlatform(img, xform, null,
0N/A 0, 0, srcWidth, srcHeight, false);
0N/A }
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Draws an image, applying a transform from image space into user space
0N/A * before drawing.
0N/A * The transformation from user space into device space is done with
0N/A * the current transform in the Graphics2D.
0N/A * The given transformation is applied to the image before the
0N/A * transform attribute in the Graphics2D state is applied.
0N/A * The rendering attributes applied include the clip, transform,
0N/A * and composite attributes. Note that the result is
0N/A * undefined, if the given transform is noninvertible.
0N/A * @param img The image to be drawn.
0N/A * This method does nothing if <code>img</code> is null.
0N/A * @param xform The transformation from image space into user space.
0N/A * @see #transform
0N/A * @see #setTransform
0N/A * @see #setComposite
0N/A * @see #clip
0N/A * @see #setClip
0N/A */
0N/A public void drawRenderedImage(RenderedImage img,
0N/A AffineTransform xform) {
0N/A
0N/A if (img == null) {
0N/A return;
0N/A }
0N/A
0N/A BufferedImage bufferedImage = null;
0N/A int srcWidth = img.getWidth();
0N/A int srcHeight = img.getHeight();
0N/A
0N/A if (srcWidth <= 0 || srcHeight <= 0) {
0N/A return;
0N/A }
0N/A
0N/A if (img instanceof BufferedImage) {
0N/A bufferedImage = (BufferedImage) img;
0N/A } else {
0N/A bufferedImage = new BufferedImage(srcWidth, srcHeight,
0N/A BufferedImage.TYPE_INT_ARGB);
0N/A Graphics2D imageGraphics = bufferedImage.createGraphics();
0N/A imageGraphics.drawRenderedImage(img, xform);
0N/A }
0N/A
0N/A drawImageToPlatform(bufferedImage, xform, null,
0N/A 0, 0, srcWidth, srcHeight, false);
0N/A
0N/A }
0N/A
0N/A}