[cairo-commit] cairo-java/test/org/freedesktop/cairo/test Snippets.java, 1.2, 1.3

Jeffrey Morgan commit at pdx.freedesktop.org
Fri Mar 4 17:59:44 PST 2005


Committed by: kuzman

Update of /cvs/cairo/cairo-java/test/org/freedesktop/cairo/test
In directory gabe:/tmp/cvs-serv1328/test/org/freedesktop/cairo/test

Modified Files:
	Snippets.java 
Log Message:
fixed a couple of bugs and added more snippets.

Index: Snippets.java
===================================================================
RCS file: /cvs/cairo/cairo-java/test/org/freedesktop/cairo/test/Snippets.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Snippets.java	4 Mar 2005 23:38:16 -0000	1.2
+++ Snippets.java	5 Mar 2005 01:59:42 -0000	1.3
@@ -13,6 +13,13 @@
 import java.lang.reflect.Method;
 
 import org.freedesktop.cairo.Cairo;
+import org.freedesktop.cairo.FontSlant;
+import org.freedesktop.cairo.FontWeight;
+import org.freedesktop.cairo.LineCap;
+import org.freedesktop.cairo.LineJoin;
+import org.freedesktop.cairo.Pattern;
+import org.freedesktop.cairo.RGBColor;
+import org.freedesktop.cairo.TextExtents;
 
 /**
  */
@@ -26,7 +33,14 @@
 		"clip",
 		"curve_to",
 		"curve_rectangle",
-		"fill_and_stroke"
+		"fill_and_stroke",
+		"fill_and_stroke2",
+		"gradient",
+		"path",
+		"set_line_cap",
+		"set_line_join",
+		"text",
+		"text_align_center"
 	};
 	
 	public static void invokeSnippet(Snippets snip, int num, Cairo cr, double width, double height) 
@@ -225,4 +239,187 @@
 		cr.closePath();
 		cr.stroke();
 	}
