jdk/src/share/classes/sun/print/PathGraphics.java
author rkennke
Fri, 07 Aug 2009 18:31:11 +0200
changeset 3928 be186a33df9b
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6795908: Refactor FontManager Reviewed-by: prr, igor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.font.CharToGlyphMapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.font.CompositeFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.font.Font2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.font.Font2DHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.font.FontManager;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    35
import sun.font.FontManagerFactory;
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
    36
import sun.font.FontUtilities;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.Paint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Polygon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.text.AttributedCharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.font.FontRenderContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.font.GlyphVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.font.TextAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.awt.font.TextLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.awt.geom.Arc2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.awt.geom.Ellipse2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.awt.geom.Line2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.awt.geom.Point2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.awt.geom.RoundRectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.awt.geom.PathIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.awt.image.BufferedImageOp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import java.awt.image.DataBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import java.awt.image.DataBufferInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import java.awt.image.ImageObserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import java.awt.image.IndexColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import java.awt.image.Raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import java.awt.image.RenderedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import java.awt.image.SampleModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import java.awt.image.SinglePixelPackedSampleModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import java.awt.image.VolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import sun.awt.image.ByteComponentRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
import sun.awt.image.ToolkitImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
import sun.awt.image.SunWritableRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
import java.awt.print.PageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
import java.awt.print.Printable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
import java.awt.print.PrinterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
import java.awt.print.PrinterGraphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
import java.awt.print.PrinterJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
public abstract class PathGraphics extends ProxyGraphics2D {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private Printable mPainter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private PageFormat mPageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private int mPageIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private boolean mCanRedraw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected boolean printingGlyphVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected PathGraphics(Graphics2D graphics, PrinterJob printerJob,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                           Printable painter, PageFormat pageFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                           int pageIndex, boolean canRedraw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        super(graphics, printerJob);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        mPainter = painter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        mPageFormat = pageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        mPageIndex = pageIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        mCanRedraw = canRedraw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Return the Printable instance responsible for drawing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * into this Graphics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    protected Printable getPrintable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return mPainter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Return the PageFormat associated with this page of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Graphics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected PageFormat getPageFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return mPageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Return the page index associated with this Graphics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    protected int getPageIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return mPageIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Return true if we are allowed to ask the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * to redraw portions of the page. In general, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * PrinterJob API, the application can be asked to do a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * redraw. When PrinterJob is emulating PrintJob then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * can not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public boolean canDoRedraws() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return mCanRedraw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      * Redraw a rectanglular area using a proxy graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public abstract void redrawRegion(Rectangle2D region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                      double scaleX, double scaleY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                      Shape clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                      AffineTransform devTransform)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    throws PrinterException ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Draws a line, using the current color, between the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * in this graphics context's coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @param   x1  the first point's <i>x</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param   y1  the first point's <i>y</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param   x2  the second point's <i>x</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param   y2  the second point's <i>y</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void drawLine(int x1, int y1, int x2, int y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        Paint paint = getPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            AffineTransform deviceTransform = getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            if (getClip() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                deviceClip(getClip().getPathIterator(deviceTransform));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            deviceDrawLine(x1, y1, x2, y2, (Color) paint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new IllegalArgumentException("Expected a Color instance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Draws the outline of the specified rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * The left and right edges of the rectangle are at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <code>x</code> and <code>x&nbsp;+&nbsp;width</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * The top and bottom edges are at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * The rectangle is drawn using the graphics context's current color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param         x   the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *                         of the rectangle to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param         y   the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *                         of the rectangle to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param         width   the width of the rectangle to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param         height   the height of the rectangle to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see          java.awt.Graphics#fillRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see          java.awt.Graphics#clearRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public void drawRect(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        Paint paint = getPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            AffineTransform deviceTransform = getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (getClip() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                deviceClip(getClip().getPathIterator(deviceTransform));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            deviceFrameRect(x, y, width, height, (Color) paint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            throw new IllegalArgumentException("Expected a Color instance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Fills the specified rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * The left and right edges of the rectangle are at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * The top and bottom edges are at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * The resulting rectangle covers an area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * <code>width</code> pixels wide by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <code>height</code> pixels tall.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * The rectangle is filled using the graphics context's current color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param         x   the <i>x</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *                         of the rectangle to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param         y   the <i>y</i> coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *                         of the rectangle to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param         width   the width of the rectangle to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param         height   the height of the rectangle to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see           java.awt.Graphics#clearRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @see           java.awt.Graphics#drawRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public void fillRect(int x, int y, int width, int height){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        Paint paint = getPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            AffineTransform deviceTransform = getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (getClip() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                deviceClip(getClip().getPathIterator(deviceTransform));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            deviceFillRect(x, y, width, height, (Color) paint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            throw new IllegalArgumentException("Expected a Color instance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
       /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Clears the specified rectangle by filling it with the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * color of the current drawing surface. This operation does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * use the current paint mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Beginning with Java&nbsp;1.1, the background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * of offscreen images may be system dependent. Applications should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * use <code>setColor</code> followed by <code>fillRect</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * ensure that an offscreen image is cleared to a specific color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param       x the <i>x</i> coordinate of the rectangle to clear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param       y the <i>y</i> coordinate of the rectangle to clear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param       width the width of the rectangle to clear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param       height the height of the rectangle to clear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see         java.awt.Graphics#fillRect(int, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @see         java.awt.Graphics#drawRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @see         java.awt.Graphics#setColor(java.awt.Color)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @see         java.awt.Graphics#setPaintMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @see         java.awt.Graphics#setXORMode(java.awt.Color)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public void clearRect(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        fill(new Rectangle2D.Float(x, y, width, height), getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Draws an outlined round-cornered rectangle using this graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * context's current color. The left and right edges of the rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * are at <code>x</code> and <code>x&nbsp;+&nbsp;width</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * respectively. The top and bottom edges of the rectangle are at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param      x the <i>x</i> coordinate of the rectangle to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param      y the <i>y</i> coordinate of the rectangle to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param      width the width of the rectangle to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param      height the height of the rectangle to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param      arcWidth the horizontal diameter of the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *                    at the four corners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param      arcHeight the vertical diameter of the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *                    at the four corners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @see        java.awt.Graphics#fillRoundRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public void drawRoundRect(int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                              int arcWidth, int arcHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        draw(new RoundRectangle2D.Float(x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                        width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                                        arcWidth, arcHeight));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Fills the specified rounded corner rectangle with the current color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * The left and right edges of the rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * are at <code>x</code> and <code>x&nbsp;+&nbsp;width&nbsp;-&nbsp;1</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * respectively. The top and bottom edges of the rectangle are at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * <code>y</code> and <code>y&nbsp;+&nbsp;height&nbsp;-&nbsp;1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @param       x the <i>x</i> coordinate of the rectangle to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @param       y the <i>y</i> coordinate of the rectangle to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param       width the width of the rectangle to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param       height the height of the rectangle to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param       arcWidth the horizontal diameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *                     of the arc at the four corners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @param       arcHeight the vertical diameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *                     of the arc at the four corners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see         java.awt.Graphics#drawRoundRect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public void fillRoundRect(int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                              int arcWidth, int arcHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        fill(new RoundRectangle2D.Float(x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                        width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                                        arcWidth, arcHeight));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Draws the outline of an oval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * The result is a circle or ellipse that fits within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * rectangle specified by the <code>x</code>, <code>y</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * <code>width</code>, and <code>height</code> arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * The oval covers an area that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <code>width&nbsp;+&nbsp;1</code> pixels wide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * and <code>height&nbsp;+&nbsp;1</code> pixels tall.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @param       x the <i>x</i> coordinate of the upper left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *                     corner of the oval to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param       y the <i>y</i> coordinate of the upper left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *                     corner of the oval to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param       width the width of the oval to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @param       height the height of the oval to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @see         java.awt.Graphics#fillOval
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public void drawOval(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        draw(new Ellipse2D.Float(x, y, width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * Fills an oval bounded by the specified rectangle with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * current color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @param       x the <i>x</i> coordinate of the upper left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *                     of the oval to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @param       y the <i>y</i> coordinate of the upper left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *                     of the oval to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @param       width the width of the oval to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @param       height the height of the oval to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @see         java.awt.Graphics#drawOval
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public void fillOval(int x, int y, int width, int height){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        fill(new Ellipse2D.Float(x, y, width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Draws the outline of a circular or elliptical arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * covering the specified rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * The resulting arc begins at <code>startAngle</code> and extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * for <code>arcAngle</code> degrees, using the current color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Angles are interpreted such that 0&nbsp;degrees
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * is at the 3&nbsp;o'clock position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * A positive value indicates a counter-clockwise rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * while a negative value indicates a clockwise rotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * The center of the arc is the center of the rectangle whose origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * <code>width</code> and <code>height</code> arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * The resulting arc covers an area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * <code>width&nbsp;+&nbsp;1</code> pixels wide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * The angles are specified relative to the non-square extents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * the bounding rectangle such that 45 degrees always falls on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * line from the center of the ellipse to the upper right corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * the bounding rectangle. As a result, if the bounding rectangle is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * noticeably longer in one axis than the other, the angles to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * start and end of the arc segment will be skewed farther along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * longer axis of the bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @param        x the <i>x</i> coordinate of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *                    upper-left corner of the arc to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @param        y the <i>y</i>  coordinate of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *                    upper-left corner of the arc to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @param        width the width of the arc to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @param        height the height of the arc to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @param        startAngle the beginning angle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @param        arcAngle the angular extent of the arc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *                    relative to the start angle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @see         java.awt.Graphics#fillArc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    public void drawArc(int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                                 int startAngle, int arcAngle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        draw(new Arc2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                             startAngle, arcAngle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                             Arc2D.OPEN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Fills a circular or elliptical arc covering the specified rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * The resulting arc begins at <code>startAngle</code> and extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * for <code>arcAngle</code> degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Angles are interpreted such that 0&nbsp;degrees
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * is at the 3&nbsp;o'clock position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * A positive value indicates a counter-clockwise rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * while a negative value indicates a clockwise rotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * The center of the arc is the center of the rectangle whose origin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * is (<i>x</i>,&nbsp;<i>y</i>) and whose size is specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * <code>width</code> and <code>height</code> arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * The resulting arc covers an area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * <code>width&nbsp;+&nbsp;1</code> pixels wide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * by <code>height&nbsp;+&nbsp;1</code> pixels tall.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * The angles are specified relative to the non-square extents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * the bounding rectangle such that 45 degrees always falls on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * line from the center of the ellipse to the upper right corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * the bounding rectangle. As a result, if the bounding rectangle is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * noticeably longer in one axis than the other, the angles to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * start and end of the arc segment will be skewed farther along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * longer axis of the bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @param        x the <i>x</i> coordinate of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *                    upper-left corner of the arc to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @param        y the <i>y</i>  coordinate of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *                    upper-left corner of the arc to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @param        width the width of the arc to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @param        height the height of the arc to be filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @param        startAngle the beginning angle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @param        arcAngle the angular extent of the arc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *                    relative to the start angle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @see         java.awt.Graphics#drawArc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public void fillArc(int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                                 int startAngle, int arcAngle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        fill(new Arc2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                             startAngle, arcAngle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                             Arc2D.PIE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * Draws a sequence of connected lines defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * arrays of <i>x</i> and <i>y</i> coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * The figure is not closed if the first point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * differs from the last point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @param       xPoints an array of <i>x</i> points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @param       yPoints an array of <i>y</i> points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @param       nPoints the total number of points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @see         java.awt.Graphics#drawPolygon(int[], int[], int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public void drawPolyline(int xPoints[], int yPoints[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                             int nPoints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        float fromX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        float fromY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        float toX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        float toY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (nPoints > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            fromX = xPoints[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            fromY = yPoints[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            for(int i = 1; i < nPoints; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                toX = xPoints[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                toY = yPoints[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                draw(new Line2D.Float(fromX, fromY, toX, toY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                fromX = toX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                fromY = toY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Draws a closed polygon defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * arrays of <i>x</i> and <i>y</i> coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Each pair of (<i>x</i>,&nbsp;<i>y</i>) coordinates defines a point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * This method draws the polygon defined by <code>nPoint</code> line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * line segments are line segments from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * The figure is automatically closed by drawing a line connecting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * the final point to the first point, if those points are different.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @param        xPoints   a an array of <code>x</code> coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @param        yPoints   a an array of <code>y</code> coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @param        nPoints   a the total number of points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @see          java.awt.Graphics#fillPolygon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @see          java.awt.Graphics#drawPolyline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public void drawPolygon(int xPoints[], int yPoints[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                     int nPoints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        draw(new Polygon(xPoints, yPoints, nPoints));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Draws the outline of a polygon defined by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * <code>Polygon</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @param        p the polygon to draw.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * @see          java.awt.Graphics#fillPolygon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @see          java.awt.Graphics#drawPolyline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    public void drawPolygon(Polygon p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        draw(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Fills a closed polygon defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * arrays of <i>x</i> and <i>y</i> coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * This method draws the polygon defined by <code>nPoint</code> line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * segments, where the first <code>nPoint&nbsp;-&nbsp;1</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * line segments are line segments from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * <code>(xPoints[i&nbsp;-&nbsp;1],&nbsp;yPoints[i&nbsp;-&nbsp;1])</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * to <code>(xPoints[i],&nbsp;yPoints[i])</code>, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * 1&nbsp;&le;&nbsp;<i>i</i>&nbsp;&le;&nbsp;<code>nPoints</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * The figure is automatically closed by drawing a line connecting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * the final point to the first point, if those points are different.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * The area inside the polygon is defined using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * even-odd fill rule, also known as the alternating rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @param        xPoints   a an array of <code>x</code> coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @param        yPoints   a an array of <code>y</code> coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @param        nPoints   a the total number of points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @see          java.awt.Graphics#drawPolygon(int[], int[], int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    public void fillPolygon(int xPoints[], int yPoints[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                            int nPoints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        fill(new Polygon(xPoints, yPoints, nPoints));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * Fills the polygon defined by the specified Polygon object with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * the graphics context's current color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * The area inside the polygon is defined using an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * even-odd fill rule, also known as the alternating rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @param        p the polygon to fill.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @see          java.awt.Graphics#drawPolygon(int[], int[], int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    public void fillPolygon(Polygon p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        fill(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * Draws the text given by the specified string, using this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * graphics context's current font and color. The baseline of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * graphics context's coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @param       str      the string to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @param       x        the <i>x</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @param       y        the <i>y</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @see         java.awt.Graphics#drawBytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @see         java.awt.Graphics#drawChars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    public void drawString(String str, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        drawString(str, (float) x, (float) y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public void drawString(String str, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        if (str.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        TextLayout layout =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            new TextLayout(str, getFont(), getFontRenderContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        layout.draw(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    protected void drawString(String str, float x, float y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                              Font font, FontRenderContext frc, float w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        TextLayout layout =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            new TextLayout(str, font, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        Shape textShape =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            layout.getOutline(AffineTransform.getTranslateInstance(x, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        fill(textShape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Draws the text given by the specified iterator, using this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * graphics context's current color. The iterator has to specify a font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * for each character. The baseline of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * graphics context's coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @param       iterator the iterator whose text is to be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @param       x        the <i>x</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @param       y        the <i>y</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @see         java.awt.Graphics#drawBytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @see         java.awt.Graphics#drawChars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    public void drawString(AttributedCharacterIterator iterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                           int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        drawString(iterator, (float) x, (float) y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    public void drawString(AttributedCharacterIterator iterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                           float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (iterator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            throw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                new NullPointerException("attributedcharacteriterator is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        TextLayout layout =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            new TextLayout(iterator, getFontRenderContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        layout.draw(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * Draws a GlyphVector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * The rendering attributes applied include the clip, transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * paint or color, and composite attributes.  The GlyphVector specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * individual glyphs from a Font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @param g The GlyphVector to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @param x,y The coordinates where the glyphs should be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @see #setPaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @see java.awt.Graphics#setColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * @see #clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    public void drawGlyphVector(GlyphVector g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                                float x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        /* We should not reach here if printingGlyphVector is already true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
         * Add an assert so this can be tested if need be.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
         * But also ensure that we do at least render properly by filling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
         * the outline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        if (printingGlyphVector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            assert !printingGlyphVector; // ie false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            fill(g.getOutline(x, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            printingGlyphVector = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            if (RasterPrinterJob.shapeTextProp ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                !printedSimpleGlyphVector(g, x, y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                fill(g.getOutline(x, y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            printingGlyphVector = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    protected static SoftReference<Hashtable<Font2DHandle,Object>>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        fontMapRef = new SoftReference<Hashtable<Font2DHandle,Object>>(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    protected int platformFontCount(Font font, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * Default implementation returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * Callers of this method must always be prepared for this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * and delegate to outlines or some other solution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    protected boolean printGlyphVector(GlyphVector gv, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    /* GlyphVectors are usually encountered because TextLayout is in use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * Some times TextLayout is needed to handle complex text or some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * rendering attributes trigger it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * We try to print GlyphVectors by reconstituting into a String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * as that is most recoverable for applications that export to formats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * such as Postscript or PDF. In some cases (eg where its not complex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * text and its just that positions aren't what we'd expect) we print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * one character at a time. positioning individually.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * Failing that, if we can directly send glyph codes to the printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * then we do that (printGlyphVector).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * As a last resort we return false and let the caller print as filled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * shapes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    boolean printedSimpleGlyphVector(GlyphVector g, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        int flags = g.getLayoutFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        /* We can't handle RTL, re-ordering, complex glyphs etc by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
         * reconstituting glyphs into a String. So if any flags besides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
         * position adjustments are set, see if we can directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
         * print the GlyphVector as glyph codes, using the positions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
         * layout has assigned. If that fails return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        if (flags != 0 && flags != GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            return printGlyphVector(g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        Font font = g.getFont();
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   703
        Font2D font2D = FontUtilities.getFont2D(font);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        if (font2D.handle.font2D != font2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            /* suspicious, may be a bad font. lets bail */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        Hashtable<Font2DHandle,Object> fontMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        synchronized (PathGraphics.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            fontMap = fontMapRef.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            if (fontMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                fontMap = new Hashtable<Font2DHandle,Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                fontMapRef =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    new SoftReference<Hashtable<Font2DHandle,Object>>(fontMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        int numGlyphs = g.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        int[] glyphCodes = g.getGlyphCodes(0, numGlyphs, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        char[] glyphToCharMap = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        char[][] mapArray = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        CompositeFont cf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        /* Build the needed maps for this font in a synchronized block */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        synchronized (fontMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            if (font2D instanceof CompositeFont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                cf = (CompositeFont)font2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                int numSlots = cf.getNumSlots();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                mapArray = (char[][])fontMap.get(font2D.handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                if (mapArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                    mapArray = new char[numSlots][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                    fontMap.put(font2D.handle, mapArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                for (int i=0; i<numGlyphs;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                    int slot = glyphCodes[i] >>> 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                    if (slot >= numSlots) { /* shouldn't happen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                    if (mapArray[slot] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                        Font2D slotFont = cf.getSlotFont(slot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                        char[] map = (char[])fontMap.get(slotFont.handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                        if (map == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                            map = getGlyphToCharMapForFont(slotFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                        mapArray[slot] = map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                glyphToCharMap = (char[])fontMap.get(font2D.handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                if (glyphToCharMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    glyphToCharMap = getGlyphToCharMapForFont(font2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                    fontMap.put(font2D.handle, glyphToCharMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        char[] chars = new char[numGlyphs];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        if (cf != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            for (int i=0; i<numGlyphs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                int gc = glyphCodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                char[] map = mapArray[gc >>> 24];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                gc = gc & 0xffffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                if (map == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                /* X11 symbol & dingbats fonts used only for global metrics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                 * so the glyph codes we have really refer to Lucida Sans
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                 * Regular.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                 * So its possible the glyph code may appear out of range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                 * Note that later on we double-check the glyph codes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                 * we get from re-creating the GV from the string are the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                 * same as those we started with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                 * If the glyphcode is INVISIBLE_GLYPH_ID then this may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                 * be \t, \n or \r which are mapped to that by layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                 * This is a case we can handle. It doesn't matter what
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                 * character we use (we use \n) so long as layout maps it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                 * back to this in the verification, since the invisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                 * glyph isn't visible :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                if (gc == CharToGlyphMapper.INVISIBLE_GLYPH_ID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    ch = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                } else if (gc < 0 || gc >= map.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                    ch = map[gc];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                if (ch != CharToGlyphMapper.INVISIBLE_GLYPH_ID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                    chars[i] = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            for (int i=0; i<numGlyphs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                int gc = glyphCodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                if (gc == CharToGlyphMapper.INVISIBLE_GLYPH_ID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    ch = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                } else if (gc < 0 || gc >= glyphToCharMap.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    ch = glyphToCharMap[gc];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                if (ch != CharToGlyphMapper.INVISIBLE_GLYPH_ID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                    chars[i] = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        FontRenderContext gvFrc = g.getFontRenderContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        GlyphVector gv2 = font.createGlyphVector(gvFrc, chars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        if (gv2.getNumGlyphs() != numGlyphs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            return printGlyphVector(g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        int[] glyphCodes2 = gv2.getGlyphCodes(0, numGlyphs, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
         * Needed to double-check remapping of X11 symbol & dingbats.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        for (int i=0; i<numGlyphs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            if (glyphCodes[i] != glyphCodes2[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                return printGlyphVector(g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        FontRenderContext g2dFrc = getFontRenderContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        boolean compatibleFRC = gvFrc.equals(g2dFrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        /* If differ only in specifying A-A or a translation, these are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
         * also compatible FRC's, and we can do one drawString call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        if (!compatibleFRC &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            gvFrc.usesFractionalMetrics() == g2dFrc.usesFractionalMetrics()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            AffineTransform gvAT = gvFrc.getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            AffineTransform g2dAT = getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            double[] gvMatrix = new double[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            double[] g2dMatrix = new double[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            gvAT.getMatrix(gvMatrix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            g2dAT.getMatrix(g2dMatrix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            compatibleFRC = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            for (int i=0;i<4;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                if (gvMatrix[i] != g2dMatrix[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                    compatibleFRC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        String str = new String(chars, 0, numGlyphs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        int numFonts = platformFontCount(font, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if (numFonts == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        float[] positions = g.getGlyphPositions(0, numGlyphs, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        boolean noPositionAdjustments =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            ((flags & GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS) == 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            samePositions(gv2, glyphCodes2, glyphCodes, positions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        /* We have to consider that the application may be directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
         * creating a GlyphVector, rather than one being created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
         * TextLayout or indirectly from drawString. In such a case, if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
         * font has layout attributes, the text may measure differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
         * when we reconstitute it into a String and ask for the length that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
         * drawString would use. For example, KERNING will be applied in such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
         * a case but that Font attribute is not applied when the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
         * directly created a GlyphVector. So in this case we need to verify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
         * that the text measures the same in both cases - ie that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
         * layout attribute has no effect. If it does we can't always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
         * use the drawString call unless we can coerce the drawString call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
         * into measuring and displaying the string to the same length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
         * That is the case where there is only one font used and we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
         * specify the overall advance of the string. (See below).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        Point2D gvAdvancePt = g.getGlyphPosition(numGlyphs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        float gvAdvanceX = (float)gvAdvancePt.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        boolean layoutAffectsAdvance = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        if (font.hasLayoutAttributes() && printingGlyphVector &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            noPositionAdjustments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            /* If TRACKING is in use then the glyph vector will report
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
             * position adjustments, then that ought to be sufficient to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
             * tell us we can't just ask native to do "drawString". But layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
             * always sets the position adjustment flag, so we don't believe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
             * it and verify the positions are really different than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
             * createGlyphVector() (with no layout) would create. However
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
             * inconsistently, TRACKING is applied when creating a GlyphVector,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
             * since it doesn't actually require "layout" (even though its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
             * considered a layout attribute), it just requires a fractional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
             * tweak to the[default]advances. So we need to specifically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
             * check for tracking until such time as as we can trust
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
             * the GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS bit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            Map<TextAttribute, ?> map = font.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            Object o = map.get(TextAttribute.TRACKING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            boolean tracking = o != null && (o instanceof Number) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                (((Number)o).floatValue() != 0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            if (tracking) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                noPositionAdjustments = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                Rectangle2D bounds = font.getStringBounds(str, gvFrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                float strAdvanceX = (float)bounds.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                if (Math.abs(strAdvanceX - gvAdvanceX) > 0.00001) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                    layoutAffectsAdvance = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        if (compatibleFRC && noPositionAdjustments && !layoutAffectsAdvance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            drawString(str, x, y, font, gvFrc, 0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        /* If positions have not been explicitly assigned, we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
         * ask the string to be drawn adjusted to this width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
         * This call is supported only in the PS generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
         * GDI has API to specify the advance for each glyph in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
         * string which could be used here too, but that is not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
         * implemented, and we'd need to update the signature of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
         * drawString method to take the advances (ie relative positions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
         * and use that instead of the width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        if (numFonts == 1 && canDrawStringToWidth() && noPositionAdjustments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            drawString(str, x, y, font, gvFrc, gvAdvanceX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        /* In some scripts chars drawn individually do not have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
         * same representation (glyphs) as when combined with other chars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
         * The logic here is erring on the side of caution, in particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
         * in including supplementary characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
         */
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2
diff changeset
   938
        if (FontUtilities.isComplexText(chars, 0, chars.length)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            return printGlyphVector(g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        /* If we reach here we have mapped all the glyphs back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
         * one-to-one to simple unicode chars that we know are in the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
         * We can call "drawChars" on each one of them in turn, setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
         * the position based on the glyph positions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
         * There's typically overhead in this. If numGlyphs is 'large',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
         * it may even be better to try printGlyphVector() in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
         * This may be less recoverable for apps, but sophisticated apps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
         * should be able to recover the text from simple glyph vectors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
         * and we can avoid penalising the more common case - although
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
         * this is already a minority case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        if (numGlyphs > 10 && printGlyphVector(g, x, y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        for (int i=0; i<numGlyphs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            String s = new String(chars, i, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            drawString(s, x+positions[i*2], y+positions[i*2+1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                       font, gvFrc, 0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    /* The same codes must be in the same positions for this to return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * This would look cleaner if it took the original GV as a parameter but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * we already have the codes and will need to get the positions array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * too in most cases anyway. So its cheaper to pass them in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * This call wouldn't be necessary if layout didn't always set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * FLAG_HAS_POSITION_ADJUSTMENTS even if the default advances are used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * and there was no re-ordering (this should be fixed some day).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    private boolean samePositions(GlyphVector gv, int[] gvcodes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                                  int[] origCodes, float[] origPositions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        int numGlyphs = gv.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        float[] gvpos = gv.getGlyphPositions(0, numGlyphs, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        /* this shouldn't happen here, but just in case */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        if (numGlyphs != gvcodes.length ||  /* real paranoia here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            origCodes.length != gvcodes.length ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            origPositions.length != gvpos.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        for (int i=0; i<numGlyphs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            if (gvcodes[i] != origCodes[i] || gvpos[i] != origPositions[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    protected boolean canDrawStringToWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    /* return an array which can map glyphs back to char codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * Glyphs which aren't mapped from a simple unicode code point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * will have no mapping in this array, and will be assumed to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * because of some substitution that we can't handle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    private static char[] getGlyphToCharMapForFont(Font2D font2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        /* NB Composites report the number of glyphs in slot 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
         * So if a string uses a char from a later slot, or a fallback slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
         * it will not be able to use this faster path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        int numGlyphs = font2D.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        int missingGlyph = font2D.getMissingGlyphCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        char[] glyphToCharMap = new char[numGlyphs];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        int glyph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        for (int i=0;i<numGlyphs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            glyphToCharMap[i] = CharToGlyphMapper.INVISIBLE_GLYPH_ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        /* Consider refining the ranges to try to map by asking the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
         * what ranges it supports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
         * Since a glyph may be mapped by multiple code points, and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
         * code can't handle that, we always prefer the earlier code point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        for (char c=0; c<0xFFFF; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
           if (c >= CharToGlyphMapper.HI_SURROGATE_START &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
               c <= CharToGlyphMapper.LO_SURROGATE_END) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            glyph = font2D.charToGlyph(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            if (glyph != missingGlyph && glyph < numGlyphs &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                (glyphToCharMap[glyph] ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                 CharToGlyphMapper.INVISIBLE_GLYPH_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                glyphToCharMap[glyph] = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        return glyphToCharMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * Strokes the outline of a Shape using the settings of the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * graphics state.  The rendering attributes applied include the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * clip, transform, paint or color, composite and stroke attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * @param s The shape to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * @see #setStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * @see #setPaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * @see java.awt.Graphics#setColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * @see #clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    public void draw(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        fill(getStroke().createStrokedShape(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * Fills the interior of a Shape using the settings of the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * graphics state. The rendering attributes applied include the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * clip, transform, paint or color, and composite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * @see #setPaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * @see java.awt.Graphics#setColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * @see #clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    public void fill(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        Paint paint = getPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            fill(s, (Color) paint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        /* The PathGraphics class only supports filling with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
         * solid colors and so we do not expect the cast of Paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
         * to Color to fail. If it does fail then something went
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
         * wrong, like the app draw a page with a solid color but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
         * then redrew it with a Gradient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            throw new IllegalArgumentException("Expected a Color instance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    public void fill(Shape s, Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        AffineTransform deviceTransform = getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        if (getClip() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            deviceClip(getClip().getPathIterator(deviceTransform));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        deviceFill(s.getPathIterator(deviceTransform), color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * Fill the path defined by <code>pathIter</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * with the specified color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * The path is provided in device coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    protected abstract void deviceFill(PathIterator pathIter, Color color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * Set the clipping path to that defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * the passed in <code>PathIterator</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    protected abstract void deviceClip(PathIterator pathIter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * Draw the outline of the rectangle without using path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * if supported by platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    protected abstract void deviceFrameRect(int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                                            int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                                            Color color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * Draw a line without using path if supported by platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    protected abstract void deviceDrawLine(int xBegin, int yBegin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                                           int xEnd, int yEnd, Color color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * Fill a rectangle using specified color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    protected abstract void deviceFillRect(int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                                           int width, int height, Color color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    /* Obtain a BI from known implementations of java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    protected BufferedImage getBufferedImage(Image img) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        if (img instanceof BufferedImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            // Otherwise we expect a BufferedImage to behave as a standard BI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            return (BufferedImage)img;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        } else if (img instanceof ToolkitImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            // This can be null if the image isn't loaded yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            // This is fine as in that case our caller will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            // as it will only draw a fully loaded image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            return ((ToolkitImage)img).getBufferedImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        } else if (img instanceof VolatileImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            // VI needs to make a new BI: this is unavoidable but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            // I don't expect VI's to be "huge" in any case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            return ((VolatileImage)img).getSnapshot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            // may be null or may be some non-standard Image which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            // shouldn't happen as Image is implemented by the platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            // not by applications
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            // If you add a new Image implementation to the platform you
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            // will need to support it here similarly to VI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * Return true if the BufferedImage argument has non-opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * bits in it and therefore can not be directly rendered by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * GDI. Return false if the image is opaque. If this function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * can not tell for sure whether the image has transparent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * pixels then it assumes that it does.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        ColorModel colorModel = bufferedImage.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        boolean hasTransparency = colorModel == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            ? true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            : colorModel.getTransparency() != ColorModel.OPAQUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
         * For the default INT ARGB check the image to see if any pixels are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
         * really transparent. If there are no transparent pixels then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
         * transparency of the color model can be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
         * We assume that IndexColorModel images have already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
         * checked for transparency and will be OPAQUE unless they actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
         * have transparent pixels present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        if (hasTransparency && bufferedImage != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                DataBuffer db =  bufferedImage.getRaster().getDataBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                SampleModel sm = bufferedImage.getRaster().getSampleModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                if (db instanceof DataBufferInt &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                    sm instanceof SinglePixelPackedSampleModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                    SinglePixelPackedSampleModel psm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                        (SinglePixelPackedSampleModel)sm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                    // Stealing the data array for reading only...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                    int[] int_data =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                        SunWritableRaster.stealData((DataBufferInt) db, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                    int x = bufferedImage.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                    int y = bufferedImage.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                    int w = bufferedImage.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                    int h = bufferedImage.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                    int stride = psm.getScanlineStride();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                    boolean hastranspixel = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                    for (int j = y; j < y+h; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                        int yoff = j * stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                        for (int i = x; i < x+w; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                            if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                                hastranspixel = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                        if (hastranspixel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                    if (hastranspixel == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                        hasTransparency = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        return hasTransparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    protected boolean isBitmaskTransparency(BufferedImage bufferedImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        ColorModel colorModel = bufferedImage.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        return (colorModel != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                colorModel.getTransparency() == ColorModel.BITMASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    /* An optimisation for the special case of ICM images which have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * bitmask transparency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    protected boolean drawBitmaskImage(BufferedImage bufferedImage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                                       AffineTransform xform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                                       Color bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                                       int srcX, int srcY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                                       int srcWidth, int srcHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        ColorModel colorModel = bufferedImage.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        IndexColorModel icm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        int [] pixels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        if (!(colorModel instanceof IndexColorModel)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            icm = (IndexColorModel)colorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        if (colorModel.getTransparency() != ColorModel.BITMASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        // to be compatible with 1.1 printing which treated b/g colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        // with alpha 128 as opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        if (bgcolor != null && bgcolor.getAlpha() < 128) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        if ((xform.getType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
             & ~( AffineTransform.TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                  | AffineTransform.TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                  | AffineTransform.TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                  )) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        if ((getTransform().getType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
             & ~( AffineTransform.TYPE_UNIFORM_SCALE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                  | AffineTransform.TYPE_TRANSLATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                  | AffineTransform.TYPE_QUADRANT_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                  )) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        BufferedImage subImage = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        Raster raster = bufferedImage.getRaster();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        int transpixel = icm.getTransparentPixel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        byte[] alphas = new byte[icm.getMapSize()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        icm.getAlphas(alphas);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        if (transpixel >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            alphas[transpixel] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        /* don't just use srcWidth & srcHeight from application - they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
         * may exceed the extent of the image - may need to clip.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
         * The image xform will ensure that points are still mapped properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        int rw = raster.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        int rh = raster.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        if (srcX > rw || srcY > rh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        int right, bottom, wid, hgt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        if (srcX+srcWidth > rw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            right = rw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            wid = right - srcX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            right = srcX+srcWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            wid = srcWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        if (srcY+srcHeight > rh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            bottom = rh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            hgt = bottom - srcY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            bottom = srcY+srcHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            hgt = srcHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        pixels = new int[wid];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        for (int j=srcY; j<bottom; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            int startx = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            raster.getPixels(srcX, j, wid, 1, pixels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            for (int i=srcX; i<right; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                if (alphas[pixels[i-srcX]] == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                    if (startx >=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                        subImage = bufferedImage.getSubimage(startx, j,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                                                             i-startx, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                        xform.translate(startx, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                        drawImageToPlatform(subImage, xform, bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                                      0, 0, i-startx, 1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                        xform.translate(-startx, -j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                        startx = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                } else if (startx < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                    startx = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            if (startx >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                subImage = bufferedImage.getSubimage(startx, j,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                                                     right - startx, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                xform.translate(startx, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                drawImageToPlatform(subImage, xform, bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                              0, 0, right - startx, 1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                xform.translate(-startx, -j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * The various <code>drawImage()</code> methods for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     * <code>PathGraphics</code> are all decomposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     * into an invocation of <code>drawImageToPlatform</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     * The portion of the passed in image defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * <code>srcX, srcY, srcWidth, and srcHeight</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     * is transformed by the supplied AffineTransform and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     * drawn using PS to the printer context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * @param   img     The image to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     *                  This method does nothing if <code>img</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * @param   xform   Used to tranform the image before drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     *                  This can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * @param   bgcolor This color is drawn where the image has transparent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     *                  pixels. If this parameter is null then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     *                  pixels already in the destination should show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     *                  through.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * @param   srcX    With srcY this defines the upper-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     *                  of the portion of the image to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * @param   srcY    With srcX this defines the upper-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     *                  of the portion of the image to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * @param   srcWidth    The width of the portion of the image to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     *                      be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * @param   srcHeight   The height of the portion of the image to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     *                      be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * @param   handlingTransparency if being recursively called to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     *                    print opaque region of transparent image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    protected abstract boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        drawImageToPlatform(Image img, AffineTransform xform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                            Color bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                            int srcX, int srcY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                            int srcWidth, int srcHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                            boolean handlingTransparency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * Draws as much of the specified image as is currently available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * The image is drawn with its top-left corner at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * space. Transparent pixels in the image do not affect whatever
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * pixels are already there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * This method returns immediately in all cases, even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * complete image has not yet been loaded, and it has not been dithered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * and converted for the current output device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * If the image has not yet been completely loaded, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * <code>drawImage</code> returns <code>false</code>. As more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * the image becomes available, the process that draws the image notifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * the specified image observer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * @param    img the specified image to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * @param    x   the <i>x</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * @param    y   the <i>y</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * @param    observer    object to be notified as more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     *                          the image is converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * @see      java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * @see      java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * @since    JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    public boolean drawImage(Image img, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        return drawImage(img, x, y, null, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * Draws as much of the specified image as has already been scaled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * to fit inside the specified rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * The image is drawn inside the specified rectangle of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * graphics context's coordinate space, and is scaled if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * necessary. Transparent pixels do not affect whatever pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * are already there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * This method returns immediately in all cases, even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * entire image has not yet been scaled, dithered, and converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * for the current output device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * If the current output representation is not yet complete, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * <code>drawImage</code> returns <code>false</code>. As more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * the image becomes available, the process that draws the image notifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * the image observer by calling its <code>imageUpdate</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * A scaled version of an image will not necessarily be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * available immediately just because an unscaled version of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * image has been constructed for this output device.  Each size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * the image may be cached separately and generated from the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * data in a separate image production sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * @param    img    the specified image to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * @param    x      the <i>x</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * @param    y      the <i>y</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * @param    width  the width of the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * @param    height the height of the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * @param    observer    object to be notified as more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     *                          the image is converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * @see      java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     * @see      java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * @since    JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    public boolean drawImage(Image img, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                             int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        return drawImage(img, x, y, width, height, null, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * Draws as much of the specified image as is currently available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * The image is drawn with its top-left corner at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * (<i>x</i>,&nbsp;<i>y</i>) in this graphics context's coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * space.  Transparent pixels are drawn in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     * background color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * This operation is equivalent to filling a rectangle of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * width and height of the specified image with the given color and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * drawing the image on top of it, but possibly more efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * This method returns immediately in all cases, even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * complete image has not yet been loaded, and it has not been dithered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * and converted for the current output device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * If the image has not yet been completely loaded, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * <code>drawImage</code> returns <code>false</code>. As more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     * the image becomes available, the process that draws the image notifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * the specified image observer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     * @param    img    the specified image to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     *                  This method does nothing if <code>img</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     * @param    x      the <i>x</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * @param    y      the <i>y</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * @param    bgcolor the background color to paint under the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     *                   non-opaque portions of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     *                   In this WPathGraphics implementation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     *                   this parameter can be null in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     *                   case that background is made a transparent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     *                   white.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * @param    observer    object to be notified as more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     *                          the image is converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * @see      java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * @see      java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * @since    JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    public boolean drawImage(Image img, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                             Color bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        boolean result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        int srcWidth = img.getWidth(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        int srcHeight = img.getHeight(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        if (srcWidth < 0 || srcHeight < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            result = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            result = drawImage(img, x, y, srcWidth, srcHeight, bgcolor, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
     * Draws as much of the specified image as has already been scaled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     * to fit inside the specified rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * The image is drawn inside the specified rectangle of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * graphics context's coordinate space, and is scaled if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     * necessary. Transparent pixels are drawn in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     * background color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     * This operation is equivalent to filling a rectangle of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     * width and height of the specified image with the given color and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     * drawing the image on top of it, but possibly more efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * This method returns immediately in all cases, even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * entire image has not yet been scaled, dithered, and converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * for the current output device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * If the current output representation is not yet complete then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * <code>drawImage</code> returns <code>false</code>. As more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * the image becomes available, the process that draws the image notifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     * the specified image observer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     * A scaled version of an image will not necessarily be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     * available immediately just because an unscaled version of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     * image has been constructed for this output device.  Each size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * the image may be cached separately and generated from the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * data in a separate image production sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     * @param    img       the specified image to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
     *                     This method does nothing if <code>img</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
     * @param    x         the <i>x</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     * @param    y         the <i>y</i> coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
     * @param    width     the width of the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
     * @param    height    the height of the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
     * @param    bgcolor   the background color to paint under the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     *                         non-opaque portions of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     * @param    observer    object to be notified as more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     *                          the image is converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     * @see      java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     * @see      java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * @see      java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * @since    JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    public boolean drawImage(Image img, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                             int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                             Color bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        boolean result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        int srcWidth = img.getWidth(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        int srcHeight = img.getHeight(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        if (srcWidth < 0 || srcHeight < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            result = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
            result = drawImage(img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                         x, y, x + width, y + height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                         0, 0, srcWidth, srcHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                         observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     * Draws as much of the specified area of the specified image as is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
     * currently available, scaling it on the fly to fit inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
     * specified area of the destination drawable surface. Transparent pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
     * do not affect whatever pixels are already there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     * This method returns immediately in all cases, even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     * image area to be drawn has not yet been scaled, dithered, and converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     * for the current output device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     * If the current output representation is not yet complete then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * <code>drawImage</code> returns <code>false</code>. As more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * the image becomes available, the process that draws the image notifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     * the specified image observer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     * This method always uses the unscaled version of the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     * to render the scaled rectangle and performs the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * scaling on the fly. It does not use a cached, scaled version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     * of the image for this operation. Scaling of the image from source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * to destination is performed such that the first coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * of the source rectangle is mapped to the first coordinate of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     * the destination rectangle, and the second source coordinate is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     * mapped to the second destination coordinate. The subimage is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * scaled and flipped as needed to preserve those mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * @param       img the specified image to be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * @param       dx1 the <i>x</i> coordinate of the first corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     *                    destination rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * @param       dy1 the <i>y</i> coordinate of the first corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     *                    destination rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * @param       dx2 the <i>x</i> coordinate of the second corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     *                    destination rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * @param       dy2 the <i>y</i> coordinate of the second corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     *                    destination rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
     * @param       sx1 the <i>x</i> coordinate of the first corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
     *                    source rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
     * @param       sy1 the <i>y</i> coordinate of the first corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
     *                    source rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * @param       sx2 the <i>x</i> coordinate of the second corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     *                    source rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * @param       sy2 the <i>y</i> coordinate of the second corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     *                    source rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     * @param       observer object to be notified as more of the image is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     *                    scaled and converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     * @see         java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * @see         java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * @see         java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    public boolean drawImage(Image img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                             int dx1, int dy1, int dx2, int dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                             int sx1, int sy1, int sx2, int sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        return drawImage(img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                         dx1, dy1, dx2, dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                         sx1, sy1, sx2, sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                         null, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     * Draws as much of the specified area of the specified image as is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     * currently available, scaling it on the fly to fit inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     * specified area of the destination drawable surface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     * Transparent pixels are drawn in the specified background color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     * This operation is equivalent to filling a rectangle of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
     * width and height of the specified image with the given color and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
     * drawing the image on top of it, but possibly more efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
     * This method returns immediately in all cases, even if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
     * image area to be drawn has not yet been scaled, dithered, and converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     * for the current output device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * If the current output representation is not yet complete then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     * <code>drawImage</code> returns <code>false</code>. As more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     * the image becomes available, the process that draws the image notifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     * the specified image observer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
     * This method always uses the unscaled version of the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
     * to render the scaled rectangle and performs the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
     * scaling on the fly. It does not use a cached, scaled version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
     * of the image for this operation. Scaling of the image from source
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
     * to destination is performed such that the first coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
     * of the source rectangle is mapped to the first coordinate of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
     * the destination rectangle, and the second source coordinate is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
     * mapped to the second destination coordinate. The subimage is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
     * scaled and flipped as needed to preserve those mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
     * @param       img the specified image to be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
     *                  This method does nothing if <code>img</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
     * @param       dx1 the <i>x</i> coordinate of the first corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     *                    destination rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     * @param       dy1 the <i>y</i> coordinate of the first corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     *                    destination rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
     * @param       dx2 the <i>x</i> coordinate of the second corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     *                    destination rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     * @param       dy2 the <i>y</i> coordinate of the second corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
     *                    destination rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
     * @param       sx1 the <i>x</i> coordinate of the first corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     *                    source rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     * @param       sy1 the <i>y</i> coordinate of the first corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     *                    source rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     * @param       sx2 the <i>x</i> coordinate of the second corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     *                    source rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     * @param       sy2 the <i>y</i> coordinate of the second corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     *                    source rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
     * @param       bgcolor the background color to paint under the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     *                    non-opaque portions of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     * @param       observer object to be notified as more of the image is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     *                    scaled and converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     * @see         java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     * @see         java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     * @see         java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    public boolean drawImage(Image img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                             int dx1, int dy1, int dx2, int dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                             int sx1, int sy1, int sx2, int sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                             Color bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        int imgWidth = img.getWidth(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        int imgHeight = img.getHeight(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        if (imgWidth < 0 || imgHeight < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        int srcWidth = sx2 - sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
        int srcHeight = sy2 - sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        /* Create a transform which describes the changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
         * from the source coordinates to the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
         * coordinates. The scaling is determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
         * ratio of the two rectangles, while the translation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
         * comes from the difference of their origins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        float scalex = (float) (dx2 - dx1) / srcWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
        float scaley = (float) (dy2 - dy1) / srcHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        AffineTransform xForm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            = new AffineTransform(scalex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                                  0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                                  0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                                  scaley,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                                  dx1 - (sx1 * scalex),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                                  dy1 - (sy1 * scaley));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        /* drawImageToPlatform needs the top-left of the source area and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
         * a positive width and height. The xform describes how to map
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
         * src->dest, so that information is not lost.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
        int tmp=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        if (sx2 < sx1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            tmp = sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
            sx1 = sx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            sx2 = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        if (sy2 < sy1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
            tmp = sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
            sy1 = sy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
            sy2 = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        /* if src area is beyond the bounds of the image, we must clip it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
         * The transform is based on the specified area, not the clipped one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        if (sx1 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
            sx1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        } else if (sx1 > imgWidth) { // empty srcArea, nothing to draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
            sx1 = imgWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        if (sx2 < 0) { // empty srcArea, nothing to draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
            sx2 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        } else if (sx2 > imgWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
            sx2 = imgWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        if (sy1 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            sy1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        } else if (sy1 > imgHeight) { // empty srcArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            sy1 = imgHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
        if (sy2 < 0) {  // empty srcArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
            sy2 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
        } else if (sy2 > imgHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            sy2 = imgHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
        srcWidth =  sx2 - sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
        srcHeight = sy2 - sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
        if (srcWidth <= 0 || srcHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        return drawImageToPlatform(img, xForm, bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                                   sx1, sy1, srcWidth, srcHeight, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * Draws an image, applying a transform from image space into user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     * before drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     * The transformation from user space into device space is done with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * the current transform in the Graphics2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * The given transformation is applied to the image before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     * transform attribute in the Graphics2D state is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     * The rendering attributes applied include the clip, transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     * and composite attributes. Note that the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     * undefined, if the given transform is noninvertible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     * @param img The image to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     *            This method does nothing if <code>img</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     * @param xform The transformation from image space into user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * @param obs The image observer to be notified as more of the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * is converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     * @see #clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
    public boolean drawImage(Image img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                             AffineTransform xform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                             ImageObserver obs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        boolean result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        int srcWidth = img.getWidth(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
        int srcHeight = img.getHeight(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        if (srcWidth < 0 || srcHeight < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            result = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            result = drawImageToPlatform(img, xform, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                                         0, 0, srcWidth, srcHeight, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * Draws a BufferedImage that is filtered with a BufferedImageOp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * The rendering attributes applied include the clip, transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * and composite attributes.  This is equivalent to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * img1 = op.filter(img, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * @param op The filter to be applied to the image before drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * @param img The BufferedImage to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     *            This method does nothing if <code>img</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * @param x,y The location in user space where the image should be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * @see #clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
    public void drawImage(BufferedImage img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                          BufferedImageOp op,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                          int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                          int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
        int srcWidth = img.getWidth(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        int srcHeight = img.getHeight(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        if (op != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            img = op.filter(img, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
        if (srcWidth <= 0 || srcHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
            AffineTransform xform = new AffineTransform(1f,0f,0f,1f,x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
            drawImageToPlatform(img, xform, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                                0, 0, srcWidth, srcHeight, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     * Draws an image, applying a transform from image space into user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     * before drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     * The transformation from user space into device space is done with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * the current transform in the Graphics2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     * The given transformation is applied to the image before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     * transform attribute in the Graphics2D state is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     * The rendering attributes applied include the clip, transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     * and composite attributes. Note that the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * undefined, if the given transform is noninvertible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * @param img The image to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     *            This method does nothing if <code>img</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     * @param xform The transformation from image space into user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     * @see #clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    public void drawRenderedImage(RenderedImage img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                                  AffineTransform xform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        BufferedImage bufferedImage = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        int srcWidth = img.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
        int srcHeight = img.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        if (srcWidth <= 0 || srcHeight <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        if (img instanceof BufferedImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            bufferedImage = (BufferedImage) img;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
            bufferedImage = new BufferedImage(srcWidth, srcHeight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                                              BufferedImage.TYPE_INT_ARGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            Graphics2D imageGraphics = bufferedImage.createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
            imageGraphics.drawRenderedImage(img, xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        drawImageToPlatform(bufferedImage, xform, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                            0, 0, srcWidth, srcHeight, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
}