[cairo-commit] CairoJava/jni libcairoJni.cpp,1.4,1.5

Soorya Kuloor commit at pdx.freedesktop.org
Tue Dec 23 09:37:42 PST 2003


Committed by: skuloor

Update of /cvs/cairo/CairoJava/jni
In directory pdx:/tmp/cvs-serv12104/jni

Modified Files:
	libcairoJni.cpp 
Log Message:
Added new font related JNI Calls

Index: libcairoJni.cpp
===================================================================
RCS file: /cvs/cairo/CairoJava/jni/libcairoJni.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** libcairoJni.cpp	17 Nov 2003 17:43:55 -0000	1.4
--- libcairoJni.cpp	23 Dec 2003 17:37:40 -0000	1.5
***************
*** 36,40 ****
  #include <libcairoJni.h>
  #include <cairo.h>
- #include <cairo-xlib.h>
  #include <gdk/gdkx.h>
  #include <gtk/gtkwidget.h>
--- 36,39 ----
***************
*** 43,46 ****
--- 42,48 ----
  #define TO_LONG(ptr) (jlong) (long) ptr
  
+ static FT_Library ft_library;
+ static bool ft_lib_init = false;
+ 
  /*
   * Internal cairo_image structure
***************
*** 252,260 ****
      gdk_window_get_internal_paint_info (((GtkWidget *) (long) widget)->window,
                                          &drawable, &x_offset, &y_offset);
- 
-     /*
-     printf("Drawable: %d, x_offset %d, y_offset %d\n",
-            drawable, x_offset, y_offset);
-     */
      
      cairo_set_target_drawable(TO_PTR(cairo_t, xrsp),
--- 254,257 ----
***************
*** 451,454 ****
--- 448,463 ----
  /*
   * Class:     org_cairographics_cairo_internal_CairoAPI
+  * Method:    getMatrix
+  * Signature: (JJ)V
+  */
+ JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_getMatrix
+ (JNIEnv *env, jclass me, jlong xrsp, jlong matrixp)
+ {
+     cairo_current_matrix(TO_PTR(cairo_t, xrsp), 
+                          TO_PTR(cairo_matrix_t, matrixp));
+ }
+ 
+ /*
+  * Class:     org_cairographics_cairo_internal_CairoAPI
   * Method:    defaultMatrix
   * Signature: (J)V
***************
*** 593,604 ****
   */
  JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_selectFont(
!     JNIEnv *env, jclass me, jlong xrsp, jstring fontName)
  {
      const char *utfchars = env->GetStringUTFChars(fontName, NULL);
!     /*
!      *casted utfchars to accept const char *
!      */
!     cairo_select_font(TO_PTR(cairo_t, xrsp), (char *)utfchars,
!     CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
      env->ReleaseStringUTFChars(fontName, utfchars);
  }
--- 602,613 ----
   */
  JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_selectFont(
!     JNIEnv *env, jclass me, jlong xrsp, jstring fontName, short slant, short weight)
  {
+ 
      const char *utfchars = env->GetStringUTFChars(fontName, NULL);
! 
!     cairo_select_font(TO_PTR(cairo_t, xrsp), (char *) utfchars, 
!                       (cairo_font_slant_t) slant, 
!                       (cairo_font_weight_t) weight);
      env->ReleaseStringUTFChars(fontName, utfchars);
  }
***************
*** 621,628 ****
   */
  JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_transformFont(
!     JNIEnv *env, jclass me, jlong xrsp,
!     cairo_matrix_t *matrix)
  {
!     cairo_transform_font(TO_PTR(cairo_t, xrsp), matrix);
  }
  
--- 630,636 ----
   */
  JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_transformFont(
!     JNIEnv *env, jclass me, jlong xrsp, jlong matrix)
  {
!     cairo_transform_font(TO_PTR(cairo_t, xrsp), TO_PTR(cairo_matrix_t, matrix));
  }
  
***************
*** 632,657 ****
   * Signature: (JLjava/lang/String;)Lcom/verano/schematx/draw/gtk/Xr$TextExtents;
   */
- 
- /* XXX: NYI 14.11.2003
  JNIEXPORT jdoubleArray JNICALL Java_org_cairographics_cairo_internal_CairoAPI_getTextExtents(
      JNIEnv *env, jclass me, jlong xrsp, jstring text)
  {
      const char* utf8text = env->GetStringUTFChars(text, NULL);
!     
!     jdoubleArray extents = env->NewDoubleArray(6);
  
-     double *elems = env->GetDoubleArrayElements(extents, NULL);
      cairo_text_extents(TO_PTR(cairo_t, xrsp),
!                        (const unsigned char *) utf8text, 
!                        elems, elems + 1,
!                        elems + 2, elems + 3,
!                        elems + 4, elems + 5);
!     env->ReleaseDoubleArrayElements(extents, elems, 0);
  
      env->ReleaseStringUTFChars(text, utf8text);
  
!     return extents;
  }
- */
  
  /*
--- 640,666 ----
   * Signature: (JLjava/lang/String;)Lcom/verano/schematx/draw/gtk/Xr$TextExtents;
   */
  JNIEXPORT jdoubleArray JNICALL Java_org_cairographics_cairo_internal_CairoAPI_getTextExtents(
      JNIEnv *env, jclass me, jlong xrsp, jstring text)
  {
      const char* utf8text = env->GetStringUTFChars(text, NULL);
!     cairo_text_extents_t extents;
  
      cairo_text_extents(TO_PTR(cairo_t, xrsp),
!                        (const unsigned char *) utf8text, &extents);
!     
!     jdoubleArray extentsArray = env->NewDoubleArray(6);
!     double *elems = env->GetDoubleArrayElements(extentsArray, NULL);
!     elems[0] = extents.x_bearing;
!     elems[1] = extents.y_bearing;
!     elems[2] = extents.width;
!     elems[3] = extents.height;
!     elems[4] = extents.x_advance;
!     elems[5] = extents.y_advance;
!     env->ReleaseDoubleArrayElements(extentsArray, elems, 0);
  
      env->ReleaseStringUTFChars(text, utf8text);
  
!     return extentsArray;
  }
  
  /*
***************
*** 664,668 ****
  {
      const char *utf8text = env->GetStringUTFChars(text, NULL);
- 
      cairo_show_text(TO_PTR(cairo_t, xrsp), (const unsigned char *) utf8text);
      env->ReleaseStringUTFChars(text, utf8text);
--- 673,676 ----
***************
*** 728,732 ****
  
      Display *dpy = GDK_WINDOW_XDISPLAY(drawable);
!     cairo_surface_t *surface = cairo_xlib_surface_create (
          dpy,
          GDK_DRAWABLE_XID(drawable),
--- 736,740 ----
  
      Display *dpy = GDK_WINDOW_XDISPLAY(drawable);
!     cairo_surface_t *surface = cairo_xlib_surface_create(
          dpy,
          GDK_DRAWABLE_XID(drawable),
***************
*** 753,756 ****
--- 761,765 ----
  }
  
+ #if 0
  /*
   * Class:     org_cairographics_cairo_internal_CairoAPI
***************
*** 758,763 ****
   * Signature: (JSIIDDDD)J
   */
- 
- /* XXX: NYI 14.11.2003
  JNIEXPORT jlong JNICALL Java_org_cairographics_cairo_internal_CairoAPI_surfaceCreateSimilarSolid(
      JNIEnv *env, jclass me, jlong neighbor,
--- 767,770 ----
***************
*** 766,770 ****
      jdouble red, jdouble green, jdouble blue, jdouble alpha)
  {
!     cairo_surface_t* surface = _cairo_surface_create_similar_solid(
          TO_PTR(cairo_surface_t, neighbor),
          (cairo_format) format,
--- 773,777 ----
      jdouble red, jdouble green, jdouble blue, jdouble alpha)
  {
!     cairo_surface_t* surface = cairo_surface_create_similar_solid(
          TO_PTR(cairo_surface_t, neighbor),
          (cairo_format) format,
***************
*** 774,778 ****
      return TO_LONG(surface);
  }
! */
  
  /*
--- 781,785 ----
      return TO_LONG(surface);
  }
! #endif
  
  /*
***************
*** 1068,1071 ****
--- 1075,1079 ----
  (JNIEnv *env, jclass me, jlong surface, jlong matrix)
  {
+     
      return cairo_surface_get_matrix(TO_PTR(cairo_surface_t, surface),
                                TO_PTR(cairo_matrix_t, matrix));
***************
*** 1324,1328 ****
          GDK_PIXMAP_XID(drawable),
          DefaultVisual (dpy, DefaultScreen (dpy)),
!         CAIRO_FORMAT_ARGB32,
          DefaultColormap (dpy, DefaultScreen (dpy)));
      
--- 1332,1336 ----
          GDK_PIXMAP_XID(drawable),
          DefaultVisual (dpy, DefaultScreen (dpy)),
!         (cairo_format) 0,
          DefaultColormap (dpy, DefaultScreen (dpy)));
      
***************
*** 1330,1345 ****
  }
  
! #if 0 /** NYI */
  /*
   * Class:     org_cairographics_cairo_internal_CairoAPI
!  * Method:    clipRegion
   * Signature: (JDDDD)V
   */
! JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_clipSurface(
      JNIEnv *env, jclass me, jlong xrs,
      int x, int y, int width, int height)
  {
!     cairo_surface_set_clip_rectangle(
!         cairo_get_target_surface(TO_PTR(cairo_t, xrs)), x, y, width, height);
  }
  #endif
--- 1338,1366 ----
  }
  
! #if 0 /* NYI */
  /*
   * Class:     org_cairographics_cairo_internal_CairoAPI
!  * Method:    clipRectangle
   * Signature: (JDDDD)V
   */
! JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_clipRectangle(
      JNIEnv *env, jclass me, jlong xrs,
      int x, int y, int width, int height)
  {
!     cairo_surface_clip_rectangle(
!         cairo_current_target_surface(TO_PTR(cairo_t, xrs)), x, y, width, height);
! }
! 
! /*
!  * Class:     org_cairographics_cairo_internal_CairoAPI
!  * Method:    surfaceClipRectangle
!  * Signature: (JDDDD)V
!  */
! JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_surfaceClipRectangle(
!     JNIEnv *env, jclass me, jlong surface,
!     int x, int y, int width, int height)
! {
!     cairo_surface_clip_rectangle(TO_PTR(cairo_surface_t, surface),
!                                  x, y, width, height);
  }
  #endif
***************
*** 1355,1356 ****
--- 1376,1572 ----
      return newPoint(env, x, y);
  }
