[kaffe] CVS kaffe (jserv): Qt AWT debugging classification and font init / font metrics info.

Kaffe CVS cvs-commits at kaffe.org
Wed Jul 14 00:13:26 PDT 2004


PatchSet 4964 
Date: 2004/07/14 07:08:11
Author: jserv
Branch: HEAD
Tag: (none) 
Log:
Qt AWT debugging classification and font init / font metrics info.

	* FAQ/FAQ.awt:
	Update usage of Qt AWT backend.

	* libraries/clib/awt/qt/clr.cc,
	libraries/clib/awt/qt/evt.cc,
	libraries/clib/awt/qt/fnt.cc,
	libraries/clib/awt/qt/gra.cc,
	libraries/clib/awt/qt/wnd.cc:
	Definite AWT debugging classification.
	Update font initialization and font metrics information.
	Color model support improvement.

Members: 
	ChangeLog:1.2528->1.2529 
	FAQ/FAQ.awt:1.10->1.11 
	libraries/clib/awt/qt/clr.cc:1.5->1.6 
	libraries/clib/awt/qt/evt.cc:1.8->1.9 
	libraries/clib/awt/qt/fnt.cc:1.5->1.6 
	libraries/clib/awt/qt/gra.cc:1.4->1.5 
	libraries/clib/awt/qt/wnd.cc:1.5->1.6 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2528 kaffe/ChangeLog:1.2529
--- kaffe/ChangeLog:1.2528	Tue Jul 13 16:38:10 2004
+++ kaffe/ChangeLog	Wed Jul 14 07:08:11 2004
@@ -1,3 +1,17 @@
+2004-07-14  Jim Huang  <jserv at kaffe.org>
+
+	* FAQ/FAQ.awt:
+	Update usage of Qt AWT backend.
+
+	* libraries/clib/awt/qt/clr.cc,
+	libraries/clib/awt/qt/evt.cc,
+	libraries/clib/awt/qt/fnt.cc,
+	libraries/clib/awt/qt/gra.cc,
+	libraries/clib/awt/qt/wnd.cc:
+	Definite AWT debugging classification.
+	Update font initialization and font metrics information.
+	Color model support improvement.
+	
 2004-07-13  Dalibor Topic  <robilad at kaffe.org>
 
 	* config/arm/jit-arm.def:
Index: kaffe/FAQ/FAQ.awt
diff -u kaffe/FAQ/FAQ.awt:1.10 kaffe/FAQ/FAQ.awt:1.11
--- kaffe/FAQ/FAQ.awt:1.10	Mon Jul 12 06:39:49 2004
+++ kaffe/FAQ/FAQ.awt	Wed Jul 14 07:08:13 2004
@@ -157,19 +157,21 @@
 
   * Qt AWT backend crashes, how can I help?
 
-    Firsr, Qt AWT backend in Kaffe is still buggy, so any feedback 
+    First, Qt AWT backend in Kaffe is still buggy, so any feedback 
     is important to developers for improving. You may attempt to 
     enable the debug option in Kaffe (configure as --enable-debug 
-    support), and execute a Java AWT application like:
+    support, read FAQ/FAQ.debugging), and execute a Java AWT 
+    application like:
 
-      kaffe -vmdebug AWT -cp <PATH> <CLASSNAME>
+      kaffe -vmdebug AWT -cp <CLASSPATH> <CLASSNAME>
 
     Qt AWT backend will dump debug messages in stderr, and you could
-    redirect to text file. It's sometimes useful for trouble shooting.
+    redirect to text file. To specify the Qt AWT native part, you
+    pass some arguments, such AWT_EVT, AWT_CLR, etc. to -vmdebug 
+    option.
 
-  Finally, if all else fails, you are on your own. Build kaffe with
-  support for debugging, read FAQ/FAQ.debugging and try to figure
-  out what's wrong using a debugger. Good luck and please keep in
+  Finally, try to figure out what's wrong using a debugger according
+  to the debugging messages you obtain. Good luck and please keep in
   touch with the kaffe mailing list kaffe at kaffe.org.
 
 Other AWT backends
Index: kaffe/libraries/clib/awt/qt/clr.cc
diff -u kaffe/libraries/clib/awt/qt/clr.cc:1.5 kaffe/libraries/clib/awt/qt/clr.cc:1.6
--- kaffe/libraries/clib/awt/qt/clr.cc:1.5	Mon Jul 12 10:20:53 2004
+++ kaffe/libraries/clib/awt/qt/clr.cc	Wed Jul 14 07:08:10 2004
@@ -54,8 +54,7 @@
   if ( !X->colorMode )
 	initColorMapping( env, clazz, X);
 
-  // uint pixel = QColor(JRED(rgb), JGREEN(rgb), JBLUE(rgb)).pixel();
-  // AWT_DBG(qqDebug("clrGetPixelValue: %8x -> %x (%d)\n", rgb, pixel, pixel));
+  DBG(AWT_CLR, qqDebug("clrGetPixelValue: %8x -> %x\n", rgb, (uint) QColor(JRED(rgb), JGREEN(rgb), JBLUE(rgb)).pixel()));
 
   return rgb;
 }
@@ -113,23 +112,20 @@
   jobject    cm = 0;
   jclass     cmClazz;
   jmethodID  cmCtorId;
-//  QColor color;
-
+  QColor color;  
 
   if ( !X->colorMode )
 	initColorMapping( env, clazz, X);
 
