示例#1
0
static void
display_text_draw(struct font_freetype_text *text,
		  struct graphics_priv *gr, struct graphics_gc_priv *fg,
		  struct graphics_gc_priv *bg, int color, struct point *p)
{
    int i, x, y, stride;
    struct font_freetype_glyph *g, **gp;
    struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 };
    struct color black = { fg->fore_r * 255, fg->fore_g * 255,
	fg->fore_b * 255, fg->fore_a * 255 };
    struct color white = { 0xffff, 0xffff, 0xffff, 0xffff };

    if (bg) {
	if (COLOR_IS_WHITE(black) && COLOR_IS_BLACK(white)) {
	    black.r = 65535;
	    black.g = 65535;
	    black.b = 65535;
	    black.a = 65535;

	    white.r = 0;
	    white.g = 0;
	    white.b = 0;
	    white.a = 65535;
	} else if (COLOR_IS_BLACK(black) && COLOR_IS_WHITE(white)) {
	    white.r = 65535;
	    white.g = 65535;
	    white.b = 65535;
	    white.a = 65535;

	    black.r = 0;
	    black.g = 0;
	    black.b = 0;
	    black.a = 65535;
	} else {
	    white.r = bg->fore_r * 255;
	    white.g = bg->fore_g * 255;
	    white.b = bg->fore_b * 255;
	    white.a = bg->fore_a * 255;
	}
    } else {
	white.r = 0;
	white.g = 0;
	white.b = 0;
	white.a = 0;
    }


    gp = text->glyph;
    i = text->glyph_count;
    x = p->x << 6;
    y = p->y << 6;
    while (i-- > 0) {
	g = *gp++;
	if (g->w && g->h && bg) {
	    stride = (g->w + 2) * 4;
	    if (color) {
		resize_ft_buffer(stride * (g->h + 2));
		gr->freetype_methods.get_shadow(g, ft_buffer, 32, stride, &white, &transparent);

		SDL_Surface *glyph_surface =
		    SDL_CreateRGBSurfaceFrom(ft_buffer, g->w + 2, g->h + 2,
			    32,
			    stride,
			    0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
		if (glyph_surface) {
		    SDL_Rect r;
		    r.x = (x + g->x) >> 6;
		    r.y = (y + g->y) >> 6;
		    r.w = g->w + 2;
		    r.h = g->h + 2;

		    SDL_BlitSurface(glyph_surface, NULL, gr->screen, &r);
		    SDL_FreeSurface(glyph_surface);
		}
	    }
	}
	x += g->dx;
	y += g->dy;
    }
static void
display_text_draw(struct font_freetype_text *text,
		  struct graphics_priv *gr, struct graphics_gc_priv *fg,
		  struct graphics_gc_priv *bg, int color, struct point *p)
{
	int i, x, y, stride;
	struct font_freetype_glyph *g, **gp;
	unsigned char *shadow, *glyph;
	struct color transparent = { 0x0000, 0x0000, 0x0000, 0x0000 };
	struct color black =
	    { fg->fr * 65535, fg->fg * 65535, fg->fb * 65535,
   fg->fa * 65535 };
	struct color white = { 0xffff, 0xffff, 0xffff, 0xffff };

	if (bg) {
		if (COLOR_IS_WHITE(black) && COLOR_IS_BLACK(white)) {
			black.r = 65535;
			black.g = 65535;
			black.b = 65535;
			black.a = 65535;

			white.r = 0;
			white.g = 0;
			white.b = 0;
			white.a = 65535;
		} else if (COLOR_IS_BLACK(black) && COLOR_IS_WHITE(white)) {
			white.r = 65535;
			white.g = 65535;
			white.b = 65535;
			white.a = 65535;

			black.r = 0;
			black.g = 0;
			black.b = 0;
			black.a = 65535;
		} else {
			white.r = bg->fr;
			white.g = bg->fg;
			white.b = bg->fb;
			white.a = bg->fa;
		}
	} else {
		white.r = 0;
		white.g = 0;
		white.b = 0;
		white.a = 0;
	}

	gp = text->glyph;
	i = text->glyph_count;
	x = p->x << 6;
	y = p->y << 6;
	while (i-- > 0) {
		g = *gp++;
		if (g->w && g->h && bg) {
			stride = (g->w + 2) * 4;
			if (color) {
				shadow = g_malloc(stride * (g->h + 2));
				gr->freetype_methods.get_shadow(g, shadow,
								32, stride,
								&white,
								&transparent);
#if USE_OPENGLES
				struct point p;
				p.x=((x + g->x) >> 6)-1;
				p.y=((y + g->y) >> 6)-1;
				draw_image_es(gr, &p, g->w+2, g->h+2, shadow);
#else
#ifdef MIRRORED_VIEW
				glPixelZoom(-1.0, -1.0);	//mirrored mode
#else
				glPixelZoom(1.0, -1.0);
#endif
				glRasterPos2d((x + g->x) >> 6,
					      (y + g->y) >> 6);
				glDrawPixels(g->w + 2, g->h + 2, PIXEL_FORMAT,
					     GL_UNSIGNED_BYTE, shadow);
#endif
				g_free(shadow);
			}
		}
		x += g->dx;
		y += g->dy;
	}