码迷,mamicode.com
首页 > 其他好文 > 详细

为OLED屏增加GUI支持3:字库

时间:2015-12-28 12:27:27      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

为OLED屏增加GUI支持3:字库


本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.

 

环境:

主机:WIN10

开发环境:MDK5.13

MCU:STM32F103


说明:
       GUI中有字库方能显示汉字,英文,数字等。英文数字等ASCII码128个字符保存显示容易,但汉字数万,如果不用字库芯片,用软件保存,则flash明显不够。所以只添加需要显示的汉字。
       本GUI用的显示方法,可以容易的显示不同字体,不同字号的汉字和ASCII码。


源代码及步骤:

1.用工具FontCvt.exe(emwin自带工具)选择需要的字体,字号,以及需要的字符(汉字,ASCII)并生成对应的.c文件


2.将此.c文件转换为指定格式。以下为微软雅黑20号字体的转换后源文件:

FHZ20.c

/**
* Copyright (c), 2015-2025
* @file FHZ20.c
* @brief 20号汉字字库,字体微软雅黑
* @author jdh
* @date 2015/9/6
* @date 2015/9/7
* @date 2015/9/9
*/

/*********************************************************************
*							头文件
**********************************************************************/

#include "font.h"

/*********************************************************************
*							静态变量
**********************************************************************/

/**
* @brief 字符:空
*/
  
