This commit is contained in:
huxi
2025-12-03 11:12:34 +08:00
parent c23ae4f24c
commit bc195654bf
8163 changed files with 3799544 additions and 92 deletions
+220
View File
@@ -0,0 +1,220 @@
#ifndef __FONT_ALL_H__
#define __FONT_ALL_H__
#include "generic/typedef.h"
#include "font/font_sdfs.h"
typedef struct {
u8 width;
u8 size;
u16 addr;
} ASCSTRUCT;
typedef struct {
unsigned int width: 6;
unsigned int height: 6;
unsigned int addr: 20;
} ASCSTRUCTV2;
//标志位
#define FONT_GET_WIDTH 0x01 /* 获取文本宽度 */
#define FONT_SHOW_PIXEL 0x02 /* 显示单行文本 */
#define FONT_SHOW_MULTI_LINE 0x04 /* 显示多行文本(默认显示一行) */
#define FONT_SHOW_SCROLL 0x08 /* 滚动显示*/
#define FONT_HIGHLIGHT_SCROLL 0x10 /* 高亮滚动显示*/
#define FONT_VERTICAL_SCROLL 0x20 /* 垂直滚动显示*/
#define FONT_SCROLL_CIRCULAR 0x40 /* 首尾相接的环形滚动*/
#define FONT_DEFAULT (FONT_SHOW_PIXEL)
#define FONT_ENCODE_ANSI 0x00 /* 内码格式 */
#define FONT_ENCODE_UNICODE 0x01 /* unicode编码格式 */
#define FONT_ENCODE_UTF8 0x02 /* utf8编码格式 */
#define FONT_ENDIAN_BIG 0x00 /* utf16 大端 */
#define FONT_ENDIAN_SMALL 0x01 /* utf16 小端 */
extern const int FONT_USE_PTR;
extern const int ARABIC_MODE_SWITCH;
extern const int HEBREW_MODE_SWITCH;
extern const int THAI_MODE_SWITCH;
extern const int MYANMAR_MODE_SWITCH;
extern const int BENGALI_MODE_SWITCH;
extern const int KHMER_MODE_SWITCH;
extern const int INDIC_MODE_SWITCH;
extern const int TIBETAN_MODE_SWITCH;
extern const int MIXLEFT_MODE_SWITCH;
extern const int MIXRIGHT_MODE_SWITCH;
extern const int FONT_UNIC_SWITCH;
struct font_file {
char *name;
FILE *fd;
};
struct font {
struct font_file file;
u16 nbytes;
u8 size;
u8 version;
u8 *pixelbuf;
};
struct dispbuf {
int format;
u32 color;
void *rect;
void *map;
};
enum FONT_STATUS {
FT_ERROR_NONE,
FT_ERROR_NOPIXFILE = 0x01, //没有字模文件
FT_ERROR_NOASCPIXFILE = 0x02, //没有ASCII字模文件
FT_ERROR_NOTABFILE = 0x04, //没有TAB文件
FT_ERROR_NOMEM = 0x08, //内存不足
FT_ERROR_CODEPAGE = 0x10, //代码页错误
};
enum BIT_DEPTH {
BIT_DEPTH_1BPP,
BIT_DEPTH_2BPP,
BIT_DEPTH_4BPP,
BIT_DEPTH_8BPP,
};
struct font_info {
struct font ascpixel; //ASCII像素
struct font pixel; //像素
struct font_file tabfile; //UNICODE转内码文件
struct font_file extfile; //UNICODE转内码文件
u8 sta; //状态
u8 ratio; //放大倍数,默认为1
u8 language_id; //语言ID
u8 bigendian; //大端模式(unicode编码)
u8 isgb2312; //是否GB2312,用以区分GBK以及GB2312字库
u8 codepage; //代码页
u16 x;
u16 y;
u16 text_width; //文本宽度
u16 text_height; //文本高度
u16 string_width; //字符串宽度
u16 string_height; //字符串高度
u16 offset; //显示偏移
u32 flags; //标志位
u8 *text_image_buf; //文本点阵缓存buf
u32 text_image_buf_size; //文本点阵缓存buf size
u32 text_image_stride; //文本点阵缓存buf对齐宽度
u16 text_image_width; //文本点阵缓存buf实际宽度
u16 text_image_height; //文本点阵缓存buf实际高度
struct dispbuf disp; //显示相关信息
void (*putchar)(struct font_info *info, u8 *pixel, u16 width, u16 height, u16 x, u16 y);
void *dc;
u16 line_num;
u16 default_code; //字库文件中不存在待显示字符时的默认替换字符编码
void *text;
short word_space; //补充字间距
short line_space; //补充行间距
short xpos_offset;
short extra_word_space_for_dep;
u32 tool_version;
int top_extra_fill : 16;
int bottom_extra_fill : 15;
int mix_start : 1;
u16 *each_line_width_info;
};
typedef struct {
u32 width : 6;
u32 height : 7;
s32 top : 8;
u32 size : 11;
s32 left : 7;
u32 addr : 25;
u8 advance_x;
} __attribute__((packed, aligned(1))) UnicInfo_new;
typedef struct {
u8 width;
u8 height;
s8 left;
s8 top;
u32 addr;
} __attribute__((packed, aligned(1))) UnicInfo_old;
typedef struct {
u8 width;
u8 height;
s8 left;
s8 top;
u8 advance_x;
} __attribute__((packed, aligned(1))) UnicInfo;
#define font_ntohl(x) (unsigned long)((x>>24)|((x>>8)&0xff00)|(x<<24)|((x&0xff00)<<8))
#define font_ntoh(x) (unsigned short int )((x>>8&0x00ff)|x<<8&0xff00)
extern const struct font_info font_info_table[];
typedef struct {
u8 codepage;
u32 ansi_offset;
u32 table_offset;
} LANG_TABLE;
struct font_new_cb_priv {
u8 *pixbuf;
u16 color;
short x;
short y;
u16 width;
u16 height;
u16 bufsize;
u16 dis_width;
u16 scroll_offset;
};
#define CP874 (1)
#define CP937 (2)
#define CP1250 (3)
#define CP1251 (4)
#define CP1252 (5)
#define CP1253 (6)
#define CP1254 (7)
#define CP1255 (8)
#define CP1256 (9)
#define CP1257 (10)
#define CP1258 (11)
#define CPKSC (12)
#define CPSJIS (13)
#define CPBIG5 (14)
#define INDIC (15)
#define TIBETAN (16)
/**
* @brief 设置内码偏移表,混合内码字库需要 *
* @param table 内码偏移表地址
* @returns 0
*/
extern int font_set_offset_table(const LANG_TABLE *table);
/* 内码偏移表 */
extern const LANG_TABLE *lange_info_table;
/**
* @brief 获取字库位深
*
* @returns 字库位深
*/
extern int Font_GetBitDepth();
/***************************************************************/
#include "font/font_textout.h"
#endif
+23
View File
@@ -0,0 +1,23 @@
#ifndef __UI_SDFS_H__
#define __UI_SDFS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "generic/typedef.h"
#include "fs/fs.h"
#define SD_SEEK_SET 0x00
#define SD_SEEK_CUR 0x01
FILE *font_sd_fopen(const char *filename, void *arg);
int font_sd_fread(FILE *fp, void *buf, u32 len);
int font_sd_fseek(FILE *fp, u8 seek_mode, u32 offset);
int font_sd_fclose(FILE *fp);
#ifdef __cplusplus
}
#endif
#endif
+206
View File
@@ -0,0 +1,206 @@
#ifndef __FONT_OUT_H__
#define __FONT_OUT_H__
#include "generic/typedef.h"
#include "font/font_all.h"
#include "font/font_unic.h"
/**
* @brief 打开字库
*
* @param info:字库信息
* @param language:语言id
*
* @returns TRUE:打开成功 FALSE:打开失败
*/
struct font_info *font_open(struct font_info *info, u8 language);
/**
* @brief 关闭字库,释放相关资源
*
* @param info
*/
void font_close(struct font_info *info);
/**
* @brief 获取内码字符宽度
*
* @param info
* @param str
* @param strlen
*
* @returns 字符串宽度
*/
u16 font_text_width(struct font_info *info, u8 *str, u16 strlen);
/**
* @brief 获取unicode编码字符宽度
*
* @param info
* @param str
* @param strlen
*
* @returns 字符串宽度
*/
u16 font_textw_width(struct font_info *info, u8 *str, u16 strlen);
/**
* @brief 获取utf8编码字符宽度
*
* @param info
* @param str
* @param strlen
*
* @returns 字符串宽度
*/
u16 font_textu_width(struct font_info *info, u8 *str, u16 strlen);
/**
* @brief 设置字库语言id
*
* @param language
*
* @returns
*/
void font_lang_set(int language);
/**
* @brief 获取字库语言id *
*
* @returns 字库语言id
*/
int font_lang_get();
// 字库换行方式 value == 1:换行时考虑单词整体性, value == 0:强制换行; 默认为1
void font_smart_line_break_set(u8 value);
/**
* @brief 字库内码显示接口
*
* @param info
* @param str
* @param strlen
*
* @returns 实际显示的编码长度
*/
u16 font_textout(struct font_info *info, u8 *str, u16 strlen, u16 x, u16 y);
/**
* @brief 字库unicode显示接口
*
* @param info
* @param str
* @param strlen
* @param x 显示起始x坐标
* @param y 显示起始Y坐标
*
* @returns 实际显示的编码长度
*/
u16 font_textout_unicode(struct font_info *info, u8 *str, u16 strlen, u16 x, u16 y);
/**
* @brief 字库utf8显示接口
*
* @param info
* @param str
* @param strlen
* @param x 显示起始x坐标
* @param y 显示起始Y坐标
*
* @returns 实际显示的编码长度
*/
u16 font_textout_utf8(struct font_info *info, u8 *str, u16 strlen, u16 x, u16 y);
/**
* @brief utf8转内码
*
* @param info
* @param utf8
* @param utf8len
* @param ansi
*
* @returns 内码长度
*/
u16 font_utf8toansi(struct font_info *info, u8 *utf8, u16 utf8len, u8 *ansi);
/**
* @brief utf16转内码
*
* @param info
* @param utf
* @param len
* @param ansi
*
* @returns 内码长度
*/
u16 font_utf16toansi(struct font_info *info, u8 *utf, u16 len, u8 *ansi);
/**
* @brief utf8转utf16
*
* @param info
* @param utf8
* @param utf8len
* @param utf16
*
* @returns utf16长度
*/
u16 font_utf8toutf16(struct font_info *info, u8 *utf8, u16 utf8len, u16 *utf16);
/**
* @brief 字库层malloc接口,弱函数,用户可自定义
*
* @param size 申请大小(byte)
* @returns buf地址
*/
void *font_malloc(size_t size);
/**
* @brief 字库层zalloc接口,弱函数,用户可自定义
*
* @param size 申请大小(byte)
* @returns buf地址
*/
void *font_zalloc(size_t size);
/**
* @brief 字库层free接口,弱函数,用户可自定义
*
* @param pv 待释放内存地址
*/
void font_free(void *pv);
/**
* @brief 字库多行显示时用于记录每行宽度信息,多行居中的功能需要
*
* @param info 字库结构体
*/
int font_create_each_line_width_info(struct font_info *info);
/**
* @brief 字库释放多行信息
*
* @param info 字库结构体
*/
void font_release_each_line_width_info(struct font_info *info);
#endif
+95
View File
@@ -0,0 +1,95 @@
#ifndef __FONT_UNIC_H__
#define __FONT_UNIC_H__
#include "generic/typedef.h"
#define PIXEL_TO_BASE_LINE(x) (((x)*26/32)+1)
/* 0xe00->0xe7f:Thai Unicode编码范围 */
/* 0x900->0x97f:Indic Unicode编码范围 */
/* 0x600->0x6ff:Arabic Unicode编码范围 */
/* 0x590->0x5ff:Hebrew Unicode编码范围 */
/* 0xf00->0xfff:Tibetan Unicode编码范围 */
enum unic_type {
UNIC_ERR,
UNIC_THAI,
UNIC_INDIC,
UNIC_ARABIC,
UNIC_HEBREW,
UNIC_TIBETAN,
UNIC_MYANMAR,
UNIC_BENGALI,
UNIC_KHMER,
UNIC_OTHER
};
enum myanmar_type {
myanmar_top,
myanmar_below,
myanmar_103c,
myanmar_half,
myanmar_follow,
myanmar_other,
};
int Font_GetCharBits(struct font_info *info, u16 unicode);
int Font_GetCharWidth(struct font_info *info, u16 unicode);
UnicInfo *Font_GetCharbuf(struct font_info *info, u16 unicode);
UnicInfo *Font_GetCharUnicInfo(struct font_info *info, u16 unicode);
bool InitFont_Unicode(struct font_info *info);
u16 TextOutW_Unicode(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
u16 TextOutW_UnicMixRightword(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
u16 TextOutW_UnicMixLeftword(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
u8 font_code_inrang(u16 code, const u16 *unicbuf, u16 len);
u16 font_left_drawbuf(struct font_info *info, u16(*buffer)[2], int *buffer_data, int *offset_xy);
u16 font_left_get_offset(struct font_info *info, u16(*buffer)[2], int *buffer_data, int left_width);
u16 font_left_get_width(struct font_info *info, u16(*buffer)[2], u16 len);
//缅甸语
enum myanmar_type font_myanmar_get_type(u16 code);
void font_myanmar_update(u16 *unicbuf, u16 len);
u16 font_myanmar_replace(struct font_info *info, u16 *unicbuf, u16 len);
void find_syllables_myanmar(uint16_t *buffer, uint32_t len, uint8_t *syllable);
u16 font_myanmar_drawbuf(struct font_info *info, u16(*buffer)[2], u16 len, int x, int y, int *offset_xy);
u16 TextOutW_UnicMyanmar(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
//孟加拉语
u8 bengali_getBaseType(u16 base);
int bengali_getMarkIndex(u16 code);
u16 font_bengali_type4_replace(struct font_info *info, u16 *unicbuf, u16 len);
u16 font_bengali_type6_replace(struct font_info *info, u16 *unicbuf, u16 len);
void bengali_getOffset(u16 text, u16 prev_text, s8 *offsety);
u16 font_bengali_reorder(struct font_info *info, u16 *unicbuf, u16 len);
u16 font_bengali_drawbuf(struct font_info *info, u16(*buffer)[2], u16 len, int x, int y, int *offset_xy);
u16 TextOutW_UnicBengali(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
//高棉语
u16 font_khmer_get_mark_type(u16 *curr, u16 *prev, u16 *next);
u16 font_khmer_replace(struct font_info *info, u16 *unicbuf, u16 len);
u16 font_khmer_reorder(struct font_info *info, u16 *unicbuf, u16 len);
u16 font_khmer_drawbuf(struct font_info *info, u16(*buffer)[2], u16 len, int x, int y, int *offset_xy);
u16 TextOutW_UnicKhmer(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
//希伯来语
u16 TextOutW_Hebrew(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
u16 TextOutW_UnicHebrew(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
//藏语
u16 TextOutW_Tibetan(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
u16 TextOutW_UnicTibetan(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
u16 font_tibetan_drawbuf(struct font_info *info, u16(*buffer)[2], u16 len, int x, int y, int *offset_xy);
u16 TextW_TibetanReplace(struct font_info *info, u16 *str_buf, u16 len);
//印地语
u16 TextOutW_Indic(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
u16 TextOutW_UnicIndic(struct font_info *info, u8 *str, u16 len, u16 x, u16 y);
void find_syllables_indic(uint16_t *buffer, uint32_t len, uint8_t *syllable);
u16 TextW_IndicReorder(struct font_info *info, u8 *str, u16 len);
u16 TextW_IndicReplace(struct font_info *info, u8 *str, u16 len);
u16 font_indic_drawbuf(struct font_info *info, u16(*buffer)[2], u16 len, int x, int y, int *offset_xy);
#endif
@@ -0,0 +1,38 @@
#ifndef __LANGUAGE_LIST_H__
#define __LANGUAGE_LIST_H__
#define Chinese_Simplified 1 //简体中文
#define Chinese_Traditional 2 //繁体中文
#define Japanese 3 //日语
#define Korean 4 //韩语
#define English 5 //英语
#define French 6 //法语
#define German 7 //德语
#define Italian 8 //意大利语
#define Dutch 9 //荷兰语
#define Portuguese 10 //葡萄牙语
#define Spanish 11 //西班牙语
#define Swedish 12 //瑞典语
#define Czech 13 //捷克语
#define Danish 14 //丹麦语
#define Polish 15 //波兰语
#define Russian 16 //俄语
#define Turkey 17 //土耳其语
#define Hebrew 18 //希伯来语
#define Thai 19 //泰语
#define Hungarian 20 //匈牙利语
#define Romanian 21 //罗马尼亚语
#define Arabic 22 //阿拉伯语
#define Vietnam 23 //越南语
#define Malay 24 //马来语
#define Tibetan 25 //藏文
#define Indic 26 //印地语
#define Myanmar 27 //缅甸语
#define Bengali 28 //孟加拉语
#define Khmer 29 //高棉语
#define MixAllLanguage 60 //混合语言
#define UnicodeMixRightword 61 //Unicode正向混合
#define UnicodeMixLeftword 62 //Unicode反向混合
#define Unicode 63 //Unicode
#endif