-//  if(color.numBitPlanes()>8) {
-    cmClazz = env->FindClass( "java/awt/image/DirectColorModel");
-    cmCtorId = env->GetMethodID( cmClazz, "<init>", "(IIIII)V");
-    cm = env->NewObject( cmClazz, cmCtorId, 24,
-         0xff0000, 0x00ff00, 0x0000ff, 0);
-//  } else {
-//    cmClazz = env->FindClass( "java/awt/IndexColorModel");
-//    cmCtorId = env->GetMethodID( cmClazz, "<init>", "(I[II)V");
-//    //rgbs = env->NewIntArray( 256, 0);
-//    //cm = env->NewObject( cmClazz, cmCtorId, 8, rgbs, 0);
-//  }
+  if (color.numBitPlanes() > 8) {
+    cmClazz = env->FindClass("java/awt/image/DirectColorModel");
+    cmCtorId = env->GetMethodID(cmClazz, "<init>", "(IIIII)V");
+    cm = env->NewObject(cmClazz, cmCtorId, 24, 0xff0000, 0x00ff00, 0x0000ff, 0);
+  } else {
+    cmClazz = env->FindClass("java/awt/IndexColorModel");
+    cmCtorId = env->GetMethodID(cmClazz, "<init>", "(I[II)V");
+    cm = env->NewObject(cmClazz, cmCtorId, 8, env->NewIntArray(256), 0);
+  }
 
   return cm;
 }
