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

Jeffrey Morgan commit at pdx.freedesktop.org
Sat Mar 5 10:49:42 PST 2005


Committed by: kuzman

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

Modified Files:
	Snippets.java 
Log Message:
more snippets

Index: Snippets.java
===================================================================
RCS file: /cvs/cairo/cairo-java/test/org/freedesktop/cairo/test/Snippets.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Snippets.java	5 Mar 2005 01:59:42 -0000	1.3
+++ Snippets.java	5 Mar 2005 18:49:40 -0000	1.4
@@ -40,7 +40,13 @@
 		"set_line_cap",
 		"set_line_join",
 		"text",
-		"text_align_center"
+		"text_align_center",
+		"text_extents",
+		"xxx_clip_rectangle",
+		"xxx_dash",
+		"xxx_long_lines",
+		"xxx_multi_segment_caps",
+		"xxx_self_intersect"
 	};
 	
 	public static void invokeSnippet(Snippets snip, int num, Cairo cr, double width, double height) 
@@ -400,14 +406,9 @@
 		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());
+		double x = 0.5 -((extents.getWidth()/2.0) + extents.getXBearing());
+		double y = 0.5 -((extents.getHeight()/2.0) + extents.getYBearing());
 
-		System.out.println("x: " + x + " y: " + y);
 		cr.moveTo(x, y);
 		cr.showText("cairo");
 
@@ -422,4 +423,141 @@
 		cr.relLineTo(1, 0);
 		cr.stroke();
 	}
+	
+	/**
+	 * text_extents snippet
+	 */
+	public void text_extents(Cairo cr, double width, double height) {
+		double x=0.1;
+		double y=0.6;
+		String utf8 = "cairo";
+		normalize (cr, width, height);
+
+		cr.selectFont("Sans", FontSlant.NORMAL, FontWeight.NORMAL);
+
+		cr.scaleFont(0.4);
+		TextExtents extents = cr.getTextExtents(utf8);
+
+		cr.moveTo(x,y);
+		cr.showText(utf8);
+
+		/* 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(x,y);
+		cr.relLineTo(0, -extents.getHeight());
+		cr.relLineTo(extents.getWidth(), 0);
+		cr.relLineTo(extents.getXBearing(), -extents.getYBearing());
+		cr.stroke();
+	}
+
+	/**
+	 * xxx_clip_rectangle snippet
+	 */
+	public void xxx_clip_rectangle(Cairo cr, double width, double height) {
+		normalize (cr, width, height);
+
+		cr.newPath();
+		cr.moveTo(.25, .25);
+		cr.lineTo(.25, .75);
+		cr.lineTo(.75, .75);
+		cr.lineTo(.75, .25);
+		cr.lineTo(.25, .25);
+		cr.closePath();
+
+		cr.clip();
+
+		cr.moveTo(0, 0);
+		cr.lineTo(1, 1);
+		cr.stroke();
+	}
+
+	/**
+	 * xxx_dash snippet
+	 */
+	public void xxx_dash(Cairo cr, double width, double height) {
+		double dashes[] = {0.20,  /* ink */
+		                   0.05,  /* skip */
+		                   0.05,  /* ink */
+		                   0.05   /* skip*/ 
+		                  };
+		double offset = -0.2; 
+
+		normalize(cr, width, height);
+
+		cr.setDash(dashes, offset);
+
+		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();
+	}
+
+	/**
+	 * xxx_long_lines snippet
+	 */
+	public void xxx_long_lines(Cairo cr, double width, double height) {
+		normalize(cr, width, height);
+
+		cr.moveTo(0.1, -50);
+		cr.lineTo(0.1,  50);
+		cr.setRGBColor(1, 0 ,0);
+		cr.stroke();
+
+		cr.moveTo(0.2, -60);
+		cr.lineTo(0.2,  60);
+		cr.setRGBColor(1, 1 ,0);
+		cr.stroke();
+
+		cr.moveTo(0.3, -70);
+		cr.lineTo(0.3,  70);
+		cr.setRGBColor(0, 1 ,0);
+		cr.stroke();
+
+		cr.moveTo(0.4, -80);
+		cr.lineTo(0.4,  80);
+		cr.setRGBColor(0, 0 ,1);
+		cr.stroke();
+	}
+
+	/**
+	 * xxx_multi_segment_caps snippet
+	 */
+	public void xxx_multi_segment_caps(Cairo cr, double width, double height) {
+		normalize(cr, width, height);
+
+		cr.moveTo(0.2, 0.3);
+		cr.lineTo(0.8, 0.3);
+
+		cr.moveTo(0.2, 0.5);
+		cr.lineTo(0.8, 0.5);
+
+		cr.moveTo(0.2, 0.7);
+		cr.lineTo(0.8, 0.7);
+
+		cr.setLineWidth(0.12);
+		cr.setLineCap (LineCap.ROUND);
+		cr.stroke();
+	}
+
+	/**
+	 * xxx_self_intersect snippet
+	 */
+	public void xxx_self_intersect(Cairo cr, double width, double height) {
+		normalize(cr, width, height);
+
+		cr.moveTo(0.3, 0.3);
+		cr.lineTo(0.7, 0.3);
+
+		cr.lineTo(0.5, 0.3);
+		cr.lineTo(0.5, 0.7);
+
+		cr.setLineWidth(0.22);
+		cr.setLineCap(LineCap.ROUND);
+		cr.setLineJoin(LineJoin.ROUND);
+		cr.stroke();
+	}
 }




More information about the cairo-commit mailing list