⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdkgraphics2d.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	catch (java.awt.geom.NoninvertibleTransformException e)	  {	  }      }  }  public void rotate(double theta)  {    transform(AffineTransform.getRotateInstance(theta));  }  public void rotate(double theta, double x, double y)  {    transform(AffineTransform.getRotateInstance(theta, x, y));  }  public void scale(double sx, double sy)  {    transform(AffineTransform.getScaleInstance(sx, sy));  }  public void translate(double tx, double ty)  {    transform(AffineTransform.getTranslateInstance(tx, ty));  }  public void translate(int x, int y)  {    translate((double) x, (double) y);  }  public void shear(double shearX, double shearY)  {    transform(AffineTransform.getShearInstance(shearX, shearY));  }  public Stroke getStroke()  {    return stroke;  }  public void setStroke(Stroke st)  {    stroke = st;    if (stroke instanceof BasicStroke)      {	BasicStroke bs = (BasicStroke) stroke;	cairoSetLineCap(bs.getEndCap());	cairoSetLineWidth(bs.getLineWidth());	cairoSetLineJoin(bs.getLineJoin());	cairoSetMiterLimit(bs.getMiterLimit());	float[] dashes = bs.getDashArray();	if (dashes != null)	  {	    double[] double_dashes = new double[dashes.length];	    for (int i = 0; i < dashes.length; i++)	      double_dashes[i] = dashes[i];	    cairoSetDash(double_dashes, double_dashes.length,	                 (double) bs.getDashPhase());	  }	else	  cairoSetDash(new double[0], 0, 0.0);      }  }  public void setStrokeUnlocked(Stroke st)  {    stroke = st;    if (stroke instanceof BasicStroke)      {	BasicStroke bs = (BasicStroke) stroke;	cairoSetLineCapUnlocked(bs.getEndCap());	cairoSetLineWidthUnlocked(bs.getLineWidth());	cairoSetLineJoinUnlocked(bs.getLineJoin());	cairoSetMiterLimitUnlocked(bs.getMiterLimit());	float[] dashes = bs.getDashArray();	if (dashes != null)	  {	    double[] double_dashes = new double[dashes.length];	    for (int i = 0; i < dashes.length; i++)	      double_dashes[i] = dashes[i];	    cairoSetDashUnlocked(double_dashes, double_dashes.length,                                 (double) bs.getDashPhase());	  }	else	  cairoSetDashUnlocked(new double[0], 0, 0.0);      }  }  ////////////////////////////////////////////////  ////// Implementation of Graphics Methods //////  ////////////////////////////////////////////////  public void setPaintMode()  {    setComposite(java.awt.AlphaComposite.SrcOver);  }  public void setXORMode(Color c)  {    setComposite(new gnu.java.awt.BitwiseXORComposite(c));  }  public void setColor(Color c)  {    if (c == null)      c = Color.BLACK;    fg = c;    paint = c;    cairoSetRGBAColor(fg.getRed() / 255.0, fg.getGreen() / 255.0,                      fg.getBlue() / 255.0, fg.getAlpha() / 255.0);  }  public void setColorUnlocked(Color c)  {    if (c == null)      c = Color.BLACK;    fg = c;    paint = c;    cairoSetRGBAColorUnlocked(fg.getRed() / 255.0, fg.getGreen() / 255.0,                      fg.getBlue() / 255.0, fg.getAlpha() / 255.0);  }  public Color getColor()  {    return fg;  }  public Color getColorUnlocked()  {    return getColor();  }  public void clipRect(int x, int y, int width, int height)  {    clip(new Rectangle(x, y, width, height));  }  public Shape getClip()  {    if (clip == null)      return null;    else      return clip.getBounds2D(); //getClipInDevSpace();  }  public Rectangle getClipBounds()  {    if (clip == null)      return null;    else      return clip.getBounds();  }  protected Rectangle2D getClipInDevSpace()  {    Rectangle2D uclip = clip.getBounds2D();    if (transform == null)      return uclip;    else      {	Point2D pos = transform.transform(new Point2D.Double(uclip.getX(),	                                                     uclip.getY()),	                                  (Point2D) null);	Point2D extent = transform.deltaTransform(new Point2D.Double(uclip	                                                             .getWidth(),	                                                             uclip	                                                             .getHeight()),	                                          (Point2D) null);	return new Rectangle2D.Double(pos.getX(), pos.getY(), extent.getX(),	                              extent.getY());      }  }  public void setClip(int x, int y, int width, int height)  {    setClip(new Rectangle2D.Double((double) x, (double) y, (double) width,                                   (double) height));  }  public void setClip(Shape s)  {    clip = s;    if (clip == null)      {	// Reset clipping.        if (component != null)          {            Dimension d = component.awtComponent.getSize();            setClip(0, 0, d.width, d.height);          }      }    else      {	cairoNewPath();	if (s instanceof Rectangle2D)	  {	    Rectangle2D r = (Rectangle2D) s;	    cairoRectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight());	  }	else	  walkPath(s.getPathIterator(null), false);	// cairoClosePath ();	cairoClip();      }  }  private static BasicStroke draw3DRectStroke = new BasicStroke();  public void draw3DRect(int x, int y, int width, int height, boolean raised)  {    Stroke tmp = stroke;    setStroke(draw3DRectStroke);    super.draw3DRect(x, y, width, height, raised);    setStroke(tmp);    updateBufferedImage();  }  public void fill3DRect(int x, int y, int width, int height, boolean raised)  {    Stroke tmp = stroke;    setStroke(draw3DRectStroke);    super.fill3DRect(x, y, width, height, raised);    setStroke(tmp);    updateBufferedImage();  }  public void drawRect(int x, int y, int width, int height)  {    draw(new Rectangle(x, y, width, height));  }  public void fillRect(int x, int y, int width, int height)  {    cairoNewPath();    cairoRectangle(x, y, width, height);    cairoFill();  }  public void clearRect(int x, int y, int width, int height)  {    if (bg != null)      cairoSetRGBAColor(bg.getRed() / 255.0, bg.getGreen() / 255.0,			bg.getBlue() / 255.0, 1.0);    cairoNewPath();    cairoRectangle(x, y, width, height);    cairoFill();    setColor(fg);    updateBufferedImage();  }  public void setBackground(Color c)  {    if (c == null)      c = Color.WHITE;    bg = c;  }  public void setBackgroundUnlocked(Color c)  {    setBackground(c);  }  public Color getBackground()  {    return bg;  }  private void doPolygon(int[] xPoints, int[] yPoints, int nPoints,                         boolean close, boolean fill)  {    if (nPoints < 1)      return;    GeneralPath gp = new GeneralPath(PathIterator.WIND_EVEN_ODD);    gp.moveTo((float) xPoints[0], (float) yPoints[0]);    for (int i = 1; i < nPoints; i++)      gp.lineTo((float) xPoints[i], (float) yPoints[i]);    if (close)      gp.closePath();    Shape sh = gp;    if (fill == false && stroke != null && ! (stroke instanceof BasicStroke))      {	sh = stroke.createStrokedShape(gp);	fill = true;      }    if (fill)      fill(sh);    else      draw(sh);  }  public void drawLine(int x1, int y1, int x2, int y2)  {    int[] xp = new int[2];    int[] yp = new int[2];    xp[0] = x1;    xp[1] = x2;    yp[0] = y1;    yp[1] = y2;    doPolygon(xp, yp, 2, false, false);  }  public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)  {    doPolygon(xPoints, yPoints, nPoints, true, true);  }  public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)  {    doPolygon(xPoints, yPoints, nPoints, true, false);  }  public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)  {    doPolygon(xPoints, yPoints, nPoints, false, false);  }  private boolean drawRaster(ColorModel cm, Raster r,                             AffineTransform imageToUser, Color bgcolor)  {    if (r == null)      return false;    SampleModel sm = r.getSampleModel();    DataBuffer db = r.getDataBuffer();    if (db == null || sm == null)      return false;    if (cm == null)      cm = ColorModel.getRGBdefault();    double[] i2u = new double[6];    if (imageToUser != null)      imageToUser.getMatrix(i2u);    else      {	i2u[0] = 1;	i2u[1] = 0;	i2u[2] = 0;	i2u[3] = 1;	i2u[4] = 0;	i2u[5] = 0;      }    int[] pixels = findSimpleIntegerArray(cm, r);    if (pixels == null)      {	// FIXME: I don't think this code will work correctly with a non-RGB	// MultiPixelPackedSampleModel. Although this entire method should 	// probably be rewritten to better utilize Cairo's different supported	// data formats.	if (sm instanceof MultiPixelPackedSampleModel)	  {	    pixels = r.getPixels(0, 0, r.getWidth(), r.getHeight(), pixels);	    for (int i = 0; i < pixels.length; i++)	      pixels[i] = cm.getRGB(pixels[i]);	  }	else	  {	    pixels = new int[r.getWidth() * r.getHeight()];	    for (int i = 0; i < pixels.length; i++)	      pixels[i] = cm.getRGB(db.getElem(i));	  }      }    // Change all transparent pixels in the image to the specified bgcolor,    // or (if there's no alpha) fill in an alpha channel so that it paints    // correctly.    if (cm.hasAlpha())      {	if (bgcolor != null && cm.hasAlpha())	  for (int i = 0; i < pixels.length; i++)	    {	      if (cm.getAlpha(pixels[i]) == 0)		pixels[i] = bgcolor.getRGB();	    }      }    else      for (int i = 0; i < pixels.length; i++)	pixels[i] |= 0xFF000000;    drawPixels(pixels, r.getWidth(), r.getHeight(), r.getWidth(), i2u);    updateBufferedImage();    return true;  }  public void drawRenderedImage(RenderedImage image, AffineTransform xform)  {    drawRaster(image.getColorModel(), image.getData(), xform, bg);  }  public void drawRenderableImage(RenderableImage image, AffineTransform xform)  {    drawRenderedImage(image.createRendering(new RenderContext(xform)), xform);  }  public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs)  {    return drawImage(img, xform, bg, obs);  }  public void drawImage(BufferedImage image, BufferedImageOp op, int x, int y)  {    Image filtered = op.filter(image, null);    drawImage(filtered, new AffineTransform(1f, 0f, 0f, 1f, x, y), bg, null);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -