Re: [Fonts]Xft/fontconfig and Non-BMP characters

2002-12-03 Thread Jungshik Shin
On Sun, 1 Dec 2002, Jungshik Shin wrote:

 While trying to make Mozilla-Xft support non-BMP characters with fonts
 like CODE2001.TTF (with pid=3/eid=10 Cmap), I found that freetype
 and Xft need a little change. Details are sent to linux-utf8 list
 (http://mail.nl.linux.org/linux-utf8/2002-12/msg0.html) and Bugzilla

  Extending XftTextExtents16() to support UTF-16 is similar to

  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
even numbered planes with the 17th bit in UTF-32 unset.)

  Keith, would you take a look?

  I also sent it to [EMAIL PROTECTED] and got a patch seq. #5522.

  Jungshik

___
Fonts mailing list
[EMAIL PROTECTED]
http://XFree86.Org/mailman/listinfo/fonts



Re: [Fonts]Xft/fontconfig and Non-BMP characters

2002-12-03 Thread Jungshik Shin



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)) | 0x1;
+   result = (FcChar32) a  0x3ff)  10) |
+ ((FcChar32) b  0x3ff))) + 0x1;
 }
 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)) + 0x1L)
+
 void
 XftTextExtents16 (Display  *dpy,
  XftFont   *pub,
@@ -156,6 +161,7 @@
 {
 FT_UInt*glyphs, glyphs_local[NUM_LOCAL];
 inti;
+intnglyphs = 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);
 }