- XChar2b *s16;
- int s16_len = 0;
- char *s2 = (char *) malloc (len + 1);
-
- if (!dpy || !font || !string || !extents || !s2) abort();
-
- strncpy (s2, (char *) string, len);
- s2[len] = 0;
- s16 = utf8_to_XChar2b (s2, &s16_len);
- free (s2);
- XTextExtents16 (font->xfont, s16, s16_len,
- &direction, &ascent, &descent, &overall);
- free (s16);
-
- extents->x = -overall.lbearing;
- extents->y = overall.ascent;
- extents->xOff = overall.width;
- extents->yOff = 0;
- extents->width = overall.rbearing - overall.lbearing;
- extents->height = overall.ascent + overall.descent;
+
+ if (!dpy || !font || !string || !extents) abort();
+
+# ifdef HAVE_XUTF8DRAWSTRING
+ {
+ XRectangle ink;
+ int advancement =
+ Xutf8TextExtents (font->fontset, (const char *) string, len, &ink, 0);
+ XmbRectangle_to_XCharStruct (ink, overall, advancement);
+ }
+# else /* !HAVE_XUTF8DRAWSTRING */
+ {
+ char *s2 = (char *) malloc (len + 1);
+ int direction, ascent, descent;
+ XChar2b *s16;
+ int s16_len = 0;
+ strncpy (s2, (char *) string, len);
+ s2[len] = 0;
+ s16 = utf8_to_XChar2b (s2, &s16_len);
+ XTextExtents16 (font->xfont, s16, s16_len,
+ &direction, &ascent, &descent, &overall);
+ free (s2);
+ free (s16);
+ }
+# endif /* !HAVE_XUTF8DRAWSTRING */
+
+ XCharStruct_to_XGlyphInfo (overall, *extents);