This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui][PATCH] fix font layout in java2d code


hi,

I just committed this to the java-gui-branch. it fixes font layout in java2d when the user matrix is subject to a non-identity transform.

-graydon

2004-03-09 Graydon Hoare <graydon@redhat.com>

	* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c:
	Fix double <-> fixed macros, reset font transform.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c:
	Likewise.

--- jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c	20 Nov 2003 22:44:01 -0000	1.2
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGlyphVector.c	10 Mar 2004 01:49:45 -0000
@@ -47,9 +47,10 @@
   double height;
 } rect_t;
 
-#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))
+#define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
+#define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
+#define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0))
+#define DOUBLE_FROM_16_16(t) ((double)(t) / 65536.0)
 
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGlyphVector_initStaticState 
   (JNIEnv *env, jclass clazz)
@@ -401,6 +402,21 @@
   return idx;
 }
 
+static void 
+assume_pointsize_and_identity_transform(double pointsize,
+					FT_Face face)
+{
+  FT_Matrix mat;
+  mat.xx = DOUBLE_TO_16_16(1);
+  mat.xy = DOUBLE_TO_16_16(0);
+  mat.yx = DOUBLE_TO_16_16(0);
+  mat.yy = DOUBLE_TO_16_16(1);    
+  FT_Set_Transform(face, &mat, NULL);
+  FT_Set_Char_Size( face, 
+		    DOUBLE_TO_26_6 (pointsize),
+		    DOUBLE_TO_26_6 (pointsize),
+		    0, 0);  
+}				    
 
 JNIEXPORT jdoubleArray JNICALL Java_gnu_java_awt_peer_gtk_GdkGlyphVector_allInkExtents 
   (JNIEnv *env, jobject self)
@@ -432,10 +448,7 @@
       g_assert (gi->glyphs != NULL);
 
       face = pango_ft2_font_get_face (gi->item->analysis.font);
-      FT_Set_Char_Size( face, 
-			DOUBLE_TO_26_6 (pointsize),
-			DOUBLE_TO_26_6 (pointsize),
-			0, 0);
+      assume_pointsize_and_identity_transform (pointsize, face);
       
       for (j = 0; j < gi->glyphs->num_glyphs; ++j)
 	{
@@ -487,10 +500,7 @@
       g_assert (gi->glyphs != NULL);
 
       face = pango_ft2_font_get_face (gi->item->analysis.font);
-      FT_Set_Char_Size( face, 
-			DOUBLE_TO_26_6 (pointsize),
-			DOUBLE_TO_26_6 (pointsize),
-			0, 0);
+      assume_pointsize_and_identity_transform (pointsize, face);
       
       for (j = 0; j < gi->glyphs->num_glyphs; ++j)
 	{
@@ -541,10 +551,8 @@
   pointsize = pango_font_description_get_size (vec->desc);
   pointsize /= (double) PANGO_SCALE;
   face = pango_ft2_font_get_face (font);
-  FT_Set_Char_Size( face, 
-		    DOUBLE_TO_26_6 (pointsize),
-		    DOUBLE_TO_26_6 (pointsize),
-		    0, 0);
+
+  assume_pointsize_and_identity_transform (pointsize, face);  
   
   FT_Load_Glyph (face, gi->glyph, FT_LOAD_DEFAULT);
 
@@ -588,11 +596,9 @@
   pointsize = pango_font_description_get_size (vec->desc);
   pointsize /= (double) PANGO_SCALE;
   face = pango_ft2_font_get_face (font);
-  FT_Set_Char_Size( face, 
-		    DOUBLE_TO_26_6 (pointsize),
-		    DOUBLE_TO_26_6 (pointsize),
-		    0, 0);
+
+  assume_pointsize_and_identity_transform (pointsize, face);  
   
   FT_Load_Glyph (face, gi->glyph, FT_LOAD_DEFAULT);
   /* FIXME: this needs to change for vertical layouts */
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c	31 Dec 2003 08:58:31 -0000	1.2
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GdkClasspathFontPeerMetrics.c	10 Mar 2004 01:49:45 -0000
@@ -53,6 +53,7 @@
   jintArray array;
   jint *metrics;
   struct peerfont *pf = NULL;
+  FT_Matrix mat;
 
   pf = NSA_GET_FONT_PTR(env, font);
   g_assert (pf != NULL);
@@ -62,14 +63,21 @@
 
   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))
+#define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0))
+#define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
+#define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0))
+#define DOUBLE_FROM_16_16(t) ((double)(t) / 65536.0)
 
   double pointsize = pango_font_description_get_size (pf->desc);
   pointsize /= (double) PANGO_SCALE;
 
+  mat.xx = DOUBLE_TO_16_16(1);
+  mat.xy = DOUBLE_TO_16_16(0);
+  mat.yx = DOUBLE_TO_16_16(0);
+  mat.yy = DOUBLE_TO_16_16(1);  
+  
   FT_Face face = pango_ft2_font_get_face (pf->font);  
+  FT_Set_Transform(face, &mat, NULL);
   FT_Set_Char_Size( face, 
 		    DOUBLE_TO_26_6 (pointsize),
 		    DOUBLE_TO_26_6 (pointsize),

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]