XftDrawRect(s->sidebar.d, &s->sidebar.select2_bg, 0, i.index*height, s->core.width, height);
}
- XftDrawString8(s->sidebar.d, cg, s->sidebar.font->fonts->font, 10, i.index*height + xftFont->ascent, (const FcChar8*)name, strlen(name));
+ FontDrawString8(s->sidebar.d, cg, s->sidebar.font, 10, i.index*height + xftFont->ascent, (const FcChar8*)name, strlen(name));
}
}
if(--font->ref == 0) {
FontDestroy(font);
}
-}
\ No newline at end of file
+}
+
+void FontDrawString8(
+ XftDraw *draw,
+ const XftColor *color,
+ NFont *font,
+ int x,
+ int y,
+ const FcChar8 *string,
+ int len)
+{
+ FcChar32 static_buffer[128];
+ FcChar32 *buf = static_buffer;
+ if(len >= 128) {
+ buf = calloc(len, sizeof(FcChar32));
+ }
+
+ // convert string from utf8 to utf32
+ int c = 0;
+ for(int i=0;i<len;) {
+ int n = FcUtf8ToUcs4(string+i, &buf[c++], len-i);
+ i += n;
+ }
+
+ FontDrawString32(draw, color, font, x, y, buf, c);
+
+ if(buf != static_buffer) {
+ free(buf);
+ }
+}
+
+void FontDrawString32(
+ XftDraw *draw,
+ const XftColor *color,
+ NFont *font,
+ int x,
+ int y,
+ const FcChar32 *string,
+ int len)
+{
+ XftFont *currentFont = FontDefault(font);
+ int pos = 0;
+ for(int i=0;i<len;i++) {
+ XftFont *cFont = FindFont(font, string[i]);
+ if(cFont != currentFont && i > pos) {
+ const FcChar32 *segStr = string+pos;
+ int segLen = i-pos;
+
+ // get extents of string segment
+ XGlyphInfo extents;
+ XftTextExtents32(XftDrawDisplay(draw), currentFont, segStr, segLen, &extents);
+
+ // draw previous characters
+ XftDrawString32(draw, color, currentFont, x, y, segStr, segLen);
+
+ x += extents.xOff;
+ pos = i;
+ }
+ currentFont = cFont;
+ }
+
+ if(pos < len) {
+ const FcChar32 *segStr = string+pos;
+ int segLen = len-pos;
+ // draw previous characters
+ XftDrawString32(draw, color, currentFont, x, y, segStr, segLen);
+ }
+
+}