[cairo-commit] CairoJava/src/org/cairographics/cairo Cairo.java, 1.5, 1.6 CairoFont.java, 1.1, 1.2 CairoMatrix.java, 1.4, 1.5 CairoException.java, 1.1, 1.2

Soorya Kuloor commit at pdx.freedesktop.org
Fri Apr 30 10:54:08 PDT 2004


Committed by: skuloor

Update of /cvs/cairo/CairoJava/src/org/cairographics/cairo
In directory pdx:/tmp/cvs-serv15913/src/org/cairographics/cairo

Modified Files:
	Cairo.java CairoFont.java CairoMatrix.java CairoException.java 
Log Message:
Moved all the related native methods to individual classes.

Index: Cairo.java
===================================================================
RCS file: /cvs/cairo/CairoJava/src/org/cairographics/cairo/Cairo.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** a/Cairo.java	23 Dec 2003 17:36:01 -0000	1.5
--- b/Cairo.java	30 Apr 2004 17:53:54 -0000	1.6
***************
*** 4,37 ****
   * Copyright (C) 2003 Verano
   * 
!  * Permission to use, copy, modify, distribute, and sell this software
!  * and its documentation for any purpose is hereby granted without
!  * fee, provided that the above copyright notice appear in all copies
!  * and that both that copyright notice and this permission notice
!  * appear in supporting documentation, and that the name of
!  * Verano not be used in advertising or publicity pertaining to
   * distribution of the software without specific, written prior permission.
!  * Verano makes no representations about the suitability of this
[...2067 lines suppressed...]
! 
!     native static short cairo_current_fill_rule(long cr);
! 
!     native static double cairo_current_line_width(long cr);
! 
!     native static short cairo_current_line_cap(long cr);
! 
!     native static short cairo_current_line_join(long cr);
! 
!     native static double cairo_current_miter_limit(long cr);
! 
!     native static void cairo_current_matrix(long cr, long matrix);
! 
!     native static long cairo_current_target_surface(long cr);
! 
!     native static void cairo_current_path(long cr, PathTracer tracer);
! 
!     native static void cairo_current_path_flat(long cr, FlatPathTracer tracer);
! }
\ No newline at end of file

Index: CairoFont.java
===================================================================
RCS file: /cvs/cairo/CairoJava/src/org/cairographics/cairo/CairoFont.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** a/CairoFont.java	23 Dec 2003 17:36:01 -0000	1.1
--- b/CairoFont.java	30 Apr 2004 17:53:54 -0000	1.2
***************
*** 30,35 ****
  package org.cairographics.cairo;
  
- import org.cairographics.cairo.internal.CairoAPI;
- 
  /**
   * This class implements Cairo font. Methods are provided to create and transform and scale the font.
--- 30,33 ----
***************
*** 58,62 ****
       *
       */
!     private CairoFont() {
      }
  
--- 56,60 ----
       *
       */
!     protected CairoFont() {
      }
  
***************
*** 70,121 ****
  
      /**
-      * Create a new font with the given characteristics.
-      * 
-      * @param family The font family
-      * @param slant The font slant
-      * @param weight The font weight
-      * @param height The font height
-      */
-     public CairoFont(String family, short slant, short weight, double height) {
-         this.handle = CairoAPI.ftFontCreate(family, slant, weight);
-         ref();
- 
-         CairoMatrix matrix = new CairoMatrix();
-         matrix.scale(height, height);
-         setTransform(matrix);
-         matrix.dispose();
-     }
- 
-     /**
-      * Create a new font with the given characteristics.
-      * 
-      * @param family The font family
-      * @param slant The font slant
-      * @param weight The font weight
-      * @param height The font height
-      */
-     public CairoFont(String family, String style, String weight, double height) {
-         this.handle = CairoAPI.ftFontCreate(family, style, weight);
-         ref();
-         
-         CairoMatrix matrix = new CairoMatrix();
-         matrix.scale(height, height);
-         setTransform(matrix);
-         matrix.dispose();
-     }
- 
-     /**
       * Increments the reference count on the font object. This is done so that the native pointer
       * does not get freed prematurely.
       */
      public void ref() {
!         CairoAPI.fontRef(handle);
!     }
! 
!     /**
!      * Decrements the reference count.
!      */
!     public void unref() {
!         dispose();
      }
  
