[cairo-commit] cairo-java/src/java/org/freedesktop/cairo Matrix.java, 1.4, 1.5 Distance.java, 1.1, 1.2 Context.java, 1.2, 1.3

Jeffrey Morgan commit at pdx.freedesktop.org
Fri May 6 06:22:03 PDT 2005


Committed by: kuzman

Update of /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo
In directory gabe:/tmp/cvs-serv15985/src/java/org/freedesktop/cairo

Modified Files:
	Matrix.java Distance.java Context.java 
Log Message:
contuned API cleanup

Index: Matrix.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/Matrix.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Matrix.java	6 May 2005 11:50:55 -0000	1.4
+++ Matrix.java	6 May 2005 13:22:01 -0000	1.5
@@ -151,8 +151,8 @@
 	 * Transforms the given distance and returns transformed co-ordinates
 	 */
 	public Distance transformDistance(Distance d) {
-		double[] dx = new double[] { d.getXDistance() };
-		double[] dy = new double[] { d.getYDistance() };
+		double[] dx = new double[] { d.getDX() };
+		double[] dy = new double[] { d.getDY() };
 		cairo_matrix_transform_distance(getHandle(), dx, dy);
 		return new Distance(dx[0], dy[0]);
 	}

Index: Distance.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/Distance.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Distance.java	23 Feb 2005 18:17:52 -0000	1.1
+++ Distance.java	6 May 2005 13:22:01 -0000	1.2
@@ -13,36 +13,36 @@
  */
 public class Distance {
 
-	private double xDistance;
-	private double yDistance;
+	private double dx;
+	private double dy;
 	
-	public Distance(double xDistance, double yDistance) {
-		this.xDistance = xDistance;
-		this.yDistance = yDistance;
+	public Distance(double dx, double dy) {
+		this.dx = dx;
+		this.dy = dy;
 	}
 	
 	/**
-	 * @return Returns the xDistance.
+	 * @return Returns the x Distance.
 	 */
-	public double getXDistance() {
-		return xDistance;
+	public double getDX() {
+		return dx;
 	}
 	/**
-	 * @param distance The xDistance to set.
+	 * @param dx The x Distance to set.
 	 */
-	public void setXDistance(double distance) {
-		xDistance = distance;
+	public void setDX(double dx) {
+		dx = dx;
 	}
 	/**
-	 * @return Returns the yDistance.
+	 * @return Returns the y Distance.
 	 */
-	public double getYDistance() {
-		return yDistance;
+	public double getDY() {
+		return dy;
 	}
 	/**
-	 * @param distance The yDistance to set.
+	 * @param dy The y Distance to set.
 	 */
-	public void setYDistance(double distance) {
-		yDistance = distance;
+	public void setDY(double dy) {
+		dy = dy;
 	}
 }

Index: Context.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/Context.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Context.java	6 May 2005 11:50:55 -0000	1.2
+++ Context.java	6 May 2005 13:22:01 -0000	1.3
@@ -46,6 +46,10 @@
         this();
         setTargetSurface(surface);
     }
+    
+    Context(Handle hndl) {
+        super(hndl);
+    }
 
     static private Handle copy(Context copy) {
     	Handle hndl = Struct.getNullHandle();
@@ -80,6 +84,19 @@
 	public void restore() {
 		cairo_restore(getHandle());
 	}
+    
+    /**
+     * This function copies all current state information from the current
+     * context. This includes the current point and path, the target surface,
+     * the transformation matrix, and so forth.
+     *
+     * The stack of states saved with save() is <emphasis>not</emphasis>
+     * copied. 
+     * @return a copy of the current Contexst
+     */
+    public Context copy() {
+        return new Context(copy(this));
+    }
 	
 	/**
 	 * Directs output for to a given {@link Surface}.
@@ -281,73 +298,54 @@
 		cairo_identity_matrix(getHandle());
 	}
 
-	public Point userToDevice(Point p) {
-		double[] points = userToDevice(p.getX(), p.getY());
-		return new Point(points[0], points[1]);
-	}
-	
     /**
-     * Transforms a point to the global co-ordinates and returns the transformed
-     * point. 
-     *  
-     * @param x
-     *            The x cordinate of the point in local co-ordinates
-     * @param y
-     *            The y cordinate of the point in local co-ordinates
-     * @return The transformed point
+     * Transform a coordinate from user space to device space by
+     * multiplying the given point by the current transformation matrix
+     * (CTM).
      */
-	public double[] userToDevice(double x, double y) {
-		double[] px = new double[] { x };
-		double[] py = new double[] { y };
-		cairo_user_to_device(getHandle(), px, py);
-		return new double[] {px[0], py[0]};
+    public Point userToDevice(Point p) {
+        double[] px = new double[] { p.getX() };
+        double[] py = new double[] { p.getY() };
+        cairo_user_to_device(getHandle(), px, py);
+		return new Point(px[0], py[0]);
 	}
 	
+    /**
+     * Transform a coordinate from device space to user space by
+     * multiplying the given point by the inverse of the current
+     * transformation matrix (CTM).
+     */
 	public Point deviceToUser(Point p) {
-		double[] points = deviceToUser(p.getX(), p.getY());
-		return new Point(points[0], points[1]);
+        double[] px = new double[] { p.getX() };
+        double[] py = new double[] { p.getY() };
+        cairo_device_to_user(getHandle(), px, py);
+		return new Point(px[0], py[0]);
 	}
 	
     /**
-     * Inverse transforms a point to the local co-ordinates and returns the transformed
-     * point.
-     * 
-     * @param x
-     *            The x cordinate of the point in global co-ordinates
-     * @param y
-     *            The y cordinate of the point in global co-ordinates
-     * @return The transformed point
+     * Transform a distance vector from user space to device space. This
+     * function is similar to userToDevice() except that the
+     * translation components of the CTM will be ignored when transforming
+     * (dx,dy).
      */
-	public double[] deviceToUser(double x, double y) {
-		double[] px = new double[] { x };
-		double[] py = new double[] { y };
-		cairo_device_to_user(getHandle(), px, py);
-		return new double[] {px[0], py[0]};
-	}
-	
-	public Distance userToDeviceDistance(Distance d) {
-		double[] dis = userToDeviceDistance(d.getXDistance(), d.getYDistance());
-		return new Distance(dis[0], dis[1]);
-	}
-	
-	public double[] userToDeviceDistance(double x, double y) {
-		double[] dx = new double[] { x };
-		double[] dy = new double[] { y };
-		cairo_user_to_device_distance(getHandle(), dx, dy);
-		return new double[] {dx[0], dy[0]};
-		
+    public Distance userToDeviceDistance(Distance d) {
+        double[] dx = new double[] { d.getDX() };
+        double[] dy = new double[] { d.getDY() };
+        cairo_user_to_device_distance(getHandle(), dx, dy);
+		return new Distance(dx[0], dy[0]);
 	}
-	
+
+    /**
+     * Transform a distance vector from device space to user space. This
+     * function is similar to deviceToUser() except that the
+     * translation components of the inverse CTM will be ignored when
+     * transforming (dx,dy).
+     */
 	public Distance deviceToUserDistance(Distance d) {
-		double[] dis = deviceToUserDistance(d.getXDistance(), d.getYDistance());
-		return new Distance(dis[0], dis[1]);
-	}
-	
-	public double[] deviceToUserDistance(double x, double y) {
-		double[] dx = new double[] { x };
-		double[] dy = new double[] { y };
-		cairo_device_to_user_distance(getHandle(), dx, dy);
-		return new double[] {dx[0], dy[0]};
+        double[] dx = new double[] { d.getDX() };
+        double[] dy = new double[] { d.getDY() };
+        cairo_device_to_user_distance(getHandle(), dx, dy);
+		return new Distance(dx[0], dy[0]);
 	}
 	
     /**
@@ -387,10 +385,6 @@
 		cairo_rel_move_to(getHandle(), dx, dy);
 	}
 	
-	public void relMoveTo(Distance d) {
-		cairo_rel_move_to(getHandle(), d.getXDistance(), d.getYDistance());
-	}
-	
     /**
      * Draws a line segment as part of the current path. The line is drawn from
      * the current point of the path to the new co-ordinates.
@@ -424,10 +418,6 @@
 		cairo_rel_line_to(getHandle(), dx, dy);
 	}
 	
-	public void relLineTo(Distance d) {
-		cairo_rel_line_to(getHandle(), d.getXDistance(), d.getYDistance());
-	}
-	
     /**
      * Draws a cubic bezier curve from the current point to (x3, y3) using 2
      * control points (x1, y1) and (x2, y2).
@@ -475,11 +465,6 @@
 		cairo_rel_curve_to(getHandle(), dx1, dy1, dx2, dy2, dx3, dy3);
 	}
 	
-	public void relCurveTo(Distance d1, Distance d2, Distance d3) {
-		cairo_rel_curve_to(getHandle(), d1.getXDistance(), d1.getYDistance(), d2.getXDistance(),
-				d2.getYDistance(), d3.getXDistance(), d3.getYDistance());
-	}
-	
     /**
      * Closes the current path by connecting current point to the starting point
      * with a line segment.
@@ -718,7 +703,7 @@
 	 * Sets the current font face.
 	 * @param font
 	 */
-	public void setFont(FontFace font) {
+	public void setFontFace(FontFace font) {
 		cairo_set_font_face(getHandle(), font.getHandle());
 	}
 
@@ -729,20 +714,37 @@
 	}
 	
     /**
-     * Returns the text extents of the given string using current font and size
-     * settings.
-     * 
-     * @param text
-     *            The text string.
-     * @return The extents of the given string
+     * Gets the extents for a string of text. The extents describe a
+     * user-space rectangle that encloses the "inked" portion of the text,
+     * (as it would be drawn by showText). Additionally, the
+     * xAdvance and yAdvance values indicate the amount by which the
+     * current point would be advanced by showText.
+     *
+     * Note that whitespace characters do not directly contribute to the
+     * size of the rectangle (extents.width and extents.height). They do
+     * contribute indirectly by changing the position of non-whitespace
+     * characters. In particular, trailing whitespace characters are
+     * likely to not affect the size of the rectangle, though they will
+     * affect the xAdvance and yAdvance values.
      */
-	public TextExtents getTextExtents(String text) {
+	public TextExtents textExtents(String text) {
 		Handle hndl = Struct.getNullHandle();
 		cairo_text_extents(getHandle(), text, hndl);
 		return new TextExtents(hndl);
 	}
 
-	public TextExtents getGlyphExtents(Glyph[] glyphs) {
+	/**
+     * Gets the extents for an array of glyphs. The extents describe a
+     * user-space rectangle that encloses the "inked" portion of the
+     * glyphs, (as they would be drawn by showGlyphs).
+     * Additionally, the xAdvance and yAdvance values indicate the
+     * amount by which the current point would be advanced by
+     * cairo_show_glyphs.
+     * 
+     * Note that whitespace glyphs do not contribute to the size of the
+     * rectangle (extents.width and extents.height).
+	 */
+    public TextExtents glyphExtents(Glyph[] glyphs) {
 		Handle hndl = Struct.getNullHandle();
 		Handle[] gHndls = new Handle[glyphs.length];
 		for (int i = 0; i < glyphs.length; i++)
@@ -889,10 +891,14 @@
 		cairo_rectangle(getHandle(), x, y, width, height);
 	}
 	
-	public void rectangle(Point p, double width, double height) {
-		cairo_rectangle(getHandle(), p.getX(), p.getY(), width, height);
+	public void rectangle(Point p1, Point p2) {
+		cairo_rectangle(getHandle(), p1.getX(), p1.getY(), p2.getX(), p2.getY());
 	}
 	
+    public void rectangle(Box box) {
+        cairo_rectangle(getHandle(), box.getX1(), box.getY1(), box.getX2(), box.getY2());
+    }
+    
     /** Constant use for drawing ellipse */
     private static final double SVG_ARC_MAGIC = 0.5522847498;
 




More information about the cairo-commit mailing list