Commit 146a1ecb by Graydon Hoare Committed by Graydon Hoare

GdkClasspathFontPeerMetrics.java: New file.

2003-11-17  Graydon Hoare  <graydon@redhat.com>

	* gnu/java/awt/peer/gtk/GdkClasspathFontPeerMetrics.java: New file.
	* gnu/java/awt/peer/gtk/GdkClasspathFontPeer.java
	(GdkFontLineMetrics): New inner class.
	(getLineMetrics): Return new GdkFontLineMetrics.
	(getFontMetrics): Return new GdkClasspathFontPeerMetrics.
	(layoutGlyphVector): Create GdkGlyphVector.
	* gnu/java/awt/peer/gtk/GdkGraphics2D.java (stateStack): New member.
	(GdkGraphics2D): Initialize state via mathod calls.
	(cairoSetMatrix, cairoShowGlyphs): Simplify native calls.
	(cairoTranslate, cairoScale, cairoRotate): Remove.
	(various methods): use setTransform for special transform cases.
	(DrawState): New inner class.
	(stateSave): New method.
	(stateRestore): New method.
	(various methods): use stateSave, stateRestore.
	(getClipInDevSpace): New method.
	(clip, clipRect, setClip, getClip, getClipBounds):
	Follow spec more closely.
	(getTransform): Return clone of transform.
	(setStroke): Set linewidth to passed width / 2.0.
	(setPaintMode): Set SrcOver rather than Xor.
	(setColor): Set paint to passed color.
	(drawRaster, drawImage, PainterThread, drawPixels): Take affine
	transform from image to user space.
	(drawRenderedImage, drawRenderableImage): Implement.
	(getFontRenderContext, getFontMetrics, drawString, getFont):
	Implement
	(drawArc, drawOval, drawRoundRect, fillArc, fillOval, fillRoundRect):
	Implement.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c:
	Match changes to java side.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeer.c:
	Release resources.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c:
	Don't use pango for metrics.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c:
	New file.