--- 68,76 ----
  
      /**
       * Increments the reference count on the font object. This is done so that the native pointer
       * does not get freed prematurely.
       */
      public void ref() {
!         cairo_font_reference(handle);
      }
  
***************
*** 125,129 ****
       */
      public void dispose() {
!         CairoAPI.destroyFont(handle);
      }
      
--- 80,84 ----
       */
      public void dispose() {
!         cairo_font_destroy(handle);
      }
      
***************
*** 135,139 ****
       */
      public void setTransform(CairoMatrix matrix) {
!         CairoAPI.fontSetTransform(this.handle, matrix.handle);
      }
  }
--- 90,113 ----
       */
      public void setTransform(CairoMatrix matrix) {
!         cairo_font_set_transform(handle, matrix.handle);
!     }
!     
!     /**
!      * Returns the current transform of this font object.
!      * 
!      * @return The current transform matrix of this font.
!      */
!     public CairoMatrix getTransform() {
!         CairoMatrix mat = new CairoMatrix();
!         cairo_font_current_transform(handle, mat.handle);
!         return mat;
      }
+     
+     /*
+      * Native methods that map into cairo functions. See cairo documentation for details.
+      */
+     native static void cairo_font_reference (long font);
+     native static void cairo_font_destroy (long font);
+     native static void cairo_font_set_transform (long font, long matrix); 
+     native static void cairo_font_current_transform (long font, long matrix);
  }

Index: CairoMatrix.java
===================================================================
RCS file: /cvs/cairo/CairoJava/src/org/cairographics/cairo/CairoMatrix.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** a/CairoMatrix.java	23 Dec 2003 17:36:01 -0000	1.4
--- b/CairoMatrix.java	30 Apr 2004 17:53:54 -0000	1.5
***************
*** 30,35 ****
  package org.cairographics.cairo;
  
- import org.cairographics.cairo.internal.*;
- 
  /**
   * This class wraps the Cairo transformation matrix.
--- 30,33 ----
***************
*** 47,54 ****
       */
      public CairoMatrix() {
!         handle = CairoAPI.matrixCreate();
      }
  
      /**
       * Constructs a matrix using the affine parameters.
       * 
--- 45,60 ----
       */
      public CairoMatrix() {
!         handle = cairo_matrix_create();
      }
  
      /**
+      * Create a matrix object, given its native pointer.
+      * @param handle
+      */
+     CairoMatrix(long handle) {
+         this.handle = handle;
+     }
+     
+     /**
       * Constructs a matrix using the affine parameters.
       * 
***************
*** 67,72 ****
          double tx,
          double ty) {
!         handle = CairoAPI.matrixCreate();
!         CairoAPI.matrixSetAffine(handle, a, b, c, d, tx, ty);
      }
  
--- 73,78 ----
          double tx,
          double ty) {
!         handle = cairo_matrix_create();
!         cairo_matrix_set_affine(handle, a, b, c, d, tx, ty);
      }
  
***************
*** 77,82 ****
       */
      public CairoMatrix(CairoMatrix other) {
!         handle = CairoAPI.matrixCreate();
!         CairoAPI.matrixCopy(handle, other.handle);
      }
  
--- 83,88 ----
       */
      public CairoMatrix(CairoMatrix other) {
!         handle = cairo_matrix_create();
!         cairo_matrix_copy(handle, other.handle);
      }
  
***************
*** 85,89 ****
       */
      public void dispose() {
!         CairoAPI.matrixDestroy(handle);
      }
  
--- 91,95 ----
       */
      public void dispose() {
!         cairo_matrix_destroy(handle);
      }
  
***************
*** 95,99 ****
      public CairoMatrix copy() {
          CairoMatrix other = new CairoMatrix();
!         CairoAPI.matrixCopy(other.handle, handle);
          return other;
      }
