PathGraphics.java revision 4798
0N/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 * 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 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 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 * 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 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any * Return the Printable instance responsible for drawing * Return the PageFormat associated with this page of * Return the page index associated with this Graphics. * Return true if we are allowed to ask the application * to redraw portions of the page. In general, with the * PrinterJob API, the application can be asked to do a * redraw. When PrinterJob is emulating PrintJob then we * Redraw a rectanglular area using a proxy graphics * Draws a line, using the current color, between the points * <code>(x1, y1)</code> and <code>(x2, y2)</code> * in this graphics context's coordinate system. * @param x1 the first point's <i>x</i> coordinate. * @param y1 the first point's <i>y</i> coordinate. * @param x2 the second point's <i>x</i> coordinate. * @param y2 the second point's <i>y</i> coordinate. * Draws the outline of the specified rectangle. * The left and right edges of the rectangle are at * <code>x</code> and <code>x + width</code>. * The top and bottom edges are at * <code>y</code> and <code>y + height</code>. * The rectangle is drawn using the graphics context's current color. * @param x the <i>x</i> coordinate * of the rectangle to be drawn. * @param y the <i>y</i> coordinate * of the rectangle to be drawn. * @param width the width of the rectangle to be drawn. * @param height the height of the rectangle to be drawn. * @see java.awt.Graphics#fillRect * @see java.awt.Graphics#clearRect * Fills the specified rectangle. * The left and right edges of the rectangle are at * <code>x</code> and <code>x + width - 1</code>. * The top and bottom edges are at * <code>y</code> and <code>y + height - 1</code>. * The resulting rectangle covers an area * <code>width</code> pixels wide by * <code>height</code> pixels tall. * The rectangle is filled using the graphics context's current color. * @param x the <i>x</i> coordinate * of the rectangle to be filled. * @param y the <i>y</i> coordinate * of the rectangle to be filled. * @param width the width of the rectangle to be filled. * @param height the height of the rectangle to be filled. * @see java.awt.Graphics#clearRect * @see java.awt.Graphics#drawRect * Clears the specified rectangle by filling it with the background * color of the current drawing surface. This operation does not * use the current paint mode. * Beginning with Java 1.1, the background color * of offscreen images may be system dependent. Applications should * use <code>setColor</code> followed by <code>fillRect</code> to * ensure that an offscreen image is cleared to a specific color. * @param x the <i>x</i> coordinate of the rectangle to clear. * @param y the <i>y</i> coordinate of the rectangle to clear. * @param width the width of the rectangle to clear. * @param height the height of the rectangle to clear. * @see java.awt.Graphics#fillRect(int, int, int, int) * @see java.awt.Graphics#drawRect * @see java.awt.Graphics#setColor(java.awt.Color) * @see java.awt.Graphics#setPaintMode * @see java.awt.Graphics#setXORMode(java.awt.Color) * Draws an outlined round-cornered rectangle using this graphics * context's current color. The left and right edges of the rectangle * are at <code>x</code> and <code>x + width</code>, * respectively. The top and bottom edges of the rectangle are at * <code>y</code> and <code>y + height</code>. * @param x the <i>x</i> coordinate of the rectangle to be drawn. * @param y the <i>y</i> coordinate of the rectangle to be drawn. * @param width the width of the rectangle to be drawn. * @param height the height of the rectangle to be drawn. * @param arcWidth the horizontal diameter of the arc * @param arcHeight the vertical diameter of the arc * @see java.awt.Graphics#fillRoundRect * Fills the specified rounded corner rectangle with the current color. * The left and right edges of the rectangle * are at <code>x</code> and <code>x + width - 1</code>, * respectively. The top and bottom edges of the rectangle are at * <code>y</code> and <code>y + height - 1</code>. * @param x the <i>x</i> coordinate of the rectangle to be filled. * @param y the <i>y</i> coordinate of the rectangle to be filled. * @param width the width of the rectangle to be filled. * @param height the height of the rectangle to be filled. * @param arcWidth the horizontal diameter * of the arc at the four corners. * @param arcHeight the vertical diameter * of the arc at the four corners. * @see java.awt.Graphics#drawRoundRect * Draws the outline of an oval. * The result is a circle or ellipse that fits within the * rectangle specified by the <code>x</code>, <code>y</code>, * <code>width</code>, and <code>height</code> arguments. * The oval covers an area that is * <code>width + 1</code> pixels wide * and <code>height + 1</code> pixels tall. * @param x the <i>x</i> coordinate of the upper left * corner of the oval to be drawn. * @param y the <i>y</i> coordinate of the upper left * corner of the oval to be drawn. * @param width the width of the oval to be drawn. * @param height the height of the oval to be drawn. * @see java.awt.Graphics#fillOval * Fills an oval bounded by the specified rectangle with the * @param x the <i>x</i> coordinate of the upper left corner * of the oval to be filled. * @param y the <i>y</i> coordinate of the upper left corner * of the oval to be filled. * @param width the width of the oval to be filled. * @param height the height of the oval to be filled. * @see java.awt.Graphics#drawOval * Draws the outline of a circular or elliptical arc * covering the specified rectangle. * The resulting arc begins at <code>startAngle</code> and extends * for <code>arcAngle</code> degrees, using the current color. * Angles are interpreted such that 0 degrees * is at the 3 o'clock position. * A positive value indicates a counter-clockwise rotation * while a negative value indicates a clockwise rotation. * The center of the arc is the center of the rectangle whose origin * is (<i>x</i>, <i>y</i>) and whose size is specified by the * <code>width</code> and <code>height</code> arguments. * The resulting arc covers an area * <code>width + 1</code> pixels wide * by <code>height + 1</code> pixels tall. * The angles are specified relative to the non-square extents of * the bounding rectangle such that 45 degrees always falls on the * line from the center of the ellipse to the upper right corner of * the bounding rectangle. As a result, if the bounding rectangle is * noticeably longer in one axis than the other, the angles to the * start and end of the arc segment will be skewed farther along the * longer axis of the bounds. * @param x the <i>x</i> coordinate of the * upper-left corner of the arc to be drawn. * @param y the <i>y</i> coordinate of the * upper-left corner of the arc to be drawn. * @param width the width of the arc to be drawn. * @param height the height of the arc to be drawn. * @param startAngle the beginning angle. * @param arcAngle the angular extent of the arc, * relative to the start angle. * @see java.awt.Graphics#fillArc * Fills a circular or elliptical arc covering the specified rectangle. * The resulting arc begins at <code>startAngle</code> and extends * for <code>arcAngle</code> degrees. * Angles are interpreted such that 0 degrees * is at the 3 o'clock position. * A positive value indicates a counter-clockwise rotation * while a negative value indicates a clockwise rotation. * The center of the arc is the center of the rectangle whose origin * is (<i>x</i>, <i>y</i>) and whose size is specified by the * <code>width</code> and <code>height</code> arguments. * The resulting arc covers an area * <code>width + 1</code> pixels wide * by <code>height + 1</code> pixels tall. * The angles are specified relative to the non-square extents of * the bounding rectangle such that 45 degrees always falls on the * line from the center of the ellipse to the upper right corner of * the bounding rectangle. As a result, if the bounding rectangle is * noticeably longer in one axis than the other, the angles to the * start and end of the arc segment will be skewed farther along the * longer axis of the bounds. * @param x the <i>x</i> coordinate of the * upper-left corner of the arc to be filled. * @param y the <i>y</i> coordinate of the * upper-left corner of the arc to be filled. * @param width the width of the arc to be filled. * @param height the height of the arc to be filled. * @param startAngle the beginning angle. * @param arcAngle the angular extent of the arc, * relative to the start angle. * @see java.awt.Graphics#drawArc * Draws a sequence of connected lines defined by * arrays of <i>x</i> and <i>y</i> coordinates. * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point. * The figure is not closed if the first point * differs from the last point. * @param xPoints an array of <i>x</i> points * @param yPoints an array of <i>y</i> points * @param nPoints the total number of points * @see java.awt.Graphics#drawPolygon(int[], int[], int) * Draws a closed polygon defined by * arrays of <i>x</i> and <i>y</i> coordinates. * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point. * This method draws the polygon defined by <code>nPoint</code> line * segments, where the first <code>nPoint - 1</code> * line segments are line segments from * <code>(xPoints[i - 1], yPoints[i - 1])</code> * to <code>(xPoints[i], yPoints[i])</code>, for * 1 ≤ <i>i</i> ≤ <code>nPoints</code>. * The figure is automatically closed by drawing a line connecting * the final point to the first point, if those points are different. * @param xPoints a an array of <code>x</code> coordinates. * @param yPoints a an array of <code>y</code> coordinates. * @param nPoints a the total number of points. * @see java.awt.Graphics#fillPolygon * @see java.awt.Graphics#drawPolyline * Draws the outline of a polygon defined by the specified * <code>Polygon</code> object. * @param p the polygon to draw. * @see java.awt.Graphics#fillPolygon * @see java.awt.Graphics#drawPolyline * Fills a closed polygon defined by * arrays of <i>x</i> and <i>y</i> coordinates. * This method draws the polygon defined by <code>nPoint</code> line * segments, where the first <code>nPoint - 1</code> * line segments are line segments from * <code>(xPoints[i - 1], yPoints[i - 1])</code> * to <code>(xPoints[i], yPoints[i])</code>, for * 1 ≤ <i>i</i> ≤ <code>nPoints</code>. * The figure is automatically closed by drawing a line connecting * the final point to the first point, if those points are different. * The area inside the polygon is defined using an * even-odd fill rule, also known as the alternating rule. * @param xPoints a an array of <code>x</code> coordinates. * @param yPoints a an array of <code>y</code> coordinates. * @param nPoints a the total number of points. * @see java.awt.Graphics#drawPolygon(int[], int[], int) * Fills the polygon defined by the specified Polygon object with * the graphics context's current color. * The area inside the polygon is defined using an * even-odd fill rule, also known as the alternating rule. * @param p the polygon to fill. * @see java.awt.Graphics#drawPolygon(int[], int[], int) * Draws the text given by the specified string, using this * graphics context's current font and color. The baseline of the * first character is at position (<i>x</i>, <i>y</i>) in this * graphics context's coordinate system. * @param str the string to be drawn. * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. * @see java.awt.Graphics#drawBytes * @see java.awt.Graphics#drawChars * Draws the text given by the specified iterator, using this * graphics context's current color. The iterator has to specify a font * for each character. The baseline of the * first character is at position (<i>x</i>, <i>y</i>) in this * graphics context's coordinate system. * @param iterator the iterator whose text is to be drawn * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. * @see java.awt.Graphics#drawBytes * @see java.awt.Graphics#drawChars * The rendering attributes applied include the clip, transform, * paint or color, and composite attributes. The GlyphVector specifies * individual glyphs from a Font. * @param g The GlyphVector to be drawn. * @param x,y The coordinates where the glyphs should be drawn. * @see java.awt.Graphics#setColor /* We should not reach here if printingGlyphVector is already true. * Add an assert so this can be tested if need be. * But also ensure that we do at least render properly by filling * Default implementation returns false. * Callers of this method must always be prepared for this, * and delegate to outlines or some other solution. /* GlyphVectors are usually encountered because TextLayout is in use. * Some times TextLayout is needed to handle complex text or some * rendering attributes trigger it. * We try to print GlyphVectors by reconstituting into a String, * as that is most recoverable for applications that export to formats * such as Postscript or PDF. In some cases (eg where its not complex * text and its just that positions aren't what we'd expect) we print * one character at a time. positioning individually. * Failing that, if we can directly send glyph codes to the printer * then we do that (printGlyphVector). * As a last resort we return false and let the caller print as filled /* We can't handle RTL, re-ordering, complex glyphs etc by * reconstituting glyphs into a String. So if any flags besides * position adjustments are set, see if we can directly * print the GlyphVector as glyph codes, using the positions * layout has assigned. If that fails return false; /* suspicious, may be a bad font. lets bail */ /* Build the needed maps for this font in a synchronized block */ /* X11 symbol & dingbats fonts used only for global metrics, * so the glyph codes we have really refer to Lucida Sans * So its possible the glyph code may appear out of range. * Note that later on we double-check the glyph codes that * we get from re-creating the GV from the string are the * same as those we started with. * If the glyphcode is INVISIBLE_GLYPH_ID then this may * be \t, \n or \r which are mapped to that by layout. * This is a case we can handle. It doesn't matter what * character we use (we use \n) so long as layout maps it * back to this in the verification, since the invisible * Needed to double-check remapping of X11 symbol & dingbats. /* If differ only in specifying A-A or a translation, these are * also compatible FRC's, and we can do one drawString call. /* We have to consider that the application may be directly * creating a GlyphVector, rather than one being created by * TextLayout or indirectly from drawString. In such a case, if the * font has layout attributes, the text may measure differently * when we reconstitute it into a String and ask for the length that * drawString would use. For example, KERNING will be applied in such * a case but that Font attribute is not applied when the application * directly created a GlyphVector. So in this case we need to verify * that the text measures the same in both cases - ie that the * layout attribute has no effect. If it does we can't always * use the drawString call unless we can coerce the drawString call * into measuring and displaying the string to the same length. * That is the case where there is only one font used and we can * specify the overall advance of the string. (See below). /* If TRACKING is in use then the glyph vector will report * position adjustments, then that ought to be sufficient to * tell us we can't just ask native to do "drawString". But layout * always sets the position adjustment flag, so we don't believe * it and verify the positions are really different than * createGlyphVector() (with no layout) would create. However * inconsistently, TRACKING is applied when creating a GlyphVector, * since it doesn't actually require "layout" (even though its * considered a layout attribute), it just requires a fractional * tweak to the[default]advances. So we need to specifically * check for tracking until such time as as we can trust * the GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS bit. /* If positions have not been explicitly assigned, we can * ask the string to be drawn adjusted to this width. * This call is supported only in the PS generator. * GDI has API to specify the advance for each glyph in a * string which could be used here too, but that is not yet * implemented, and we'd need to update the signature of the * drawString method to take the advances (ie relative positions) * and use that instead of the width. /* In some scripts chars drawn individually do not have the * same representation (glyphs) as when combined with other chars. * The logic here is erring on the side of caution, in particular * in including supplementary characters. /* If we reach here we have mapped all the glyphs back * one-to-one to simple unicode chars that we know are in the font. * We can call "drawChars" on each one of them in turn, setting * the position based on the glyph positions. * There's typically overhead in this. If numGlyphs is 'large', * it may even be better to try printGlyphVector() in this case. * This may be less recoverable for apps, but sophisticated apps * should be able to recover the text from simple glyph vectors * and we can avoid penalising the more common case - although * this is already a minority case. /* The same codes must be in the same positions for this to return true. * This would look cleaner if it took the original GV as a parameter but * we already have the codes and will need to get the positions array * too in most cases anyway. So its cheaper to pass them in. * This call wouldn't be necessary if layout didn't always set the * FLAG_HAS_POSITION_ADJUSTMENTS even if the default advances are used * and there was no re-ordering (this should be fixed some day). /* this shouldn't happen here, but just in case */ /* return an array which can map glyphs back to char codes. * Glyphs which aren't mapped from a simple unicode code point * will have no mapping in this array, and will be assumed to be * because of some substitution that we can't handle. /* NB Composites report the number of glyphs in slot 0. * So if a string uses a char from a later slot, or a fallback slot, * it will not be able to use this faster path. /* Consider refining the ranges to try to map by asking the font * what ranges it supports. * Since a glyph may be mapped by multiple code points, and this * code can't handle that, we always prefer the earlier code point. for (
char c=
0; c<
0xFFFF; c++) {
* Strokes the outline of a Shape using the settings of the current * graphics state. The rendering attributes applied include the * clip, transform, paint or color, composite and stroke attributes. * @param s The shape to be drawn. * @see java.awt.Graphics#setColor * Fills the interior of a Shape using the settings of the current * graphics state. The rendering attributes applied include the * clip, transform, paint or color, and composite. * @see java.awt.Graphics#setColor /* The PathGraphics class only supports filling with * solid colors and so we do not expect the cast of Paint * to Color to fail. If it does fail then something went * wrong, like the app draw a page with a solid color but * then redrew it with a Gradient. * Fill the path defined by <code>pathIter</code> * with the specified color. * The path is provided in device coordinates. * Set the clipping path to that defined by * the passed in <code>PathIterator</code>. * Draw the outline of the rectangle without using path * if supported by platform. * Draw a line without using path if supported by platform. * Fill a rectangle using specified color. /* Obtain a BI from known implementations of java.awt.Image // Otherwise we expect a BufferedImage to behave as a standard BI // This can be null if the image isn't loaded yet. // This is fine as in that case our caller will return // as it will only draw a fully loaded image // VI needs to make a new BI: this is unavoidable but // I don't expect VI's to be "huge" in any case. // may be null or may be some non-standard Image which // shouldn't happen as Image is implemented by the platform // If you add a new Image implementation to the platform you // will need to support it here similarly to VI. * Return true if the BufferedImage argument has non-opaque * bits in it and therefore can not be directly rendered by * GDI. Return false if the image is opaque. If this function * can not tell for sure whether the image has transparent * pixels then it assumes that it does. * For the default INT ARGB check the image to see if any pixels are * really transparent. If there are no transparent pixels then the * transparency of the color model can be ignored. * We assume that IndexColorModel images have already been * checked for transparency and will be OPAQUE unless they actually * have transparent pixels present. // Stealing the data array for reading only... for (
int j = y; j < y+h; j++) {
for (
int i = x; i < x+w; i++) {
/* An optimisation for the special case of ICM images which have // to be compatible with 1.1 printing which treated b/g colors // with alpha 128 as opaque /* don't just use srcWidth & srcHeight from application - they * may exceed the extent of the image - may need to clip. * The image xform will ensure that points are still mapped properly. * The various <code>drawImage()</code> methods for * <code>PathGraphics</code> are all decomposed * into an invocation of <code>drawImageToPlatform</code>. * The portion of the passed in image defined by * <code>srcX, srcY, srcWidth, and srcHeight</code> * is transformed by the supplied AffineTransform and * drawn using PS to the printer context. * @param img The image to be drawn. * This method does nothing if <code>img</code> is null. * @param xform Used to tranform the image before drawing. * @param bgcolor This color is drawn where the image has transparent * pixels. If this parameter is null then the * pixels already in the destination should show * @param srcX With srcY this defines the upper-left corner * of the portion of the image to be drawn. * @param srcY With srcX this defines the upper-left corner * of the portion of the image to be drawn. * @param srcWidth The width of the portion of the image to * @param srcHeight The height of the portion of the image to * @param handlingTransparency if being recursively called to * print opaque region of transparent image protected abstract boolean * Draws as much of the specified image as is currently available. * The image is drawn with its top-left corner at * (<i>x</i>, <i>y</i>) in this graphics context's coordinate * space. Transparent pixels in the image do not affect whatever * pixels are already there. * This method returns immediately in all cases, even if the * complete image has not yet been loaded, and it has not been dithered * and converted for the current output device. * If the image has not yet been completely loaded, then * <code>drawImage</code> returns <code>false</code>. As more of * the image becomes available, the process that draws the image notifies * the specified image observer. * @param img the specified image to be drawn. * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. * @param observer object to be notified as more of * the image is converted. * @see java.awt.image.ImageObserver * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) * Draws as much of the specified image as has already been scaled * to fit inside the specified rectangle. * The image is drawn inside the specified rectangle of this * graphics context's coordinate space, and is scaled if * necessary. Transparent pixels do not affect whatever pixels * This method returns immediately in all cases, even if the * entire image has not yet been scaled, dithered, and converted * for the current output device. * If the current output representation is not yet complete, then * <code>drawImage</code> returns <code>false</code>. As more of * the image becomes available, the process that draws the image notifies * the image observer by calling its <code>imageUpdate</code> method. * A scaled version of an image will not necessarily be * available immediately just because an unscaled version of the * image has been constructed for this output device. Each size of * the image may be cached separately and generated from the original * data in a separate image production sequence. * @param img the specified image to be drawn. * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. * @param width the width of the rectangle. * @param height the height of the rectangle. * @param observer object to be notified as more of * the image is converted. * @see java.awt.image.ImageObserver * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) * Draws as much of the specified image as is currently available. * The image is drawn with its top-left corner at * (<i>x</i>, <i>y</i>) in this graphics context's coordinate * space. Transparent pixels are drawn in the specified * This operation is equivalent to filling a rectangle of the * width and height of the specified image with the given color and then * drawing the image on top of it, but possibly more efficient. * This method returns immediately in all cases, even if the * complete image has not yet been loaded, and it has not been dithered * and converted for the current output device. * If the image has not yet been completely loaded, then * <code>drawImage</code> returns <code>false</code>. As more of * the image becomes available, the process that draws the image notifies * the specified image observer. * @param img the specified image to be drawn. * This method does nothing if <code>img</code> is null. * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. * @param bgcolor the background color to paint under the * non-opaque portions of the image. * In this WPathGraphics implementation, * this parameter can be null in which * case that background is made a transparent * @param observer object to be notified as more of * the image is converted. * @see java.awt.image.ImageObserver * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) * Draws as much of the specified image as has already been scaled * to fit inside the specified rectangle. * The image is drawn inside the specified rectangle of this * graphics context's coordinate space, and is scaled if * necessary. Transparent pixels are drawn in the specified * This operation is equivalent to filling a rectangle of the * width and height of the specified image with the given color and then * drawing the image on top of it, but possibly more efficient. * This method returns immediately in all cases, even if the * entire image has not yet been scaled, dithered, and converted * for the current output device. * If the current output representation is not yet complete then * <code>drawImage</code> returns <code>false</code>. As more of * the image becomes available, the process that draws the image notifies * the specified image observer. * A scaled version of an image will not necessarily be * available immediately just because an unscaled version of the * image has been constructed for this output device. Each size of * the image may be cached separately and generated from the original * data in a separate image production sequence. * @param img the specified image to be drawn. * This method does nothing if <code>img</code> is null. * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. * @param width the width of the rectangle. * @param height the height of the rectangle. * @param bgcolor the background color to paint under the * non-opaque portions of the image. * @param observer object to be notified as more of * the image is converted. * @see java.awt.image.ImageObserver * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) * Draws as much of the specified area of the specified image as is * currently available, scaling it on the fly to fit inside the * specified area of the destination drawable surface. Transparent pixels * do not affect whatever pixels are already there. * This method returns immediately in all cases, even if the * image area to be drawn has not yet been scaled, dithered, and converted * for the current output device. * If the current output representation is not yet complete then * <code>drawImage</code> returns <code>false</code>. As more of * the image becomes available, the process that draws the image notifies * the specified image observer. * This method always uses the unscaled version of the image * to render the scaled rectangle and performs the required * scaling on the fly. It does not use a cached, scaled version * of the image for this operation. Scaling of the image from source * to destination is performed such that the first coordinate * of the source rectangle is mapped to the first coordinate of * the destination rectangle, and the second source coordinate is * mapped to the second destination coordinate. The subimage is * scaled and flipped as needed to preserve those mappings. * @param img the specified image to be drawn * @param dx1 the <i>x</i> coordinate of the first corner of the * @param dy1 the <i>y</i> coordinate of the first corner of the * @param dx2 the <i>x</i> coordinate of the second corner of the * @param dy2 the <i>y</i> coordinate of the second corner of the * @param sx1 the <i>x</i> coordinate of the first corner of the * @param sy1 the <i>y</i> coordinate of the first corner of the * @param sx2 the <i>x</i> coordinate of the second corner of the * @param sy2 the <i>y</i> coordinate of the second corner of the * @param observer object to be notified as more of the image is * @see java.awt.image.ImageObserver * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) * Draws as much of the specified area of the specified image as is * currently available, scaling it on the fly to fit inside the * specified area of the destination drawable surface. * Transparent pixels are drawn in the specified background color. * This operation is equivalent to filling a rectangle of the * width and height of the specified image with the given color and then * drawing the image on top of it, but possibly more efficient. * This method returns immediately in all cases, even if the * image area to be drawn has not yet been scaled, dithered, and converted * for the current output device. * If the current output representation is not yet complete then * <code>drawImage</code> returns <code>false</code>. As more of * the image becomes available, the process that draws the image notifies * the specified image observer. * This method always uses the unscaled version of the image * to render the scaled rectangle and performs the required * scaling on the fly. It does not use a cached, scaled version * of the image for this operation. Scaling of the image from source * to destination is performed such that the first coordinate * of the source rectangle is mapped to the first coordinate of * the destination rectangle, and the second source coordinate is * mapped to the second destination coordinate. The subimage is * scaled and flipped as needed to preserve those mappings. * @param img the specified image to be drawn * This method does nothing if <code>img</code> is null. * @param dx1 the <i>x</i> coordinate of the first corner of the * @param dy1 the <i>y</i> coordinate of the first corner of the * @param dx2 the <i>x</i> coordinate of the second corner of the * @param dy2 the <i>y</i> coordinate of the second corner of the * @param sx1 the <i>x</i> coordinate of the first corner of the * @param sy1 the <i>y</i> coordinate of the first corner of the * @param sx2 the <i>x</i> coordinate of the second corner of the * @param sy2 the <i>y</i> coordinate of the second corner of the * @param bgcolor the background color to paint under the * non-opaque portions of the image. * @param observer object to be notified as more of the image is * @see java.awt.image.ImageObserver * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) /* Create a transform which describes the changes * from the source coordinates to the destination * coordinates. The scaling is determined by the * ratio of the two rectangles, while the translation * comes from the difference of their origins. /* drawImageToPlatform needs the top-left of the source area and * a positive width and height. The xform describes how to map * src->dest, so that information is not lost. /* if src area is beyond the bounds of the image, we must clip it. * The transform is based on the specified area, not the clipped one. }
else if (
sx1 >
imgWidth) {
// empty srcArea, nothing to draw if (
sx2 <
0) {
// empty srcArea, nothing to draw if (
sy2 <
0) {
// empty srcArea * Draws an image, applying a transform from image space into user space * The transformation from user space into device space is done with * the current transform in the Graphics2D. * The given transformation is applied to the image before the * transform attribute in the Graphics2D state is applied. * The rendering attributes applied include the clip, transform, * and composite attributes. Note that the result is * undefined, if the given transform is noninvertible. * @param img The image to be drawn. * This method does nothing if <code>img</code> is null. * @param xform The transformation from image space into user space. * @param obs The image observer to be notified as more of the image * Draws a BufferedImage that is filtered with a BufferedImageOp. * The rendering attributes applied include the clip, transform * and composite attributes. This is equivalent to: * img1 = op.filter(img, null); * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null); * @param op The filter to be applied to the image before drawing. * @param img The BufferedImage to be drawn. * This method does nothing if <code>img</code> is null. * @param x,y The location in user space where the image should be drawn. * Draws an image, applying a transform from image space into user space * The transformation from user space into device space is done with * the current transform in the Graphics2D. * The given transformation is applied to the image before the * transform attribute in the Graphics2D state is applied. * The rendering attributes applied include the clip, transform, * and composite attributes. Note that the result is * undefined, if the given transform is noninvertible. * @param img The image to be drawn. * This method does nothing if <code>img</code> is null. * @param xform The transformation from image space into user space.