5 楼
chenzep [专家分:3640] 发布于 2006-05-02 10:03:00
不知道你有没有关于字体显示实现方面的知识,下面是一个显示一个字的程序,给你理解一下字体显示的原理.
在字体库中,如果人家没有预置,如果要自己显示,原理很简单,但过程也很繁杂.
程序我没有编译过,不过用来说明原理就足够了,如果在汇编中实现,那就更繁杂了.
作者:小小虫子
呵呵 是这样的 我的女朋友的名字有一个字是“璟” 在hzk16字库里是没有这个字的 我想在dos下显示她的名字 一直没办法 然后看了图灵机哥哥的文章 很有想法 终于昨晚有时间把她给画出来了 呵呵 好开心 (这不是灌水吧 哈哈 ) 代码如下
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <bios.h>
#include <malloc.h>
#include <conio.h>
const unsigned char fnt16c[][32]=
{
{
0x04, 0x80, 0x0e, 0xa0, 0x78, 0x90, 0x08, 0x90, 0x08, 0x84,
0xff, 0xfe, 0x08, 0x80, 0x08, 0x90, 0x0a, 0x90, 0x0c, 0x60,
0x18, 0x40, 0x68, 0xa0, 0x09, 0x20, 0x0a, 0x14, 0x38, 0x1c,
},
{
0x00, 0x78, 0x3f, 0x80, 0x11, 0x10, 0x09, 0x20, 0x7f, 0xfe,
0x42, 0x02, 0x82, 0x04, 0x7f, 0xf8, 0x04, 0x00, 0x07, 0xf0,
0x0a, 0x20, 0x09, 0x40, 0x10, 0x80, 0x11, 0x60, 0x22, 0x1c,
},
{ /*璟*/
0x00, 0x04, 0x10, 0x7e, 0xf8, 0x44, 0x20, 0x7c, 0x20, 0x44,
0x20, 0x7c, 0xf8, 0x10, 0x23, 0xff, 0x20, 0x00, 0x20, 0xfe,
0x38, 0x82, 0xe0, 0xfe, 0x40, 0x94, 0x00, 0x92, 0x01, 0x32,
},
};
void showfontc16x15(int color,int bkcolor, int x, int y,int no)
//putpixel(x ,y,color);是tc的画点函数
{ int i,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15;
unsigned char char_a;
//to record x coordinate
x1 = x+1;
x2 = x+2;
x3 = x+3;
x4 = x+4;
x5 = x+5;
x6 = x+6;
x7 = x+7;
x8 = x+8;
x9 = x+9;
x10 = x+10;
x11 = x+11;
x12 = x+12;
x13 = x+13;
x14 = x+14;
x15 = x+15;
for( i=0; i<30; i+=2)
{
char_a=fnt16c[no][i];
if ( char_a & 0x80 ) putpixel(x ,y,color);
if ( char_a & 0x40 ) putpixel(x1 ,y,color);
if ( char_a & 0x20 ) putpixel(x2 ,y,color);
if ( char_a & 0x10 ) putpixel(x3 ,y,color);
if ( char_a & 0x08 ) putpixel(x4 ,y,color);
if ( char_a & 0x04 ) putpixel(x5 ,y,color);
if ( char_a & 0x02 ) putpixel(x6 ,y,color);
if ( char_a & 0x01 ) putpixel(x7 ,y,color);
char_a=fnt16c[no][i+1];
if ( char_a & 0x80 ) putpixel(x8 ,y,color);
if ( char_a & 0x40 ) putpixel(x9 ,y,color);
if ( char_a & 0x20 ) putpixel(x10,y,color);
if ( char_a & 0x10 ) putpixel(x11,y,color);
if ( char_a & 0x08 ) putpixel(x12,y,color);
if ( char_a & 0x04 ) putpixel(x13,y,color);
if ( char_a & 0x02 ) putpixel(x14,y,color);
if ( char_a & 0x01 ) putpixel(x15,y,color);
y++;
}
}
void main(void)
{
int gd=detect,gm;
initgraph(&gd,&gm,"");
showfontc16x15(white,black,200,130,0);
showfontc16x15(white,black,250,130,1);
showfontc16x15(white,black,300,130,2);
showfontc16x15(white,black,350,130,2);
getch();
closegraph();
}