--- 101,105 ----
      public CairoMatrix copy() {
          CairoMatrix other = new CairoMatrix();
!         cairo_matrix_copy(other.handle, handle);
          return other;
      }
***************
*** 103,107 ****
       */
      public void setIdentity() {
!         CairoAPI.matrixSetIdentity(handle);
      }
  
--- 109,113 ----
       */
      public void setIdentity() {
!         cairo_matrix_set_identity(handle);
      }
  
***************
*** 112,116 ****
       */
      public double[] getAffine() {
!         return CairoAPI.matrixGetAffine(this.handle);
      }
  
--- 118,122 ----
       */
      public double[] getAffine() {
!         return cairo_matrix_get_affine(handle);
      }
  
***************
*** 132,136 ****
          double tx,
          double ty) {
!         CairoAPI.matrixSetAffine(handle, a, b, c, d, tx, ty);
      }
  
--- 138,142 ----
          double tx,
          double ty) {
!         cairo_matrix_set_affine(handle, a, b, c, d, tx, ty);
      }
  
***************
*** 142,146 ****
       */
      public void translate(double tx, double ty) {
!         CairoAPI.matrixTranslate(handle, tx, ty);
      }
  
--- 148,152 ----
       */
      public void translate(double tx, double ty) {
!         cairo_matrix_translate(handle, tx, ty);
      }
  
***************
*** 152,156 ****
       */
      public void scale(double sx, double sy) {
!         CairoAPI.matrixScale(handle, sx, sy);
      }
  
--- 158,162 ----
       */
      public void scale(double sx, double sy) {
!         cairo_matrix_scale(handle, sx, sy);
      }
  
***************
*** 161,165 ****
       */
      public void rotate(double radians) {
!         CairoAPI.matrixRotate(handle, radians);
      }
  
--- 167,171 ----
       */
      public void rotate(double radians) {
!         cairo_matrix_rotate(handle, radians);
      }
  
***************
*** 172,178 ****
       */
      public void rotate(double radians, double cx, double cy) {
!         CairoAPI.matrixTranslate(handle, cx, cy);
!         CairoAPI.matrixRotate(handle, radians);
!         CairoAPI.matrixTranslate(handle, -cx, -cy);
      }
  
--- 178,184 ----
       */
      public void rotate(double radians, double cx, double cy) {
!         cairo_matrix_translate(handle, cx, cy);
!         cairo_matrix_rotate(handle, radians);
!         cairo_matrix_translate(handle, -cx, -cy);
      }
  
***************
*** 182,186 ****
       */
      public void invert() {
!         CairoAPI.matrixInvert(handle);
      }
  
--- 188,192 ----
       */
      public void invert() {
!         cairo_matrix_invert(handle);
      }
  
***************
*** 194,198 ****
      public static CairoMatrix multiply(CairoMatrix a, CairoMatrix b) {
          CairoMatrix product = new CairoMatrix();
!         CairoAPI.matrixMultiply(product.handle, a.handle, b.handle);
          return product;
      }
--- 200,204 ----
      public static CairoMatrix multiply(CairoMatrix a, CairoMatrix b) {
          CairoMatrix product = new CairoMatrix();
!         cairo_matrix_multiply(product.handle, a.handle, b.handle);
          return product;
      }
***************
*** 206,224 ****
          CairoMatrix other = secondMatrix;
          CairoMatrix tmp = copy();
!         CairoAPI.matrixMultiply(handle, tmp.handle, other.handle);
          tmp.dispose();
      }
  
      /**
-      * Rotate from the given vector.
-      * 
-      * @param x
-      * @param y
-      */
-     public void rotateFromVector(double x, double y) {
-         // TODO Implement this
-     }
- 
-     /**
       * Appends uniform scaling transformation to this matrix.
       * 
--- 212,220 ----
          CairoMatrix other = secondMatrix;
          CairoMatrix tmp = copy();
!         cairo_matrix_multiply(handle, tmp.handle, other.handle);
          tmp.dispose();
      }
  
      /**
       * Appends uniform scaling transformation to this matrix.
       * 
***************
*** 237,241 ****
       */
      public double[] getTransformedPoint(double x, double y) {
!         return CairoAPI.matrixTransformPoint(this.handle, x, y);
      }
  
