[Vm-dev] [commit][3731] Apply the changes of Mr Hachisuka for multibyte character composition.

commits at squeakvm.org commits at squeakvm.org
Wed May 25 23:56:03 UTC 2016


Revision: 3731
Author:   lewis
Date:     2016-05-25 16:56:00 -0700 (Wed, 25 May 2016)
Log Message:
-----------
Apply the changes of Mr Hachisuka for multibyte character composition.
The diff is in the earlier email from Yoshiki:
      http://lists.squeakfoundation.org/pipermail/squeak-dev/2016-May/189599.html
      http://www2.asu.ac.jp/hachi/v3/scratch14ime.html

Changes are licenced MIT: http://lists.squeakfoundation.org/pipermail/squeak-dev/2016-May/189646.html

Adapt the patch to use the -compositioninput option of the X11 display module. Also fix invocation of that option, which was missing the necessary declaration in sqUnixMain.c (hence did not work).

With this change, if the -compositioninput options is on the command line, or if the equivalent SQUEAK_COMPOSITIONINPUT environment variable is set, then the recordPendingKeys() function in the X11 desplay module will use the enhancement of Mr. Hachisuka. Otherwise the original recordPendingKeys() logic is used.

Modified Paths:
--------------
    branches/Cog/platforms/unix/vm-display-X11/sqUnixX11.c

Modified: branches/Cog/platforms/unix/vm-display-X11/sqUnixX11.c
===================================================================
--- branches/Cog/platforms/unix/vm-display-X11/sqUnixX11.c	2016-05-25 00:32:44 UTC (rev 3730)
+++ branches/Cog/platforms/unix/vm-display-X11/sqUnixX11.c	2016-05-25 23:56:00 UTC (rev 3731)
@@ -1713,29 +1713,100 @@
 
 static int recordPendingKeys(void)
 {
-  if (inputCount > 0)
+  if (compositionInput)
     {
-      int i= iebOut - iebIn;
-      for (i= (i > 0 ? i : IEB_SIZE + i) / 4; i > 0; -- i)
+      if (inputCount <= 0) {
+	if (inputBuf != inputString) {
+	  free(inputBuf);
+	  inputBuf= inputString;
+	}
+	return 0;
+      }
+    
+      int utf32= 0;
+      while (inputCount > 0) {
+# if defined(DEBUG_XIM)
+	fprintf(stderr, "%3d pending key 0x%02x\n", inputCount, *pendingKey);
+# endif
+	/* 110x xxxx 10xx xxxx */
+	if (inputCount >= 2 &&
+    	    pendingKey[0] >= 0xc0 && pendingKey[0] <= 0xdf && 
+    	    pendingKey[1] >= 0x80 && pendingKey[1] <= 0xbf)
+	  {
+	    utf32= ((pendingKey[0] & 0x1f) << 6) |
+		    (pendingKey[1] & 0x3f);
+	    recordKeyboardEvent(0, EventKeyDown, modifierState, utf32);
+	    recordKeyboardEvent(0, EventKeyChar, modifierState, utf32);
+	    pendingKey += 2;
+	    inputCount -= 2;
+	  }
+	/* 1110 xxxx 10xx xxxx 10xx xxxx */
+	else if (inputCount >= 3 &&
+		 pendingKey[0] >= 0xe0 && pendingKey[0] <= 0xef && 
+		 pendingKey[1] >= 0x80 && pendingKey[1] <= 0xbf && 
+		 pendingKey[2] >= 0x80 && pendingKey[2] <= 0xbf)
+	  {
+	    utf32= ((pendingKey[0]  & 0x0f) << 12) | 
+		    ((pendingKey[1] & 0x3f) << 6) | 
+		    (pendingKey[2] & 0x3f);
+	    recordKeyboardEvent(0, EventKeyDown, modifierState, utf32);
+	    recordKeyboardEvent(0, EventKeyChar, modifierState, utf32);
+	    pendingKey += 3;
+	    inputCount -= 3;
+	  }
+	/* 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx */
+	else if (inputCount >= 4 &&
+		 pendingKey[0] >= 0xf0 && pendingKey[0] <= 0xf7 && 
+		 pendingKey[1] >= 0x80 && pendingKey[1] <= 0xbf && 
+		 pendingKey[2] >= 0x80 && pendingKey[2] <= 0xbf && 
+		 pendingKey[3] >= 0x80 && pendingKey[3] <= 0xbf)
+	  {
+	    utf32= ((pendingKey[0] & 0x07) << 18) | 
+		    ((pendingKey[1] & 0x3f) << 12) |
+		    ((pendingKey[2] & 0x3f) << 6) |
+		    (pendingKey[3] & 0x3f);
+	    recordKeyboardEvent(0, EventKeyDown, modifierState, utf32);
+	    recordKeyboardEvent(0, EventKeyChar, modifierState, utf32);
+	    pendingKey += 4;
+	    inputCount -= 4;
+	  }
+	else
+	  {
+	    recordKeyboardEvent(*pendingKey, EventKeyDown, modifierState, 0);
+	    recordKeyboardEvent(*pendingKey, EventKeyChar, modifierState, 0);
+	    recordKeystroke(*pendingKey); /* DEPRECATED */
+	    pendingKey++;
+	    inputCount--;
+	  }
+      }
+      return 0;
+    }
+  else
+    {
+      if (inputCount > 0)
 	{
+	  int i= iebOut - iebIn;
+	  for (i= (i > 0 ? i : IEB_SIZE + i) / 4; i > 0; -- i)
+	    {
 # if defined(DEBUG_XIM)
-	  fprintf(stderr, "%3d pending key %2d=0x%02x\n", inputCount, i, *pendingKey);
+	      fprintf(stderr, "%3d pending key %2d=0x%02x\n", inputCount, i, *pendingKey);
 # endif
-	  recordKeyboardEvent(*pendingKey, EventKeyDown, modifierState, 0);
-	  recordKeyboardEvent(*pendingKey, EventKeyChar, modifierState, 0);
-	  recordKeystroke(*pendingKey);  /* DEPRECATED */
-	  ++pendingKey;
-	  if (--inputCount == 0) break;
+	      recordKeyboardEvent(*pendingKey, EventKeyDown, modifierState, 0);
+	      recordKeyboardEvent(*pendingKey, EventKeyChar, modifierState, 0);
+	      recordKeystroke(*pendingKey);  /* DEPRECATED */
+	      ++pendingKey;
+	      if (--inputCount == 0) break;
+	    }
+	  return 1;
 	}
-      return 1;
+      /* inputBuf is allocated by lookupKeys */
+      if (inputBuf != inputString)
+	{
+	  free(inputBuf);
+	  inputBuf= inputString;
+	}
+      return 0;
     }
-  /* inputBuf is allocated by lookupKeys */
-  if (inputBuf != inputString)
-    {
-      free(inputBuf);
-      inputBuf= inputString;
-    }
-  return 0;
 }
 
 static int xkeysym2ucs4(KeySym keysym);



More information about the Vm-dev mailing list