日期:2014-05-20 浏览次数:20818 次
package sun.java2d; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.RenderingHints.Key; import java.awt.geom.Area; import java.awt.geom.AffineTransform; import java.awt.geom.NoninvertibleTransformException; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.image.BufferedImage; import java.awt.image.BufferedImageOp; import java.awt.image.RenderedImage; import java.awt.image.renderable.RenderableImage; import java.awt.image.renderable.RenderContext; import java.awt.image.AffineTransformOp; import java.awt.image.Raster; import java.awt.image.SampleModel; import java.awt.image.VolatileImage; import java.awt.image.WritableRaster; import java.awt.Image; import java.awt.Composite; import java.awt.Color; import java.awt.color.ColorSpace; import java.awt.image.DataBuffer; import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; import java.awt.image.DirectColorModel; import java.awt.GraphicsConfiguration; import java.awt.Paint; import java.awt.GradientPaint; import java.awt.LinearGradientPaint; import java.awt.RadialGradientPaint; import java.awt.TexturePaint; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.geom.PathIterator; import java.awt.geom.GeneralPath; import java.awt.Shape; import java.awt.Stroke; import java.awt.FontMetrics; import java.awt.Rectangle; import java.text.AttributedCharacterIterator; import java.awt.Font; import java.awt.image.ImageObserver; import java.awt.image.ColorConvertOp; import java.awt.Transparency; import java.awt.font.GlyphVector; import java.awt.font.TextLayout; import sun.font.FontDesignMetrics; import sun.font.StandardGlyphVector; import sun.java2d.pipe.PixelDrawPipe; import sun.java2d.pipe.PixelFillPipe; import sun.java2d.pipe.ShapeDrawPipe; import sun.java2d.pipe.ValidatePipe; import sun.java2d.pipe.ShapeSpanIterator; import sun.java2d.pipe.Region; import sun.java2d.pipe.RegionIterator; import sun.java2d.pipe.TextPipe; import sun.java2d.pipe.DrawImagePipe; import sun.java2d.pipe.LoopPipe; import sun.java2d.loops.FontInfo; import sun.java2d.loops.RenderLoops; import sun.java2d.loops.CompositeType; import sun.java2d.loops.SurfaceType; import sun.java2d.loops.Blit; import sun.java2d.loops.BlitBg; import sun.java2d.loops.MaskFill; import sun.font.FontManager; import java.awt.font.FontRenderContext; import sun.java2d.loops.XORComposite; import sun.awt.ConstrainableGraphics; import sun.awt.SunHints; import java.util.Map; import java.util.Iterator; import sun.awt.image.OffScreenImage; import sun.misc.PerformanceLogger; /** * This is a the master Graphics2D superclass for all of the Sun * Graphics implementations. This class relies on subclasses to * manage the various device information, but provides an overall * general framework for performing all of the requests in the * Graphics and Graphics2D APIs. * * @author Jim Graham */ public final class SunGraphics2D extends Graphics2D implements ConstrainableGraphics, Cloneable { /* * Attribute States */ /* Paint */ public static final int PAINT_CUSTOM = 6; /* Any other Paint object */ public static final int PAINT_TEXTURE = 5; /* Tiled Image */ public static final int PAINT_RAD_GRADIENT = 4; /* Color RadialGradient */ public static final int PAINT_LIN_GRADIENT = 3; /* Color LinearGradient */ public static final int PAINT_GRADIENT = 2; /* Color Gradient */ public static final int PAINT_ALPHACOLOR = 1; /* Non-opaque Color */ public static final int PAINT_OPAQUECOLOR = 0; /* Opaque Color */ /* Composite*/ public static final int COMP_CUSTOM = 3;/* Custom Composite */ public static final int COMP_XOR = 2;/* XOR Mode Composite */ public static final int COMP_ALPHA = 1;/* AlphaComposite */ public static final int COMP_ISCOPY = 0;/* simple stores into destination, * i.e. Src, SrcOverNoEa, and other * alpha modes which replace * the destination. */ /* Stroke */ public static final int STROKE_CUSTOM = 3; /* custom Stroke */ public static final int STROKE_WIDE = 2; /* BasicStroke */ public static final int STROKE_THINDASHED = 1; /* BasicStroke */ public static final int STROKE_THIN = 0; /* BasicStroke */ /* Transform */ public static final int TRANSFORM_GENERIC = 4; /* any 3x2 */ public static final int TRANSFORM_TRANSLATESCALE = 3; /* scale XY */ public static final int TRANSFORM_ANY_TRANSLATE = 2; /* non-int translate */ public static final int TRANSFORM_INT_TRANSLATE = 1; /* int translate */ public static final int TRANSFORM_ISIDENT = 0; /* Identity */ /* Clipping */ public static final int CLIP_SHAPE = 2; /* arbitrary clip */ public static final int CLIP_RECTANGULAR = 1; /* rectangular clip */ public static final int CLIP_DEVICE = 0; /* no clipping set */ /* The following fields are used when the current Paint is a Color. */ public int eargb; // ARGB value with ExtraAlpha baked in public int pixel; // pixel value for eargb public SurfaceData surfaceData; public PixelDrawPipe drawpipe; public PixelFillPipe fillpipe; public DrawImagePipe imagepipe; public ShapeDrawPipe shapepipe; public TextPipe textpipe; public MaskFill alphafill; public RenderLoops loops; public CompositeType imageComp; /* Image Transparency checked on fly */ public int paintState; public int compositeState; public int strokeState; public int transformState; public int clipState; public Color foregroundColor; public Color backgroundColor; public AffineTransform transform; public int transX; public int transY; protected static final Stroke defaultStroke = new BasicStroke(); protected static final Composite defaultComposite = AlphaComposite.SrcOver; private static final Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12); public Paint paint; public Stroke stroke; public Composite composite; protected Font font; protected FontMetrics fontMetrics; public int renderHint; public int antialiasHint; public int textAntialiasHint; private int fractionalMetricsHint; /* A gamma adjustment to the colour used in lcd text blitting */ public int lcdTextContrast; private static int lcdTextContrastDefaultValue = 140; private int interpolationHint; // raw value of rendering Hint public int strokeHint; public int interpolationType; // algorithm choice based on // interpolation and render Hints public RenderingHints hints; public Region constrainClip; // lightweight bounds public int constrainX; public int constrainY; public Region clipRegion; public Shape usrClip; protected Region devClip; // Actual physical drawable // cached state for text rendering private boolean validFontInfo; private FontInfo fontInfo; private FontInfo glyphVectorFontInfo; private FontRenderContext glyphVectorFRC; private final static int slowTextTransformMask = AffineTransform.TYPE_GENERAL_TRANSFORM | AffineTransform.TYPE_MASK_ROTATION | AffineTransform.TYPE_FLIP; static { if (PerformanceLogger.loggingEnabled()) { PerformanceLogger.setTime("SunGraphics2D static initialization"); } } public SunGraphics2D(SurfaceData sd, Color fg, Color bg, Font f) { surfaceData = sd; foregroundColor = fg; backgroundColor = bg; transform = new AffineTransform(); stroke = defaultStroke; composite = defaultComposite; paint = foregroundColor; imageComp = CompositeType.SrcOverNoEa; renderHint = SunHints.INTVAL_RENDER_DEFAULT; antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT; fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF; lcdTextContrast = lcdTextContrastDefaultValue; interpolationHint = -1; strokeHint = SunHints.INTVAL_STROKE_DEFAULT; interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR; validateColor(); font = f; if (font == null) { font = defaultFont; } loops = sd.getRenderLoops(this); setDevClip(sd.getBounds()); invalidatePipe(); }