--- 233,237 ----
       */
      public double[] getTransformedPoint(double x, double y) {
!         return cairo_matrix_transform_point(this.handle, x, y);
      }
  
***************
*** 248,252 ****
       */
      public double[] getTransformedDistance(double dx, double dy) {
!         return CairoAPI.matrixTransformDistance(this.handle, dx, dy);
      }
  }
--- 244,279 ----
       */
      public double[] getTransformedDistance(double dx, double dy) {
!         return cairo_matrix_transform_distance(this.handle, dx, dy);
      }
+ 
+ 
+     native static long cairo_matrix_create ();
+ 
+     native static void cairo_matrix_destroy (long matrix);
+ 
+     native static void cairo_matrix_copy (long matrix, long other);
+ 
+     native static void cairo_matrix_set_identity (long matrix);
+ 
+     native static void cairo_matrix_set_affine (long cr,
+                  double a, double b,
+                  double c, double d,
+                  double tx, double ty);
+ 
+     native static void cairo_matrix_set_affine (long cr, double[] affine);
+     native static double[] cairo_matrix_get_affine (long matrix);
+ 
+     native static void cairo_matrix_translate (long matrix, double tx, double ty);
+ 
+     native static void cairo_matrix_scale (long matrix, double sx, double sy);
+ 
+     native static void cairo_matrix_rotate (long matrix, double radians);
+ 
+     native static void cairo_matrix_invert (long matrix);
+ 
+     native static void cairo_matrix_multiply (long result, long a, long b);
+ 
+     native static double[] cairo_matrix_transform_distance (long matrix, double dx, double dy);
+ 
+     native static double[] cairo_matrix_transform_point (long matrix, double x, double y);
  }

Index: CairoException.java
===================================================================
RCS file: /cvs/cairo/CairoJava/src/org/cairographics/cairo/CairoException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** a/CairoException.java	23 Dec 2003 17:36:01 -0000	1.1
--- b/CairoException.java	30 Apr 2004 17:53:54 -0000	1.2
***************
*** 31,40 ****
  
  /**
!  * This is the runtime exception thrown by almost all of Xr related methods and classes.
   */
  public class CairoException extends RuntimeException {
  
      /**
!      * The Xr error code. Will be one of Xr.STATUS_xxxx codes.
       */
      short errCode;
--- 31,50 ----
  
  /**
!  * This is the runtime exception thrown by almost all of cairo related methods and classes.
   */
  public class CairoException extends RuntimeException {
  
+     /*
+      * Cairo function call status constants
+      */
+     public final static short STATUS_SUCCESS = 0;
+     public final static short STATUS_NO_MEMORY = 1;
+     public final static short STATUS_INVALID_RESTORE = 2;
+     public final static short STATUS_INVALID_POPGROUP = 3;
+     public final static short STATUS_NO_CURRENT_POINT = 4;
+     public final static short STATUS_INVALID_MATRIX = 5;
+ 
      /**
!      * The cairo error code. Will be one of STATUS_xxxx codes.
       */
      short errCode;
***************
*** 44,51 ****
       * 
       * @param code Error code
-      * @param message Error message
       */
!     public CairoException(short code, String message) {
!         super(message);
          this.errCode = code;
      }
--- 54,60 ----
       * 
       * @param code Error code
       */
!     public CairoException(short code) {
!         super(cairo_status_string(code));
          this.errCode = code;
      }
***************
*** 54,61 ****
       * Returns the error code of this exception.
       * 
!      * @return Xr error code, one of Xr.STATUS_xxx codes.
       */
      public short getErrorCode() {
          return errCode;
      }
  }
--- 63,75 ----
       * Returns the error code of this exception.
       * 
!      * @return cairo error code, one of STATUS_xxx codes.
       */
      public short getErrorCode() {
          return errCode;
      }
+ 
+     /*
+      * Native method
+      */
+     native static String cairo_status_string (long cr);
  }





More information about the cairo-commit mailing list