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

📄 devfont.c

📁 the embedded GUI for SamSung s3c2410 cpu based board.is microwindows0.90
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 2000, 2002, 2003 Greg Haerr <greg@censoft.com> * Portions Copyright (c) 2002 by Koninklijke Philips Electronics N.V. *//** * These routines do the necessary range checking, clipping, and cursor * overwriting checks, and then call the lower level device dependent * routines to actually do the drawing.  The lower level routines are * only called when it is known that all the pixels to be drawn are * within the device area and are visible. * * * Device-independent font and text drawing routines *//*#define NDEBUG*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include "device.h"#include "devfont.h"#include "../drivers/genfont.h"/** * The current font. */static PMWFONT	gr_pfont;/* temp extern decls*/extern MWPIXELVAL gr_foreground;extern MWPIXELVAL gr_background;extern MWBOOL gr_usebg;void corefont_drawtext(PMWFONT pfont, PSD psd, MWCOORD x, MWCOORD y,		const void *text, int cc, MWTEXTFLAGS flags);static int  utf8_to_utf16(const unsigned char *utf8, int cc,		unsigned short *unicode16);/** * Set the font for future calls. * * @param pfont The font to use.  If NULL, the font is not changed. * @return The old font. */PMWFONTGdSetFont(PMWFONT pfont){	PMWFONT	oldfont = gr_pfont;	if (pfont)		gr_pfont = pfont;	return oldfont;}/** * Select a font, based on various parameters. * If plogfont is specified, name and height parms are ignored * and instead used from MWLOGFONT. *  * If height is 0, match based on passed name, trying * builtins first for speed, then other font renderers. * If not found, return 0.  If height=0 is used for * scalable font renderers, a call to GdSetFontSize with * requested height must occur before rendering. * * If height not 0, perform same match based on name, * but return builtin font best match from height if * not otherwise found. * * @param psd      The screen that this font will be displayed on. * @param name     The name of the font.  May be NULL.  Ignored if *                 plogfont is specified. * @param height   The height of the font in pixels.  Ignored if *                 plogfont is specified. * @param plogfont A structure describing the font, or NULL. * @return         A new font, or NULL on error. */PMWFONTGdCreateFont(PSD psd, const char *name, MWCOORD height,	const PMWLOGFONT plogfont){	int 		i;	int		fontht;	int		fontno; 	int		fontclass;	int		fontattr = 0;	PMWFONT		pfont;	PMWCOREFONT	pf = psd->builtin_fonts;	MWFONTINFO	fontinfo;	MWSCREENINFO 	scrinfo;	const char *	fontname;#if !FONTMAPPER	char 		fontmapper_fontname[MWLF_FACESIZE + 1];#endif	GdGetScreenInfo(psd, &scrinfo);	/* if plogfont not specified, use passed name, height and any class*/	if (!plogfont) {		/* if name not specified, use first builtin*/		if (!name || !name[0])			name = pf->name;		fontname = name;		fontclass = MWLF_CLASS_ANY;	} else {		/* otherwise, use MWLOGFONT name, height and class*/#if FONTMAPPER		fontname = NULL; /* Paranoia */ 		fontclass = select_font(plogfont, &fontname);#else		/* Copy the name from plogfont->lfFaceName to fontmapper_fontname		 * Note that it may not be NUL terminated in the source string,		 * so we're careful to NUL terminate it here.		 */		strncpy(fontmapper_fontname, plogfont->lfFaceName, MWLF_FACESIZE);		fontmapper_fontname[MWLF_FACESIZE] = '\0';		fontname = fontmapper_fontname;		if (!fontname[0])	/* if name not specified, use first builtin*/			fontname = pf->name;		fontclass = plogfont->lfClass;#endif		height = plogfont->lfHeight;		if (plogfont->lfUnderline)			fontattr = MWTF_UNDERLINE;	}	height = abs(height);	/* check builtin fonts first for speed*/ 	if (!height && (fontclass == MWLF_CLASS_ANY || fontclass == MWLF_CLASS_BUILTIN)) {  		for(i = 0; i < scrinfo.fonts; ++i) { 			if(!strcmpi(pf[i].name, fontname)) {  				pf[i].fontsize = pf[i].cfont->height;				pf[i].fontattr = fontattr;DPRINTF("createfont: (height == 0) found builtin font %s (%d)\n", fontname, i);  				return (PMWFONT)&pf[i];  			}  		}		/* 		 * Specified height=0 and no builtin font matched name.		 * if not font found with other renderer, no font		 * will be loaded, and 0 returned.		 *		 * We used to return the first builtin font.  If a font		 * return needs to be guaranteed, specify a non-zero		 * height, and the closest builtin font to the specified		 * height will always be returned.		 */  	}	/* try to load font (regardless of height) using other renderers*/#ifdef HAVE_FNT_SUPPORT	if (fontclass == MWLF_CLASS_ANY || fontclass == MWLF_CLASS_FNT) {		pfont = (PMWFONT) fnt_createfont(fontname, height, fontattr);		if (pfont) {			DPRINTF("fnt_createfont: using font %s\n", fontname);			return(pfont);		}		EPRINTF("fnt_createfont: %s,%d not found\n", fontname, height);	}#endif#ifdef HAVE_PCF_SUPPORT	if (fontclass == MWLF_CLASS_ANY || fontclass == MWLF_CLASS_PCF) {		pfont = (PMWFONT) pcf_createfont(fontname, height, fontattr);		if (pfont) {			DPRINTF("pcf_createfont: using font %s\n", fontname);			return(pfont);		}		EPRINTF("pcf_createfont: %s,%d not found\n", fontname, height);	}#endif#if HAVE_FREETYPE_SUPPORT 	if (fontclass == MWLF_CLASS_ANY || fontclass == MWLF_CLASS_FREETYPE) {		if (freetype_init(psd)) {			/* FIXME auto antialias for height > 14 for kaffe*/			if (plogfont && plogfont->lfHeight > 14 &&				plogfont->lfQuality)					fontattr |= MWTF_ANTIALIAS;			pfont = (PMWFONT)freetype_createfont(fontname, height,					fontattr);			if(pfont) {				/* FIXME kaffe kluge*/				pfont->fontattr |= MWTF_FREETYPE;				return pfont;			} 			EPRINTF("freetype_createfont: %s,%d not found\n",				fontname, height);		}  	}#endif#if HAVE_FREETYPE_2_SUPPORT 	if (fontclass == MWLF_CLASS_ANY || fontclass == MWLF_CLASS_FREETYPE) {		if (freetype2_init(psd)) {			/* FIXME auto antialias for height > 14 for kaffe*/			if (plogfont && plogfont->lfHeight > 14 &&				plogfont->lfQuality)					fontattr |= MWTF_ANTIALIAS;			pfont = (PMWFONT)freetype2_createfont(fontname, height,					fontattr);			if(pfont) {				/* FIXME kaffe kluge*/				pfont->fontattr |= MWTF_FREETYPE;				return pfont;			}			EPRINTF("freetype2_createfont: %s,%d not found\n",				fontname, height);		}  	}#endif#if HAVE_T1LIB_SUPPORT	if (fontclass == MWLF_CLASS_ANY || fontclass == MWLF_CLASS_T1LIB) {		if (t1lib_init(psd)) {			pfont = (PMWFONT)t1lib_createfont(fontname, height,					fontattr);			if(pfont)				return pfont;			EPRINTF("t1lib_createfont: %s,%d not found\n",				fontname, height);		}  	}#endif#if HAVE_HZK_SUPPORT	if (fontclass == MWLF_CLASS_ANY || fontclass == MWLF_CLASS_HZK) {		/* Make sure the library is initialized */		if (hzk_init(psd)) {			pfont = (PMWFONT)hzk_createfont(fontname, height, fontattr);			if(pfont)						return pfont;			EPRINTF("hzk_createfont: %s,%d not found\n", fontname, height);		}	}#endif#if HAVE_EUCJP_SUPPORT 	if (fontclass == MWLF_CLASS_ANY || fontclass == MWLF_CLASS_MGL) {		pfont = (PMWFONT)eucjp_createfont(fontname, height, fontattr);		if (pfont) {			DPRINTF("eujcp_createfont: using font %s\n", fontname);			return pfont;		}		EPRINTF("eucjp_createfont: %s,%d not found\n", fontname, height);	}#endif	/*	 * No font yet found.  If height specified, we'll return	 * a builtin font.  Otherwise 0 will be returned.	 */ 	if (height != 0 && (fontclass == MWLF_CLASS_ANY || fontclass == MWLF_CLASS_BUILTIN)) {		/* find builtin font closest in height*/		fontno = 0;		height = abs(height);		fontht = MAX_MWCOORD;		for(i = 0; i < scrinfo.fonts; ++i) {			pfont = (PMWFONT)&pf[i];			GdGetFontInfo(pfont, &fontinfo);			if(fontht > abs(height-fontinfo.height)) { 				fontno = i;				fontht = abs(height-fontinfo.height);			}		}		pf[fontno].fontsize = pf[fontno].cfont->height;		pf[fontno].fontattr = fontattr;DPRINTF("createfont: (height != 0) using builtin font %s (%d)\n", pf[fontno].name, fontno);		return (PMWFONT)&pf[fontno];	}	/* no font matched: don't load font, return 0*/DPRINTF("createfont: no font found, returning NULL\n");	return 0;}/** * Set the size of a font. * * @param pfont    The font to modify. * @param fontsize The new size. * @return         The old size. */MWCOORDGdSetFontSize(PMWFONT pfont, MWCOORD fontsize){	MWCOORD oldfontsize = pfont->fontsize;	pfont->fontsize = fontsize;	if (pfont->fontprocs->SetFontSize)	    pfont->fontprocs->SetFontSize(pfont, fontsize);	return oldfontsize;}/** * Set the rotation angle of a font. * * @param pfont        The font to modify. * @param tenthdegrees The new rotation angle, in tenths of degrees. * @return             The old rotation angle, in tenths of degrees. */intGdSetFontRotation(PMWFONT pfont, int tenthdegrees){	MWCOORD oldrotation = pfont->fontrotation;	pfont->fontrotation = tenthdegrees;	if (pfont->fontprocs->SetFontRotation)	    pfont->fontprocs->SetFontRotation(pfont, tenthdegrees);		return oldrotation;}/** * Set/reset font attributes (MWTF_KERNING, MWTF_ANTIALIAS) * for a font. * * @param pfont    The font to modify. * @param setflags The flags to set.  Overrides clrflags. * @param clrflags The flags to clear. * @return         The old font attributes. */intGdSetFontAttr(PMWFONT pfont, int setflags, int clrflags){	MWCOORD	oldattr = pfont->fontattr;	pfont->fontattr &= ~clrflags;	pfont->fontattr |= setflags;	if (pfont->fontprocs->SetFontAttr)	    pfont->fontprocs->SetFontAttr(pfont, setflags, clrflags);		return oldattr;}/** * Unload and deallocate a font.  Do not use the font once it has been * destroyed. * * @param pfont The font to deallocate. */voidGdDestroyFont(PMWFONT pfont){	if (pfont->fontprocs->DestroyFont)		pfont->fontprocs->DestroyFont(pfont);}/** * Return information about a specified font. * * @param pfont The font to query. * @param pfontinfo Recieves the result of the query * @return TRUE on success, FALSE on error. */MWBOOLGdGetFontInfo(PMWFONT pfont, PMWFONTINFO pfontinfo){	if(!pfont || !pfont->fontprocs->GetFontInfo)		return FALSE;

⌨️ 快捷键说明

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