- #include <stdio.h>
- #include <string.h>
- #include "ASIICTable.h"
- typedef enum _ASCII_Type_
- {
- ASCII_W8_H16 = 1,
- ASCII_W14_H24,
- };
- /*
- *功能:在指定的区域指定的坐标下显示一个ASCii 14*24 点阵字符
- *参数:char c 要显示的字符
- int x, int y 显示字符的区域内横纵坐标
- int l 显示区域的像素宽度
- short *p 显示区域的数组表示(类似帧缓冲)
- short colour 显示字符的颜色
- */
- void displayBigChar(char c, int x, int y, int l, short *p, short colour)
- {
- char ac[48];
- short *pd = NULL;
- short *pd2 = NULL;
- short line;
- int i, j;
- pd2 = p + (y * l) + x; //显示缓冲中对应字符显示坐标的起始位置
- i = (c - 0x20) * 48; //每个ASCii字符的字模大小为48个字节,第一个可显示字符为空格
- memcpy(ac, &nAsciiDot[i], 48);
- for(i = 0; i < 24; i++) //先点阵的行,后列
- {
- pd = pd2 + (i * l);
- line = (ac[2*i]<<8) | ac[2*i + 1];
- for(j = 0; j < 14; j++)
- {
- if((line<<j) & 0x8000) //找到点阵中为1的位
- {
- *pd = colour;
- }
- pd++;
- }
- }
- }
- /*
- *功能:在指定的区域指定的坐标下显示一个ASCii 8*16 点阵字符
- *参数:char c 要显示的字符
- int x, int y 显示字符的区域内横纵坐标
- int l 显示区域的像素宽度
- short *p 显示区域的数组表示(类似帧缓冲)
- short colour 显示字符的颜色
- */
- void displaySmallChar(char c, int x, int y, int l, short *p, short colour)
- {
- char ac[16];
- short *pd = NULL;
- short *pd2 = NULL;
- int i, j;
- pd2 = p + (y * l) + x;
- i = (c - 0x20) * 16;
- memcpy(ac, &ASIICTable[i], 16);
- for(i = 0; i < 16; i++)
- {
- pd = pd2 + (i * l);
- for(j = 0; j < 8; j++)
- {
- if((ac[i] << j) & 0x80)
- {
- *pd = colour;
- }
- pd++;
- }
- }
- }
- /*
- *功能:在指定的区域指定的坐标下显示ASCii字符串
- *参数:const char *info 要显示的ASCii字符串
- int x, int y 显示字符串的区域内起始横纵坐标
- int l 显示区域的像素宽度
- short *p 显示区域的数组表示(类似帧缓冲)
- short colour 显示字符的颜色
- int type ASCii字符使用的点阵类型
- */
- int displayInfo(const char *info, int x, int y, int l, short *p, short colour, int type)
- {
- int i, len = 0;
- if((NULL == info) || (NULL == p))
- {
- return -1;
- }
- len = strlen(info);
- if(ASCII_W14_H24 == type)
- {
- for(i = 0; i < len; i++)
- displayBigChar(*(info + i), x + i*13, y, l, p, colour); //13为两个字符的间距
- }
- else
- {
- for(i = 0; i < len; i++)
- displaySmallChar(*(info + i), x + i*10, y, l, p, colour);//10为两个字符的间距
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/051220137817.html
来源: http://www.codesnippet.cn/detail/051220137817.html