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

📄 gdkgraphics2d.java

📁 gcc的JAVA模块的源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  public void clip (Shape s)  {      // update it      if (clip == null || s == null)	  clip = s;      else if (s instanceof Rectangle2D	       && clip instanceof Rectangle2D)	  {	      Rectangle2D r = (Rectangle2D)s;	      Rectangle2D curr = (Rectangle2D)clip;	      clip = curr.createIntersection (r);	  }      else	  throw new UnsupportedOperationException ();      // draw it      if (clip != null)	  {	      cairoNewPath ();	      if (clip instanceof Rectangle2D)		  {		      Rectangle2D r = (Rectangle2D)clip;		      cairoRectangle (r.getX (), r.getY (), 				      r.getWidth (), r.getHeight ());		  }	      else		  walkPath (clip.getPathIterator (null));	      cairoClosePath ();	      cairoClip ();	  }  }  public Paint getPaint ()  {    return paint;  }  public AffineTransform getTransform ()  {      return (AffineTransform) transform.clone ();  }  public void setPaint (Paint p)  {    if (paint == null)        return;          paint = p;    if (paint instanceof Color)      {        setColor ((Color) paint);      }    else if (paint instanceof TexturePaint)      {        TexturePaint tp = (TexturePaint) paint;        BufferedImage img = tp.getImage ();        int pixels[] = img.getRGB(0, 0, img.getWidth (),                                   img.getHeight (), null,                                   0, img.getWidth ());        setTexturePixels (pixels, img.getWidth (),                           img.getHeight (), img.getWidth ());      }    else if (paint instanceof GradientPaint)      {        GradientPaint gp = (GradientPaint) paint;        Point2D p1 = gp.getPoint1 ();        Point2D p2 = gp.getPoint2 ();        Color c1 = gp.getColor1 ();        Color c2 = gp.getColor2 ();                setGradient (p1.getX (), p1.getY (),                     p2.getX (), p2.getY (),                     c1.getRed (), c1.getGreen (),                      c1.getBlue (), c1.getAlpha (),                     c2.getRed (), c2.getGreen (),                      c2.getBlue (), c2.getAlpha (),                     gp.isCyclic ());      }    else      throw new java.lang.UnsupportedOperationException ();  }  public void setTransform (AffineTransform tx)  {    transform = tx;    if (transform != null)      {        double m[] = new double[6];        transform.getMatrix (m);        cairoSetMatrix (m);      }  }  public void transform (AffineTransform tx)  {    if (transform == null)      transform = new AffineTransform (tx);    else      transform.concatenate (tx);    setTransform (transform);  }  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() / 2.0);        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 ());                  }      }  }  ////////////////////////////////////////////////  ////// 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)  {    fg = c;    paint = c;    cairoSetRGBColor (fg.getRed() / 255.0,                       fg.getGreen() / 255.0,                       fg.getBlue() / 255.0);    cairoSetAlpha ((fg.getAlpha() & 255) / 255.0);  }  public Color getColor ()  {    return fg;  }  public void clipRect (int x, int y, int width, int height)  {      clip (new Rectangle (x, y, width, height));  }  public Shape getClip ()  {    return 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)  {      cairoNewPath ();      cairoRectangle (x, y, width, height);      cairoClosePath ();      cairoClip ();      clip = new Rectangle2D.Double ((double)x, (double)y, 				     (double)width, (double)height);  }  public void setClip (Shape s)  {    clip (s);  }  public void draw3DRect(int x, int y, int width,                          int height, boolean raised)  {    Color std = fg;    Color light = std.brighter();    Color dark = std.darker();    if (!raised)      {        Color t = light;        light = dark;        dark = t;      }        double x1 = (double) x;    double x2 = (double) x + width;    double y1 = (double) y;    double y2 = (double) y + height;    stateSave ();        cairoNewPath ();        boolean normalize;    normalize = hints.containsValue (RenderingHints.VALUE_STROKE_NORMALIZE)                || hints.containsValue (RenderingHints.VALUE_STROKE_DEFAULT);		    if (normalize)       {    	x1 += 0.5;	y1 += 0.5; 	x2 += 0.5;	y2 += 0.5;       }        setColor (light);    cairoMoveTo (x1, y1);    cairoLineTo (x2, y1);    cairoLineTo (x2, y2);    cairoStroke ();        cairoNewPath ();    setColor (dark);    cairoMoveTo (x1, y1);    cairoLineTo (x1, y2);    cairoLineTo (x2, y2);    cairoStroke ();        stateRestore ();      }  public void fill3DRect(int x, int y, int width,                          int height, boolean raised)  {    double step = 1.0;    if (stroke != null && stroke instanceof BasicStroke)      {        BasicStroke bs = (BasicStroke) stroke;        step = bs.getLineWidth();      }    Color bright = fg.brighter ();    Color dark = fg.darker ();          draw3DRect (x, y, width, height, raised);        stateSave ();    translate (step/2.0, step/2.0);    cairoNewPath ();    cairoRectangle ((double) x, (double) y,                     ((double) width) - step,                     ((double) height) - step );    cairoClosePath ();    cairoFill ();    stateRestore ();  }  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)  {    fill(new Rectangle (x, y, width, height));  }  public void clearRect (int x, int y, int width, int height)  {    stateSave ();    cairoSetRGBColor (bg.getRed() / 255.0,                       bg.getGreen() / 255.0,                       bg.getBlue() / 255.0);    cairoSetAlpha (1.0);    cairoNewPath ();    cairoRectangle (x, y, width, height);    cairoClosePath ();    cairoFill ();    stateRestore ();  }  public void setBackground(Color c)  {    bg = 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)  {    if (r == null)      return false;    SampleModel sm = r.getSampleModel ();    DataBuffer db = r.getDataBuffer ();    if (db == null || sm == null)      return false;

⌨️ 快捷键说明

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