+
+	/**
+	 * fill_and_stroke2 snippet
+	 */
+	public void fill_and_stroke2(Cairo cr, double width, double height) {
+		normalize (cr, width, height);
+
+		cr.moveTo(0.5, 0.1);
+		cr.lineTo(0.9, 0.9);
+		cr.relLineTo(-0.4, 0.0);
+		cr.curveTo(0.2, 0.9, 0.2, 0.5, 0.5, 0.5);
+		cr.closePath();
+
+		cr.moveTo(0.25, 0.1);
+		cr.relLineTo(0.2, 0.2);
+		cr.relLineTo(-0.2, 0.2);
+		cr.relLineTo(-0.2, -0.2);
+		cr.closePath();
+
+
+		cr.save();
+	    cr.setRGBColor(0, 0, 1);
+	    cr.fill();
+		cr.restore();
+
+		cr.stroke();
+	}
+
+	/**
+	 * gradient snippet
+	 */
+	public void gradient(Cairo cr, double width, double height) {
+		
+		normalize (cr, width, height);
+
+		Pattern pat = new Pattern(0.0, 0.0, 0.0, 1.0);
+		pat.addColorStop(1, new RGBColor(0, 0, 0), 1);
+		pat.addColorStop(0, new RGBColor(1, 1, 1), 1);
+		cr.rectangle(0,0,1,1);
+		cr.setPattern(pat);
+		cr.fill();
+
+		pat.dispose();
+		pat = new Pattern(0.45, 0.4, 0.1, 0.4, 0.4, 0.5);
+		pat.addColorStop(0, new RGBColor(1, 1, 1), 1);
+		pat.addColorStop(1, new RGBColor(0, 0, 0), 1);
+		cr.setPattern(pat);
+		cr.arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
+		cr.fill();
+		pat.dispose();
+	}
+
+	/**
+	 * path snippet
+	 */
+	public void path(Cairo cr, double width, double height) {
+		normalize(cr, width, height);
+		cr.moveTo(0.5, 0.1);
+		cr.lineTo(0.9, 0.9);
+		cr.relLineTo(-0.4, 0.0);
+		cr.curveTo(0.2, 0.9, 0.2, 0.5, 0.5, 0.5);
+
+		cr.stroke();
+	}
+
+	/**
+	 * set_line_cap snippet
+	 */
+	public void set_line_cap(Cairo cr, double width, double height) {
+		normalize(cr, width, height);
+		cr.setLineWidth(0.12);
+		cr.setLineCap(LineCap.BUTT); /* default */
+		cr.moveTo(0.25, 0.2); 
+		cr.lineTo(0.25, 0.8);
+		cr.stroke();
+		cr.setLineCap(LineCap.ROUND);
+		cr.moveTo(0.5, 0.2); 
+		cr.lineTo(0.5, 0.8);
+		cr.stroke();
+		cr.setLineCap(LineCap.SQUARE);
+		cr.moveTo(0.75, 0.2); 
+		cr.lineTo(0.75, 0.8);
+		cr.stroke();
+
+		/* draw helping lines */
+		cr.setRGBColor(1,0.2,0.2);
+		cr.setLineWidth(0.01);
+		cr.moveTo(0.25, 0.2); 
+		cr.lineTo(0.25, 0.8);
+		cr.moveTo(0.5, 0.2);  
+		cr.lineTo(0.5, 0.8);
+		cr.moveTo(0.75, 0.2); 
+		cr.lineTo(0.75, 0.8);
+		cr.stroke();
+	}
+
+	/**
+	 * set_line_join snippet
+	 */
+	public void set_line_join(Cairo cr, double width, double height) {
+		normalize(cr, width, height);
+		cr.setLineWidth(0.16);
+		cr.moveTo(0.3, 0.33);
+		cr.relLineTo(0.2, -0.2);
+		cr.relLineTo(0.2, 0.2);
+		cr.setLineJoin(LineJoin.MITER); /* default */
+		cr.stroke();
+
+		cr.moveTo(0.3, 0.63);
+		cr.relLineTo(0.2, -0.2);
+		cr.relLineTo(0.2, 0.2);
+		cr.setLineJoin(LineJoin.BEVEL);
+		cr.stroke();
+
+		cr.moveTo(0.3, 0.93);
+		cr.relLineTo(0.2, -0.2);
+		cr.relLineTo(0.2, 0.2);
+		cr.setLineJoin(LineJoin.ROUND);
+		cr.stroke();
+
+
+	}
+
+	/**
+	 * text snippet
+	 */
+	public void text(Cairo cr, double width, double height) {
+		normalize (cr, width, height);
+		cr.selectFont("Sans", FontSlant.NORMAL, FontWeight.BOLD);
+		cr.scaleFont(0.35);
+
+		cr.moveTo(0.04, 0.53);
+		cr.showText("Hello");
+
+		cr.moveTo(0.27, 0.65);
+		cr.textPath("void");
+		cr.save();
+		cr.setRGBColor(0.5,0.5,1);
+		cr.fill();
+		cr.restore();
+		cr.setLineWidth(0.01);
+		cr.stroke();
+
+		/* draw helping lines */
+		cr.setRGBColor(1,0.2,0.2);
+		cr.setAlpha(0.6);
+		cr.arc(0.04, 0.53, 0.02, 0, 2*M_PI);
+		cr.arc(0.27, 0.65, 0.02, 0, 2*M_PI);
+		cr.fill();
+	}
+
+	/**
+	 * text_align_center snippet
+	 */
+	public void text_align_center(Cairo cr, double width, double height) {
+
+		normalize (cr, width, height);
+
+		cr.selectFont("Sans", FontSlant.NORMAL, FontWeight.NORMAL);
+		cr.scaleFont(0.2);
+		TextExtents extents = cr.getTextExtents("cairo");
+		System.out.println(extents.getWidth());
+		System.out.println(extents.getHeight());
+		System.out.println(extents.getXBearing());
+		System.out.println(extents.getYBearing());
+		double x = 0.5-(extents.getWidth()/2 + extents.getXBearing());
+		double y = 0.5-(extents.getHeight()/2 + extents.getYBearing());
+
+		System.out.println("x: " + x + " y: " + y);
+		cr.moveTo(x, y);
+		cr.showText("cairo");
+
+		/* draw helping lines */
+		cr.setRGBColor(1,0.2,0.2);
+		cr.setAlpha(0.6);
+		cr.arc(x, y, 0.05, 0, 2*M_PI);
+		cr.fill();
+		cr.moveTo(0.5, 0);
+		cr.relLineTo(0, 1);
+		cr.moveTo(0, 0.5);
+		cr.relLineTo(1, 0);
+		cr.stroke();
+	}
 }




More information about the cairo-commit mailing list