Esempio n. 1
0
File: gui.c Progetto: mortehu/bra
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");

}
float XftTextRenderer::drawRange(const WebCoreTextRun *run, const WebCoreTextStyle *style, int from, int to, int x, int y, const XftColor* color, bool shouldMeasure)
{
    int width = 0;
    XGlyphInfo extents;
    if (style->letterSpacing) {
	while (from<to) {
	    XftTextExtents16(xdisplay, 
			     font->xftFont,
			     reinterpret_cast<const XftChar16*>(run->characters + from),     
			     1,
			     &extents);

	    XftDrawString16(xftdraw,
			    color,
			    font->xftFont,
			    x,
			    y,
			    reinterpret_cast<const XftChar16*>(run->characters + from),
			    1);
	    x += extents.xOff + style->letterSpacing;
	    ++from;
	    width += extents.xOff + style->letterSpacing;
	}
	return width;
    } else {
	if (shouldMeasure) {
	    XftTextExtents16(xdisplay, 
			     font->xftFont,
			     reinterpret_cast<const XftChar16*>(run->characters + from),
			     to - from,			     
			     &extents);
	    width += extents.xOff;
	}

	XftDrawString16(xftdraw,
			color,
			font->xftFont,
			x,
			y,
			reinterpret_cast<const XftChar16*>(run->characters + from),
			to - from);
    }

    return width;
}
Esempio n. 3
0
void ui_draw_piece(char piece, int pos)
{
	int x = 0;
	int y = 0;
	ui_board_pos_to_pixel(pos, &x, &y);

	/* top of square, text is aligned at bottom */
	y += UI_SIZE_SQUARE_HEIGHT;
	y += UI_POS_FONT_OFFSET_Y;

	XftChar16 piecechar;
	XftChar16 piececharbg;
	ui_piece_char(piece, &piecechar, &piececharbg);

	XftColor* color = NULL;
	XftColor* colorbg = NULL;
	ui_piece_color(piece, &color, &colorbg);

	XftDrawString16(ui_xftdraw, colorbg, ui_piecefont, x, y, &piececharbg, 1);
	XftDrawString16(ui_xftdraw, color, ui_piecefont, x, y, &piecechar, 1);
}
Esempio n. 4
0
static void ui_draw_full_move_str(int x, int y, int maxwidth, int movenum, const char* whitepgn, const char* blackpgn)
{
	int numwidth = 0;

	if (movenum > 0) {
		char numstr[8];
		snprintf(numstr, 8, "%d.", movenum);
		ui_draw_info_string_tag(numstr, x, y, maxwidth, NULL);

		int numcnt = strlen(numstr) > 7 ? strlen(numstr) : 7;
		numwidth =  numcnt * ui_infofontchwidth;
	}

	x += numwidth;
	maxwidth -= numwidth;

	int whitewidth = 0;
	if (NULL != whitepgn && '\0' != (*whitepgn)) {
		ui_draw_info_string(whitepgn, x, y, maxwidth, &whitewidth);
	} else {
		XftChar16 dotch = 0x2026; // unicode ... character

		/* get width of three dots */
		XGlyphInfo extents;
		XftTextExtents16(ui_display, ui_infofont, &dotch, 1, &extents);

		whitewidth = extents.width;

		XftDrawString16(ui_xftdraw, &ui_infocolor, ui_infofont, x, y, &dotch, 1);
	}

	whitewidth = whitewidth < (ui_infofontchwidth * 8) ? (ui_infofontchwidth * 8) : whitewidth;

	x += whitewidth + UI_SPACING_X_INFO;
	maxwidth -= whitewidth + UI_SPACING_X_INFO;

	if (NULL != blackpgn && '\0' != (*blackpgn)) {
		ui_draw_info_string(blackpgn, x, y, maxwidth, NULL);
	}
}
Esempio n. 5
0
static void ui_draw_string( const char* str, XftFont* font, XftColor* color, int x, int y, int maxwidth, int* width)
{
	XftChar16 dotch = 0x2026; // unicode ... character

	/* get width of three dots */
	XGlyphInfo extents;
	XftTextExtents16(ui_display, font, &dotch, 1, &extents);

	int sizepoints = extents.width;

	size_t cutlen = 0;

	XftTextExtentsUtf8(ui_display, font, (XftChar8*) str, strlen(str), &extents);

	int totlen = extents.width;

	while (totlen > maxwidth && cutlen < strlen(str)) {
		++cutlen;

		XftTextExtentsUtf8(ui_display, font, (XftChar8*) str, strlen(str) - cutlen, &extents);
		totlen = extents.width + sizepoints;
	}

	if (NULL != width) {
		*width = 0;
	}

	if (totlen <= maxwidth) {
		XftDrawStringUtf8(ui_xftdraw, color, font, x, y, (XftChar8*) str, strlen(str) - cutlen);

		if (cutlen > 0) {
			XftDrawString16(ui_xftdraw, color, font, x + extents.width, y, &dotch, 1);
		}

		if (NULL != width) {
			*width = totlen;
		}
	}
}
Esempio n. 6
0
PlatformFont::CharInfo &x86UNIXFont::getCharInfo(const UTF16 ch) const
{
  Display *display = XOpenDisplay(getenv("DISPLAY"));
  if (!display )
    AssertFatal(false, "createFont: cannot connect to X server");

  static PlatformFont::CharInfo c;
  dMemset(&c, 0, sizeof(c));
  c.bitmapIndex = 0;
  c.xOffset     = 0;
  c.yOffset     = 0;

  XftFont *fontInfo  = XftFontOpenName(display, DefaultScreen(display), mFontName);
  if (!fontInfo)
    AssertFatal(false, "createFont: cannot load font");

  int screen = DefaultScreen(display);
  // Create the pixmap to draw on.
  Drawable pixmap = XCreatePixmap(display,
				  DefaultRootWindow(display),
				  fontInfo->max_advance_width,
				  fontInfo->height,
				  DefaultDepth(display, screen));
  // And the Xft wrapper around it.
  XftDraw *draw = XftDrawCreate(display,
                                pixmap,
                                DefaultVisual(display, screen),
                                DefaultColormap(display, screen));
  // Allocate some colors, we don't use XftColorAllocValue here as that
  // Don't appear to function correctly (or I'm using it wrong) As we only do
  // this twice per new un cached font it isn't that big of a penalty. (Each
  // call to XftColorAllocName involves a round trip to the X Server)
  XftColor black, white;
  XftColorAllocName(display,
                    DefaultVisual(display, screen),
                    DefaultColormap(display, screen),
                    "black",
                    &black);
  // White
  XftColorAllocName(display,
                    DefaultVisual(display, screen),
                    DefaultColormap(display, screen),
                    "white",
                    &white);
  
  XGlyphInfo charinfo;
  XftTextExtents16(display, fontInfo, &ch, 1, &charinfo);
  c.height     = fontInfo->height;
  c.xOrigin    = 0; 
  c.yOrigin    = fontInfo->ascent;
  c.xIncrement = charinfo.xOff;
  c.width      = charinfo.xOff;
  // kick out early if the character is undrawable
  if( c.width == 0 || c.height == 0)
    return c;

  // allocate a greyscale bitmap and clear it.
  int bitmapDataSize = c.width * c.height;
  c.bitmapData = new U8[bitmapDataSize];
  dMemset(c.bitmapData, 0, bitmapDataSize);

  XftDrawRect (draw, &black, 0, 0, fontInfo->max_advance_width, fontInfo->height);
  XftDrawString16 (draw, &white, fontInfo, 0, fontInfo->ascent, &ch, 1);
  // grab the pixmap image

  XImage *ximage = XGetImage(display, pixmap, 0, 0, 
			     charinfo.xOff, fontInfo->height, 
			     AllPlanes, XYPixmap);
  if (!ximage)
    AssertFatal(false, "cannot get x image");
  int x, y;

  // grab each pixel and store it in the scratchPad
  for(y = 0; y < fontInfo->height; y++)
  {
    for(x = 0; x < charinfo.xOff; x++)
      c.bitmapData[y * charinfo.xOff + x] = static_cast<U8>(XGetPixel(ximage, x, y));
  }
  XDestroyImage(ximage);

  XftColorFree(display, DefaultVisual(display, screen),
               DefaultColormap(display, screen), &black);
  XftColorFree(display, DefaultVisual(display, screen),
               DefaultColormap(display, screen), &white);
  XftDrawDestroy(draw);
  XFreePixmap(display, pixmap);
  XCloseDisplay(display);

  return c;
}