From: Axel Wagner Date: Thu, 16 Sep 2010 23:52:04 +0000 (+0200) Subject: Write a wrapper around xcb_image_text_16() X-Git-Tag: 4.0.1~7^2~66 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0dc802c7b5a41f4e6205e2632eca8bee86276b2a;p=i3%2Fi3 Write a wrapper around xcb_image_text_16() xcb_image_text_16() can only process up to 255 glyphs, so we write a wrapper around it for arbitrary long strings --- diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 43ac8beb..e1495e66 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -103,6 +103,31 @@ uint32_t predict_text_extents(xcb_char2b_t *text, uint32_t length) { return width; } +/* + * Draws text given in UCS-2-encoding to a given drawable and position + * + */ +void draw_text(xcb_drawable_t drawable, xcb_gcontext_t ctx, int16_t x, int16_t y, + xcb_char2b_t *text, uint32_t glyph_count) { + int offset = 0; + int16_t pos_x = x; + while (glyph_count > 0) { + uint8_t chunk_size = MIN(255, glyph_count); + uint32_t chunk_width = predict_text_extents(text + offset, chunk_size); + + xcb_image_text_16(xcb_connection, + chunk_size, + drawable, + ctx, + pos_x, y, + text + offset); + + offset += chunk_size; + pos_x += chunk_width; + glyph_count -= chunk_size; + } +} + /* * Converts a colorstring to a colorpixel as expected from xcb_change_gc. * s is assumed to be in the format "rrggbb"