www.pudn.com > emGUI.rar > genfont.c
/* * general font * * * COPYRIGHT (c) 2001 - 2010. * emTech System Corporation. * * The license and distribution terms for this file may be * found in found in the file LICENSE. */ /* Huangf emcore@263.net */ /* stolen from microwindows & optimize for Chinese */ /* * Copyright (c) 1999, 2000 Greg Haerr* * Screen Driver Utilities * * Microwindows Proportional Font Routines (proportional font format) * * This file contains the generalized low-level font/text * drawing routines. Both fixed and proportional fonts are * supported, with fixed pitch structure allowing much smaller * font files. */ #include #include "emGUI.h" #include "devfont.h" /* compiled in fonts*/ extern MWCFONT font_rom8x16, font_rom8x8; extern MWCFONT font_winFreeSansSerif11x13; extern MWCFONT font_winFreeSystem14x16; extern MWCFONT font_winSystem14x16; extern MWCFONT font_winMSSansSerif11x13; extern MWCFONT font_winTerminal8x12; extern MWCFONT font_helvB10, font_helvB12, font_helvR10; extern MWCFONT font_X5x7, font_X6x13; /* handling routines for MWCOREFONT*/ static MWFONTPROCS fontprocs = { MWTF_ASCII, /* routines expect ascii*/ (void *)gen_getfontinfo, gen_gettextsize, gen_gettextbits, gen_unloadfont, (void *)corefont_drawtext, NULL, /* setfontsize*/ NULL, /* setfontrotation*/ NULL, /* setfontattr*/ }; /* first font is default font if no match*/ MWCOREFONT gen_fonts[NUMBER_FONTS] = { #if HAVEMSFONTS {&fontprocs, 0, 0, 0, MWFONT_SYSTEM_VAR, &font_winSystem14x16}, {&fontprocs, 0, 0, 0, MWFONT_GUI_VAR, &font_winMSSansSerif11x13}, {&fontprocs, 0, 0, 0, MWFONT_OEM_FIXED, &font_winTerminal8x12}, {&fontprocs, 0, 0, 0, MWFONT_SYSTEM_FIXED, &font_X6x13} #else {&fontprocs, 0, 0, 0, MWFONT_SYSTEM_VAR, &font_winFreeSystem14x16}, {&fontprocs, 0, 0, 0, MWFONT_GUI_VAR, &font_winFreeSansSerif11x13}, {&fontprocs, 0, 0, 0, MWFONT_OEM_FIXED, &font_rom8x16}, {&fontprocs, 0, 0, 0, MWFONT_SYSTEM_FIXED, &font_X6x13} #endif }; /* * Generalized low level get font info routine. This * routine works with fixed and proportional fonts. */ boolean gen_getfontinfo(PMWFONT pfont, PMWFONTINFO pfontinfo) { PMWCFONT pf = ((PMWCOREFONT)pfont)->cfont; int i; pfontinfo->maxwidth = pf->maxwidth; pfontinfo->height = pf->height; pfontinfo->baseline = pf->ascent; pfontinfo->firstchar = pf->firstchar; pfontinfo->lastchar = pf->firstchar + pf->size - 1; pfontinfo->fixed = pf->width == NULL? TRUE: FALSE; for(i=0; i<256; ++i) { if(pf->width == NULL) pfontinfo->widths[i] = pf->maxwidth; else { if(i firstchar || i >= pf->firstchar+pf->size) pfontinfo->widths[i] = 0; else pfontinfo->widths[i] = pf->width[i-pf->firstchar]; } } return TRUE; } /* * Generalized low level routine to calc bounding box for text output. * Handles both fixed and proportional fonts. Passed ascii string. */ void gen_gettextsize( PMWFONT pfont, const void *text, int cc, int *pwidth, int *pheight, int *pbase ) { PMWCFONT pf = ((PMWCOREFONT)pfont)->cfont; const unsigned short *str = text; unsigned int c; int width; if(pf->width == NULL) width = cc * pf->maxwidth; else { width = 0; while(--cc >= 0) { c = *str++; if (c > 0x7f) { width += 12; /* FIXME*/ } else{ if(c >= pf->firstchar && c < pf->firstchar+pf->size) width += pf->width[c - pf->firstchar]; } } } *pwidth = width; *pheight = pf->height; *pbase = pf->ascent; } /* * Generalized low level routine to get the bitmap associated * with a character. Handles fixed and proportional fonts. */ void gen_gettextbits( PMWFONT pfont, int ch, MWIMAGEBITS *retmap, int *pwidth, int *pheight, int *pbase ) { PMWCFONT pf = ((PMWCOREFONT)pfont)->cfont; int n, count, width; MWIMAGEBITS * bits; #if 0 /* decode chinese gb2312*/ int CH = ((unsigned int)ch) >> 8, CL = ((unsigned int)ch) & 0xFF; if (CH >= 0xA1 && CH < 0xF8 && CL >= 0xA1 && CL < 0xFF) { int Pos = ((CH - 0xA1) * 94 + (CL - 0xA1)) * 18; int i; extern unsigned char GUO_GB2312_12X12_FONT_BITMAP[]; *pwidth = width = 12; *pheight = 12; *pbase = 0; for (i = 0; i < 6; i++) { unsigned char *DstBitmap = ((unsigned char *)retmap) + i * 4; unsigned char *FontBitmap = GUO_GB2312_12X12_FONT_BITMAP + Pos + i * 3; DstBitmap[0] = FontBitmap[1]; DstBitmap[1] = FontBitmap[0]; DstBitmap[2] = FontBitmap[1] << 4; DstBitmap[3] = FontBitmap[2]; } return; } #endif /* if char not in font, map to first character by default*/ if(ch < pf->firstchar || ch >= pf->firstchar+pf->size) ch = pf->firstchar; ch -= pf->firstchar; /* get font bitmap depending on fixed pitch or not*/ bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch)); width = pf->width ? pf->width[ch] : pf->maxwidth; count = MWIMAGE_WORDS(width) * pf->height; for(n=0; n height; *pbase = pf->ascent; } void gen_unloadfont( PMWFONT pfont ) { }