/[classpath]/classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java
ViewVC logotype

Diff of /classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by mkoch, Tue Nov 4 11:24:08 2003 UTC revision 1.4 by graydon, Thu Nov 20 22:27:36 2003 UTC
# Line 47  import java.awt.image.renderable.*; Line 47  import java.awt.image.renderable.*;
47    
48  import java.text.AttributedCharacterIterator;  import java.text.AttributedCharacterIterator;
49  import java.util.Map;  import java.util.Map;
50    import java.util.Stack;
51  import java.lang.Integer;  import java.lang.Integer;
52  import gnu.java.awt.ClasspathToolkit;  import gnu.java.awt.ClasspathToolkit;
53  import gnu.java.awt.peer.ClasspathFontPeer;  import gnu.java.awt.peer.ClasspathFontPeer;
# Line 78  public class GdkGraphics2D extends Graph Line 79  public class GdkGraphics2D extends Graph
79    private AffineTransform transform;    private AffineTransform transform;
80    private GtkComponentPeer component;    private GtkComponentPeer component;
81    private Font font;      private Font font;  
82    
83      private Stack stateStack;
84        
85    native private int[] initState (GtkComponentPeer component);    native private int[] initState (GtkComponentPeer component);
86    native private void initState (int width, int height);    native private void initState (int width, int height);
# Line 122  public class GdkGraphics2D extends Graph Line 125  public class GdkGraphics2D extends Graph
125        clip = new Rectangle (g.getClipBounds ());        clip = new Rectangle (g.getClipBounds ());
126    
127      if (g.transform == null)      if (g.transform == null)
128        transform = null;        transform = AffineTransform.getTranslateInstance (0.5, 0.5);
129      else      else
130        transform = new AffineTransform (g.transform);        transform = new AffineTransform (g.transform);
131    
132        font = g.font;
133      component = g.component;      component = g.component;
134      copyState (g);      copyState (g);
135    
136      setColor (fg);      setColor (fg);
137        setBackground (bg);
138        setPaint (paint);
139        setStroke (stroke);
140      setClip (clip);      setClip (clip);
141      setTransform (transform);      setTransform (transform);
142        stateStack = new Stack();
143    }    }
144    
145    GdkGraphics2D (int width, int height)    GdkGraphics2D (int width, int height)
146    {    {
147      initState (width, height);      initState (width, height);
148      bg = Color.black;  
149      fg = Color.black;      setColor(Color.black);
150      transform = new AffineTransform ();      setBackground (Color.black);
151        setPaint (getColor());
152        setFont (new Font("SansSerif", Font.PLAIN, 12));
153        setTransform (AffineTransform.getTranslateInstance (0.5, 0.5));
154        setStroke (new BasicStroke ());
155    
156        stateStack = new Stack();
157    }    }
158    
159    GdkGraphics2D (GtkComponentPeer component)    GdkGraphics2D (GtkComponentPeer component)
160    {    {
161      this.component = component;      this.component = component;
162      int rgb[] = initState (component);      int rgb[] = initState (component);
163      fg = new Color (rgb[0], rgb[1], rgb[2]);  
164      bg = new Color (rgb[3], rgb[4], rgb[5]);      setColor (new Color (rgb[0], rgb[1], rgb[2]));
165      transform = new AffineTransform ();      setBackground (new Color (rgb[3], rgb[4], rgb[5]));
166        setPaint (getColor());
167        setFont (new Font("SansSerif", Font.PLAIN, 12));
168        setTransform (AffineTransform.getTranslateInstance (0.5, 0.5));
169        setStroke (new BasicStroke ());
170    
171        stateStack = new Stack ();
172    }    }
173    
174    
# Line 160  public class GdkGraphics2D extends Graph Line 180  public class GdkGraphics2D extends Graph
180    private native void gdkDrawDrawable (GdkGraphics2D other, int x, int y);    private native void gdkDrawDrawable (GdkGraphics2D other, int x, int y);
181    
182    // drawing utility methods    // drawing utility methods
183    private native void drawPixels (int pixels[], int w, int h, int stride);    private native void drawPixels (int pixels[], int w, int h, int stride, double i2u[]);
184    private native void setTexturePixels (int pixels[], int w, int h, int stride);    private native void setTexturePixels (int pixels[], int w, int h, int stride);
185    private native void setGradient (double x1, double y1,    private native void setGradient (double x1, double y1,
186                                     double x2, double y2,                                     double x2, double y2,
# Line 171  public class GdkGraphics2D extends Graph Line 191  public class GdkGraphics2D extends Graph
191    // simple passthroughs to cairo    // simple passthroughs to cairo
192    private native void cairoSave ();    private native void cairoSave ();
193    private native void cairoRestore ();    private native void cairoRestore ();
194    private native void cairoSetMatrix (double m00, double m10,    private native void cairoSetMatrix (double m[]);
                                       double m01, double m11,  
                                       double m02, double m12);  
195    private native void cairoSetFont (GdkClasspathFontPeer peer);    private native void cairoSetFont (GdkClasspathFontPeer peer);
196    private native void cairoShowGlyphs (int codes[],    private native void cairoShowGlyphs (int codes[],
197                                         float positions[],                                         float positions[]);
                                        int nglyphs);  
198    private native void cairoSetOperator (int cairoOperator);    private native void cairoSetOperator (int cairoOperator);
199    private native void cairoSetRGBColor (double red, double green, double blue);    private native void cairoSetRGBColor (double red, double green, double blue);
200    private native void cairoSetAlpha (double alpha);    private native void cairoSetAlpha (double alpha);
# Line 187  public class GdkGraphics2D extends Graph Line 204  public class GdkGraphics2D extends Graph
204    private native void cairoSetLineJoin (int cairoLineJoin);    private native void cairoSetLineJoin (int cairoLineJoin);
205    private native void cairoSetDash (double dashes[], int ndash, double offset);    private native void cairoSetDash (double dashes[], int ndash, double offset);
206    private native void cairoSetMiterLimit (double limit);    private native void cairoSetMiterLimit (double limit);
   private native void cairoTranslate (double tx, double ty);  
   private native void cairoScale (double sx, double sy);  
   private native void cairoRotate (double angle);  
207    private native void cairoNewPath ();    private native void cairoNewPath ();
208    private native void cairoMoveTo (double x, double y);    private native void cairoMoveTo (double x, double y);
209    private native void cairoLineTo (double x, double y);    private native void cairoLineTo (double x, double y);
210    private native void cairoCurveTo (double x1, double y1,    private native void cairoCurveTo (double x1, double y1,
211                                   double x2, double y2,                                      double x2, double y2,
212                                   double x3, double y3);                                        double x3, double y3);  
213    private native void cairoRelMoveTo (double dx, double dy);    private native void cairoRelMoveTo (double dx, double dy);
214    private native void cairoRelLineTo (double dx, double dy);    private native void cairoRelLineTo (double dx, double dy);
215    private native void cairoRelCurveTo (double dx1, double dy1,    private native void cairoRelCurveTo (double dx1, double dy1,
216                                      double dx2, double dy2,                                         double dx2, double dy2,
217                                      double dx3, double dy3);                                         double dx3, double dy3);
218    private native void cairoRectangle (double x, double y,    private native void cairoRectangle (double x, double y,
219                                     double width, double height);                                     double width, double height);
220    private native void cairoClosePath ();    private native void cairoClosePath ();
# Line 213  public class GdkGraphics2D extends Graph Line 227  public class GdkGraphics2D extends Graph
227    ////// General Drawing Support Methods //////    ////// General Drawing Support Methods //////
228    /////////////////////////////////////////////    /////////////////////////////////////////////
229    
230        private class DrawState
231        {
232            private Paint paint;
233            private Stroke stroke;
234            private Color fg;
235            private Color bg;
236            private Shape clip;
237            private AffineTransform transform;
238            private Font font;  
239            DrawState (GdkGraphics2D g)
240            {
241                this.paint = g.paint;
242                this.stroke = g.stroke;
243                this.fg = g.fg;
244                this.bg = g.bg;
245                this.clip = g.clip;
246                if (g.transform != null)
247                    this.transform = (AffineTransform) g.transform.clone();
248                this.font = g.font;
249            }
250            public void restore(GdkGraphics2D g)
251            {
252                g.paint = this.paint;
253                g.stroke = this.stroke;
254                g.fg = this.fg;
255                g.bg = this.bg;
256                g.clip = this.clip;
257                g.transform = this.transform;
258                g.font = this.font;
259            }
260        }
261        
262        private void stateSave ()
263        {
264            stateStack.push (new DrawState (this));
265            cairoSave ();
266        }
267    
268        private void stateRestore ()
269        {
270            ((DrawState)(stateStack.pop ())).restore (this);
271            cairoRestore ();
272        }
273    
274    
275    double x;    double x;
276    double y;    double y;
277    private void setPos (double nx, double ny)    private void setPos (double nx, double ny)
# Line 288  public class GdkGraphics2D extends Graph Line 347  public class GdkGraphics2D extends Graph
347          return;          return;
348        }        }
349    
350      cairoSave ();      stateSave ();
351      cairoNewPath ();      cairoNewPath ();
352      if (s instanceof Rectangle2D)      if (s instanceof Rectangle2D)
353        {        {
# Line 298  public class GdkGraphics2D extends Graph Line 357  public class GdkGraphics2D extends Graph
357      else            else      
358        walkPath (s.getPathIterator (null));        walkPath (s.getPathIterator (null));
359      cairoStroke ();      cairoStroke ();
360      cairoRestore ();      stateRestore ();
361    }    }
362    
363    public void fill(Shape s)    public void fill (Shape s)
364    {    {
365      cairoSave();      stateSave();
366      cairoNewPath ();      cairoNewPath ();
367      if (s instanceof Rectangle2D)      if (s instanceof Rectangle2D)
368        {        {
# Line 313  public class GdkGraphics2D extends Graph Line 372  public class GdkGraphics2D extends Graph
372      else            else      
373        walkPath (s.getPathIterator (null));        walkPath (s.getPathIterator (null));
374      cairoFill ();      cairoFill ();
375      cairoRestore ();      stateRestore ();
376    }    }
377    
378    public void clip (Shape s)    public void clip (Shape s)
379    {    {
380      clip = s;        // update it
381      cairoNewPath ();  
382      if (s instanceof Rectangle2D)        if (clip == null || s == null)
383        {            clip = s;
384          Rectangle2D r = (Rectangle2D)s;        else if (s instanceof Rectangle2D
385          cairoRectangle (r.getX (), r.getY (),                 && clip instanceof Rectangle2D)
386                          r.getWidth (), r.getHeight ());            {
387        }                Rectangle2D r = (Rectangle2D)s;
388      else                      Rectangle2D curr = (Rectangle2D)clip;
389        walkPath (s.getPathIterator (null));                clip = curr.createIntersection (r);
390      cairoClosePath ();            }
391      cairoClip ();        else
392              throw new UnsupportedOperationException ();
393    
394          // draw it
395          if (clip != null)
396              {
397                  cairoNewPath ();
398                  if (clip instanceof Rectangle2D)
399                      {
400                          Rectangle2D r = (Rectangle2D)clip;
401                          cairoRectangle (r.getX (), r.getY (),
402                                          r.getWidth (), r.getHeight ());
403                      }
404                  else
405                      walkPath (clip.getPathIterator (null));
406                  cairoClosePath ();
407                  cairoClip ();
408              }
409    }    }
410    
411    public Paint getPaint ()    public Paint getPaint ()
# Line 339  public class GdkGraphics2D extends Graph Line 415  public class GdkGraphics2D extends Graph
415    
416    public AffineTransform getTransform ()    public AffineTransform getTransform ()
417    {    {
418      return transform;        return (AffineTransform) transform.clone ();
419    }    }
420    
421    public void setPaint (Paint p)    public void setPaint (Paint p)
422    {    {
423        if (paint == null)
424            return;
425          
426      paint = p;      paint = p;
427      if (paint instanceof Color)      if (paint instanceof Color)
428        {        {
# Line 385  public class GdkGraphics2D extends Graph Line 464  public class GdkGraphics2D extends Graph
464        {        {
465          double m[] = new double[6];          double m[] = new double[6];
466          transform.getMatrix (m);          transform.getMatrix (m);
467          cairoSetMatrix (m[0], m[1], m[2], m[3], m[4], m[5]);          cairoSetMatrix (m);
468        }        }
469    }    }
470    
# Line 400  public class GdkGraphics2D extends Graph Line 479  public class GdkGraphics2D extends Graph
479    
480    public void rotate(double theta)    public void rotate(double theta)
481    {    {
482      if (transform != null)      transform (AffineTransform.getRotateInstance (theta));
       transform.rotate (theta);  
     cairoRotate (theta);  
483    }    }
484    
485    public void rotate(double theta, double x, double y)    public void rotate(double theta, double x, double y)
486    {    {
487      if (transform != null)      transform (AffineTransform.getRotateInstance (theta, x, y));
       transform.rotate (theta, x, y);  
     cairoTranslate (x, y);  
     cairoRotate (theta);  
     cairoTranslate (-x, -y);  
488    }    }
489    
490    public void scale(double sx, double sy)    public void scale(double sx, double sy)
491    {    {
492      if (transform != null)      transform (AffineTransform.getScaleInstance (sx, sy));
       transform.scale (sx, sy);  
     cairoScale (sx, sy);  
493    }    }
494    
495    public void translate (double tx, double ty)    public void translate (double tx, double ty)
496    {    {
497      if (transform != null)      transform (AffineTransform.getTranslateInstance (tx, ty));
       transform.translate (tx, ty);  
     cairoTranslate (tx, ty);  
498    }    }
499    
500    public void translate (int x, int y)    public void translate (int x, int y)
# Line 433  public class GdkGraphics2D extends Graph Line 502  public class GdkGraphics2D extends Graph
502      translate ((double) x, (double) y);      translate ((double) x, (double) y);
503    }    }
504    
505      public void shear(double shearX, double shearY)
506      {
507        transform (AffineTransform.getShearInstance (shearX, shearY));
508      }
509    
510    public Stroke getStroke()    public Stroke getStroke()
511    {    {
512      return stroke;      return stroke;
# Line 445  public class GdkGraphics2D extends Graph Line 519  public class GdkGraphics2D extends Graph
519        {        {
520          BasicStroke bs = (BasicStroke) stroke;          BasicStroke bs = (BasicStroke) stroke;
521          cairoSetLineCap (bs.getEndCap());          cairoSetLineCap (bs.getEndCap());
522          cairoSetLineWidth (bs.getLineWidth());          cairoSetLineWidth (bs.getLineWidth() / 2.0);
523          cairoSetLineJoin (bs.getLineJoin());          cairoSetLineJoin (bs.getLineJoin());
524          cairoSetMiterLimit (bs.getMiterLimit());          cairoSetMiterLimit (bs.getMiterLimit());
525          float dashes[] = bs.getDashArray();          float dashes[] = bs.getDashArray();
# Line 467  public class GdkGraphics2D extends Graph Line 541  public class GdkGraphics2D extends Graph
541    
542    public void setPaintMode ()    public void setPaintMode ()
543    {    {
544      setComposite (java.awt.AlphaComposite.Xor);      setComposite (java.awt.AlphaComposite.SrcOver);
545    }    }
546    
547    public void setXORMode (Color c)    public void setXORMode (Color c)
# Line 478  public class GdkGraphics2D extends Graph Line 552  public class GdkGraphics2D extends Graph
552    public void setColor (Color c)    public void setColor (Color c)
553    {    {
554      fg = c;      fg = c;
555        paint = c;
556      cairoSetRGBColor (fg.getRed() / 255.0,      cairoSetRGBColor (fg.getRed() / 255.0,
557                        fg.getGreen() / 255.0,                        fg.getGreen() / 255.0,
558                        fg.getBlue() / 255.0);                        fg.getBlue() / 255.0);
# Line 491  public class GdkGraphics2D extends Graph Line 566  public class GdkGraphics2D extends Graph
566    
567    public void clipRect (int x, int y, int width, int height)    public void clipRect (int x, int y, int width, int height)
568    {    {
569      // this is *slightly* different than all the other clip functions: it        clip (new Rectangle (x, y, width, height));
     // intersects the clip area with the new clip rectangle. obviously.  of  
     // course, since Shape doesn't *have* any way of intersecting with a  
     // rectangle, we will promote the current clipping region to its  
     // bounding rectangle and then intersect with that.  
     if (clip == null)  
       {  
         cairoNewPath ();  
         cairoRectangle (x, y, width, height);  
         cairoClosePath ();  
         cairoClip ();  
         clip = new Rectangle (x, y, width, height);  
       }  
     else  
       {  
         clip (clip.getBounds ().intersection  
               (new Rectangle (x, y, width, height)));  
       }  
570    }    }
571    
572    public Shape getClip ()    public Shape getClip ()
573    {    {
574      return clip;      return getClipInDevSpace ();
575    }    }
576    
577    public Rectangle getClipBounds ()    public Rectangle getClipBounds ()
# Line 524  public class GdkGraphics2D extends Graph Line 582  public class GdkGraphics2D extends Graph
582        return clip.getBounds ();        return clip.getBounds ();
583    }    }
584    
585        protected Rectangle2D getClipInDevSpace ()
586        {
587            Rectangle2D uclip = clip.getBounds2D ();
588            if (transform == null)
589                return uclip;
590            else
591                {
592                    Point2D pos = transform.transform (new Point2D.Double(uclip.getX (),
593                                                                          uclip.getY ()),
594                                                       (Point2D)null);              
595                    Point2D extent = transform.deltaTransform (new Point2D.Double(uclip.getWidth (),
596                                                                                  uclip.getHeight ()),
597                                                               (Point2D)null);
598                    return new Rectangle2D.Double (pos.getX (), pos.getY (),
599                                                   extent.getX (), extent.getY ());      
600                }
601        }
602    
603    public void setClip (int x, int y, int width, int height)    public void setClip (int x, int y, int width, int height)
604    {    {
605      cairoNewPath ();        cairoNewPath ();
606      cairoRectangle (x, y, width, height);        cairoRectangle (x, y, width, height);
607      cairoClosePath ();        cairoClosePath ();
608      cairoClip ();        cairoClip ();
609      clip = new Rectangle (x, y, width, height);        clip = new Rectangle2D.Double ((double)x, (double)y,
610                                         (double)width, (double)height);
611    }    }
612    
613    public void setClip (Shape s)    public void setClip (Shape s)
# Line 558  public class GdkGraphics2D extends Graph Line 635  public class GdkGraphics2D extends Graph
635      double y1 = (double) y;      double y1 = (double) y;
636      double y2 = (double) y + height;      double y2 = (double) y + height;
637    
638      cairoSave ();      stateSave ();
639            
640      cairoNewPath ();      cairoNewPath ();
641      setColor (light);      setColor (light);
# Line 574  public class GdkGraphics2D extends Graph Line 651  public class GdkGraphics2D extends Graph
651      cairoLineTo (x2, y2);      cairoLineTo (x2, y2);
652      cairoStroke ();      cairoStroke ();
653            
654      cairoRestore ();          stateRestore ();    
     setColor (std);  
   
655    }    }
656    
657    public void fill3DRect(int x, int y, int width,    public void fill3DRect(int x, int y, int width,
# Line 594  public class GdkGraphics2D extends Graph Line 669  public class GdkGraphics2D extends Graph
669                
670      draw3DRect (x, y, width, height, raised);      draw3DRect (x, y, width, height, raised);
671            
672      cairoSave ();      stateSave ();
673      cairoTranslate (step/2.0, step/2.0);      translate (step/2.0, step/2.0);
674      cairoNewPath ();      cairoNewPath ();
675      cairoRectangle ((double) x, (double) y,      cairoRectangle ((double) x, (double) y,
676                      ((double) width) - step,                      ((double) width) - step,
677                      ((double) height) - step );                      ((double) height) - step );
678      cairoClosePath ();      cairoClosePath ();
679      cairoFill ();      cairoFill ();
680      cairoRestore ();      stateRestore ();
681    }    }
682    
683    
# Line 618  public class GdkGraphics2D extends Graph Line 693  public class GdkGraphics2D extends Graph
693    
694    public void clearRect (int x, int y, int width, int height)    public void clearRect (int x, int y, int width, int height)
695    {    {
696      cairoSave ();      stateSave ();
697      cairoSetRGBColor (bg.getRed() / 255.0,      cairoSetRGBColor (bg.getRed() / 255.0,
698                        bg.getGreen() / 255.0,                        bg.getGreen() / 255.0,
699                        bg.getBlue() / 255.0);                        bg.getBlue() / 255.0);
# Line 627  public class GdkGraphics2D extends Graph Line 702  public class GdkGraphics2D extends Graph
702      cairoRectangle (x, y, width, height);      cairoRectangle (x, y, width, height);
703      cairoClosePath ();      cairoClosePath ();
704      cairoFill ();      cairoFill ();
705      cairoRestore ();      stateRestore ();
706    }    }
707    
708    public void setBackground(Color c)    public void setBackground(Color c)
# Line 635  public class GdkGraphics2D extends Graph Line 710  public class GdkGraphics2D extends Graph
710      bg = c;      bg = c;
711    }    }
712    
   
713    public Color getBackground()    public Color getBackground()
714    {    {
715      return bg;      return bg;
716    }    }
717    
   
718    private void doPolygon(int[] xPoints, int[] yPoints, int nPoints,    private void doPolygon(int[] xPoints, int[] yPoints, int nPoints,
719                           boolean close, boolean fill)                           boolean close, boolean fill)
720    {        {    
# Line 698  public class GdkGraphics2D extends Graph Line 771  public class GdkGraphics2D extends Graph
771      doPolygon (xPoints, yPoints, nPoints, false, false);      doPolygon (xPoints, yPoints, nPoints, false, false);
772    }    }
773    
774    private boolean drawRaster (ColorModel cm, Raster r)    private boolean drawRaster (ColorModel cm, Raster r,
775                                  AffineTransform imageToUser)
776    {    {
777      if (r == null)      if (r == null)
778        return false;        return false;
# Line 712  public class GdkGraphics2D extends Graph Line 786  public class GdkGraphics2D extends Graph
786      if (cm == null)      if (cm == null)
787        cm = ColorModel.getRGBdefault ();        cm = ColorModel.getRGBdefault ();
788    
789        double[] i2u = new double[6];
790        if (imageToUser != null)
791          imageToUser.getMatrix(i2u);
792        else
793          {
794            i2u[0] = 1; i2u[1] = 0;
795            i2u[2] = 0; i2u[3] = 1;
796            i2u[2] = 0; i2u[3] = 0;
797          }
798    
799      int pixels[] = null;      int pixels[] = null;
800    
801      if (sm.getDataType () == DataBuffer.TYPE_INT &&      if (sm.getDataType () == DataBuffer.TYPE_INT &&
# Line 735  public class GdkGraphics2D extends Graph Line 819  public class GdkGraphics2D extends Graph
819          pixels = pixels2;          pixels = pixels2;
820        }        }
821            
822      cairoSave ();      stateSave ();
823      cairoTranslate (x, y);      translate (x, y);
824      drawPixels (pixels, r.getWidth (), r.getHeight (), r.getWidth ());      drawPixels (pixels, r.getWidth (), r.getHeight (), r.getWidth (), i2u);
825      cairoRestore ();          stateRestore ();    
826      return true;      return true;
827    }    }
828    
829    public boolean drawImage (Image img, int x, int y,    public void drawRenderedImage(RenderedImage image,
830                              ImageObserver observer)                                  AffineTransform xform)
831      {
832        drawRaster (image.getColorModel(), image.getData(), xform);
833      }
834      
835      public void drawRenderableImage(RenderableImage image,
836                                      AffineTransform xform)
837      {
838        drawRenderedImage (image.createRendering (new RenderContext (xform)), xform);
839      }
840      
841      public boolean drawImage(Image img,
842                               AffineTransform xform,
843                               ImageObserver obs)
844    {    {
845      if (img instanceof GtkOffScreenImage &&      if (img instanceof GtkOffScreenImage &&
846          img.getGraphics () instanceof GdkGraphics2D &&                      img.getGraphics () instanceof GdkGraphics2D &&            
847          (transform == null || transform.isIdentity ()))          (xform == null
848             || xform.getType () == AffineTransform.TYPE_IDENTITY
849             || xform.getType () == AffineTransform.TYPE_TRANSLATION)
850            )
851        {        {
852          // we are being asked to flush a double buffer from Gdk          // we are being asked to flush a double buffer from Gdk
853          GdkGraphics2D g2 = (GdkGraphics2D) img.getGraphics ();          GdkGraphics2D g2 = (GdkGraphics2D) img.getGraphics ();
854          gdkDrawDrawable (g2, x, y);          gdkDrawDrawable (g2, (int)xform.getTranslateX(), (int)xform.getTranslateY());
855          return true;          return true;
856        }        }
857      else      else
# Line 760  public class GdkGraphics2D extends Graph Line 860  public class GdkGraphics2D extends Graph
860            {            {
861              // draw an image which has actually been loaded into memory fully              // draw an image which has actually been loaded into memory fully
862              BufferedImage b = (BufferedImage) img;              BufferedImage b = (BufferedImage) img;
863              return drawRaster (b.getColorModel (), b.getData ());              return drawRaster (b.getColorModel (), b.getData (), xform);
864            }                    }        
865          else          else
866            {            {
867              // begin progressive loading in a separate thread              // begin progressive loading in a separate thread
868              new PainterThread (this, img);              new PainterThread (this, img, xform);
869              return false;              return false;
870            }            }
871        }        }
872    }    }
873    
874      public void drawImage(BufferedImage image,
875                            BufferedImageOp op,
876                            int x,
877                            int y)
878      {
879        Image filtered = op.filter(image, null);
880        drawImage(filtered, new AffineTransform(1f,0f,0f,1f,x,y), null);
881      }
882    
883      public boolean drawImage (Image img, int x, int y,
884                                ImageObserver observer)
885      {
886        return drawImage(img, new AffineTransform(1f,0f,0f,1f,x,y), observer);    
887      }
888    
889    
890    ////////////////////////////////////////    ////////////////////////////////////////
891    ////// Supporting Private Classes //////    ////// Supporting Private Classes //////
# Line 790  public class GdkGraphics2D extends Graph Line 905  public class GdkGraphics2D extends Graph
905      GdkGraphics2D gr;      GdkGraphics2D gr;
906      Image image;      Image image;
907      ColorModel defaultModel;      ColorModel defaultModel;
908        AffineTransform xform;
909    
910      public PainterThread (GdkGraphics2D g, Image im)      public PainterThread (GdkGraphics2D g, Image im, AffineTransform xf)
911      {      {
912        image = im;        image = im;
913          xform = xf;
914        this.gr = (GdkGraphics2D) g.create ();        this.gr = (GdkGraphics2D) g.create ();
915        new Thread (this).start ();        new Thread (this).start ();
916      }      }
# Line 823  public class GdkGraphics2D extends Graph Line 940  public class GdkGraphics2D extends Graph
940      public void setPixels (int x, int y, int w, int h, ColorModel model,      public void setPixels (int x, int y, int w, int h, ColorModel model,
941                             int[] pixels, int off, int scansize)                             int[] pixels, int off, int scansize)
942        {        {
943          gr.cairoSave ();          gr.stateSave ();
944          gr.cairoTranslate (x, y);          gr.translate (x, y);
945    
946          if (model == null)          if (model == null)
947            model = defaultModel;            model = defaultModel;
# Line 843  public class GdkGraphics2D extends Graph Line 960  public class GdkGraphics2D extends Graph
960          else          else
961            pixels2 = pixels;            pixels2 = pixels;
962    
963          gr.drawPixels (pixels2, w, h, scansize);          double[] xf = new double[6];
964          gr.cairoRestore ();          xform.getMatrix(xf);        
965            gr.drawPixels (pixels2, w, h, scansize, xf);
966            gr.stateRestore ();
967        }        }
968    
969      public void setProperties (java.util.Hashtable props)      public void setProperties (java.util.Hashtable props)
# Line 934  public class GdkGraphics2D extends Graph Line 1053  public class GdkGraphics2D extends Graph
1053    ////// Unimplemented Stubs and Overloads //////    ////// Unimplemented Stubs and Overloads //////
1054    ///////////////////////////////////////////////    ///////////////////////////////////////////////
1055    
   public boolean drawImage(Image image,  
                            AffineTransform xform,  
                            ImageObserver obs)  
   {  
     throw new java.lang.UnsupportedOperationException ();  
   }  
     
   public void drawImage(BufferedImage image,  
                         BufferedImageOp op,  
                         int x,  
                         int y)  
   {  
     throw new java.lang.UnsupportedOperationException ();  
   }  
     
   public void drawRenderedImage(RenderedImage image,  
                                 AffineTransform xform)  
   {  
     throw new java.lang.UnsupportedOperationException ();  
   }  
     
   public void drawRenderableImage(RenderableImage image,  
                                   AffineTransform xform)  
   {  
     throw new java.lang.UnsupportedOperationException ();  
   }  
   
   public void drawString(String text, float x, float y)  
   {  
     throw new java.lang.UnsupportedOperationException ();  
   }  
1056        
   public void drawString(AttributedCharacterIterator iterator,  
                          float x, float y)  
   {  
     throw new java.lang.UnsupportedOperationException ();  
   }  
1057            
1058    public boolean hit(Rectangle rect, Shape text,    public boolean hit(Rectangle rect, Shape text,
1059                       boolean onStroke)                       boolean onStroke)
# Line 1014  public class GdkGraphics2D extends Graph Line 1097  public class GdkGraphics2D extends Graph
1097      throw new java.lang.UnsupportedOperationException ();      throw new java.lang.UnsupportedOperationException ();
1098    }    }
1099    
   public void shear(double shearX, double shearY)  
   {  
     throw new java.lang.UnsupportedOperationException ();  
   }  
   
1100    public Composite getComposite()    public Composite getComposite()
1101    {    {
1102      throw new java.lang.UnsupportedOperationException ();      throw new java.lang.UnsupportedOperationException ();
# Line 1026  public class GdkGraphics2D extends Graph Line 1104  public class GdkGraphics2D extends Graph
1104    
1105    public FontRenderContext getFontRenderContext ()    public FontRenderContext getFontRenderContext ()
1106    {    {
1107      throw new java.lang.UnsupportedOperationException ();      return new FontRenderContext (transform, true, true);
1108    }    }
1109    
1110    public void drawGlyphVector (GlyphVector g, float x, float y)    public void drawGlyphVector (GlyphVector g, float x, float y)
1111    {        {    
1112      cairoSave ();      stateSave ();
1113      cairoTranslate ((double)x, (double)y);      setFont (g.getFont ());
1114        translate ((double)x, (double)y);
1115        cairoMoveTo (0, 0);
1116      int nglyphs = g.getNumGlyphs ();      int nglyphs = g.getNumGlyphs ();
1117      int codes[] = g.getGlyphCodes (0, nglyphs, (int []) null);      int codes[] = g.getGlyphCodes (0, nglyphs, (int []) null);
1118      float posns[] = g.getGlyphPositions (0, nglyphs, (float []) null);      float posns[] = g.getGlyphPositions (0, nglyphs, (float []) null);
1119      cairoShowGlyphs (codes, posns, nglyphs);      cairoShowGlyphs (codes, posns);
1120      cairoRestore ();      stateRestore ();
1121    }    }
1122    
1123    public void copyArea (int x, int y, int width, int height, int dx, int dy)    public void copyArea (int x, int y, int width, int height, int dx, int dy)
# Line 1048  public class GdkGraphics2D extends Graph Line 1128  public class GdkGraphics2D extends Graph
1128    public void drawArc (int x, int y, int width, int height,    public void drawArc (int x, int y, int width, int height,
1129                         int startAngle, int arcAngle)                         int startAngle, int arcAngle)
1130    {    {
1131      throw new java.lang.UnsupportedOperationException ();      draw (new Arc2D.Double((double)x, (double)y,
1132                               (double)width, (double)height,
1133                               (double)startAngle, (double)arcAngle,
1134                               Arc2D.OPEN));
1135    }    }
1136    
1137    public boolean drawImage (Image img, int x, int y, Color bgcolor,    public boolean drawImage (Image img, int x, int y, Color bgcolor,
# Line 1085  public class GdkGraphics2D extends Graph Line 1168  public class GdkGraphics2D extends Graph
1168    
1169    public void drawOval(int x, int y, int width, int height)    public void drawOval(int x, int y, int width, int height)
1170    {    {
1171      throw new java.lang.UnsupportedOperationException ();      drawArc (x, y, width, height, 0, 360);
1172    }    }
1173    
1174    public void drawRoundRect(int x, int y, int width, int height,    public void drawRoundRect(int x, int y, int width, int height,
1175                              int arcWidth, int arcHeight)                              int arcWidth, int arcHeight)
1176    {    {
1177      throw new java.lang.UnsupportedOperationException ();      int x1 = x + arcWidth, x2 = x + width - arcWidth;
1178        int y1 = y + arcHeight, y2 = y + height - arcHeight;
1179        fillRect (x1, y, x2 - x1, height);
1180        fillRect (x, y1, width, y2 - y1);
1181        fillArc (x, y, arcWidth, arcHeight, 90, 90);
1182        fillArc (x1, y, arcWidth, arcHeight, 0, 90);
1183        fillArc (x2, y2, arcWidth, arcHeight, 270, 90);
1184        fillArc (x, y2, arcWidth, arcHeight, 180, 90);
1185    }    }
1186    
1187    public void drawString (String str, int x, int y)    public void drawString (String str, int x, int y)
1188    {    {
1189      throw new java.lang.UnsupportedOperationException ();      drawString (str, (float)x, (float)y);
1190      }
1191    
1192      public void drawString (String str, float x, float y)
1193      {
1194        GlyphVector gv = font.createGlyphVector (getFontRenderContext(), str);
1195        drawGlyphVector (gv, x, y);
1196    }    }
1197    
1198    public void drawString (AttributedCharacterIterator ci, int x, int y)    public void drawString (AttributedCharacterIterator ci, int x, int y)
1199    {    {
1200      throw new java.lang.UnsupportedOperationException ();      drawString (ci, (float)x, (float)y);
1201      }
1202    
1203      public void drawString (AttributedCharacterIterator ci, float x, float y)
1204      {
1205        GlyphVector gv = font.createGlyphVector (getFontRenderContext(), ci);
1206        drawGlyphVector (gv, x, y);
1207    }    }
1208    
1209    public void fillArc (int x, int y, int width, int height,    public void fillArc (int x, int y, int width, int height,
1210                         int startAngle, int arcAngle)                         int startAngle, int arcAngle)
1211    {    {
1212      cairoNewPath ();      fill (new Arc2D.Double((double)x, (double)y,
1213      walkPath (new Arc2D.Double((double)x, (double)y,                             (double)width, (double)height,
1214                                 (double)width, (double)height,                             (double)startAngle, (double)arcAngle,
1215                                 (double)startAngle, (double)arcAngle,                             Arc2D.OPEN));
                                Arc2D.PIE).getPathIterator (null));  
     cairoClosePath ();  
     cairoFill ();  
1216    }    }
1217    
1218    public void fillOval(int x, int y, int width, int height)    public void fillOval(int x, int y, int width, int height)
1219    {    {
1220      throw new java.lang.UnsupportedOperationException ();      fillArc (x, y, width, height, 0, 360);
1221    }    }
1222    
1223    public void fillRoundRect (int x, int y, int width, int height,    public void fillRoundRect (int x, int y, int width, int height,
1224                               int arcWidth, int arcHeight)                               int arcWidth, int arcHeight)
1225    {    {
1226      throw new java.lang.UnsupportedOperationException ();      int x1 = x + arcWidth, x2 = x + width - arcWidth;
1227        int y1 = y + arcHeight, y2 = y + height - arcHeight;
1228        fillRect (x1, y, x2 - x1, height);
1229        fillRect (x, y1, width, y2 - y1);
1230        fillArc (x, y, arcWidth, arcHeight, 90, 90);
1231        fillArc (x1, y, arcWidth, arcHeight, 0, 90);
1232        fillArc (x2, y2, arcWidth, arcHeight, 270, 90);
1233        fillArc (x, y2, arcWidth, arcHeight, 180, 90);
1234    }    }
1235    
1236    public Font getFont ()    public Font getFont ()
1237    {    {
1238      throw new java.lang.UnsupportedOperationException ();      return font;
1239    }    }
1240    
1241    public FontMetrics getFontMetrics ()    public FontMetrics getFontMetrics ()
1242    {    {
1243      throw new java.lang.UnsupportedOperationException ();      return Toolkit.getDefaultToolkit ().getFontMetrics (font);
1244    }    }
1245    
1246    public FontMetrics getFontMetrics (Font f)    public FontMetrics getFontMetrics (Font f)
1247    {    {
1248      throw new java.lang.UnsupportedOperationException ();      return Toolkit.getDefaultToolkit ().getFontMetrics (f);
1249    }    }
1250    
1251    public void setFont (Font f)    public void setFont (Font f)

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26