[cairo-commit] cairo-java/test/kapow Kapow.java,1.1,1.2

Jeffrey Morgan commit at pdx.freedesktop.org
Tue Mar 8 07:35:25 PST 2005


Committed by: kuzman

Update of /cvs/cairo/cairo-java/test/kapow
In directory gabe:/tmp/cvs-serv31244/test/kapow

Modified Files:
	Kapow.java 
Log Message:
added current_path callbacks - does not include native calls at this time so cannot be used.

Index: Kapow.java
===================================================================
RCS file: /cvs/cairo/cairo-java/test/kapow/Kapow.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Kapow.java	8 Mar 2005 11:58:33 -0000	1.1
+++ Kapow.java	8 Mar 2005 15:35:23 -0000	1.2
@@ -10,6 +10,7 @@
 package kapow;
 
 import org.freedesktop.cairo.Cairo;
+import org.freedesktop.cairo.CurrentPath;
 import org.freedesktop.cairo.FontSlant;
 import org.freedesktop.cairo.FontWeight;
 import org.freedesktop.cairo.Format;
@@ -22,10 +23,10 @@
  */
 public class Kapow {
 	
-	private Cairo cr;
+	public Cairo cr;
 	private String filename = "kapow.png";
-	private int IMAGE_WIDTH = 384;
-	private int IMAGE_HEIGHT = 256;
+	public int IMAGE_WIDTH = 384;
+	public int IMAGE_HEIGHT = 256;
 
 	private int SPIKES = 10;
 	private int SHADOW_OFFSET = 10;
@@ -122,11 +123,54 @@
 	}
 	
 	private void makeTextPath(double x, double y, String text) {
-		
+	    cr.moveTo(x, y);
+        cr.textPath(text);
+        cr.setCurrentPathFlat(new MyPath());
 	}
 
 	public static void main(String[] args) {
 
 		
 	}
+    
+    private class MyPath implements CurrentPath {
+        
+        private boolean firstTime = true;
+
+        public void cairoMoveTo(double x, double y) {
+            if (firstTime) {
+                cr.newPath();
+                firstTime = false;
+            }
+            double[] newPoint = bendIt(x, y);
+            cr.moveTo(newPoint[0], newPoint[1]);
+        }
+
+        public void cairoLineTo(double x, double y) {
+            double[] newPoint = bendIt(x, y);
+            cr.lineTo(newPoint[0], newPoint[1]);
+        }
+
+        public void cairoCurveTo(double x1, double y1, double x2, double y2, double x3, double y3) {}
+
+        public void cairoClosePath() {
+            cr.closePath();
+        }
+        
+        private double[] bendIt(double x, double y) {
+            double cx = IMAGE_WIDTH / 2;
+            double cy = 500;
+            double angle, radius, t;
+            double[] retval = new double[2];
+
+            angle = Math.PI / 2 - (x - cx) / IMAGE_WIDTH;
+            t = 3 * Math.PI / 4 - angle + 0.05;
+            angle = 3 * Math.PI / 4 - Math.pow(t, 1.8);
+            radius = cy - (IMAGE_HEIGHT / 2 + (y - IMAGE_HEIGHT / 2) * t * 2);
+
+            retval[0] = cx + Math.cos(angle) * radius;
+            retval[1] = cy - Math.sin(angle) * radius;
+            return retval;
+        }
+    }
 }




More information about the cairo-commit mailing list