+ 
+ /*
+  * Class:     org_cairographics_cairo_internal_CairoAPI
+  * Method:    setFont
+  * Signature: (JJ)V
+  */
+ JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_setFont
+   (JNIEnv *env, jclass me, jlong xrsp, jlong fontp)
+ {
+     cairo_set_font(TO_PTR(cairo_t, xrsp),
+                    TO_PTR(cairo_font_t, fontp));
+ }
+ 
+ /*
+  * Class:     org_cairographics_cairo_internal_CairoAPI
+  * Method:    getCurrentFont
+  * Signature: (J)J
+  */
+ JNIEXPORT jlong JNICALL Java_org_cairographics_cairo_internal_CairoAPI_getCurrentFont
+   (JNIEnv *env, jclass me, jlong xrsp)
+ {
+     return TO_LONG(cairo_current_font(TO_PTR(cairo_t, xrsp)));
+ }
+ 
+ /*
+  * Class:     org_cairographics_cairo_internal_CairoAPI
+  * Method:    fontRef
+  * Signature: (J)V
+  */
+ JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_fontRef
+ (JNIEnv *env, jclass me, jlong fontp)
+ {
+     cairo_font_reference(TO_PTR(cairo_font_t, fontp));
+ }
+ 
+ 
+ /*
+  * Class:     org_cairographics_cairo_internal_CairoAPI
+  * Method:    destroyFont
+  * Signature: (J)V
+  */
+ JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_destroyFont
+   (JNIEnv *env, jclass me, jlong fontp)
+ {
+     cairo_font_destroy(TO_PTR(cairo_font_t, fontp));
+ }
+ 
+ /*
+  * Class:     org_cairographics_cairo_internal_CairoAPI
+  * Method:    ftFontCreate
+  * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J
+  */
+ JNIEXPORT jlong JNICALL Java_org_cairographics_cairo_internal_CairoAPI_ftFontCreate__Ljava_lang_String_2SS
+ (JNIEnv *env, jclass me, jstring family, jshort slant, jshort weight)
+ {
+     const char *family_utf = env->GetStringUTFChars(family, NULL);
+     cairo_font_t *font = NULL;
+     FcPattern * pat = NULL;
+     int fcslant;
+     int fcweight;
+     FT_Error error;
+ 
+     pat = FcPatternCreate ();
+     if (pat == NULL)
+         return 0;
+ 
+     switch (weight)
+     {
+     case CAIRO_FONT_WEIGHT_BOLD:
+         fcweight = FC_WEIGHT_BOLD;
+         break;
+     case CAIRO_FONT_WEIGHT_NORMAL:
+     default:
+         fcweight = FC_WEIGHT_MEDIUM;
+         break;
+     }
+ 
+     switch (slant)
+     {
+     case CAIRO_FONT_SLANT_ITALIC:
+         fcslant = FC_SLANT_ITALIC;
+         break;
+     case CAIRO_FONT_SLANT_OBLIQUE:
+ 	fcslant = FC_SLANT_OBLIQUE;
+         break;
+     case CAIRO_FONT_SLANT_NORMAL:
+     default:
+         fcslant = FC_SLANT_ROMAN;
+         break;
+     }
+ 
+     FcPatternAddString (pat, FC_FAMILY, (const FcChar8*) family_utf);
+     FcPatternAddInteger (pat, FC_SLANT, fcslant);
+     FcPatternAddInteger (pat, FC_WEIGHT, fcweight);
+ 
+     if (ft_lib_init == false) {
+         error = FT_Init_FreeType (&ft_library);
+         if (error) {
+             FcPatternDestroy (pat);
+             return 0;
+         }
+         ft_lib_init = true;
+     }
+ 
+     font = cairo_ft_font_create (ft_library, pat);
+     if (font == NULL)
+ 	return 0;
+ 
+ #define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
+ 
+     FT_Set_Char_Size (cairo_ft_font_face(font),
+                       DOUBLE_TO_26_6 (1.0),
+                       DOUBLE_TO_26_6 (1.0),
+                       0, 0);
+ 
+   
+     FcPatternDestroy (pat);
+     env->ReleaseStringUTFChars(family, family_utf);
+     return TO_LONG(font);  
+ }
+ 
+ /*
+  * Class:     org_cairographics_cairo_internal_CairoAPI
+  * Method:    ftFontCreate
+  * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J
+  */
+ JNIEXPORT jlong JNICALL Java_org_cairographics_cairo_internal_CairoAPI_ftFontCreate__Ljava_lang_String_2Ljava_lang_String_2Ljava_lang_String_2
+ (JNIEnv *env, jclass me, jstring family, jstring slant, jstring weight)
+ {
+     const char *family_utf = env->GetStringUTFChars(family, NULL);
+     const char *slant_utf =  env->GetStringUTFChars(slant, NULL);
+     const char *weight_utf =  env->GetStringUTFChars(weight, NULL);
+ 
+     char fontBuf[256];
+     strcpy(fontBuf, family_utf);
+     strcat(fontBuf, ":");
+     strcat(fontBuf, weight_utf);
+     strcat(fontBuf, ":");
+     strcat(fontBuf, slant_utf);
+     
+     cairo_font_t *font = NULL;
+     FcPattern * pat = NULL;
+     FT_Error error;
+ 
+     pat = FcNameParse ((const FcChar8*) fontBuf);
+     if (pat == NULL)
+         return 0;
+ 
+     /*
+     FcPatternAddString (pat, FC_FAMILY, (const FcChar8*) family_utf);
+     FcPatternAddString (pat, FC_SLANT, (const FcChar8*) slant_utf);
+     FcPatternAddString (pat, FC_WEIGHT, (const FcChar8*) weight_utf);
+     */
+ 
+     if (ft_lib_init == false) {
+         error = FT_Init_FreeType (&ft_library);
+         if (error) {
+             FcPatternDestroy (pat);
+             return 0;
+         }
+         ft_lib_init = true;
+     }
+ 
+     font = cairo_ft_font_create (ft_library, pat);
+     if (font == NULL)
+ 	return 0;
+ 
+ #define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
+ 
+     FT_Set_Char_Size (cairo_ft_font_face(font),
+                       DOUBLE_TO_26_6 (1.0),
+                       DOUBLE_TO_26_6 (1.0),
+                       0, 0);
+ 
+   
+     FcPatternDestroy (pat);
+     env->ReleaseStringUTFChars(family, family_utf);
+     env->ReleaseStringUTFChars(slant, slant_utf);
+     env->ReleaseStringUTFChars(weight, weight_utf);
+     return TO_LONG(font);  
+ }
+ 
+ /*
+  * Class:     org_cairographics_cairo_internal_CairoAPI
+  * Method:    fontSetTransform
+  * Signature: (JJ)V
+  */
+ JNIEXPORT void JNICALL Java_org_cairographics_cairo_internal_CairoAPI_fontSetTransform
+ (JNIEnv *env, jclass me, jlong fontp, jlong matrixp)
+ {
+     cairo_font_set_transform(TO_PTR(cairo_font_t, fontp),
+                              TO_PTR(cairo_matrix_t, matrixp));
+ }
+ 
+ 





More information about the cairo-commit mailing list