?? devfont.c
字號(hào):
/*
* Font Device Driver
*
*
* 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) 2000 Greg Haerr <greg@censoft.com>
* T1lib Adobe type1 routines contributed by Vidar Hokstad
* Freetype TrueType routines contributed by Martin Jolicoeur
* Han Zi Ku routines contributed by Tanghao and Jauming
*
* Device-independent font and text drawing routines
*
* 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.
*/
/*#define NDEBUG*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <string.h>
#include "emGUI.h"
#if (UNIX | DOS_DJGPP)
#define strcmpi strcasecmp
#endif
/*
* Set the font for future calls.
*/
PMWFONT GrGCSetFont(
GID gc,
PMWFONT pfont
)
{
PMWFONT oldfont;
oldfont = gc->gr_font;
gc->gr_font = 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, return builtin font from passed name.
* Otherwise find builtin font best match based on height.
*/
PMWFONT
GrCreateFont(
const char *name
)
{
if (strcasecmp(name, MWFONT_SYSTEM_VAR) == 0){
return (PMWFONT)&gen_fonts[0];
}
if (strcasecmp(name, MWFONT_GUI_VAR) == 0){
return (PMWFONT)&gen_fonts[1];
}
if (strcasecmp(name, MWFONT_OEM_FIXED) == 0){
return (PMWFONT)&gen_fonts[2];
}
if (strcasecmp(name, MWFONT_SYSTEM_FIXED) == 0){
return (PMWFONT)&gen_fonts[3];
}
return NULL;
}
/* Set the font size for the passed font*/
int
GrSetFontSize(
PMWFONT pfont,
int fontsize
)
{
int oldfontsize = pfont->fontsize;
pfont->fontsize = fontsize;
if (pfont->fontprocs->SetFontSize)
pfont->fontprocs->SetFontSize(pfont, fontsize);
return oldfontsize;
}
/* Set the font rotation angle in tenths of degrees for the passed font*/
int
GrSetFontRotation(
PMWFONT pfont,
int tenthdegrees
)
{
int 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 the passed font.
*/
int
GrSetFontAttr(
PMWFONT pfont,
int setflags,
int clrflags
)
{
int oldattr = pfont->fontattr;
pfont->fontattr &= ~clrflags;
pfont->fontattr |= setflags;
if (pfont->fontprocs->SetFontAttr)
pfont->fontprocs->SetFontAttr(pfont, setflags, clrflags);
return oldattr;
}
/* Unload and deallocate font*/
void
GrDestroyFont(
PMWFONT pfont
)
{
if (pfont->fontprocs->DestroyFont)
pfont->fontprocs->DestroyFont(pfont);
}
/* Return information about a specified font*/
boolean
GrGetFontInfo(
PMWFONT pfont,
PMWFONTINFO pfontinfo
)
{
if(!pfont || !pfont->fontprocs->GetFontInfo)
return FALSE;
return pfont->fontprocs->GetFontInfo(pfont, pfontinfo);
}
/* Get the width and height of passed text string in the passed font*/
void
GrGetTextSize(
PMWFONT pfont,
const void *str,
int cc,
int *pwidth,
int *pheight,
int *pbase,
int flags
)
{
const void *text;
text = str;
if(cc <= 0 || !pfont->fontprocs->GetTextSize) {
*pwidth = *pheight = *pbase = 0;
return;
}
/* calc height and width of string*/
pfont->fontprocs->GetTextSize(pfont, text, cc, pwidth, pheight, pbase);
}
/* Draw a text string at a specifed coordinates in the foreground color
* (and possibly the background color), applying clipping if necessary.
* The background color is only drawn if the gr_usebg flag is set.
* Use the current font.
*/
void
GrText(
WndID win,
GID gc,
int x,
int y,
const void *str,
int cc,
int flags
)
{
const void *text;
text = str;
if(cc <= 0 || !gc->gr_font->fontprocs->DrawText)
return;
x += win->left;
y += win->top;
/* draw text string*/
gc->gr_font->fontprocs->DrawText(win, gc, x, y, text, cc, flags);
}
/*
* Draw ascii text using COREFONT type font.
*/
void
corefont_drawtext(
WndID win,
GID gc,
int x,
int y,
const void *text,
int cc,
int flags
)
{
const unsigned short *str = text;
int width; /* width of text area */
int height; /* height of text area */
int base; /* baseline of text*/
int startx, starty;
MWIMAGEBITS bitmap[24 * 24 / MWIMAGE_BITSPERIMAGE];
PMWFONT pfont = gc->gr_font;
pfont->fontprocs->GetTextSize(pfont, str, cc, &width, &height, &base);
if(flags & MWTF_BASELINE)
y -= base;
else if(flags & MWTF_BOTTOM)
y -= (height - 1);
startx = x;
starty = y + base;
/* Get the bitmap for each character individually, and then display
* them using clipping for each one.
*/
while (--cc >= 0) {
unsigned int ch = *str++;
pfont->fontprocs->GetTextBits(
pfont,
ch,
bitmap,
&width,
&height,
&base
);
/* note: change to bitmap*/
GrBitmap(win, gc, x, y, width, height, bitmap);
x += width;
}
if (pfont->fontattr & MWTF_UNDERLINE){
GrLine(win, gc, startx, starty, x, starty, FALSE);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -