On Tue, 3 Dec 2002, Jungshik Shin wrote:

>   Attached is my patch(a bit revised) to extend XftTextExtents16 to
> support UTF-16 and to fix a typo in fstr.c of fontconfig(which makes the
> conversion from UTF-16 to UCS-4 not work correctly for characters in

  Sorry I forogot to attach it. This time, it's really attached.

  Jungshik
Index: xc/lib/fontconfig/src/fcstr.c
===================================================================
RCS file: /cvs/xc/lib/fontconfig/src/fcstr.c,v
retrieving revision 1.10
diff -u -r1.10 fcstr.c
--- xc/lib/fontconfig/src/fcstr.c       2002/08/31 22:17:32     1.10
+++ xc/lib/fontconfig/src/fcstr.c       2002/12/04 03:10:13
@@ -282,8 +282,8 @@
         */
        if ((b & 0xfc00) != 0xdc00)
            return 0;
-       result = ((((FcChar32) a & 0x3ff) << 10) |
-                 ((FcChar32) b & 0x3ff)) | 0x10000;
+       result = (((((FcChar32) a & 0x3ff) << 10) |
+                 ((FcChar32) b & 0x3ff))) + 0x10000;
     }
     else
        result = a;
Index: xc/lib/Xft/xftextent.c
===================================================================
RCS file: /cvs/xc/lib/Xft/xftextent.c,v
retrieving revision 1.9
diff -u -r1.9 xftextent.c
--- xc/lib/Xft/xftextent.c      2002/10/11 17:53:02     1.9
+++ xc/lib/Xft/xftextent.c      2002/12/04 03:10:14
@@ -147,6 +147,11 @@
        free (glyphs);
 }
 
+#define IS_HIGH_SURROGATE(u) (((FcChar16) (u) & 0xfc00L) == 0xd800L)
+#define IS_LOW_SURROGATE(u)  (((FcChar16) (u) & 0xfc00L) == 0xdc00L)
+#define SURROGATE_TO_UCS4(h,l) (((((FT_UInt) (h) & 0x03ffL) << 10) | \
+                                ((FT_UInt) (l) & 0x03ffL)) + 0x10000L)
+
 void
 XftTextExtents16 (Display          *dpy,
                  XftFont           *pub,
@@ -156,6 +161,7 @@
 {
     FT_UInt        *glyphs, glyphs_local[NUM_LOCAL];
     int                    i;
+    int                    nglyphs = 0;
 
     if (len <= NUM_LOCAL)
        glyphs = glyphs_local;
@@ -169,8 +175,19 @@
        }
     }
     for (i = 0; i < len; i++)
-       glyphs[i] = XftCharIndex (dpy, pub, string[i]);
-    XftGlyphExtents (dpy, pub, glyphs, len, extents);
+    {
+       if (IS_HIGH_SURROGATE(string[i]) && i + 1 < len && 
+           IS_LOW_SURROGATE(string[i + 1]))
+       {
+           glyphs[nglyphs++] = XftCharIndex (dpy, pub, 
+                               SURROGATE_TO_UCS4(string[i], string[i + 1])); 
+           ++i;
+       }
+       else 
+           glyphs[nglyphs++] = XftCharIndex (dpy, pub, string[i]);
+    }
+
+    XftGlyphExtents (dpy, pub, glyphs, nglyphs, extents);
     if (glyphs != glyphs_local)
        free (glyphs);
 }

Reply via email to