⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 devfont.c

📁 the embedded GUI for SamSung s3c2410 cpu based board.is microwindows0.90
💻 C
📖 第 1 页 / 共 3 页
字号:
	return pfont->fontprocs->GetFontInfo(pfont, pfontinfo);}/** * Draws text onto a drawing surface (e.g. the screen or a double-buffer). * Uses the current font, current foreground color, and possibly the * current background color.  Applies clipping if necessary. * The background color is only drawn if the gr_usebg flag is set. * * @param psd   The destination drawing surface.  Non-NULL. * @param x     The X co-ordinate to draw the text. * @param y     The Y co-ordinate to draw the text.  The flags specify *              whether this is the top (MWTF_TOP), bottom (MWTF_BOTTOM), *              or baseline (MWTF_BASELINE) of the text. * @param str   The string to display.  Non-NULL. * @param cc    The length of str.  For Asian DBCS encodings, this is *              specified in bytes.  For all other encodings such as ASCII, *              UTF8 and UC16, it is specified in characters.  For ASCII *              and DBCS encodings, this may be set to -1, and the length *              will be calculated automatically. * @param flags Flags specifying the encoding of str and the position of the *              text.  Specifying the vertical position is mandatory. *              The encoding of str defaults to ASCII if not specified. */voidGdText(PSD psd, MWCOORD x, MWCOORD y, const void *str, int cc,MWTEXTFLAGS flags){	const void *	text;	int		defencoding = gr_pfont->fontprocs->encoding;	int		force_uc16 = 0;	unsigned long	buf[256];	/*	 * DBCS encoding is handled a little special: if the selected	 * font is a builtin, then we'll force a conversion to UC16	 * rather than converting to the renderer specification.  This is	 * because we allow DBCS-encoded strings to draw using the	 * specially-compiled-in font if the character is not ASCII.	 * This is specially handled in corefont_drawtext below.	 *	 * If the font is not builtin, then the drawtext routine must handle	 * all glyph output, including ASCII.	 */	if (flags & MWTF_DBCSMASK) {		/* force double-byte sequences to UC16 if builtin font only*/		if (gr_pfont->fontprocs->GetTextBits == gen_gettextbits &&		    gr_pfont->fontprocs->DrawText == corefont_drawtext) {			defencoding = MWTF_UC16;			force_uc16 = 1;		}	}	/* convert encoding if required*/	if((flags & (MWTF_PACKMASK|MWTF_DBCSMASK)) != defencoding) {		cc = GdConvertEncoding(str, flags, cc, buf, defencoding);		flags &= ~MWTF_PACKMASK;	/* keep DBCS bits for drawtext*/		flags |= defencoding;		text = buf;	} else text = str;	/* use strlen for char count when ascii or dbcs*/	if(cc == -1 && (flags & MWTF_PACKMASK) == MWTF_ASCII)		cc = strlen((char *)str);	if(cc <= 0 || !gr_pfont->fontprocs->DrawText)		return;	/* draw text string, DBCS flags may still be set*/	if (!force_uc16)	/* remove DBCS flags if not needed*/		flags &= ~MWTF_DBCSMASK;	gr_pfont->fontprocs->DrawText(gr_pfont, psd, x, y, text, cc, flags);}/* * Draw ascii text using COREFONT type font. */voidcorefont_drawtext(PMWFONT pfont, PSD psd, MWCOORD x, MWCOORD y,	const void *text, int cc, MWTEXTFLAGS flags){	const unsigned char *str = text;	const unsigned short *istr = text;	MWCOORD		width;			/* width of text area */	MWCOORD 	height;			/* height of text area */	MWCOORD		base;			/* baseline of text*/	MWCOORD		startx, starty;	const MWIMAGEBITS *bitmap;		/* bitmap for characters */	MWBOOL		bgstate;	int		clip;	if (flags & MWTF_DBCSMASK)		dbcs_gettextsize(pfont, istr, cc, flags, &width, &height, &base);	else pfont->fontprocs->GetTextSize(pfont, str, cc, flags, &width, &height, &base);		if (flags & MWTF_BASELINE)		y -= base;	else if (flags & MWTF_BOTTOM)		y -= (height - 1);	startx = x;	starty = y + base;	bgstate = gr_usebg;	switch (clip = GdClipArea(psd, x, y, x + width - 1, y + height - 1)) {	case CLIP_VISIBLE:		/* clear background once for all characters*/		if (gr_usebg)			psd->FillRect(psd, x, y, x + width - 1, y + height - 1,				gr_background);		/* FIXME if we had a low-level text drawer, plug in here:		psd->DrawText(psd, x, y, str, cc, gr_foreground, pfont);		GdFixCursor(psd);		return;		*/		/* save state for combined routine below*/		bgstate = gr_usebg;		gr_usebg = FALSE;		break;	case CLIP_INVISIBLE:		return;	}	/* Get the bitmap for each character individually, and then display	 * them possibly using clipping for each one.	 */	/*	 * If the string was marked as DBCS, then we've forced the conversion	 * to UC16 in GdText.  Here we special-case the non-ASCII values and	 * get the bitmaps from the specially-compiled-in font.  Otherwise,	 * we draw them using the normal pfont->fontprocs->GetTextBits.	 */	while (--cc >= 0 && x < psd->xvirtres) {		if (flags & MWTF_DBCSMASK)			dbcs_gettextbits(pfont, *istr++, flags, &bitmap, &width,				&height, &base);		else pfont->fontprocs->GetTextBits(pfont, *str++, &bitmap, &width,			&height, &base);		if (clip == CLIP_VISIBLE)			drawbitmap(psd, x, y, width, height, bitmap);		else			GdBitmap(psd, x, y, width, height, bitmap);		x += width;	}	if (pfont->fontattr & MWTF_UNDERLINE)		GdLine(psd, startx, starty, x, starty, FALSE);	/* restore background draw state*/	gr_usebg = bgstate;	GdFixCursor(psd);}#if HAVE_FNT_SUPPORT | HAVE_PCF_SUPPORT/* * Draw MWTF_UC16 text using COREFONT type font. */voidgen16_drawtext(PMWFONT pfont, PSD psd, MWCOORD x, MWCOORD y,	const void *text, int cc, MWTEXTFLAGS flags){	const unsigned short *str = text;	MWCOORD		width;			/* width of text area */	MWCOORD		height;			/* height of text area */	MWCOORD		base;			/* baseline of text */	MWCOORD		startx, starty;	const MWIMAGEBITS *bitmap;		/* bitmap for characters */	MWBOOL		bgstate;	int		clip;	pfont->fontprocs->GetTextSize(pfont, str, cc, flags, &width, &height, &base);	if (flags & MWTF_BASELINE)		y -= base;	else if (flags & MWTF_BOTTOM)		y -= (height - 1);	startx = x;	starty = y + base;	bgstate = gr_usebg;	switch (clip = GdClipArea(psd, x, y, x + width - 1, y + height - 1)) {	case CLIP_VISIBLE:		/* clear background once for all characters*/		if (gr_usebg)			psd->FillRect(psd, x, y, x + width - 1, y + height - 1,				gr_background);		/* FIXME if we had a low-level text drawer, plug in here:		psd->DrawText(psd, x, y, str, cc, gr_foreground, pfont);		GdFixCursor(psd);		return;		*/		/* save state for combined routine below*/		bgstate = gr_usebg;		gr_usebg = FALSE;		break;	case CLIP_INVISIBLE:		return;	}	/* Get the bitmap for each character individually, and then display	 * them using clipping for each one.	 */	while (--cc >= 0 && x < psd->xvirtres) {		unsigned int ch = *str++;		pfont->fontprocs->GetTextBits(pfont, ch, &bitmap, &width,			&height, &base);		if (clip == CLIP_VISIBLE)			drawbitmap(psd, x, y, width, height, bitmap);		else			GdBitmap(psd, x, y, width, height, bitmap);		x += width;	}	if (pfont->fontattr & MWTF_UNDERLINE)		GdLine(psd, startx, starty, x, starty, FALSE);	/* restore background draw state*/	gr_usebg = bgstate;	GdFixCursor(psd);}#endif /* HAVE_FNT_SUPPORT | HAVE_PCF_SUPPORT*/#if HAVE_T1LIB_SUPPORT | HAVE_FREETYPE_SUPPORT/* * Produce blend table from src and dst based on passed alpha table * Used because we don't quite yet have GdArea with alphablending, * so we pre-blend fg/bg colors for fade effect. */voidalphablend(PSD psd, OUTPIXELVAL *out, MWPIXELVAL src, MWPIXELVAL dst,	unsigned char *alpha, int count){	unsigned int	a, d;	unsigned char	r, g, b;	MWCOLORVAL	palsrc, paldst;	extern MWPALENTRY gr_palette[256];	while (--count >= 0) {	    a = *alpha++;#define BITS(pixel,shift,mask)	(((pixel)>>shift)&(mask))	    if(a == 0)		*out++ = dst;	    else if(a == 255)		*out++ = src;	    else 		switch(psd->pixtype) {	        case MWPF_TRUECOLOR0888:	        case MWPF_TRUECOLOR888:		    d = BITS(dst, 16, 0xff);		    r = (unsigned char)(((BITS(src, 16, 0xff) - d)*a)>>8) + d;		    d = BITS(dst, 8, 0xff);		    g = (unsigned char)(((BITS(src, 8, 0xff) - d)*a)>>8) + d;		    d = BITS(dst, 0, 0xff);		    b = (unsigned char)(((BITS(src, 0, 0xff) - d)*a)>>8) + d;		    *out++ = (r << 16) | (g << 8) | b;		    break;	        case MWPF_TRUECOLOR565:		    d = BITS(dst, 11, 0x1f);		    r = (unsigned char)(((BITS(src, 11, 0x1f) - d)*a)>>8) + d;		    d = BITS(dst, 5, 0x3f);		    g = (unsigned char)(((BITS(src, 5, 0x3f) - d)*a)>>8) + d;		    d = BITS(dst, 0, 0x1f);		    b = (unsigned char)(((BITS(src, 0, 0x1f) - d)*a)>>8) + d;		    *out++ = (r << 11) | (g << 5) | b;		    break;	        case MWPF_TRUECOLOR555:		    d = BITS(dst, 10, 0x1f);		    r = (unsigned char)(((BITS(src, 10, 0x1f) - d)*a)>>8) + d;		    d = BITS(dst, 5, 0x1f);		    g = (unsigned char)(((BITS(src, 5, 0x1f) - d)*a)>>8) + d;		    d = BITS(dst, 0, 0x1f);		    b = (unsigned char)(((BITS(src, 0, 0x1f) - d)*a)>>8) + d;		    *out++ = (r << 10) | (g << 5) | b;		    break;	        case MWPF_TRUECOLOR332:		    d = BITS(dst, 5, 0x07);		    r = (unsigned char)(((BITS(src, 5, 0x07) - d)*a)>>8) + d;		    d = BITS(dst, 2, 0x07);		    g = (unsigned char)(((BITS(src, 2, 0x07) - d)*a)>>8) + d;		    d = BITS(dst, 0, 0x03);		    b = (unsigned char)(((BITS(src, 0, 0x03) - d)*a)>>8) + d;		    *out++ = (r << 5) | (g << 2) | b;		    break;	        case MWPF_PALETTE:		    /* reverse lookup palette entry for blend ;-)*/		    palsrc = GETPALENTRY(gr_palette, src);		    paldst = GETPALENTRY(gr_palette, dst);		    d = REDVALUE(paldst);		    r = (unsigned char)(((REDVALUE(palsrc) - d)*a)>>8) + d;		    d = GREENVALUE(paldst);		    g = (unsigned char)(((GREENVALUE(palsrc) - d)*a)>>8) + d;		    d = BLUEVALUE(paldst);		    b = (unsigned char)(((BLUEVALUE(palsrc) - d)*a)>>8) + d;		    *out++ = GdFindNearestColor(gr_palette, (int)psd->ncolors,				MWRGB(r, g, b));		    break;	  	}	}}#endif /*HAVE_T1LIB_SUPPORT | HAVE_FREETYPE_SUPPORT*/#if !HAVE_FREETYPE_SUPPORTintGdGetTextSizeEx(PMWFONT pfont, const void *str, int cc,int nMaxExtent,	int* lpnFit, int* alpDx,MWCOORD *pwidth,MWCOORD *pheight,	MWCOORD *pbase, MWTEXTFLAGS flags){	*pwidth = *pheight = *pbase = 0;	return 0;}voidGdFreeFontList(MWFONTLIST ***fonts, int n){}voidGdGetFontList(MWFONTLIST ***fonts, int *numfonts){	*numfonts = -1;}#endif /* !HAVE_FREETYPE_SUPPORT*//** * Convert text from one encoding to another. * Input cc and returned cc is character count, not bytes. * Return < 0 on error or can't translate. * * @param istr   Input string. * @param iflags Encoding of istr, as MWTF_xxx constants. * @param cc     The length of istr.  For Asian DBCS encodings, this is *               specified in bytes.  For all other encodings such as ASCII, *               UTF8 and UC16, it is specified in characters.  For ASCII *               and DBCS encodings, this may be set to -1, and the length *               will be calculated automatically. * @param ostr   Output string. * @param oflags Encoding of ostr, as MWTF_xxx constants. * @return       Number of characters (not bytes) converted. */intGdConvertEncoding(const void *istr, MWTEXTFLAGS iflags, int cc, void *ostr,	MWTEXTFLAGS oflags){	const unsigned char 	*istr8;	const unsigned short 	*istr16;	const unsigned long	*istr32;	unsigned char 		*ostr8;	unsigned short 		*ostr16;	unsigned long		*ostr32;	unsigned int		ch;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -