Exemple #1
0
void
gui_draw_wtext_length(struct gui_instance *gi, struct gui_font *font,
                      int x, int y, const wchar_t *text, size_t length,
                      unsigned int color)
{
  XftColor xft_color;

  xft_color.pixel = color | 0xff000000;
  xft_color.color.red = (color >> 16) * 0x0101;
  xft_color.color.green = ((color >> 8) & 0xff) * 0x0101;
  xft_color.color.blue = (color & 0xff) * 0x0101;
  xft_color.color.alpha = 0xffff;

  if (sizeof (wchar_t) == 4)
    {
      XftDrawString32 (gi->fontdraw, &xft_color, font->xft_font,
                       x, y + font->xft_font->ascent,
                       (const unsigned int *) text, length);
    }
  else if (sizeof (wchar_t) == 2)
    {
      XftDrawString16 (gi->fontdraw, &xft_color, font->xft_font,
                       x, y + font->xft_font->ascent,
                       (const unsigned short *) text, length);
    }
  else
    assert (!"Unexpected size of wchar_t");

}
Exemple #2
0
void
WMDrawImageString(WMScreen *scr, Drawable d, WMColor *color, WMColor *background,
                  WMFont *font, int x, int y, char *text, int length)
{
    XftColor textColor;
    XftColor bgColor;

    wassertr(font!=NULL);

    textColor.color.red = color->color.red;
    textColor.color.green = color->color.green;
    textColor.color.blue = color->color.blue;
    textColor.color.alpha = color->alpha;;
    textColor.pixel = W_PIXEL(color);

    bgColor.color.red = background->color.red;
    bgColor.color.green = background->color.green;
    bgColor.color.blue = background->color.blue;
    bgColor.color.alpha = background->alpha;;
    bgColor.pixel = W_PIXEL(background);

    XftDrawChange(scr->xftdraw, d);

    XftDrawRect(scr->xftdraw, &bgColor, x, y,
                WMWidthOfString(font, text, length),
                font->height);

    if (font->screen->useWideChar) {
        wchar_t *wtext;
        const char *mtext;
        int len;

        mtext = text;
        wtext = (wchar_t *)wmalloc(sizeof(wchar_t)*(length+1));
        len = wmbsnrtowcs(wtext, &mtext, length, length);
        if (len>0) {
            XftDrawString32(scr->xftdraw, &textColor, font->font,
                            x, y + font->y, (XftChar32*)wtext, len);
        } else if (len==-1) {
            wwarning(_("Conversion to widechar failed (possible invalid "
                       "multibyte sequence): '%s':(pos %d)\n"),
                     text, mtext-text+1);
            /* we can draw normal text, or we can draw as much widechar
             * text as was already converted until the error. go figure */
            /*XftDrawString8(scr->xftdraw, &textColor, font->font,
             x, y + font->y, (XftChar8*)text, length);*/
        }
        wfree(wtext);
    } else if (font->screen->useMultiByte) {
        XftDrawStringUtf8(scr->xftdraw, &textColor, font->font,
                          x, y + font->y, (XftChar8*)text, length);
    } else {
        XftDrawString8(scr->xftdraw, &textColor, font->font,
                       x, y + font->y, (XftChar8*)text, length);
    }
}
Exemple #3
0
static void
drawtext(GRect *clip, Rune *str, int len, int x, int y, GColor c)
{
	XftColor col;

	x += clip->x;
	y += clip->y;

	// set clip!
	xftcolor(&col, c);
	XftDrawString32(xft, &col, font, x, y, (FcChar32 *)str, len);
}