[Xcb] Proportional fonts and text extents

Jake LeMaster ssoundasleep at gmail.com
Sat Apr 25 16:10:47 PDT 2009

Hi, I'm getting strange and unreliable results when querying text extents
for proportional fonts. (I have no issues with monospace fonts.)
The overall_width that's returned is often a few pixels larger than what it
should be. It seems like XCB is assuming all characters in a string are the
same pixel width, which will give wrong results if you use a proportional
font with "slim" characters like 'i', '1', '/', '(', etc.

However, this could very likely be an issue with how I'm setting up the
xcb_char2b_t that I send to xcb_query_text_extents().

xcb_char2b_t *build_chars(char *str, int length)
        xcb_char2b_t *ret = malloc(length * sizeof(xcb_char2b_t));
        int i;

        for (i = 0; i < length; i++) {
                if (str[i] < length) {
                        ret[i].byte1 = str[i];
                        ret[i].byte2 = '\0';

        return ret;

Parameter "str" is the string I want extents on, obviously, and "length"
woud be strlen(str). Is this how I should be going about it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/xcb/attachments/20090425/1bf86f93/attachment.html 

More information about the Xcb mailing list