[Xcb] Proportional fonts and text extents
Peter Harris
pharris at opentext.com
Mon Apr 27 08:02:57 PDT 2009
Jake LeMaster wrote:
>
> I threw this together to compare extents results for whatever font you
> want to specify on a test string:
>
> http://ircage.org/spewns/shiz/extents.c
Just so you are aware, xcb_query_text_extents is the equivalent of
XQueryTextExtents.
There is currently no equivalent to XTextExtents in xcb. The equivalent
function would use the results of an xcb_query_font to do the
calculations without needing to communicate with the server. If you do
write this function, we would like to add it to xcb/util. Thanks!
> When using the 2 proportional fonts I have in there, I get results of...
>
> xcb extents returns a width of: [265]
> Xlib extents returns a width of: [249]
>
> xcb extents returns a width of: [371]
> Xlib extents returns a width of: [300]
>
> The difference can be significant, as you see. When I use the 2
> monospace fonts though, I get the results I'd expect...
>
> xcb extents returns a width of: [371]
> Xlib extents returns a width of: [371]
>
> xcb extents returns a width of: [318]
> Xlib extents returns a width of: [318]
>
> Thoughts?
There's a couple of bugs in your implementation of build_chars.
First, you compare individual character codepoints against the desired
length of the string. I'm sure that's a typo. Second, byte1 is the
high-byte, and byte2 is the low-byte.
So your function should probably read something more like:
xcb_char2b_t *build_chars(const char *str, size_t length)
{
int i;
xcb_char2b_t *ret = malloc(length * sizeof(xcb_char2b_t));
if (!ret)
return NULL;
for (i = 0; i < length; i++) {
ret[i].byte1 = 0;
ret[i].byte2 = str[i];
}
return ret;
}
Peter Harris
--
Open Text Connectivity Solutions Group
Peter Harris http://www.opentext.com/connectivity
Research and Development Phone: +1 905 762 6001
pharris at opentext.com Toll Free: 1 877 359 4866
More information about the Xcb
mailing list