Initial commit
This commit is contained in:
163
FW/Core/my_src/font_text.c
Normal file
163
FW/Core/my_src/font_text.c
Normal file
@@ -0,0 +1,163 @@
|
||||
#include "w25qxx.h"
|
||||
#include "ltdc_drv.h"
|
||||
#include "font_text.h"
|
||||
#include "string.h"
|
||||
#include "lcd_base_display.h"
|
||||
#include "file_cache.h"
|
||||
#include "internal_flash.h"
|
||||
|
||||
#define F24addr FLASH_FONT_START_ADDR
|
||||
|
||||
void set_font_color(unsigned int point_color, unsigned int back_color)
|
||||
{
|
||||
POINT_COLOR = point_color;
|
||||
BACK_COLOR = back_color;
|
||||
}
|
||||
|
||||
//code 字符指针开始
|
||||
//从字库中查找出字模
|
||||
//code 字符串的开始地址,GBK码
|
||||
//mat 数据存放地址 (size/8+((size%8)?1:0))*(size) bytes大小
|
||||
//size:字体大小
|
||||
void Get_HzMat(unsigned char *code,unsigned char *mat,unsigned char size)
|
||||
{
|
||||
static unsigned char kkk[256];
|
||||
unsigned char qh,ql;
|
||||
unsigned char i;
|
||||
unsigned long foffset;
|
||||
unsigned char csize=(size/8+((size%8)?1:0))*(size);//得到字体一个字符对应点阵集所占的字节数
|
||||
qh=*code;
|
||||
ql=*(++code);
|
||||
/*
|
||||
if(qh<0x81||ql<0x40||ql==0xff||qh==0xff)//非常用汉字
|
||||
{
|
||||
for(i=0;i<csize;i++)*mat++=0x00;//填充满格
|
||||
return; //结束访问
|
||||
}
|
||||
if(ql<0x7f)ql-=0x40;//注意!
|
||||
else ql-=0x41;
|
||||
qh-=0x81;
|
||||
foffset=((unsigned long)190*qh+ql)*csize;//得到字库中的字节偏移量
|
||||
*/
|
||||
foffset = 72UL*((qh-15-0xa1)*94 + (ql-0xa1));
|
||||
|
||||
if(24 == size){
|
||||
//W25QXX_Read(mat,foffset+0,csize);
|
||||
//memcpy(mat, (unsigned char *)(FLASH_USER_FONT_24X24 + foffset), csize);
|
||||
}
|
||||
/*
|
||||
switch(size)
|
||||
{
|
||||
case 12:
|
||||
W25QXX_Read(mat,foffset+ftinfo.f12addr,csize);
|
||||
break;
|
||||
case 16:
|
||||
W25QXX_Read(mat,foffset+ftinfo.f16addr,csize);
|
||||
break;
|
||||
case 24:
|
||||
W25QXX_Read(mat,foffset+ftinfo.f24addr,csize);
|
||||
break;
|
||||
case 32:
|
||||
W25QXX_Read(mat,foffset+ftinfo.f32addr,csize);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
//显示一个指定大小的汉字
|
||||
//x,y :汉字的坐标
|
||||
//font:汉字GBK码
|
||||
//size:字体大小
|
||||
//mode:0,正常显示,1,叠加显示
|
||||
void Show_Font(unsigned short x,unsigned short y,unsigned char *font,unsigned char size,unsigned char mode)
|
||||
{
|
||||
unsigned char temp,t,t1;
|
||||
unsigned short y0=y;
|
||||
unsigned char dzk[128];
|
||||
unsigned char csize=(size/8+((size%8)?1:0))*(size); //得到字体一个字符对应点阵集所占的字节数
|
||||
if(size!=12&&size!=16&&size!=24&&size!=32)return; //不支持的size
|
||||
Get_HzMat(font,dzk,size); //得到相应大小的点阵数据
|
||||
for(t=0;t<csize;t++)
|
||||
{
|
||||
temp=dzk[t]; //得到点阵数据
|
||||
for(t1=0;t1<8;t1++)
|
||||
{
|
||||
if(temp&0x80)LTDC_Draw_Point(x,y,POINT_COLOR);
|
||||
else if(mode==0)LTDC_Draw_Point(x,y,BACK_COLOR);
|
||||
temp<<=1;
|
||||
y++;
|
||||
if((y-y0)==size)
|
||||
{
|
||||
y=y0;
|
||||
x++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//在指定位置开始显示一个字符串
|
||||
//支持自动换行
|
||||
//(x,y):起始坐标
|
||||
//width,height:区域
|
||||
//str :字符串
|
||||
//size :字体大小
|
||||
//mode:0,非叠加方式;1,叠加方式
|
||||
void Show_Str(unsigned short x,unsigned short y,unsigned short width,unsigned short height,unsigned char*str,unsigned char size,unsigned char mode)
|
||||
{
|
||||
unsigned short x0=x;
|
||||
unsigned short y0=y;
|
||||
unsigned char bHz=0; //字符或者中文
|
||||
while(*str!=0)//数据未结束
|
||||
{
|
||||
if(!bHz)
|
||||
{
|
||||
if(*str>0x80)bHz=1;//中文
|
||||
else //字符
|
||||
{
|
||||
if(x>(x0+width-size/2))//换行
|
||||
{
|
||||
y+=size;
|
||||
x=x0;
|
||||
}
|
||||
if(y>(y0+height-size))break;//越界返回
|
||||
if(*str==13)//换行符号
|
||||
{
|
||||
y+=size;
|
||||
x=x0;
|
||||
str++;
|
||||
}
|
||||
else LCD_ShowChar(x,y,*str,size,mode);//有效部分写入
|
||||
str++;
|
||||
x+=size/2; //字符,为全字的一半
|
||||
}
|
||||
}else//中文
|
||||
{
|
||||
bHz=0;//有汉字库
|
||||
if(x>(x0+width-size))//换行
|
||||
{
|
||||
y+=size;
|
||||
x=x0;
|
||||
}
|
||||
if(y>(y0+height-size))break;//越界返回
|
||||
Show_Font(x,y,str,size,mode); //显示这个汉字,空心显示
|
||||
str+=2;
|
||||
x+=size;//下一个汉字偏移
|
||||
}
|
||||
}
|
||||
}
|
||||
//在指定宽度的中间显示字符串
|
||||
//如果字符长度超过了len,则用Show_Str显示
|
||||
//len:指定要显示的宽度
|
||||
void Show_Str_Mid(unsigned short x,unsigned short y,unsigned char*str,unsigned char size,unsigned char len)
|
||||
{
|
||||
unsigned short strlenth=0;
|
||||
strlenth=strlen((const char*)str);
|
||||
strlenth*=size/2;
|
||||
/*
|
||||
if(strlenth>len)Show_Str(x,y,lcddev.width,lcddev.height,str,size,1);
|
||||
else
|
||||
{
|
||||
strlenth=(len-strlenth)/2;
|
||||
Show_Str(strlenth+x,y,lcddev.width,lcddev.height,str,size,1);
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user