Index: kaffe/libraries/clib/awt/qt/evt.cc
diff -u kaffe/libraries/clib/awt/qt/evt.cc:1.8 kaffe/libraries/clib/awt/qt/evt.cc:1.9
--- kaffe/libraries/clib/awt/qt/evt.cc:1.8	Mon Jul 12 10:20:53 2004
+++ kaffe/libraries/clib/awt/qt/evt.cc	Wed Jul 14 07:08:10 2004
@@ -93,7 +93,7 @@
 }
 
 bool EventDispatcher::eventFilter(QObject* o, QEvent* e) {
-  DBG(AWT, qqDebug("event type=%d widget=%p\n", e->type(), o));
+  DBG(AWT_EVT, qqDebug("event type=%d widget=%p\n", e->type(), o));
   QEvent* newEvent = NULL;
   EventPacket* packet = NULL;
   bool processed = false;
@@ -116,7 +116,7 @@
     }
 
     case QEvent::Show: {
-      DBG(AWT, qqDebug("Event Show: srcIdx=%d\n", X->srcIdx));
+      DBG(AWT_EVT, qqDebug("Event Show: srcIdx=%d\n", X->srcIdx));
 
 #if (QT_VERSION < 300)
       newEvent = (QEvent*) new QShowEvent(true);
@@ -130,7 +130,7 @@
     }
     
     case QEvent::Hide: {
-      DBG(AWT, qqDebug("Event Hid: srcIdx=%d\n", X->srcIdx));
+      DBG(AWT_EVT, qqDebug("Event Hid: srcIdx=%d\n", X->srcIdx));
 
 #if (QT_VERSION < 300)
       newEvent = (QEvent*) new QHideEvent(true);
@@ -145,7 +145,7 @@
     
     case QEvent::FocusIn:
     case QEvent::FocusOut: {
-      DBG(AWT, qqDebug("Event Focus: srcIdx=%d\n", X->srcIdx));
+      DBG(AWT_EVT, qqDebug("Event Focus: srcIdx=%d\n", X->srcIdx));
       QFocusEvent* tmpFocusEvent = (QFocusEvent*)e;
       newEvent = (QEvent*) new QFocusEvent(tmpFocusEvent->type());
       ((QFocusEvent*)newEvent)->setReason(tmpFocusEvent->reason());
@@ -155,7 +155,7 @@
 
     case QEvent::KeyPress:
     case QEvent::KeyRelease: {
-      DBG(AWT, qqDebug("Event Key: srcIdx=%d\n", X->srcIdx));
+      DBG(AWT_EVT, qqDebug("Event Key: srcIdx=%d\n", X->srcIdx));
       QKeyEvent* tmpKeyEvent = (QKeyEvent*)e;
       newEvent = (QEvent*) new QKeyEvent(tmpKeyEvent->type(),tmpKeyEvent->key(),
 	tmpKeyEvent->ascii(), tmpKeyEvent->state(), tmpKeyEvent->text(),
@@ -167,7 +167,7 @@
     case QEvent::MouseButtonPress:
     case QEvent::MouseButtonRelease:
     case QEvent::MouseMove: {
-      DBG(AWT, qqDebug("Event MouseButton: srcIdx=%d\n", X->srcIdx));
+      DBG(AWT_EVT, qqDebug("Event MouseButton: srcIdx=%d\n", X->srcIdx));
       QMouseEvent* tmpMouseEvent = (QMouseEvent*)e;
       newEvent = (QEvent*) new QMouseEvent(tmpMouseEvent->type(),
         tmpMouseEvent->pos(), tmpMouseEvent->button(),
@@ -176,7 +176,7 @@
       break;
     }
     case QEvent::Paint: {
-      DBG(AWT, qqDebug("Event Paint: srcIdx=%d\n", X->srcIdx));
+      DBG(AWT_EVT, qqDebug("Event Paint: srcIdx=%d\n", X->srcIdx));
       QPaintEvent* tmpPaintEvent = (QPaintEvent*)e;
       newEvent = (QEvent*) new QPaintEvent(tmpPaintEvent->rect(),
         tmpPaintEvent->erased());
@@ -184,7 +184,7 @@
       break;
     }
     case QEvent::Move: {
-      DBG(AWT, qqDebug("Event Move: srcIdx=%d\n", X->srcIdx));
+      DBG(AWT_EVT, qqDebug("Event Move: srcIdx=%d\n", X->srcIdx));
       QPoint data(((QWidget*)o)->width(), ((QWidget*)o)->height());
       QMoveEvent* tmpMoveEvent = (QMoveEvent*)e;
       // Hide width/height in oldPos of newEvent
@@ -194,7 +194,7 @@
       break;
     }
     case QEvent::Resize: {
-      DBG(AWT, qqDebug("Event Resize: srcIdx=%d\n", X->srcIdx));
+      DBG(AWT_EVT, qqDebug("Event Resize: srcIdx=%d\n", X->srcIdx));
       QSize data(((QWidget*)o)->x(), ((QWidget*)o)->y());
       QResizeEvent* tmpResizeEvent = (QResizeEvent*)e;
       // Hide x/y in oldSize of newEvent
@@ -283,15 +283,15 @@
 {
   jclass Component;
 
-  DBG(AWT, qqDebug("evtInit\n"));
+  DBG(AWT_EVT, qqDebug("evtInit\n"));
 
   if ( ComponentEvent != NULL ){
-    DBG(AWT, qqDebug("evtInit called twice\n"));
+    DBG(AWT_EVT, qqDebug("evtInit called twice\n"));
     return NULL;
   }
 
   if(qapp == NULL) {
-    DBG(AWT, qqDebug("evtInit: qapp not initialized!\n"));
+    DBG(AWT_EVT, qqDebug("evtInit: qapp not initialized!\n"));
   }
 
   eventDispatcher = new EventDispatcher();
@@ -362,7 +362,7 @@
       
 
     case QEvent::Destroy: {
-      DBG(AWT, qqDebug("processing Destroy: SrcIdx=%d\n", index));
+      DBG(AWT_EVT, qqDebug("processing Destroy: SrcIdx=%d\n", index));
       /*
        * We should get this just for windows which have been destroyed from an
        * external client, since removeNotify() calls evtUnregisterSource() (i.e.
@@ -376,13 +376,13 @@
     }
     
     case QEvent::Reparent: {
-      DBG(AWT, qqDebug("processing Reparent: SrcIdx=%d\n", index));
+      DBG(AWT_EVT, qqDebug("processing Reparent: SrcIdx=%d\n", index));
       return NULL;
     }
 
     case QEvent::FocusIn:
     case QEvent::FocusOut: {
-      DBG(AWT, qqDebug("processing %s: SrcIdx=%d\n",(event->type() == QEvent::FocusIn)?"FocusIn":"FocusOut",index));
+      DBG(AWT_EVT, qqDebug("processing %s: SrcIdx=%d\n",(event->type() == QEvent::FocusIn)?"FocusIn":"FocusOut",index));
       int evtId;
       int et = event->type();
       if ( et == QEvent::FocusIn ) {
@@ -404,7 +404,7 @@
 
     case QEvent::KeyPress:
     case QEvent::KeyRelease: { 
-      DBG(AWT, qqDebug("processing %s: SrcIdx=%d\n",(event->type() == QEvent::KeyPress)?"KeyPress":"KeyRelease",index));
+      DBG(AWT_EVT, qqDebug("processing %s: SrcIdx=%d\n",(event->type() == QEvent::KeyPress)?"KeyPress":"KeyRelease",index));
       QKeyEvent *keyEvent = (QKeyEvent*)event;
       int             n, keyCode, keyChar, mod;
       
@@ -441,7 +441,7 @@
       int evtId = (((QEvent*)keyEvent)->type() == QEvent::KeyPress)? KEY_PRESSED : KEY_RELEASED;
       mod = keyMod(keyEvent->state());
       
-      DBG(AWT, qqDebug("KeyEvent: idx=%d keyCode=%d keyChar=%c mod=%d\n", index, keyCode,keyChar,mod));
+      DBG(AWT_EVT, qqDebug("KeyEvent: idx=%d keyCode=%d keyChar=%c mod=%d\n", index, keyCode,keyChar,mod));
 
       return env->CallStaticObjectMethod( KeyEvent, getKeyEvent,
                                           index, evtId, keyCode, keyChar, mod);
@@ -449,7 +449,7 @@
     }
     
     case QEvent::MouseButtonPress: {
-      DBG(AWT, qqDebug("processing MouseButtonPress Event SrcIdx=%d\n", index));
+      DBG(AWT_EVT, qqDebug("processing MouseButtonPress Event SrcIdx=%d\n", index));
       QMouseEvent* mouseEvent = (QMouseEvent*)event;
       // check the diff between event.xbutton.button and QMouseEvent::button()
       if (checkSource( X, index) ){
@@ -464,7 +464,7 @@
         mouseEvent->x(), mouseEvent->y());
     }
     case QEvent::MouseButtonRelease: {
-      DBG(AWT, qqDebug("processing MouseButtonRelease Event SrcIdx=%d\n", index));
+      DBG(AWT_EVT, qqDebug("processing MouseButtonRelease Event SrcIdx=%d\n", index));
       QMouseEvent* mouseEvent = (QMouseEvent*)event;
       // check the diff between event.xbutton.button and QMouseEvent::button()
       return env->CallStaticObjectMethod(MouseEvent, getMouseEvent,
@@ -472,21 +472,21 @@
         mouseEvent->x(), mouseEvent->y());
     }
     case QEvent::MouseMove: {
-      DBG(AWT, qqDebug("processing MouseMove Event SrcIdx=%d\n", index));
+      DBG(AWT_EVT, qqDebug("processing MouseMove Event SrcIdx=%d\n", index));
       QMouseEvent* mouseEvent = (QMouseEvent*)event;
       return env->CallStaticObjectMethod(MouseEvent, getMouseEvent,
         index, MOUSE_MOVED, 0,
         mouseEvent->x(), mouseEvent->y());
     }
     case QEvent::Paint: {
-      DBG(AWT, qqDebug("processing Paint Event SrcIdx=%d\n", index));
+      DBG(AWT_EVT, qqDebug("processing Paint Event SrcIdx=%d\n", index));
       QPaintEvent* paintEvent = (QPaintEvent*)event;
       QRect rect=paintEvent->rect();
       return env->CallStaticObjectMethod(PaintEvent, getPaintEvent,
         index, UPDATE, rect.x(), rect.y(), rect.width(), rect.height());
     }
     case QEvent::Move: {
-      DBG(AWT, qqDebug("processing Move Event SrcIdx=%d\n", index));
+      DBG(AWT_EVT, qqDebug("processing Move Event SrcIdx=%d\n", index));
       QMoveEvent* moveEvent = (QMoveEvent*)event;
       QPoint pos, data;
       pos = moveEvent->pos();
@@ -495,7 +495,7 @@
         index, COMPONENT_RESIZED, pos.x(), pos.y(), data.x(), data.y());
     }
     case QEvent::Resize: {
-      DBG(AWT, qqDebug("processing Resize Event SrcIdx=%d\n", index));
+      DBG(AWT_EVT, qqDebug("processing Resize Event SrcIdx=%d\n", index));
       QResizeEvent* resizeEvent = (QResizeEvent*)event;
       QSize size, data;
       size = resizeEvent->size();
@@ -515,7 +515,7 @@
   QEvent *event;
   int index;
 
-  DBG(AWT, qqDebug("getNextEvent..\n"));
+  DBG(AWT_EVT, qqDebug("getNextEvent..\n"));
   pollJavaClipboard(env);
 
   if (g_event_queue.count()) {
@@ -539,7 +539,7 @@
 {
   jobject jEvt = NULL;
 
-  DBG(AWT, qqDebug("peekEvent..\n"));
+  DBG(AWT_EVT, qqDebug("peekEvent..\n"));
 #if 0
   if ( nextEvent( env, clazz, X, False) && ((getSourceIdx( X, (void*)X->event.xany.window) >= 0)) ) {
 	if ( (jEvt = (processEvent[X->event.xany.type])( env, X)) )
@@ -582,7 +582,7 @@
  */
 void Java_java_awt_Toolkit_evtWakeup(JNIEnv* env, jclass clazz)
 {
-  DBG(AWT, qqDebug("evtWakeup\n"));
+  DBG(AWT_EVT, qqDebug("evtWakeup\n"));
 }
 
 /*
@@ -604,7 +604,7 @@
    */
   int i = getSourceIdx( X, wnd);
 
-  DBG(AWT, qqDebug("registerSource( %p) -> %d\n", wnd, i));
+  DBG(AWT_EVT, qqDebug("registerSource( %p) -> %d\n", wnd, i));
 
   return i;
 }
@@ -624,7 +624,7 @@
   if ( X->lastWindow == wnd )
 	X->lastWindow = 0;
 
-  DBG(AWT, qqDebug("unregisterSource( %p) -> %d\n", wnd, i));
+  DBG(AWT_EVT, qqDebug("unregisterSource( %p) -> %d\n", wnd, i));
 
   return i;
 }
Index: kaffe/libraries/clib/awt/qt/fnt.cc
diff -u kaffe/libraries/clib/awt/qt/fnt.cc:1.5 kaffe/libraries/clib/awt/qt/fnt.cc:1.6
--- kaffe/libraries/clib/awt/qt/fnt.cc:1.5	Mon Jul 12 10:20:53 2004
+++ kaffe/libraries/clib/awt/qt/fnt.cc	Wed Jul 14 07:08:10 2004
@@ -20,80 +20,45 @@
  * Font support
  */
 
-/*
- * this is our ultima ratio in case everything else fails, at least this
- * one should be.
- */
-#ifdef QPE
-char* backupFont = "unifont";
-#else
-char* backupFont = "fixed";
-#endif
-
-/*
- * these are (hopefully) the most usual font weight names, ordered
- * in our preferred lookup sequence (from PLAIN to BOLD)
- */
-char* weight[] = { "medium", "normal", "regular", "thin", "light",
-                   "black", "demibold", "heavy", "extrabold", "extrablack", "bold" };
-#define NWEIGHT 11
-
-/*
- * these are finally the size offsets we want to try
- */
-int dsize[] = { 0, 10, -10, 20, -20, 30, -30, 40, -40 };
-#define NDSIZE 9
-
-/*
- * Our font lookup strategy is like this: every mapping that can be known
- * a priori goes into java.awt.Defaults, everything that might be specified
- * at runtime (sizes, slant, weight) has to be handled here. In detail:
- * 
- * (1) foundry, family, encoding and everything EXCEPT of weight,slant,size
- *     are specified in java.awt.Defaults FontSpec strings, which are used
- *     as simple C format specifications
- * (2) since both BOLD and ITALIC map to more than one attribute value
- *     (e.g. ITALIC-> "o", "i"), and many fonts are not available in all
- *     sizes, we have to make up a sequence of alternate specs to search
- * (3) the search first tries to vary sizes, then weights, then slants
- * (4) in case all of this fails, it directly tries the font spec
- * (5) if this fails, too, it backs up to what is supposed to be a safe
- *     standard font (fix size)
- *
- * Once again - we don't try to deduce Qt font family names from the Java 
- * names, that's in java.awt.Defaults, and Defaults is meant to be the 
- * thing which adapts the AWT to your Qt installation/preferences. Don't 
- * lament, modify it!
- */
-
 void*
 Java_java_awt_Toolkit_fntInitFont ( JNIEnv* env, jclass clazz, jstring jSpec,
                                     jint style, jint size )
 {
   int  i, j, k, i0, i1, j0, j1, di, dj;
   char buf[160];
-  char *spec = java2CString( env, X, jSpec);
+  char *spec = (char *) env->GetStringChars(jSpec,NULL);
   QFont *qf;
-  int weight=QFont::Normal;
-  bool italic=FALSE;
+  int weight = QFont::Normal;
+  bool italic = FALSE;
 
-  DBG(AWT, qqDebug("fntInitFont...%s\n",spec));
+  DBG(AWT_FNT, qDebug("fntInitFont...%s\n",spec));
 
-  if ( style & 0x1 ) { /* we have a Font.BOLD request */
-    //i0 = NWEIGHT - 1; i1 = -1; di = -1;
-    weight = QFont::Bold;
-  }
-  else {
-    //i0 = 0; i1 = NWEIGHT; di = 1;
+  /*
+   * Use values from the java.awt.Font class
+   */
+  static int boldValue = -1;
+  static int italicValue = -1;
+
+  /* 
+   * Symbolic lookups are expensive, cache the values
+   */
+  if (boldValue < 0 || italicValue < 0) {
+    jfieldID fieldID;
+    jclass theClass;
+
+    theClass = env->FindClass("java.awt.Font");
+    fieldID = env->GetStaticFieldID(theClass, "BOLD", "I");
+    boldValue = env->GetStaticIntField(theClass, fieldID);
+
+    fieldID = env->GetStaticFieldID(theClass, "ITALIC", "I");
+    italicValue = env->GetStaticIntField(theClass, fieldID);
   }
 
-  if ( style & 0x2 ) { /* we have a Font.ITALIC request */
-    //j0 = NSLANT - 1; j1 = -1; dj = -1;
+  if (style & boldValue)
+    weight = QFont::Bold;
+  if (style & italicValue)
     italic = TRUE;
-  }
-  else {
-    //j0 = 0; j1 = NSLANT; dj = 1;
-  }
+
   qf = new QFont(spec, size, weight, italic);
   return (void*) qf;
 }
@@ -140,7 +105,7 @@
 
   QFontMetrics fm((QFont)(*fs));
   int w =  ((fm.minRightBearing() - fm.minLeftBearing()) == fm.maxWidth()) ? fm.maxWidth() : 0;
-  DBG(AWT, qqDebug("fntGetFixedWidth %d\n",w));
+  DBG(AWT_FNT, qqDebug("fntGetFixedWidth %d\n", w));
   return w;
 }
 
@@ -148,7 +113,7 @@
 Java_java_awt_Toolkit_fntGetHeight ( JNIEnv* env, jclass clazz, QFont* fs )
 {
   QFontMetrics fm((QFont)(*fs));
-  return fm.ascent() + fm.descent() +1;
+  return fm.ascent() + fm.descent() + 1;
 }
 
 jint
@@ -182,7 +147,7 @@
 jboolean
 Java_java_awt_Toolkit_fntIsWideFont ( JNIEnv* env, jclass clazz, QFont* fs )
 {
-  DBG(AWT, qqDebug("fntIsWideFont\n"));
+  DBG(AWT_FNT, qqDebug("fntIsWideFont\n"));
   return 0;
   // XXX: like: (fs->min_byte1 | fs->max_byte1);
 }
@@ -205,7 +170,7 @@
   for( i=0;i<n;i++)
   jw[i] = fm.width(QChar((char)i));
   env->ReleaseIntArrayElements( widths, jw, 0);
-  DBG(AWT, qqDebug("fntGetWidths %d\n",fm.maxWidth()));
+  DBG(AWT_FNT, qqDebug("fntGetWidths %d\n",fm.maxWidth()));
   return widths;
 }
 
@@ -219,12 +184,13 @@
   int       n = env->GetArrayLength( jBytes);
   int       w;
   QFontMetrics fm((QFont)(*fs));
-  if ( off+len > n ) len = n - off;
+  if ( off  + len > n ) 
+    len = n - off;
   QByteArray a;
-  a.setRawData(jb+off,len);
+  a.setRawData(jb + off, len);
   w = fm.width(QString(a),len);
   env->ReleaseByteArrayElements( jBytes, jb, JNI_ABORT);
-  DBG(AWT, qqDebug("fntBytesWidth %s %d\n",jb+off, w));
+  DBG(AWT_FNT, qqDebug("fntBytesWidth %s %d\n",jb + off, w));
   return w;
 }
 
@@ -235,7 +201,7 @@
   jChar = (jChar << 8) | (jChar >> 8);
 #endif
   QFontMetrics fm((QFont)(*fs));
-  DBG(AWT, qqDebug("fntCharWidth...\n"));
+  DBG(AWT_FNT, qqDebug("fntCharWidth...\n"));
 
   return fm.width(QChar((ushort)jChar));
 }
@@ -247,60 +213,47 @@
   jboolean  isCopy;
   jchar    *jc = env->GetCharArrayElements( jChars, &isCopy);
   int      n = env->GetArrayLength( jChars);
-  ushort *b;
-  QChar  *unicode;
   int      w;
-  QFontMetrics fm((QFont)(*fs));
-  DBG(AWT, qqDebug("fntCharsWidth...\n"));
+  QFontMetrics *fm = new QFontMetrics((QFont) (*fs));
+  DBG(AWT_FNT, qDebug("fntCharsWidth...\n"));
 
-  if ( off+len > n ) len = n - off;
+  if ( off+len > n ) 
+    len = n - off;
 
-#ifndef WORDS_BIGENDIAN
-  n = sizeof(ushort)*len;
-  b = (ushort*) getBuffer( X,n);
-  swab( (jc+off), b, n);
-#else
-  b = (ushort *) (jc + off);
-#endif
-  int i;
-  unicode = new QChar[len];
-  for(i=0;i<len;i++)
-    unicode[i] = QChar((ushort)*(b+i));
+/* XXX: Unicode
+  ushort *b = (ushort *) (jc + off);
+  QChar *unicode = new QChar[len];
+  for (int i = 0; i < len; i++)
+    unicode[i] = QChar((ushort) *(b + i));
+ */
 
-  w = fm.width(QString(jchar2CString(X,jc+off,len)));
+  w = fm->width(QString((new QByteArray())->assign((char*) jc + off, len)));
   env->ReleaseCharArrayElements( jChars, jc, JNI_ABORT);
-  DBG(AWT, qqDebug("fntCharsWidth %s %d\n",jchar2CString(X,jc+off,len),w));
+  delete fm;
   return w;
 }
 
+// XXX: implement
 jint
 Java_java_awt_Toolkit_fntStringWidth ( JNIEnv* env, jclass clazz, QFont* fs, jstring jStr )
 {
   jboolean isCopy;
-  const jchar    *jc = env->GetStringChars( jStr, &isCopy);
-  int      len = env->GetStringLength( jStr);
-  int      w, n;
-  ushort *b;
-  QChar  *unicode;
-  QFontMetrics fm((QFont)(*fs));
-
-
-#ifndef WORDS_BIGENDIAN
-  n = sizeof(ushort)*len;
-  b = (ushort*) getBuffer( X, n);
-  swab( jc, b, n);
-#else
-  b= (ushort*) jc;
-#endif
-  int i;
-  unicode = new QChar[len];
-  for(i=0;i<len;i++)
-    unicode[i] = QChar((ushort)*(b+i));
-
-  w = fm.width(QString(jchar2CString(X,jc,len)));
+  const jchar *jc = env->GetStringChars(jStr, &isCopy);
+  int len = env->GetStringLength(jStr);
+  if (len <= 0)
+    return 0;
+
+  int w;
+/* XXX: Unicode
+  ushort *b = (ushort*) jc;
+  QChar  *unicode = new QChar[len];
+ */
+  QFontMetrics *fm = new QFontMetrics((QFont) (*fs));
+  w = fm->boundingRect(QString(jchar2CString(X,jc,len))).width();
 
-  DBG(AWT, qqDebug("fntStringWidth %s %d\n",jchar2CString(X,jc,len),w));
+  DBG(AWT_FNT, qDebug("fntStringWidth %s %d\n",jchar2CString(X,jc,len),w));
   env->ReleaseStringChars( jStr, jc);
+  delete fm;
   return w;
 }
 
Index: kaffe/libraries/clib/awt/qt/gra.cc
diff -u kaffe/libraries/clib/awt/qt/gra.cc:1.4 kaffe/libraries/clib/awt/qt/gra.cc:1.5
--- kaffe/libraries/clib/awt/qt/gra.cc:1.4	Mon Jul 12 10:20:53 2004
+++ kaffe/libraries/clib/awt/qt/gra.cc	Wed Jul 14 07:08:10 2004
@@ -33,7 +33,7 @@
 {
   QPaintDevice*       drw;
 
-  DBG(AWT, qqDebug("initGraphics: gr %p (tgt %p, type=%d) xo %d,yo %d  %d,%d - %d,%d  %p %x %x\n",
+  DBG(AWT_GRA, qqDebug("initGraphics: gr %p (tgt %p, type=%d) xo %d,yo %d  %d,%d - %d,%d  %p %x %x\n",
     gr, tgt,tgtType, xOff,yOff, xClip,yClip,wClip,hClip, fnt,fg,bg));
 
   if ( tgt ) {
@@ -43,11 +43,11 @@
         break;          /* Window   */
       case 1:
         drw = (QPixmap*)(((Image*)tgt)->qpm);
-        DBG(AWT, qqDebug("tgt = IMAGE drw=%p\n",drw));
+        DBG(AWT_GRA, qqDebug("tgt = IMAGE drw=%p\n",drw));
         break;     /* Image    */
       case 2:
         drw = ((Graphics*)tgt)->drw;
-        DBG(AWT, qqDebug("tgt = GRAPHICS\n"));
+        DBG(AWT_GRA, qqDebug("tgt = GRAPHICS\n"));
         break;  /* Graphics */
       default:
         qFatal("illegal Graphics target: %d\n", tgtType);
@@ -69,7 +69,7 @@
   }
 
   gr->painter = new QPainter(drw);
-  DBG(AWT, qqDebug("painter=%x\n", gr->painter));
+  DBG(AWT_GRA, qqDebug("painter=%x\n", gr->painter));
 
   gr->painter->setPen(QCOLOR(fg));
   gr->painter->setBrush(QCOLOR(fg));
@@ -102,7 +102,7 @@
 void Java_java_awt_Toolkit_graFreeGraphics(JNIEnv* env, jclass clazz,
   Graphics* gr)
 {
-  DBG(AWT, qqDebug("freeGraphics: %p\n", gr));
+  DBG(AWT_GRA, qqDebug("freeGraphics: %p\n", gr));
 
   if(gr->painter)
     delete gr->painter;
@@ -114,7 +114,7 @@
   Graphics* gr, jint x, jint y, jint width, jint height,
   jint xDelta, jint yDelta )
 {
-  DBG(AWT, qqDebug("copyArea: %p, %d,%d-%d,%d  %d,%d\n", gr, x,y,width,height, xDelta,yDelta));
+  DBG(AWT_GRA, qqDebug("copyArea: %p, %d,%d-%d,%d  %d,%d\n", gr, x,y,width,height, xDelta,yDelta));
 
   /* some X servers act alleric on that (careless bitblt, again) */
   if ( (width < 0) || (height < 0) )
@@ -127,7 +127,7 @@
 void Java_java_awt_Toolkit_graClearRect(JNIEnv* env, jclass clazz,
   Graphics* gr, jint x, jint y, jint width, jint height)
 {
-  DBG(AWT, qqDebug("clearRect: %p, %d,%d-%d,%d\n", gr, x,y,width,height));
+  DBG(AWT_GRA, qqDebug("clearRect: %p, %d,%d-%d,%d\n", gr, x,y,width,height));
 
   QPainter *painter = (QPainter*)gr->painter;
   painter->fillRect(x + gr->x0, y + gr->y0, width, height, QCOLOR(gr->bg));
@@ -149,7 +149,7 @@
   jb = env->GetByteArrayElements( jBytes, &isCopy);
   jbo = jb + offset;
 
-  DBG(AWT, qqDebug("drawBytes: %p, %p,%d,%d  \"%s\"  %d,%d\n", gr,
+  DBG(AWT_GRA, qqDebug("drawBytes: %p, %p,%d,%d  \"%s\"  %d,%d\n", gr,
 				 jBytes,offset,len, jb, x,y));
 
   if ( offset+len > n )
@@ -180,7 +180,7 @@
   jc = env->GetCharArrayElements( jChars, &isCopy);
   jco = jc + offset;
 
-  DBG(AWT, qqDebug("drawChars: %p, %p,%d,%d  \"%s\"  %d,%d\n", gr, jChars,offset,len,
+  DBG(AWT_GRA, qqDebug("drawChars: %p, %p,%d,%d  \"%s\"  %d,%d\n", gr, jChars,offset,len,
 				 jchar2CString(X,jco,len), x,y));
 
   if ( offset+len > n )
@@ -212,7 +212,7 @@
   if ( !str ) return;
 
   cstr = java2CString(env, X, str);
-  DBG(AWT, qqDebug("drawString: %p  \"%s\"  %d,%d\n", gr, cstr, x,y));
+  DBG(AWT_GRA, qqDebug("drawString: %p  \"%s\"  %d,%d\n", gr, cstr, x,y));
   painter = (QPainter*)gr->painter;
 
   QString qstr(cstr);
@@ -495,7 +495,7 @@
 void Java_java_awt_Toolkit_graSetColor(JNIEnv* env, jclass clazz,
   Graphics* gr, jint clr)
 {
-  DBG(AWT, qqDebug("setColor: gr=%p, clr=%x, painter=%x\n", gr, clr,
+  DBG(AWT_GRA, qqDebug("setColor: gr=%p, clr=%x, painter=%x\n", gr, clr,
     gr->painter));
 
   gr->fg = clr;
Index: kaffe/libraries/clib/awt/qt/wnd.cc
diff -u kaffe/libraries/clib/awt/qt/wnd.cc:1.5 kaffe/libraries/clib/awt/qt/wnd.cc:1.6
--- kaffe/libraries/clib/awt/qt/wnd.cc:1.5	Mon Jul 12 10:20:53 2004
+++ kaffe/libraries/clib/awt/qt/wnd.cc	Wed Jul 14 07:08:10 2004
@@ -121,7 +121,7 @@
 void Java_java_awt_Toolkit_wndSetTitle(JNIEnv* env, jclass clazz,
   void* wnd, jstring jTitle )
 {
-  DBG(AWT, qqDebug("wndSetTitle\n"));
+  DBG(AWT_WND, qqDebug("wndSetTitle\n"));
   if ( jTitle ) {
     char *buf = java2CString( env, X, jTitle);
     ((QWidget*)wnd)->setCaption(QString(buf));
@@ -132,11 +132,11 @@
 void Java_java_awt_Toolkit_wndSetResizable(JNIEnv* env, jclass clazz,
   void* wnd, jboolean isResizable, int x, int y, int width, int height)
 {
-  DBG(AWT, qqDebug("wndSetResizable\n"));
+  DBG(AWT_WND, qqDebug("wndSetResizable\n"));
   int min_width, max_width;
   int min_height, max_height;
 
-  DBG(AWT, qqDebug("setResizable: %p, %d, %d,%d,%d,%d\n",
+  DBG(AWT_WND, qqDebug("setResizable: %p, %d, %d,%d,%d,%d\n",
     wnd, isResizable, x, y, width, height));
 
   if ( !isResizable ) {
@@ -186,9 +186,9 @@
   jstring jTitle, jint x, jint y, jint width, jint height,
   jint jCursor, jint clrBack, jboolean isResizable)
 {
-  DBG(AWT, qqDebug("wndCreateFrame\n"));
+  DBG(AWT_WND, qqDebug("wndCreateFrame\n"));
   QFrame *mw = new QFrame();
-  DBG(AWT, qqDebug("createFrame( %p, %d,%d,%d,%d,..) -> %p\n", 
+  DBG(AWT_WND, qqDebug("createFrame( %p, %d,%d,%d,%d,..) -> %p\n", 
     jTitle, x, y, width, height, mw));
 
   if ( width <= 0 )  width = 1;
@@ -206,7 +206,7 @@
   Java_java_awt_Toolkit_wndSetTitle(env, clazz, (void*)mw, jTitle);
 
   int idx = registerSource( X, (QWidget*)mw, 0, WND_FRAME);
-  DBG(AWT, qqDebug("registerSource: mw=%p idx=%d\n",mw,idx));
+  DBG(AWT_WND, qqDebug("registerSource: mw=%p idx=%d\n",mw,idx));
   return (void*)mw;
 }
 
@@ -215,7 +215,7 @@
   void* owner, jint x, jint y, jint width, jint height,
   jint jCursor, jint clrBack )
 {
-  DBG(AWT, qqDebug("wndCreateWindow\n"));
+  DBG(AWT_WND, qqDebug("wndCreateWindow\n"));
 
   QFrame* mw = new QFrame((QWidget*)owner);
   mw->setFrameStyle(QFrame::Panel|QFrame::Raised);
@@ -224,7 +224,7 @@
   y = p.y();
   // Owner
 
-  DBG(AWT, qqDebug("createWindow( %p, %d,%d,%d,%d,..) -> %p\n", 
+  DBG(AWT_WND, qqDebug("createWindow( %p, %d,%d,%d,%d,..) -> %p\n", 
           owner,x,y,width,height, mw));
 
   if ( width <= 0 )  width = 1;
@@ -237,7 +237,7 @@
   mw->setBackgroundColor(QCOLOR(clrBack));
 
   int idx = registerSource( X, (QWidget*)mw, (QWidget*)owner, WND_WINDOW);
-  DBG(AWT, qqDebug("registerSource: mw=%p idx=%d\n",mw,idx));
+  DBG(AWT_WND, qqDebug("registerSource: mw=%p idx=%d\n",mw,idx));
   return (void*)mw;
 }
 
@@ -251,7 +251,7 @@
     (Window)owner, jTitle, x, y, width, height,
     jCursor, clrBack, isResizable); */
 
-  DBG(AWT, qqDebug("wndCreateDialog\n"));
+  DBG(AWT_WND, qqDebug("wndCreateDialog\n"));
   QFrame* mw = new QFrame();
   mw->setFrameStyle(QFrame::Panel|QFrame::Raised);
   QPoint p = mw->mapToParent(mw->mapFromGlobal(QPoint(x,y)));
@@ -260,7 +260,7 @@
 
   // Owner
 
-  DBG(AWT, qqDebug("createDialog( %p,%p, %d,%d,%d,%d,..) -> %p\n", 
+  DBG(AWT_WND, qqDebug("createDialog( %p,%p, %d,%d,%d,%d,..) -> %p\n", 
     owner, jTitle, x, y, width, height, mw));
 
   if ( width <= 0 )  width = 1;
@@ -278,7 +278,7 @@
   Java_java_awt_Toolkit_wndSetTitle(env, clazz, (void*)mw, jTitle);
 
   int idx = registerSource( X, (QWidget*)mw, (QWidget*)owner, WND_DIALOG);
-  DBG(AWT, qqDebug("registerSource: mw=%p idx=%d\n",mw,idx));
+  DBG(AWT_WND, qqDebug("registerSource: mw=%p idx=%d\n",mw,idx));
   return (void*)mw;
 }
 
@@ -288,7 +288,7 @@
 {
   int i = getSourceIdx( X, wnd);
 
-  DBG(AWT, qqDebug("destroy window: %p (%d)\n", wnd, i));
+  DBG(AWT_WND, qqDebug("destroy window: %p (%d)\n", wnd, i));
 
   if ( (i >= 0) && !(X->windows[i].flags & WND_DESTROYED) ) {
     if ( wnd == X->focusFwd ) {
@@ -322,7 +322,7 @@
 {
   int i = getSourceIdx( X, wnd);
 
-  DBG(AWT, qqDebug("request focus: %lx (%d)\n", wnd, i));
+  DBG(AWT_WND, qqDebug("request focus: %lx (%d)\n", wnd, i));
 
   if ( (i < 0) || (X->windows[i].flags & WND_DESTROYED) )
     return;
@@ -373,7 +373,7 @@
 void Java_java_awt_Toolkit_wndSetBounds(JNIEnv* env, jclass clazz, void* wnd,
   jint x, jint y, jint width, jint height, jboolean isResizable)
 {
-  DBG(AWT, qqDebug("setBounds: %p %d,%d,%d,%d\n", wnd, x, y,
+  DBG(AWT_WND, qqDebug("setBounds: %p %d,%d,%d,%d\n", wnd, x, y,
     width, height));
 
   if(width < 0) width = 1;
@@ -397,7 +397,7 @@
 void Java_java_awt_Toolkit_wndRepaint(JNIEnv* env, jclass clazz, void* wnd,
   jint x, jint y, jint width, jint height )
 {
-  DBG(AWT, qqDebug("wndRepaint: %lx %d,%d,%d,%d\n", wnd, x, y, width, height));
+  DBG(AWT_WND, qqDebug("wndRepaint: %lx %d,%d,%d,%d\n", wnd, x, y, width, height));
 
   ((QWidget*)wnd)->repaint(x, y, width, height);  // or use update?
 }
@@ -414,7 +414,7 @@
   int     i = getSourceIdx( X, wnd);
   void*  owner;
 
-  DBG(AWT, qqDebug("setVisible: %lx (%d) %d\n", wnd, i, showIt));
+  DBG(AWT_WND, qqDebug("setVisible: %lx (%d) %d\n", wnd, i, showIt));
 
   if ( (i < 0) || (X->windows[i].flags & WND_DESTROYED) )
     return;
@@ -448,14 +448,14 @@
 
 void Java_java_awt_Toolkit_wndToBack(JNIEnv* env, jclass clazz, void* wnd)
 {
-  DBG(AWT, qqDebug("toBack: %p\n", wnd));
+  DBG(AWT_WND, qqDebug("toBack: %p\n", wnd));
   ((QWidget*)wnd)->lower();
 }
 
 
 void Java_java_awt_Toolkit_wndToFront(JNIEnv* env, jclass clazz, void* wnd)
 {
-  DBG(AWT, qqDebug("toFront: %p\n", wnd));
+  DBG(AWT_WND, qqDebug("toFront: %p\n", wnd));
   ((QWidget*)wnd)->raise();
 }
 
@@ -463,6 +463,6 @@
 void Java_java_awt_Toolkit_wndSetCursor(JNIEnv* env, jclass clazz,
   void* wnd, jint jCursor)
 {
-  DBG(AWT, qqDebug("setCursor: %lx, %d\n", (QWidget *)wnd, jCursor));
+  DBG(AWT_WND, qqDebug("setCursor: %lx, %d\n", (QWidget *)wnd, jCursor));
   ((QWidget*)wnd)->setCursor(QCursor( getCursor(jCursor)));
 }




More information about the kaffe mailing list