unsigned char Hz20_0020[ 20] = { /* code 0020, SPACE */
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_002E[ 20] = { /* code 002E, FULL STOP */
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  ________,
  _XX_____,
  _XX_____,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_0030[ 20] = { /* code 0030, DIGIT ZERO */
  ________,
  ________,
  ________,
  ________,
  ________,
  ___XXX__,
  __X__X__,
  _X____X_,
  _X____X_,
  _X____X_,
  _X____X_,
  _X____X_,
  _X____X_,
  _X____X_,
  __X__X__,
  __XXX___,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_0031[ 20] = { /* code 0031, DIGIT ONE */
  ________,
  ________,
  ________,
  ________,
  ________,
  ____X___,
  __XXX___,
  _XX_X___,
  ____X___,
  ____X___,
  ____X___,
  ____X___,
  ____X___,
  ____X___,
  ____X___,
  ____X___,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_0032[ 20] = { /* code 0032, DIGIT TWO */
  ________,
  ________,
  ________,
  ________,
  ________,
  __XXXX__,
  _X___XX_,
  ______X_,
  ______X_,
  ______X_,
  _____X__,
  ___XX___,
  __XX____,
  _XX_____,
  _X______,
  _XXXXXX_,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_0033[ 20] = { /* code 0033, DIGIT THREE */
  ________,
  ________,
  ________,
  ________,
  ________,
  __XXX___,
  _X___X__,
  _____X__,
  _____X__,
  ____XX__,
  __XX____,
  ____XX__,
  _____X__,
  _____X__,
  _X__XX__,
  __XXX___,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_0034[ 20] = { /* code 0034, DIGIT FOUR */
  ________,
  ________,
  ________,
  ________,
  ________,
  _____X__,
  ____XX__,
  ___XXX__,
  ___X_X__,
  __X__X__,
  _XX__X__,
  XX___X__,
  XXXXXXXX,
  _____X__,
  _____X__,
  _____X__,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_0035[ 20] = { /* code 0035, DIGIT FIVE */
  ________,
  ________,
  ________,
  ________,
  ________,
  _XXXXX__,
  _X______,
  _X______,
  _X______,
  _X______,
  _XXXXX__,
  _____XX_,
  ______X_,
  ______X_,
  _____XX_,
  _XXXX___,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_0036[ 20] = { /* code 0036, DIGIT SIX */
  ________,
  ________,
  ________,
  ________,
  ________,
  ___XXX__,
  __X_____,
  _X______,
  _X______,
  _X_XXX__,
  _XX__XX_,
  _X____X_,
  _X____X_,
  _X____X_,
  __X__X__,
  ___XXX__,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_0037[ 20] = { /* code 0037, DIGIT SEVEN */
  ________,
  ________,
  ________,
  ________,
  ________,
  XXXXXXX_,
  _____X__,
  _____X__,
  ____X___,
  ____X___,
  ___X____,
  ___X____,
  ___X____,
  __X_____,
  __X_____,
  __X_____,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_0038[ 20] = { /* code 0038, DIGIT EIGHT */
  ________,
  ________,
  ________,
  ________,
  ________,
  __XXXX__,
  _XX__XX_,
  _X____X_,
  _X____X_,
  __X__X__,
  __XXXX__,
  _XX__XX_,
  _X____X_,
  _X____X_,
  _XX__XX_,
  __XXXX__,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_0039[ 20] = { /* code 0039, DIGIT NINE */
  ________,
  ________,
  ________,
  ________,
  ________,
  __XXXX__,
  __X__X__,
  _X____X_,
  _X____X_,
  _X____X_,
  _XX__XX_,
  __XXX_X_,
  ______X_,
  _____X__,
  __X__X__,
  __XXX___,
  ________,
  ________,
  ________,
  ________};

unsigned char Hz20_006D[ 40] = { /* code 006D, LATIN SMALL LETTER M */
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  _X_XXX__,XXX_____,
  _XX__XXX,___X____,
  _X____X_,___X____,
  _X____X_,___X____,
  _X____X_,___X____,
  _X____X_,___X____,
  _X____X_,___X____,
  _X____X_,___X____,
  ________,________,
  ________,________,
  ________,________,
  ________,________};

unsigned char Hz20_CBD1[ 40] = { /* code 641C */
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  __X___XX,X_______,
  __X__XX_,XXXXX___,
  XXXXXX__,X___X___,
  __X__XXX,X_XXX___,
  __X__X__,X___X___,
  __XX_XXX,XXXXX___,
  _XXXX___,X_______,
  X_X__XXX,XXXX____,
  __X___X_,__XX____,
  __X____X,_XX_____,
  __X____X,XX______,
  XXX_XXX_,__XXXX__,
  ________,________,
  ________,________,
  ________,________};

unsigned char Hz20_CBF7[ 40] = { /* code 7D22 */
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  _______X,________,
  _XXXXXXX,XXXXX___,
  _______X,________,
  _XXXXXXX,XXXXX___,
  _X___X__,XX__X___,
  _X_XXXXX,X___X___,
  ______X_,_XX_____,
  ____XX__,__XX____,
  __XXXXXX,XXXXX___,
  ____X__X,_X______,
  __XX___X,__XX____,
  XX__XXXX,____X___,
  ________,________,
  ________,________,
  ________,________};

/**
* @brief 字符:正
*/
  
unsigned char Hz20_D5FD[ 40] = { /* code 6B63 */
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  _XXXXXXX,XXXXX___,
  _______X,________,
  _______X,________,
  __X____X,________,
  __X____X,________,
  __X____X,XXXXX___,
  __X____X,________,
  __X____X,________,
  __X____X,________,
  __X____X,________,
  __X____X,________,
  XXXXXXXX,XXXXXX__,
  ________,________,
  ________,________,
  ________,________};

/**
* @brief 字符:常
*/
  
unsigned char Hz20_B3A3[ 40] = { /* code 5E38 */
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  __XX__X_,__XX____,
  ___XX_X_,_XX_____,
  _XXXXXXX,XXXXX___,
  _X______,____X___,
  _X_XXXXX,XXX_X___,
  ___X____,__X_____,
  ___XXXXX,XXX_____,
  _______X,________,
  __XXXXXX,XXXX____,
  __X____X,___X____,
  __X____X,_XXX____,
  _______X,________,
  ________,________,
  ________,________,
  ________,________};

/**
* @brief 字符:超
*/
  
unsigned char Hz20_B3AC[ 40] = { /* code 8D85 */
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ___X__XX,XXXXX___,
  ___X____,X___X___,
  XXXXXX__,X___X___,
  ___X___X,____X___,
  ___X__X_,_XXX____,
  XXXXXX__,________,
  ___X___X,XXXXX___,
  _X_X___X,____X___,
  _X_XXX_X,____X___,
  _X_X___X,XXXXX___,
  X_XX____,________,
  X__XXXXX,XXXXXX__,
  ________,________,
  ________,________,
  ________,________};

/**
* @brief 字符:距
*/

unsigned char Hz20_BEE0[ 40] = { /* code 8DDD */
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  _XXXX__X,XXXXXX__,
  _X__X__X,________,
  _X__X__X,________,
  _XXXX__X,________,
  _X_X___X,XXXXX___,
  ___X___X,____X___,
  _X_XXX_X,____X___,
  _X_X___X,XXXXX___,
  _X_X___X,____X___,
  _X_X___X,________,
  _X_XXX_X,________,
  XXX____X,XXXXXX__,
  ________,________,
  ________,________,
  ________,________};

/**
* @brief 字符:失
*/

unsigned char Hz20_CAA7[ 40] = { /* code 5931 */
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ___X___X,________,
  ___X___X,________,
  __XXXXXX,XXXXX___,
  __X____X,________,
  _X_____X,________,
  _______X,________,
  _XXXXXXX,XXXXXX__,
  ______XX,________,
  ______X_,X_______,
  ____XX__,_X______,
  __XX____,__XX____,
  XX______,____XX__,
  ________,________,
  ________,________,
  ________,________};

/**
* @brief 字符:踪
*/
  
unsigned char Hz20_D7D9[ 40] = { /* code 8E2A */
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  ________,________,
  _XXXX___,_XX_____,
  _X__X_XX,XXXXXX__,
  _X__X_X_,_____X__,
  _XXXX___,________,
  _X_X___X,XXXXX___,
  ___X____,________,
  _X_XX_XX,XXXXXX__,
  _X_X____,_X______,
  _X_X___X,_X_X____,
  _X_X__X_,_X__X___,
  XXX_XX__,_X___X__,
  _______X,XX______,
  ________,________,
  ________,________,
  ________,________};

/*********************************************************************
*							函数
**********************************************************************/

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/

uint8_t GB18030_20X20_get_height(void)
{
	return 20;
}

/**
* @brief 得到地址
* @param font:字体
* @param ch:待读取的字符
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/

uint8_t GB18030_20X20_get_address(uint16_t ch,struct _Font_Type *font_type,uint32_t *addr) 
{ 
	switch (ch)
	{
		//空
		case 0x0020:
		{
			font_type->width = 4;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0020;
			break;
		}
		//.
		case 0x002E:
		{
			font_type->width = 3;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_002E;
			break;
		}
		//0
		case 0x0030:
		{
			font_type->width = 8;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0030;
			break;
		}
		//1
		case 0x0031:
		{
			font_type->width = 8;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0031;
			break;
		}
		//2
		case 0x0032:
		{
			font_type->width = 8;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0032;
			break;
		}
		//3
		case 0x0033:
		{
			font_type->width = 8;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0033;
			break;
		}
		//4
		case 0x0034:
		{
			font_type->width = 8;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0034;
			break;
		}
		//5
		case 0x0035:
		{
			font_type->width = 8;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0035;
			break;
		}
		//6
		case 0x0036:
		{
			font_type->width = 8;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0036;
			break;
		}
		//7
		case 0x0037:
		{
			font_type->width = 8;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0037;
			break;
		}
		//8
		case 0x0038:
		{
			font_type->width = 8;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0038;
			break;
		}
		//9
		case 0x0039:
		{
			font_type->width = 8;
			font_type->height = 20;
			font_type->size = 20;
			*addr = (uint32_t)Hz20_0039;
			break;
		}
		//m
		case 0x006D:
		{
			font_type->width = 13;
			font_type->height = 20;
			font_type->size = 40;
			*addr = (uint32_t)Hz20_006D;
			break;
		}
		//搜
		case 0xCBD1:
		{
			font_type->width = 14;
			font_type->height = 20;
			font_type->size = 40;
			*addr = (uint32_t)Hz20_CBD1;
			break;
		}
		//索
		case 0xCBF7:
		{
			font_type->width = 14;
			font_type->height = 20;
			font_type->size = 40;
			*addr = (uint32_t)Hz20_CBF7;
			break;
		}
		//正
		case 0xD5FD:
		{
			font_type->width = 14;
			font_type->height = 20;
			font_type->size = 40;
			*addr = (uint32_t)Hz20_D5FD;
			break;
		}
		//常
		case 0xB3A3:
		{
			font_type->width = 14;
			font_type->height = 20;
			font_type->size = 40;
			*addr = (uint32_t)Hz20_B3A3;
			break;
		}
		//超
		case 0xB3AC:
		{
			font_type->width = 14;
			font_type->height = 20;
			font_type->size = 40;
			*addr = (uint32_t)Hz20_B3AC;
			break;
		}
		//距
		case 0xBEE0:
		{
			font_type->width = 14;
			font_type->height = 20;
			font_type->size = 40;
			*addr = (uint32_t)Hz20_BEE0;
			break;
		}
		//失
		case 0xCAA7:
		{
			font_type->width = 14;
			font_type->height = 20;
			font_type->size = 40;
			*addr = (uint32_t)Hz20_CAA7;
			break;
		}
		//踪
		case 0xD7D9:
		{
			font_type->width = 14;
			font_type->height = 20;
			font_type->size = 40;
			*addr = (uint32_t)Hz20_D7D9;
			break;
		}
		default:
		{
			return 0;
		}
	}
	
	return 1;
}




3.将对应的字体宏定义填入字库文件头文件中

/**
* @brief 17*17点阵GB18030汉字
*/


#define GB18030_20X20    2



font.h

/**
* Copyright (c), 2015-2025
* @file font.h
* @brief 字库文件头文件
* @author jdh
* @date 2015/9/6
* @date 2015/9/7
*/

#ifndef _FONT_H_
#define _FONT_H_

/*********************************************************************
*							头文件
**********************************************************************/

#include "inf_lcd.h"

/*********************************************************************
*							宏定义
**********************************************************************/

/**
* @brief 点阵字符宏定义
*/

#define	________	0x0
#define	_______X	0x1
#define	______X_	0x2
#define	______XX	0x3
#define	_____X__	0x4
#define	_____X_X	0x5
#define	_____XX_	0x6
#define	_____XXX	0x7
#define	____X___	0x8
#define	____X__X	0x9
#define	____X_X_	0xa
#define	____X_XX	0xb
#define	____XX__	0xc
#define	____XX_X	0xd
#define	____XXX_	0xe
#define	____XXXX	0xf
#define	___X____	0x10
#define	___X___X	0x11
#define	___X__X_	0x12
#define	___X__XX	0x13
#define	___X_X__	0x14
#define	___X_X_X	0x15
#define	___X_XX_	0x16
#define	___X_XXX	0x17
#define	___XX___	0x18
#define	___XX__X	0x19
#define	___XX_X_	0x1a
#define	___XX_XX	0x1b
#define	___XXX__	0x1c
#define	___XXX_X	0x1d
#define	___XXXX_	0x1e
#define	___XXXXX	0x1f
#define	__X_____	0x20
#define	__X____X	0x21
#define	__X___X_	0x22
#define	__X___XX	0x23
#define	__X__X__	0x24
#define	__X__X_X	0x25
#define	__X__XX_	0x26
#define	__X__XXX	0x27
#define	__X_X___	0x28
#define	__X_X__X	0x29
#define	__X_X_X_	0x2a
#define	__X_X_XX	0x2b
#define	__X_XX__	0x2c
#define	__X_XX_X	0x2d
#define	__X_XXX_	0x2e
#define	__X_XXXX	0x2f
#define	__XX____	0x30
#define	__XX___X	0x31
#define	__XX__X_	0x32
#define	__XX__XX	0x33
#define	__XX_X__	0x34
#define	__XX_X_X	0x35
#define	__XX_XX_	0x36
#define	__XX_XXX	0x37
#define	__XXX___	0x38
#define	__XXX__X	0x39
#define	__XXX_X_	0x3a
#define	__XXX_XX	0x3b
#define	__XXXX__	0x3c
#define	__XXXX_X	0x3d
#define	__XXXXX_	0x3e
#define	__XXXXXX	0x3f
#define	_X______	0x40
#define	_X_____X	0x41
#define	_X____X_	0x42
#define	_X____XX	0x43
#define	_X___X__	0x44
#define	_X___X_X	0x45
#define	_X___XX_	0x46
#define	_X___XXX	0x47
#define	_X__X___	0x48
#define	_X__X__X	0x49
#define	_X__X_X_	0x4a
#define	_X__X_XX	0x4b
#define	_X__XX__	0x4c
#define	_X__XX_X	0x4d
#define	_X__XXX_	0x4e
#define	_X__XXXX	0x4f
#define	_X_X____	0x50
#define	_X_X___X	0x51
#define	_X_X__X_	0x52
#define	_X_X__XX	0x53
#define	_X_X_X__	0x54
#define	_X_X_X_X	0x55
#define	_X_X_XX_	0x56
#define	_X_X_XXX	0x57
#define	_X_XX___	0x58
#define	_X_XX__X	0x59
#define	_X_XX_X_	0x5a
#define	_X_XX_XX	0x5b
#define	_X_XXX__	0x5c
#define	_X_XXX_X	0x5d
#define	_X_XXXX_	0x5e
#define	_X_XXXXX	0x5f
#define	_XX_____	0x60
#define	_XX____X	0x61
#define	_XX___X_	0x62
#define	_XX___XX	0x63
#define	_XX__X__	0x64
#define	_XX__X_X	0x65
#define	_XX__XX_	0x66
#define	_XX__XXX	0x67
#define	_XX_X___	0x68
#define	_XX_X__X	0x69
#define	_XX_X_X_	0x6a
#define	_XX_X_XX	0x6b
#define	_XX_XX__	0x6c
#define	_XX_XX_X	0x6d
#define	_XX_XXX_	0x6e
#define	_XX_XXXX	0x6f
#define	_XXX____	0x70
#define	_XXX___X	0x71
#define	_XXX__X_	0x72
#define	_XXX__XX	0x73
#define	_XXX_X__	0x74
#define	_XXX_X_X	0x75
#define	_XXX_XX_	0x76
#define	_XXX_XXX	0x77
#define	_XXXX___	0x78
#define	_XXXX__X	0x79
#define	_XXXX_X_	0x7a
#define	_XXXX_XX	0x7b
#define	_XXXXX__	0x7c
#define	_XXXXX_X	0x7d
#define	_XXXXXX_	0x7e
#define	_XXXXXXX	0x7f
#define	X_______	0x80
#define	X______X	0x81
#define	X_____X_	0x82
#define	X_____XX	0x83
#define	X____X__	0x84
#define	X____X_X	0x85
#define	X____XX_	0x86
#define	X____XXX	0x87
#define	X___X___	0x88
#define	X___X__X	0x89
#define	X___X_X_	0x8a
#define	X___X_XX	0x8b
#define	X___XX__	0x8c
#define	X___XX_X	0x8d
#define	X___XXX_	0x8e
#define	X___XXXX	0x8f
#define	X__X____	0x90
#define	X__X___X	0x91
#define	X__X__X_	0x92
#define	X__X__XX	0x93
#define	X__X_X__	0x94
#define	X__X_X_X	0x95
#define	X__X_XX_	0x96
#define	X__X_XXX	0x97
#define	X__XX___	0x98
#define	X__XX__X	0x99
#define	X__XX_X_	0x9a
#define X__XX_XX	0x9b
#define X__XXX__	0x9c
#define X__XXX_X	0x9d
#define	X__XXXX_	0x9e
#define	X__XXXXX	0x9f
#define	X_X_____	0xa0
#define	X_X____X	0xa1
#define	X_X___X_	0xa2
#define	X_X___XX	0xa3
#define	X_X__X__	0xa4
#define	X_X__X_X	0xa5
#define	X_X__XX_	0xa6
#define	X_X__XXX	0xa7
#define	X_X_X___	0xa8
#define	X_X_X__X	0xa9
#define	X_X_X_X_	0xaa
#define	X_X_X_XX	0xab
#define	X_X_XX__	0xac
#define	X_X_XX_X	0xad
#define	X_X_XXX_	0xae
#define	X_X_XXXX	0xaf
#define	X_XX____	0xb0
#define X_XX___X	0xb1
#define	X_XX__X_	0xb2
#define	X_XX__XX	0xb3
#define	X_XX_X__	0xb4
#define	X_XX_X_X	0xb5
#define	X_XX_XX_	0xb6
#define	X_XX_XXX	0xb7
#define	X_XXX___	0xb8
#define	X_XXX__X	0xb9
#define	X_XXX_X_	0xba
#define	X_XXX_XX	0xbb
#define	X_XXXX__	0xbc
#define	X_XXXX_X	0xbd
#define	X_XXXXX_	0xbe
#define	X_XXXXXX	0xbf
#define	XX______	0xc0
#define	XX_____X	0xc1
#define	XX____X_	0xc2
#define	XX____XX	0xc3
#define	XX___X__	0xc4
#define	XX___X_X	0xc5
#define	XX___XX_	0xc6
#define	XX___XXX	0xc7
#define	XX__X___	0xc8
#define	XX__X__X	0xc9
#define	XX__X_X_	0xca
#define	XX__X_XX	0xcb
#define	XX__XX__	0xcc
#define	XX__XX_X	0xcd
#define	XX__XXX_	0xce
#define XX__XXXX	0xcf
#define	XX_X____	0xd0
#define	XX_X___X	0xd1
#define	XX_X__X_	0xd2
#define	XX_X__XX	0xd3
#define	XX_X_X__	0xd4
#define	XX_X_X_X	0xd5
#define	XX_X_XX_	0xd6
#define	XX_X_XXX	0xd7
#define	XX_XX___	0xd8
#define	XX_XX__X	0xd9
#define	XX_XX_X_	0xda
#define	XX_XX_XX	0xdb
#define	XX_XXX__	0xdc
#define	XX_XXX_X	0xdd
#define	XX_XXXX_	0xde
#define	XX_XXXXX	0xdf
#define	XXX_____	0xe0
#define	XXX____X	0xe1
#define	XXX___X_	0xe2
#define	XXX___XX	0xe3
#define	XXX__X__	0xe4
#define	XXX__X_X	0xe5
#define	XXX__XX_	0xe6
#define	XXX__XXX	0xe7
#define	XXX_X___	0xe8
#define	XXX_X__X	0xe9
#define	XXX_X_X_	0xea
#define	XXX_X_XX	0xeb
#define	XXX_XX__	0xec
#define	XXX_XX_X	0xed
#define	XXX_XXX_	0xee
#define	XXX_XXXX	0xef
#define	XXXX____	0xf0
#define	XXXX___X	0xf1
#define	XXXX__X_	0xf2
#define	XXXX__XX	0xf3
#define	XXXX_X__	0xf4
#define	XXXX_X_X	0xf5
#define	XXXX_XX_	0xf6
#define	XXXX_XXX	0xf7
#define	XXXXX___	0xf8
#define	XXXXX__X	0xf9
#define	XXXXX_X_	0xfa
#define	XXXXX_XX	0xfb
#define	XXXXXX__	0xfc
#define	XXXXXX_X	0xfd
#define	XXXXXXX_	0xfe
#define	XXXXXXXX	0xff

/*********************************************************************
*							字体定义
**********************************************************************/

/**
* @brief 17*17点阵GB18030汉字
*/

#define GB18030_17X17				1

/**
* @brief 17*17点阵GB18030汉字
*/

#define GB18030_20X20				2

/**
* @brief 24*24点阵GB18030汉字
*/

#define GB18030_24X24				3

/**
* @brief 30*30点阵GB18030汉字
*/

#define GB18030_30X30				4

/**
* @brief 37*37点阵粗体GB18030汉字
*/

#define GB18030_37X37B				5

/**
* @brief 40*40点阵粗体GB18030汉字
*/

#define GB18030_40X40B				6

/**
* @brief 48*48点阵GB18030汉字
*/

#define GB18030_48X48				7

/*********************************************************************
*							数据结构
**********************************************************************/

/**
* @brief 字体结构
*/

struct _Font_Type
{
	uint8_t width;
	uint8_t height;
	uint8_t size;
};

/*********************************************************************
*							函数
**********************************************************************/

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/

uint8_t font_get_height(uint8_t font);

/**
* @brief 读取字库
* @param font:字体
* @param c:待读取的字符
* @param font_type:返回的字体信息
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/

uint8_t font_read(uint8_t font,uint16_t c,struct _Font_Type *font_type,uint32_t *addr);

#endif



4.将对应的接口填入字库文件源文件中

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/


extern uint8_t GB18030_20X20_get_height(void);


/**
* @brief 得到地址
* @param font:字体
* @param ch:待读取的字符
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/


extern uint8_t GB18030_20X20_get_address(uint16_t ch,struct _Font_Type *font_type,uint32_t *addr);


font_get_height函数与font_read函数也需要做对应修改。


font.c:

/**
* Copyright (c), 2015-2025
* @file font.c
* @brief 字库文件主文件
* @author jdh
* @date 2015/9/6
* @date 2015/9/7
*/

/*********************************************************************
*							头文件
**********************************************************************/

#include "font.h"
#include "string.h"

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/

extern uint8_t GB18030_17X17_get_height(void);

/**
* @brief 得到地址
* @param font:字体
* @param ch:待读取的字符
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/

extern uint8_t GB18030_17X17_get_address(uint16_t ch,struct _Font_Type *font_type,uint32_t *addr);

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/

extern uint8_t GB18030_20X20_get_height(void);

/**
* @brief 得到地址
* @param font:字体
* @param ch:待读取的字符
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/

extern uint8_t GB18030_20X20_get_address(uint16_t ch,struct _Font_Type *font_type,uint32_t *addr);

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/

extern uint8_t GB18030_24X24_get_height(void);
	
/**
* @brief 得到地址
* @param font:字体
* @param ch:待读取的字符
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/

extern uint8_t GB18030_24X24_get_address(uint16_t ch,struct _Font_Type *font_type,uint32_t *addr);

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/

extern uint8_t GB18030_30X30_get_height(void);
	
/**
* @brief 得到地址
* @param font:字体
* @param ch:待读取的字符
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/

extern uint8_t GB18030_30X30_get_address(uint16_t ch,struct _Font_Type *font_type,uint32_t *addr);

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/

uint8_t GB18030_37X37B_get_height(void);

/**
* @brief 得到地址
* @param font:字体
* @param ch:待读取的字符
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/

uint8_t GB18030_37X37B_get_address(uint16_t ch,struct _Font_Type *font_type,uint32_t *addr);

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/

uint8_t GB18030_40X40B_get_height(void);

/**
* @brief 得到地址
* @param font:字体
* @param ch:待读取的字符
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/

uint8_t GB18030_40X40B_get_address(uint16_t ch,struct _Font_Type *font_type,uint32_t *addr);

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/

uint8_t GB18030_48X48_get_height(void);

/**
* @brief 得到地址
* @param font:字体
* @param ch:待读取的字符
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/

uint8_t GB18030_48X48_get_address(uint16_t ch,struct _Font_Type *font_type,uint32_t *addr);

/*********************************************************************
*							静态变量
**********************************************************************/

///**
//* @brief 字体结构
//*/

//static struct _Font_Type Font_Type[FONT_NUM + 1];

///*********************************************************************
//*							静态函数
//**********************************************************************/

///**
//* @brief 初始化字体类型
//*/

//static void init_font_type(void);

/*********************************************************************
*							函数
**********************************************************************/

/**
* @brief 得到字体高度
* @param font:字体
* @retval 高度
*/

uint8_t font_get_height(uint8_t font)
{
	switch (font)
	{
		case GB18030_17X17:
		{
			return GB18030_17X17_get_height();
		}
		case GB18030_20X20:
		{
			return GB18030_20X20_get_height();
		}
		case GB18030_24X24:
		{
			return GB18030_24X24_get_height();
		}
		case GB18030_30X30:
		{
			return GB18030_30X30_get_height();
		}
		case GB18030_37X37B:
		{
			return GB18030_37X37B_get_height();
		}
		case GB18030_40X40B:
		{
			return GB18030_40X40B_get_height();
		}
		case GB18030_48X48:
		{
			return GB18030_48X48_get_height();
		}
		default:
		{
			return 0;
		}
	}
}

/**
* @brief 读取字库
* @param font:字体
* @param c:待读取的字符
* @param font_type:返回的字体信息
* @param addr:数据存储地址
* @retval 读取结果.0:失败,1:成功
*/

uint8_t font_read(uint8_t font,uint16_t c,struct _Font_Type *font_type,uint32_t *addr)
{	
	switch (font)
	{
		case GB18030_17X17:
		{
			if (GB18030_17X17_get_address(c,font_type,addr))
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		case GB18030_20X20:
		{
			if (GB18030_20X20_get_address(c,font_type,addr))
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		case GB18030_24X24:
		{
			if (GB18030_24X24_get_address(c,font_type,addr))
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		case GB18030_30X30:
		{
			if (GB18030_30X30_get_address(c,font_type,addr))
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		case GB18030_37X37B:
		{
			if (GB18030_37X37B_get_address(c,font_type,addr))
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		case GB18030_40X40B:
		{
			if (GB18030_40X40B_get_address(c,font_type,addr))
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		case GB18030_48X48:
		{
			if (GB18030_48X48_get_address(c,font_type,addr))
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		default:
		{
			return 0;
		}
	}
}



5.读取并显示可参考以下函数:
/**
* @brief 在指定位置显示单个字符
* @param x:x坐标
* @param y:y坐标
* @param font:字体
* @param c:字符
*/

void gui_disp_char_at(uint16_t x,uint16_t y,uint8_t font,uint16_t c)
{
	struct _Font_Type font_type;
	//uint8_t buf[100] = {0};
	uint8_t *buf_pt = 0;
	uint16_t i = 0;
	uint16_t j = 0;
	uint8_t k = 0;
	uint8_t bit = 0;
	uint8_t num_valid_bit = 0;
	uint8_t num_valid_byte = 0;
	
//	//读取字体信息
//	font_type = font_read_type(font);
	//读取字符信息
	font_read(font,c,&font_type,(uint32_t *)&buf_pt);
	//buf_pt = buf;
	
	//有效位数
	num_valid_bit = font_type.width % 8;
	//有效字节数
	num_valid_byte = font_type.width / 8;
	for (i = 0;i < font_type.height;i++)
	{
		for (j = 0;j < num_valid_byte;j++)
		{
			for (k = 0;k < 8;k++)
			{
				bit = (*buf_pt >> (7 - k)) & 0x1;
				gui_interface_draw_pixel(x + j * 8 + k,y + i,bit);
			}
			buf_pt++;
		}
		for (k = 0;k < num_valid_bit;k++)
		{
			bit = (*buf_pt >> (7 - k)) & 0x1;
			gui_interface_draw_pixel(x + j * 8 + k,y + i,bit);
		}
		if (num_valid_bit > 0)
		{
			buf_pt++;
		}
	}
}

例:
gui_disp_char_at(0,0,GB18030_20X20,"正")






为OLED屏增加GUI支持3:字库

标签:

原文地址:http://blog.csdn.net/jdh99/article/details/50416962

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!