From-SVN: r73776
parent 531547e9
2003-11-17 Graydon Hoare <graydon@redhat.com>
* gnu/java/awt/peer/gtk/GdkClasspathFontPeerMetrics.java: New file.
* gnu/java/awt/peer/gtk/GdkClasspathFontPeer.java
(GdkFontLineMetrics): New inner class.
(getLineMetrics): Return new GdkFontLineMetrics.
(getFontMetrics): Return new GdkClasspathFontPeerMetrics.
(layoutGlyphVector): Create GdkGlyphVector.
* gnu/java/awt/peer/gtk/GdkGraphics2D.java (stateStack): New member.
(GdkGraphics2D): Initialize state via mathod calls.
(cairoSetMatrix, cairoShowGlyphs): Simplify native calls.
(cairoTranslate, cairoScale, cairoRotate): Remove.
(various methods): use setTransform for special transform cases.
(DrawState): New inner class.
(stateSave): New method.
(stateRestore): New method.
(various methods): use stateSave, stateRestore.
(getClipInDevSpace): New method.
(clip, clipRect, setClip, getClip, getClipBounds):
Follow spec more closely.
(getTransform): Return clone of transform.
(setStroke): Set linewidth to passed width / 2.0.
(setPaintMode): Set SrcOver rather than Xor.
(setColor): Set paint to passed color.
(drawRaster, drawImage, PainterThread, drawPixels): Take affine
transform from image to user space.
(drawRenderedImage, drawRenderableImage): Implement.
(getFontRenderContext, getFontMetrics, drawString, getFont):
Implement
(drawArc, drawOval, drawRoundRect, fillArc, fillOval, fillRoundRect):
Implement.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c:
Match changes to java side.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeer.c:
Release resources.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c:
Don't use pango for metrics.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c:
New file.
2003-11-19 Guilhem Lavaux <guilhem@kaffe.org> 2003-11-19 Guilhem Lavaux <guilhem@kaffe.org>
Jim Pick <jim@kaffe.org> Jim Pick <jim@kaffe.org>
......
...@@ -49,6 +49,7 @@ import java.util.Map; ...@@ -49,6 +49,7 @@ import java.util.Map;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.text.CharacterIterator; import java.text.CharacterIterator;
import java.text.AttributedCharacterIterator; import java.text.AttributedCharacterIterator;
import java.text.StringCharacterIterator;
import java.awt.font.TextAttribute; import java.awt.font.TextAttribute;
import gnu.classpath.Configuration; import gnu.classpath.Configuration;
import gnu.java.awt.peer.ClasspathFontPeer; import gnu.java.awt.peer.ClasspathFontPeer;
...@@ -180,10 +181,56 @@ public class GdkClasspathFontPeer extends ClasspathFontPeer ...@@ -180,10 +181,56 @@ public class GdkClasspathFontPeer extends ClasspathFontPeer
throw new UnsupportedOperationException (); throw new UnsupportedOperationException ();
} }
protected class GdkFontLineMetrics extends LineMetrics
{
FontMetrics fm;
int nchars;
public GdkFontLineMetrics (FontMetrics m, int n)
{
fm = m;
nchars = n;
}
public float getAscent()
{
return (float) fm.getAscent ();
}
public int getBaselineIndex()
{
return Font.ROMAN_BASELINE;
}
public float[] getBaselineOffsets()
{
return new float[3];
}
public float getDescent()
{
return (float) fm.getDescent ();
}
public float getHeight()
{
return (float) fm.getHeight ();
}
public float getLeading() { return 0.f; }
public int getNumChars() { return nchars; }
public float getStrikethroughOffset() { return 0.f; }
public float getStrikethroughThickness() { return 0.f; }
public float getUnderlineOffset() { return 0.f; }
public float getUnderlineThickness() { return 0.f; }
}
public LineMetrics getLineMetrics (Font font, CharacterIterator ci, public LineMetrics getLineMetrics (Font font, CharacterIterator ci,
int begin, int limit, FontRenderContext rc) int begin, int limit, FontRenderContext rc)
{ {
throw new UnsupportedOperationException (); return new GdkFontLineMetrics (getFontMetrics (font), limit - begin);
} }
public Rectangle2D getMaxCharBounds (Font font, FontRenderContext rc) public Rectangle2D getMaxCharBounds (Font font, FontRenderContext rc)
...@@ -214,25 +261,32 @@ public class GdkClasspathFontPeer extends ClasspathFontPeer ...@@ -214,25 +261,32 @@ public class GdkClasspathFontPeer extends ClasspathFontPeer
public boolean hasUniformLineMetrics (Font font) public boolean hasUniformLineMetrics (Font font)
{ {
throw new UnsupportedOperationException (); return true;
} }
public GlyphVector layoutGlyphVector (Font font, FontRenderContext frc, public GlyphVector layoutGlyphVector (Font font, FontRenderContext frc,
char[] chars, int start, int limit, char[] chars, int start, int limit,
int flags) int flags)
{ {
throw new UnsupportedOperationException (); int nchars = (limit - start) + 1;
char[] nc = new char[nchars];
for (int i = 0; i < nchars; ++i)
nc[i] = chars[start + i];
return createGlyphVector (font, frc,
new StringCharacterIterator (new String (nc)));
} }
public LineMetrics getLineMetrics (Font font, String str, public LineMetrics getLineMetrics (Font font, String str,
FontRenderContext frc) FontRenderContext frc)
{ {
throw new UnsupportedOperationException(); return new GdkFontLineMetrics (getFontMetrics (font), str.length ());
} }
public FontMetrics getFontMetrics (Font font) public FontMetrics getFontMetrics (Font font)
{ {
throw new UnsupportedOperationException(); return new GdkClasspathFontPeerMetrics (font);
} }
} }
......
/* GdkClasspathFontPeerMetrics.java
Copyright (C) 1999, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.awt.peer.gtk;
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
public class GdkClasspathFontPeerMetrics extends FontMetrics
{
private final int native_state = GtkGenericPeer.getUniqueInteger();
private static final int ASCENT = 0, MAX_ASCENT = 1,
DESCENT = 2, MAX_DESCENT = 3,
MAX_ADVANCE = 4;
private int[] metrics;
private native int[] initState (Object font);
public GdkClasspathFontPeerMetrics (Font font)
{
super (font);
metrics = initState (font.getPeer());
}
public int stringWidth (String str)
{
GlyphVector gv = font.createGlyphVector
(new FontRenderContext
(new AffineTransform (), false, false), str);
Rectangle2D r = gv.getVisualBounds ();
return (int) r.getWidth ();
}
public int charWidth (char ch)
{
return stringWidth (new String (new char[] { ch }));
}
public int charsWidth (char data[], int off, int len)
{
return stringWidth (new String (data, off, len));
}
/*
Sun's Motif implementation always returns 0 or 1 here (???), but
going by the X11 man pages, it seems as though we should return
font.ascent + font.descent.
*/
public int getLeading ()
{
return 1;
// return metrics[ASCENT] + metrics[DESCENT];
}
public int getAscent ()
{
return metrics[ASCENT];
}
public int getMaxAscent ()
{
return metrics[MAX_ASCENT];
}
public int getDescent ()
{
return metrics[DESCENT];
}
public int getMaxDescent ()
{
return metrics[MAX_DESCENT];
}
public int getMaxAdvance ()
{
return metrics[MAX_ADVANCE];
}
}
...@@ -120,6 +120,13 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeer_setFont ...@@ -120,6 +120,13 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeer_setFont
pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, self); pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, self);
g_assert (pfont != NULL); g_assert (pfont != NULL);
if (pfont->ctx != NULL)
g_object_unref (pfont->ctx);
if (pfont->font != NULL)
g_object_unref (pfont->font);
if (pfont->desc != NULL)
pango_font_description_free (pfont->desc);
pfont->desc = pango_font_description_new (); pfont->desc = pango_font_description_new ();
g_assert (pfont->desc != NULL); g_assert (pfont->desc != NULL);
...@@ -153,7 +160,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeer_setFont ...@@ -153,7 +160,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeer_setFont
pfont->font = pango_font_map_load_font (map, pfont->ctx, pfont->desc); pfont->font = pango_font_map_load_font (map, pfont->ctx, pfont->desc);
g_assert (pfont->font != NULL); g_assert (pfont->font != NULL);
gdk_threads_leave (); gdk_threads_leave ();
} }
......
/* gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c
Copyright (C) 1999, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
#include <math.h>
#include "gtkpeer.h"
#include "gdkfont.h"
#include "gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.h"
#define ASCENT 0
#define MAX_ASCENT 1
#define DESCENT 2
#define MAX_DESCENT 3
#define MAX_ADVANCE 4
#define NUM_METRICS 5
JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics_initState
(JNIEnv *env, jobject self, jobject font)
{
jintArray array;
jint *metrics;
struct peerfont *pf = NULL;
pf = NSA_GET_FONT_PTR(env, font);
g_assert (pf != NULL);
array = (*env)->NewIntArray (env, NUM_METRICS);
metrics = (*env)->GetIntArrayElements (env, array, NULL);
gdk_threads_enter ();
#define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 63.0))
#define DOUBLE_FROM_26_6(t) (((double)((t) >> 6)) \
+ ((double)((t) & 0x3F) / 63.0))
double pointsize = pango_font_description_get_size (pf->desc);
pointsize /= (double) PANGO_SCALE;
FT_Face face = pango_ft2_font_get_face (pf->font);
FT_Set_Char_Size( face,
DOUBLE_TO_26_6 (pointsize),
DOUBLE_TO_26_6 (pointsize),
0, 0);
metrics[ASCENT] = ceil (DOUBLE_FROM_26_6(face->size->metrics.ascender));
metrics[MAX_ASCENT] = metrics[ASCENT];
metrics[DESCENT] = floor (DOUBLE_FROM_26_6(face->size->metrics.descender));
if (metrics[DESCENT] < 0)
metrics[DESCENT] = - metrics[DESCENT];
metrics[MAX_DESCENT] = metrics[DESCENT];
metrics[MAX_ADVANCE] = ceil (DOUBLE_FROM_26_6(face->size->metrics.max_advance));
gdk_threads_leave ();
(*env)->ReleaseIntArrayElements (env, array, metrics, 0);
return array;
}
...@@ -302,6 +302,8 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_copyState ...@@ -302,6 +302,8 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_copyState
g_old = (struct graphics2d *) NSA_GET_G2D_PTR (env, old); g_old = (struct graphics2d *) NSA_GET_G2D_PTR (env, old);
g_assert (g_old != NULL); g_assert (g_old != NULL);
if (g_old->debug) printf ("copying state from existing graphics2d\n");
g->drawable = g_old->drawable; g->drawable = g_old->drawable;
g->debug = g_old->debug; g->debug = g_old->debug;
...@@ -316,7 +318,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_copyState ...@@ -316,7 +318,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_copyState
else else
init_graphics2d_as_pixbuf (g); init_graphics2d_as_pixbuf (g);
cairo_surface_set_filter (g->surface, CAIRO_FILTER_BILINEAR); cairo_surface_set_filter (g->surface, CAIRO_FILTER_FAST);
gdk_threads_leave (); gdk_threads_leave ();
...@@ -649,36 +651,61 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_setTexturePixels ...@@ -649,36 +651,61 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_setTexturePixels
} }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_drawPixels JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_drawPixels
(JNIEnv *env, jobject obj, jintArray jarr, jint w, jint h, jint stride) (JNIEnv *env, jobject obj, jintArray java_pixels,
jint w, jint h, jint stride, jdoubleArray java_matrix)
{ {
struct graphics2d *gr = NULL; struct graphics2d *gr = NULL;
jint *jpixels = NULL; jint *native_pixels = NULL;
jdouble *native_matrix = NULL;
gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
g_assert (gr != NULL); g_assert (gr != NULL);
if (gr->debug) printf ("drawPixels (%d pixels, %dx%d, stride: %d)\n", if (gr->debug) printf ("drawPixels (%d pixels, %dx%d, stride: %d)\n",
(*env)->GetArrayLength (env, jarr), w, h, stride); (*env)->GetArrayLength (env, java_pixels), w, h, stride);
jpixels = (*env)->GetIntArrayElements (env, jarr, NULL); native_pixels = (*env)->GetIntArrayElements (env, java_pixels, NULL);
g_assert (jpixels != 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 (gr); begin_drawing_operation (gr);
{ {
cairo_surface_t *surf = cairo_surface_create_for_image ((char *)jpixels, cairo_matrix_t *mat = NULL;
cairo_surface_t *surf = cairo_surface_create_for_image ((char *)native_pixels,
CAIRO_FORMAT_ARGB32, CAIRO_FORMAT_ARGB32,
w, h, stride * 4); w, h, stride * 4);
cairo_surface_set_filter (surf, CAIRO_FILTER_BILINEAR); 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);
if (native_matrix[0] != 1.
|| native_matrix[1] != 0.
|| native_matrix[2] != 0.
|| native_matrix[3] != 1.)
{
cairo_surface_set_filter (surf, CAIRO_FILTER_BILINEAR);
cairo_surface_set_filter (gr->surface, CAIRO_FILTER_BILINEAR);
}
else
{
cairo_surface_set_filter (surf, CAIRO_FILTER_FAST);
cairo_surface_set_filter (gr->surface, CAIRO_FILTER_FAST);
}
cairo_show_surface (gr->cr, surf, w, h); cairo_show_surface (gr->cr, surf, w, h);
cairo_surface_set_filter (gr->surface, CAIRO_FILTER_FAST);
cairo_matrix_destroy (mat);
cairo_surface_destroy (surf); cairo_surface_destroy (surf);
} }
end_drawing_operation (gr); end_drawing_operation (gr);
(*env)->ReleaseIntArrayElements (env, jarr, jpixels, 0); (*env)->ReleaseIntArrayElements (env, java_pixels, native_pixels, 0);
(*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0);
} }
...@@ -706,25 +733,34 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRestore ...@@ -706,25 +733,34 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRestore
} }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetMatrix JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetMatrix
(JNIEnv *env, jobject obj, (JNIEnv *env, jobject obj, jdoubleArray java_matrix)
jdouble m00, jdouble m10,
jdouble m01, jdouble m11,
jdouble m02, jdouble m12)
{ {
struct graphics2d *gr = NULL; struct graphics2d *gr = NULL;
jdouble *native_matrix = NULL;
gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
g_assert (gr != NULL); g_assert (gr != NULL);
if (gr->debug) printf ("cairo_set_matrix\n");
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_t * mat = cairo_matrix_create ();
cairo_matrix_set_affine (mat, cairo_matrix_set_affine (mat,
m00, m10, native_matrix[0], native_matrix[1],
m01, m11, native_matrix[2], native_matrix[3],
m02, m12); native_matrix[4], native_matrix[5]);
cairo_set_matrix (gr->cr, mat); cairo_set_matrix (gr->cr, mat);
cairo_matrix_destroy (mat); cairo_matrix_destroy (mat);
} }
(*env)->ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0);
update_pattern_transform (gr); update_pattern_transform (gr);
} }
...@@ -750,8 +786,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetFont ...@@ -750,8 +786,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetFont
ft = cairo_ft_font_create_for_ft_face (face); ft = cairo_ft_font_create_for_ft_face (face);
g_assert (ft != NULL); g_assert (ft != NULL);
if (gr->debug) printf ("cairo_set_font '%s'\n", if (gr->debug) printf ("cairo_set_font '%s'\n", face->family_name);
face->family_name);
cairo_set_font (gr->cr, ft); cairo_set_font (gr->cr, ft);
...@@ -765,40 +800,46 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetFont ...@@ -765,40 +800,46 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetFont
} }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoShowGlyphs JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoShowGlyphs
(JNIEnv *env, jobject obj, jintArray jcodes, jfloatArray jposns, jint nglyphs) (JNIEnv *env, jobject obj, jintArray java_codes, jfloatArray java_posns)
{ {
struct graphics2d *gr = NULL; struct graphics2d *gr = NULL;
cairo_glyph_t *glyphs = NULL; cairo_glyph_t *glyphs = NULL;
jfloat *posns = NULL; jfloat *native_posns = NULL;
jint *codes = NULL; jint *native_codes = NULL;
jint i; jint i;
jint ncodes, nposns;
gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj); gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
g_assert (gr != NULL); g_assert (gr != NULL);
if (gr->debug) printf ("cairo_show_glyphs (%d glyphs)\n", nglyphs); native_codes = (*env)->GetIntArrayElements (env, java_codes, NULL);
native_posns = (*env)->GetFloatArrayElements (env, java_posns, NULL);
g_assert (native_codes != NULL);
g_assert (native_posns != NULL);
glyphs = malloc (sizeof(cairo_glyph_t) * nglyphs); ncodes = (*env)->GetArrayLength (env, java_codes);
g_assert (glyphs); nposns = (*env)->GetArrayLength (env, java_posns);
g_assert (2 * ncodes == nposns);
codes = (*env)->GetIntArrayElements (env, jcodes, NULL); if (gr->debug) printf ("cairo_show_glyphs (%d glyphs)\n", ncodes);
g_assert (codes != NULL);
posns = (*env)->GetFloatArrayElements (env, jposns, NULL); glyphs = malloc (sizeof(cairo_glyph_t) * ncodes);
g_assert (posns != NULL); g_assert (glyphs);
for (i = 0; i < nglyphs; ++i) for (i = 0; i < ncodes; ++i)
{ {
glyphs[i].index = codes[i]; glyphs[i].index = native_codes[i];
glyphs[i].x = (double) posns[2*i]; glyphs[i].x = (double) native_posns[2*i];
glyphs[i].y = (double) posns[2*i + 1]; glyphs[i].y = (double) native_posns[2*i + 1];
if (gr->debug) printf ("cairo_show_glyphs (glyph %d (code %d) : %f,%f)\n",
i, glyphs[i].index, glyphs[i].x, glyphs[i].y);
} }
(*env)->ReleaseIntArrayElements (env, jcodes, codes, 0); (*env)->ReleaseIntArrayElements (env, java_codes, native_codes, 0);
(*env)->ReleaseFloatArrayElements (env, jposns, posns, 0); (*env)->ReleaseFloatArrayElements (env, java_posns, native_posns, 0);
begin_drawing_operation (gr); begin_drawing_operation (gr);
cairo_show_glyphs (gr->cr, glyphs, nglyphs); cairo_show_glyphs (gr->cr, glyphs, ncodes);
end_drawing_operation (gr); end_drawing_operation (gr);
free(glyphs); free(glyphs);
...@@ -991,38 +1032,6 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetMiterLim ...@@ -991,38 +1032,6 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoSetMiterLim
cairo_set_miter_limit (gr->cr, miter); cairo_set_miter_limit (gr->cr, miter);
} }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoTranslate
(JNIEnv *env, jobject obj, jdouble dx, jdouble dy)
{
struct graphics2d *gr = NULL;
gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
g_assert (gr != NULL);
if (gr->debug) printf ("cairo_translate (%f, %f)\n", dx, dy);
cairo_translate (gr->cr, dx, dy);
update_pattern_transform (gr);
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoScale
(JNIEnv *env, jobject obj, jdouble sx, jdouble sy)
{
struct graphics2d *gr = NULL;
gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
g_assert (gr != NULL);
if (gr->debug) printf ("cairo_scale (%f, %f)\n", sx, sy);
cairo_scale (gr->cr, sx, sy);
update_pattern_transform (gr);
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoRotate
(JNIEnv *env, jobject obj, jdouble angle)
{
struct graphics2d *gr = NULL;
gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
g_assert (gr != NULL);
if (gr->debug) printf ("cairo_rotate %f\n", angle);
cairo_rotate (gr->cr, angle);
update_pattern_transform (gr);
}
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoNewPath JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoNewPath
(JNIEnv *env, jobject obj) (JNIEnv *env, jobject obj)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment