/[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.15.2.9 by gnu_andrew, Tue Aug 2 20:12:09 2005 UTC revision 1.15.2.10 by gnu_andrew, Sat Sep 10 15:31:37 2005 UTC
# Line 45  import java.awt.AlphaComposite; Line 45  import java.awt.AlphaComposite;
45  import java.awt.BasicStroke;  import java.awt.BasicStroke;
46  import java.awt.Color;  import java.awt.Color;
47  import java.awt.Composite;  import java.awt.Composite;
48    import java.awt.Dimension;
49  import java.awt.Font;  import java.awt.Font;
50  import java.awt.FontMetrics;  import java.awt.FontMetrics;
51  import java.awt.GradientPaint;  import java.awt.GradientPaint;
# Line 106  public class GdkGraphics2D extends Graph Line 107  public class GdkGraphics2D extends Graph
107      if (Configuration.INIT_LOAD_LIBRARY)      if (Configuration.INIT_LOAD_LIBRARY)
108        System.loadLibrary("gtkpeer");        System.loadLibrary("gtkpeer");
109    
110      if (GtkToolkit.useGraphics2D())      initStaticState();
       initStaticState();  
111    }    }
112        
113    static native void initStaticState();    static native void initStaticState();
# Line 132  public class GdkGraphics2D extends Graph Line 132  public class GdkGraphics2D extends Graph
132    Composite comp;    Composite comp;
133    private Stack stateStack;    private Stack stateStack;
134    
135      private native void initStateUnlocked(GtkComponentPeer component);
136    private native void initState(GtkComponentPeer component);    private native void initState(GtkComponentPeer component);
137    private native void initState(int width, int height);    private native void initState(int width, int height);
138    private native void initState(int[] pixes, int width, int height);    private native void initState(int[] pixes, int width, int height);
139    private native void copyState(GdkGraphics2D g);    private native void copyState(GdkGraphics2D g);
140    public native void dispose();    public native void dispose();
141    private native void cairoSurfaceSetFilter(int filter);    private native void cairoSurfaceSetFilter(int filter);
142      private native void cairoSurfaceSetFilterUnlocked(int filter);
143    native void connectSignals(GtkComponentPeer component);    native void connectSignals(GtkComponentPeer component);
144    
145    public void finalize()    public void finalize()
# Line 236  public class GdkGraphics2D extends Graph Line 238  public class GdkGraphics2D extends Graph
238      stateStack = new Stack();      stateStack = new Stack();
239    }    }
240    
241      void initComponentGraphics2DUnlocked()
242      {
243        initStateUnlocked(component);
244    
245        setColorUnlocked(component.awtComponent.getForeground());
246        setBackgroundUnlocked(component.awtComponent.getBackground());
247        setPaintUnlocked(getColorUnlocked());
248        setTransformUnlocked(new AffineTransform());
249        setStrokeUnlocked(new BasicStroke());
250        setRenderingHintsUnlocked(getDefaultHints());
251        setFontUnlocked(new Font("SansSerif", Font.PLAIN, 12));
252    
253        stateStack = new Stack();
254      }
255    
256    GdkGraphics2D(BufferedImage bimage)    GdkGraphics2D(BufferedImage bimage)
257    {    {
258      this.bimage = bimage;      this.bimage = bimage;
# Line 280  public class GdkGraphics2D extends Graph Line 297  public class GdkGraphics2D extends Graph
297    // drawing utility methods    // drawing utility methods
298    private native void drawPixels(int[] pixels, int w, int h, int stride,    private native void drawPixels(int[] pixels, int w, int h, int stride,
299                                   double[] i2u);                                   double[] i2u);
300      private native void setTexturePixelsUnlocked(int[] pixels, int w, int h, int stride);
301    private native void setTexturePixels(int[] pixels, int w, int h, int stride);    private native void setTexturePixels(int[] pixels, int w, int h, int stride);
302    private native void setGradient(double x1, double y1, double x2, double y2,    private native void setGradient(double x1, double y1, double x2, double y2,
303                                    int r1, int g1, int b1, int a1, int r2,                                    int r1, int g1, int b1, int a1, int r2,
304                                    int g2, int b2, int a2, boolean cyclic);                                    int g2, int b2, int a2, boolean cyclic);
305      private native void setGradientUnlocked(double x1, double y1, double x2, double y2,
306                                      int r1, int g1, int b1, int a1, int r2,
307                                      int g2, int b2, int a2, boolean cyclic);
308    
309    // simple passthroughs to cairo    // simple passthroughs to cairo
310    private native void cairoSave();    private native void cairoSave();
311    private native void cairoRestore();    private native void cairoRestore();
312    private native void cairoSetMatrix(double[] m);    private native void cairoSetMatrix(double[] m);
313      private native void cairoSetMatrixUnlocked(double[] m);
314    private native void cairoSetOperator(int cairoOperator);    private native void cairoSetOperator(int cairoOperator);
315    private native void cairoSetRGBAColor(double red, double green,    private native void cairoSetRGBAColor(double red, double green,
316                                          double blue, double alpha);                                          double blue, double alpha);
317      private native void cairoSetRGBAColorUnlocked(double red, double green,
318                                            double blue, double alpha);
319    private native void cairoSetFillRule(int cairoFillRule);    private native void cairoSetFillRule(int cairoFillRule);
320    private native void cairoSetLineWidth(double width);    private native void cairoSetLineWidth(double width);
321      private native void cairoSetLineWidthUnlocked(double width);
322    private native void cairoSetLineCap(int cairoLineCap);    private native void cairoSetLineCap(int cairoLineCap);
323      private native void cairoSetLineCapUnlocked(int cairoLineCap);
324    private native void cairoSetLineJoin(int cairoLineJoin);    private native void cairoSetLineJoin(int cairoLineJoin);
325      private native void cairoSetLineJoinUnlocked(int cairoLineJoin);
326    private native void cairoSetDash(double[] dashes, int ndash, double offset);    private native void cairoSetDash(double[] dashes, int ndash, double offset);
327      private native void cairoSetDashUnlocked(double[] dashes, int ndash, double offset);
328    
329    private native void cairoSetMiterLimit(double limit);    private native void cairoSetMiterLimit(double limit);
330      private native void cairoSetMiterLimitUnlocked(double limit);
331    private native void cairoNewPath();    private native void cairoNewPath();
332    private native void cairoMoveTo(double x, double y);    private native void cairoMoveTo(double x, double y);
333    private native void cairoLineTo(double x, double y);    private native void cairoLineTo(double x, double y);
# Line 689  public class GdkGraphics2D extends Graph Line 718  public class GdkGraphics2D extends Graph
718        throw new java.lang.UnsupportedOperationException();        throw new java.lang.UnsupportedOperationException();
719    }    }
720    
721      public void setPaintUnlocked(Paint p)
722      {
723        if (paint == null)
724          return;
725    
726        paint = p;
727        if (paint instanceof Color)
728          {
729            setColorUnlocked((Color) paint);
730          }
731        else if (paint instanceof TexturePaint)
732          {
733            TexturePaint tp = (TexturePaint) paint;
734            BufferedImage img = tp.getImage();
735    
736            // map the image to the anchor rectangle  
737            int width = (int) tp.getAnchorRect().getWidth();
738            int height = (int) tp.getAnchorRect().getHeight();
739    
740            double scaleX = width / (double) img.getWidth();
741            double scaleY = width / (double) img.getHeight();
742    
743            AffineTransform at = new AffineTransform(scaleX, 0, 0, scaleY, 0, 0);
744            AffineTransformOp op = new AffineTransformOp(at, getRenderingHints());
745            BufferedImage texture = op.filter(img, null);
746            int[] pixels = texture.getRGB(0, 0, width, height, null, 0, width);
747            setTexturePixelsUnlocked(pixels, width, height, width);
748          }
749        else if (paint instanceof GradientPaint)
750          {
751            GradientPaint gp = (GradientPaint) paint;
752            Point2D p1 = gp.getPoint1();
753            Point2D p2 = gp.getPoint2();
754            Color c1 = gp.getColor1();
755            Color c2 = gp.getColor2();
756            setGradientUnlocked(p1.getX(), p1.getY(), p2.getX(), p2.getY(), c1.getRed(),
757                        c1.getGreen(), c1.getBlue(), c1.getAlpha(), c2.getRed(),
758                        c2.getGreen(), c2.getBlue(), c2.getAlpha(), gp.isCyclic());
759          }
760        else
761          throw new java.lang.UnsupportedOperationException();
762      }
763    
764    public void setTransform(AffineTransform tx)    public void setTransform(AffineTransform tx)
765    {    {
766      transform = tx;      transform = tx;
# Line 700  public class GdkGraphics2D extends Graph Line 772  public class GdkGraphics2D extends Graph
772        }        }
773    }    }
774    
775      public void setTransformUnlocked(AffineTransform tx)
776      {
777        transform = tx;
778        if (transform != null)
779          {
780            double[] m = new double[6];
781            transform.getMatrix(m);
782            cairoSetMatrixUnlocked(m);
783          }
784      }
785    
786    public void transform(AffineTransform tx)    public void transform(AffineTransform tx)
787    {    {
788      if (transform == null)      if (transform == null)
# Line 784  public class GdkGraphics2D extends Graph Line 867  public class GdkGraphics2D extends Graph
867              cairoSetDash(double_dashes, double_dashes.length,              cairoSetDash(double_dashes, double_dashes.length,
868                           (double) bs.getDashPhase());                           (double) bs.getDashPhase());
869            }            }
870            else
871              cairoSetDash(new double[0], 0, 0.0);
872          }
873      }
874    
875      public void setStrokeUnlocked(Stroke st)
876      {
877        stroke = st;
878        if (stroke instanceof BasicStroke)
879          {
880            BasicStroke bs = (BasicStroke) stroke;
881            cairoSetLineCapUnlocked(bs.getEndCap());
882            cairoSetLineWidthUnlocked(bs.getLineWidth());
883            cairoSetLineJoinUnlocked(bs.getLineJoin());
884            cairoSetMiterLimitUnlocked(bs.getMiterLimit());
885            float[] dashes = bs.getDashArray();
886            if (dashes != null)
887              {
888                double[] double_dashes = new double[dashes.length];
889                for (int i = 0; i < dashes.length; i++)
890                  double_dashes[i] = dashes[i];
891                cairoSetDashUnlocked(double_dashes, double_dashes.length,
892                                     (double) bs.getDashPhase());
893              }
894            else
895              cairoSetDashUnlocked(new double[0], 0, 0.0);
896        }        }
897    }    }
898    
# Line 812  public class GdkGraphics2D extends Graph Line 921  public class GdkGraphics2D extends Graph
921                        fg.getBlue() / 255.0, fg.getAlpha() / 255.0);                        fg.getBlue() / 255.0, fg.getAlpha() / 255.0);
922    }    }
923    
924      public void setColorUnlocked(Color c)
925      {
926        if (c == null)
927          c = Color.BLACK;
928    
929        fg = c;
930        paint = c;
931        cairoSetRGBAColorUnlocked(fg.getRed() / 255.0, fg.getGreen() / 255.0,
932                          fg.getBlue() / 255.0, fg.getAlpha() / 255.0);
933      }
934    
935    public Color getColor()    public Color getColor()
936    {    {
937      return fg;      return fg;
938    }    }
939    
940      public Color getColorUnlocked()
941      {
942        return getColor();
943      }
944    
945    public void clipRect(int x, int y, int width, int height)    public void clipRect(int x, int y, int width, int height)
946    {    {
947      clip(new Rectangle(x, y, width, height));      clip(new Rectangle(x, y, width, height));
# Line 864  public class GdkGraphics2D extends Graph Line 989  public class GdkGraphics2D extends Graph
989    public void setClip(Shape s)    public void setClip(Shape s)
990    {    {
991      clip = s;      clip = s;
992      if (s != null)      if (clip == null)
993          {
994            // Reset clipping.
995            Dimension d = component.awtComponent.getSize();
996            setClip(0, 0, d.width, d.height);
997          }
998        else
999        {        {
1000          cairoNewPath();          cairoNewPath();
1001          if (s instanceof Rectangle2D)          if (s instanceof Rectangle2D)
# Line 929  public class GdkGraphics2D extends Graph Line 1060  public class GdkGraphics2D extends Graph
1060      bg = c;      bg = c;
1061    }    }
1062    
1063      public void setBackgroundUnlocked(Color c)
1064      {
1065        setBackground(c);
1066      }
1067    
1068    public Color getBackground()    public Color getBackground()
1069    {    {
1070      return bg;      return bg;
# Line 1180  public class GdkGraphics2D extends Graph Line 1316  public class GdkGraphics2D extends Graph
1316                       || hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT);                       || hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT);
1317    }    }
1318    
1319      public void setRenderingHintsUnlocked(Map hints)
1320      {
1321        this.hints = new RenderingHints(getDefaultHints());
1322        this.hints.add(new RenderingHints(hints));
1323    
1324        if (hints.containsKey(RenderingHints.KEY_INTERPOLATION))
1325          {
1326            if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR))
1327              cairoSurfaceSetFilterUnlocked(0);
1328    
1329            else if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR))
1330              cairoSurfaceSetFilterUnlocked(1);
1331          }
1332    
1333        if (hints.containsKey(RenderingHints.KEY_ALPHA_INTERPOLATION))
1334          {
1335            if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED))
1336              cairoSurfaceSetFilterUnlocked(2);
1337    
1338            else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY))
1339              cairoSurfaceSetFilterUnlocked(3);
1340    
1341            else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT))
1342              cairoSurfaceSetFilterUnlocked(4);
1343          }
1344    
1345        shiftDrawCalls = hints.containsValue(RenderingHints.VALUE_STROKE_NORMALIZE)
1346                         || hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT);
1347      }
1348    
1349    public void addRenderingHints(Map hints)    public void addRenderingHints(Map hints)
1350    {    {
1351      this.hints.add(new RenderingHints(hints));      this.hints.add(new RenderingHints(hints));
# Line 1344  public class GdkGraphics2D extends Graph Line 1510  public class GdkGraphics2D extends Graph
1510    
1511    public void drawString(String str, float x, float y)    public void drawString(String str, float x, float y)
1512    {    {
1513        if (str == null || str.length() == 0)
1514          return;
1515    
1516      drawGlyphVector(getFont().createGlyphVector(null, str), x, y);      drawGlyphVector(getFont().createGlyphVector(null, str), x, y);
1517      updateBufferedImage ();      updateBufferedImage ();
1518    }    }
# Line 1443  public class GdkGraphics2D extends Graph Line 1612  public class GdkGraphics2D extends Graph
1612          .getFont(f.getName(), f.getAttributes());              .getFont(f.getName(), f.getAttributes());    
1613    }    }
1614    
1615      public void setFontUnlocked(Font f)
1616      {
1617        setFont (f);
1618      }
1619    
1620    public String toString()    public String toString()
1621    {    {
1622      return  (getClass().getName()      return  (getClass().getName()

Legend:
Removed from v.1.15.2.9  
changed lines
  Added in v.1.15.2.10

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