gnu_java_awt_peer_gtk_gdkgraphics2d.c

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· C语言 代码 · 共 1,622 行 · 第 1/4 页

C
1,622
字号
  if (gr->debug) printf ("drawPixels (%d pixels, %dx%d, stride: %d)\n",			 (*env)->GetArrayLength (env, java_pixels), w, h, stride);  native_pixels = (*env)->GetIntArrayElements (env, java_pixels, NULL);  native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL);  g_assert (native_pixels != NULL);  g_assert (native_matrix != NULL);  g_assert ((*env)->GetArrayLength (env, java_matrix) == 6);  begin_drawing_operation (env, gr);   {   cairo_matrix_t *mat = NULL;   cairo_surface_t *surf = cairo_surface_create_for_image ((char *)native_pixels, 							   CAIRO_FORMAT_ARGB32, 							   w, h, stride * 4);      mat = cairo_matrix_create ();   cairo_matrix_set_affine (mat, 			    native_matrix[0], native_matrix[1],			    native_matrix[2], native_matrix[3],			    native_matrix[4], native_matrix[5]);   cairo_surface_set_matrix (surf, mat);   cairo_surface_set_filter (surf, cairo_surface_get_filter(gr->surface));   cairo_show_surface (gr->cr, surf, w, h);   cairo_matrix_destroy (mat);   cairo_surface_destroy (surf); }   end_drawing_operation (env, gr);  (*env)->ReleaseIntArrayElements (env, java_pixels, native_pixels, 0); (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0);   gdk_threads_leave();}/* passthrough methods to cairo */JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSave    (JNIEnv *env, jobject obj){  struct graphics2d *gr = NULL;  gdk_threads_enter();  if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; }  gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);  g_assert (gr != NULL);  if (gr->debug) printf ("cairo_save\n");  cairo_save (gr->cr);  gdk_threads_leave();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRestore    (JNIEnv *env, jobject obj){  struct graphics2d *gr = NULL;  gdk_threads_enter();  if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; }  gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);  g_assert (gr != NULL);  if (gr->debug) printf ("cairo_restore\n");  cairo_restore (gr->cr);  update_pattern_transform (gr);  gdk_threads_leave();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetMatrix    (JNIEnv *env, jobject obj, jdoubleArray java_matrix){  struct graphics2d *gr = NULL;  jdouble *native_matrix = NULL;  gdk_threads_enter();  if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; }  gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);  /* cairoSetMatrix was called before this graphics object's component     was realized. */  if (gr == NULL) { gdk_threads_leave (); return; }  native_matrix = (*env)->GetDoubleArrayElements (env, java_matrix, NULL);    g_assert (native_matrix != NULL);  g_assert ((*env)->GetArrayLength (env, java_matrix) == 6);  if (gr->debug) printf ("cairo_set_matrix [ %f, %f, %f, %f, %f, %f ]\n",			 native_matrix[0], native_matrix[1],			 native_matrix[2], native_matrix[3],			 native_matrix[4], native_matrix[5]);  {    cairo_matrix_t * mat = cairo_matrix_create ();    cairo_matrix_set_affine (mat, 			     native_matrix[0], native_matrix[1],			     native_matrix[2], native_matrix[3],			     native_matrix[4], native_matrix[5]);    cairo_set_matrix (gr->cr, mat);    cairo_matrix_destroy (mat);  }  (*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0);  update_pattern_transform (gr);  gdk_threads_leave();}static voidinstall_font_peer(cairo_t *cr,		  struct peerfont *pfont,		  int debug){  cairo_font_t *ft;  FT_Face face = NULL;  g_assert(cr != NULL);  g_assert(pfont != NULL);    if (pfont->graphics_resource == NULL)    {      face = pango_ft2_font_get_face (pfont->font);      g_assert (face != NULL);            ft = cairo_ft_font_create_for_ft_face (face);      g_assert (ft != NULL);            if (debug) printf ("install_font_peer made new cairo font for '%s' at %f\n", 			 face->family_name,			 (pango_font_description_get_size (pfont->desc) / 			  (double)PANGO_SCALE));          cairo_set_font (cr, ft);       cairo_font_destroy (ft);      cairo_scale_font (cr, 			(pango_font_description_get_size (pfont->desc) / 			 (double)PANGO_SCALE));      ft = cairo_current_font (cr);      pfont->graphics_resource = ft;    }  else    {      if (debug) printf ("install_font_peer reused existing font resource\n");      ft = (cairo_font_t *) pfont->graphics_resource;      cairo_set_font (cr, ft);           }}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics2D_releasePeerGraphicsResource   (JNIEnv *env, jclass clazz __attribute__ ((unused)), jobject java_font){  struct peerfont *pfont = NULL;  g_assert(java_font != NULL);  gdk_threads_enter();  pfont = (struct peerfont *) NSA_GET_FONT_PTR (env, java_font);  g_assert (pfont != NULL);  if (pfont->graphics_resource != NULL)    {      cairo_font_destroy ((cairo_font_t *) pfont->graphics_resource);      pfont->graphics_resource = NULL;    }  gdk_threads_leave();}static voidpaint_glyph_run(JNIEnv *env,		struct graphics2d *gr,		cairo_glyph_t **glyphs,		gint *n_glyphs,		PangoLayoutRun *run){  gint i = 0;  gint x = 0, y = 0;  g_assert (gr != NULL);  g_assert (glyphs != NULL);  g_assert (n_glyphs != NULL);  g_assert (run != NULL);  if (run->glyphs != NULL && run->glyphs->num_glyphs > 0)    {      if (*n_glyphs < run->glyphs->num_glyphs)	{	  *glyphs = g_realloc(*glyphs, 			      (sizeof(cairo_glyph_t) 			       * run->glyphs->num_glyphs));	  *n_glyphs = run->glyphs->num_glyphs;	}            g_assert (*glyphs != NULL);      if (gr->debug) printf ("painting %d glyphs: ", run->glyphs->num_glyphs);      for (i = 0; i < run->glyphs->num_glyphs; ++i)	{	  	  (*glyphs)[i].index = run->glyphs->glyphs[i].glyph;	  (*glyphs)[i].x =	    ((double) (x + run->glyphs->glyphs[i].geometry.x_offset)) 	    / ((double) PANGO_SCALE);	  (*glyphs)[i].y =	    ((double) (y + run->glyphs->glyphs[i].geometry.y_offset)) 	    / ((double) PANGO_SCALE);	  	  if (gr->debug) printf(" (%ld @ %f,%f)",  				(*glyphs)[i].index,  				(*glyphs)[i].x, 				(*glyphs)[i].y);	    	  x += run->glyphs->glyphs[i].geometry.width;	}      if (gr->debug) printf("\n");      begin_drawing_operation (env, gr);      cairo_show_glyphs (gr->cr, *glyphs, run->glyphs->num_glyphs);      end_drawing_operation (env, gr);          }}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoDrawGlyphVector   (JNIEnv *env, jobject self,     jobject font,    jfloat x, jfloat y, jint n,    jintArray java_codes,    jfloatArray java_positions){    struct graphics2d *gr = NULL;  struct peerfont *pfont = NULL;  cairo_glyph_t *glyphs = NULL;  int *native_codes;  float *native_positions;  jint i = 0;  g_assert (self != NULL);  g_assert (java_codes != NULL);  g_assert (java_positions != NULL);  gdk_threads_enter ();  if (peer_is_disposed(env, self)) { gdk_threads_leave(); return; }  gr = (struct graphics2d *)NSA_GET_G2D_PTR (env, self);  g_assert (gr != NULL);  pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, font);  g_assert (pfont != NULL);  install_font_peer(gr->cr, pfont, gr->debug);  glyphs = malloc( sizeof(cairo_glyph_t) * n);  g_assert (glyphs != NULL);  native_codes = (*env)->GetIntArrayElements (env, java_codes, NULL);  native_positions = (*env)->GetFloatArrayElements (env, java_positions, NULL);    for (i = 0; i < n; ++i)    {      glyphs[i].index = native_codes[i];      glyphs[i].x = x + native_positions[ 2*i ];      glyphs[i].y = y + native_positions[ 2*i + 1];    }  (*env)->ReleaseFloatArrayElements (env, java_positions, native_positions, 0);  (*env)->ReleaseIntArrayElements (env, java_codes, native_codes, 0);  begin_drawing_operation (env, gr);    cairo_show_glyphs (gr->cr, glyphs, n);  end_drawing_operation (env, gr);  gdk_threads_leave ();    free(glyphs);}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoDrawGdkTextLayout   (JNIEnv *env, jobject self, jobject java_layout, jfloat x, jfloat y){  /*    * FIXME: Some day we expect either cairo or pango will know how to make   * a pango layout paint to a cairo surface. that day is not yet here.   */  struct graphics2d *gr = NULL;  struct textlayout *tl = NULL;  PangoLayoutIter *i = NULL;  PangoLayoutRun *run = NULL;  cairo_glyph_t *glyphs = NULL;  gint n_glyphs = 0;  g_assert (self != NULL);  g_assert (java_layout != NULL);  gr = (struct graphics2d *)NSA_GET_G2D_PTR (env, self);  tl = (struct textlayout *)NSA_GET_TEXT_LAYOUT_PTR (env, java_layout);  g_assert (gr != NULL);  g_assert (tl != NULL);  g_assert (tl->pango_layout != NULL);  if (gr->debug) printf ("painting pango layout\n");  gdk_threads_enter ();  if (peer_is_disposed(env, self)) { gdk_threads_leave(); return; }  i = pango_layout_get_iter (tl->pango_layout);  g_assert (i != NULL);  cairo_translate (gr->cr, x, y);  do     {      run = pango_layout_iter_get_run (i);      if (run != NULL)	paint_glyph_run (env, gr, &glyphs, &n_glyphs, run);    }   while (pango_layout_iter_next_run (i));    if (glyphs != NULL)    g_free (glyphs);  cairo_translate (gr->cr, -x, -y);    pango_layout_iter_free (i);  gdk_threads_leave ();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetOperator    (JNIEnv *env, jobject obj, jint op){  struct graphics2d *gr = NULL;  gdk_threads_enter();  if (peer_is_disposed(env, obj)) { gdk_threads_leave(); return; }  gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);  g_assert (gr != NULL);  if (gr->debug) printf ("cairo_set_operator %d\n", op);  switch ((enum java_awt_alpha_composite_rule) op)    {    case java_awt_alpha_composite_CLEAR:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_CLEAR);      break;          case java_awt_alpha_composite_SRC:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_SRC);      break;          case java_awt_alpha_composite_SRC_OVER:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_OVER);      break;    case java_awt_alpha_composite_DST_OVER:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_OVER_REVERSE);      break;    case java_awt_alpha_composite_SRC_IN:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_IN);      break;    case java_awt_alpha_composite_DST_IN:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_IN_REVERSE);      break;    case java_awt_alpha_composite_SRC_OUT:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_OUT);      break;    case java_awt_alpha_composite_DST_OUT:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_OUT_REVERSE);      break;    case java_awt_alpha_composite_DST:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_DST);      break;    case java_awt_alpha_composite_SRC_ATOP:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_ATOP);      break;    case java_awt_alpha_composite_DST_ATOP:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_ATOP_REVERSE);      break;    case java_awt_alpha_composite_XOR:       cairo_set_operator (gr->cr, CAIRO_OPERATOR_XOR);      break;    }  gdk_threads_leave();}JNIEXPORT void JNICALLJava_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetRGBColor    (JNIEnv *env, jobject obj, jdouble r, jdouble g, jdouble b){  struct graphics2d *gr = NULL;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?