Files
xInfo/components/chinese_font/include/ChineseFont.h
T
2026-08-31 15:05:13 +08:00

54 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file ChineseFont.h
* @brief 自定义 UTF-8 中文字体系统(16×16 点阵,基于 Unifont)。
*
* 提供 Paint_DrawString_UTF8() 函数,支持中英文混合渲染:
* - ASCII 字符 → 使用原有英文字体引擎
* - 中文字符 → 查自定义 UTF-8 点阵表
*
* 字体数据由 tools/gen_font.py 从 Unifont hex 文件自动生成,
* 存放在 font16cn_data.cpp 中。如需添加新字符,
* 编辑脚本中的 CHARS 列表并重新运行即可。
*/
#ifndef CHINESE_FONT_H
#define CHINESE_FONT_H
#include <cstdint>
/// 单个 UTF-8 中文字符的点阵数据
struct UTF8_Char {
uint8_t index[3]; ///< UTF-8 编码的 3 个字节
uint8_t matrix[32]; ///< 16×16 单色位图 = 16 行 × 2 字节/行 = 32 字节
};
/// UTF-8 中文字体描述
struct UTF8_Font {
const UTF8_Char *table; ///< 字符表(按 Unicode 排序)
uint16_t size; ///< 字符表中的条目数
uint16_t asciiWidth; ///< ASCII 字符宽度(像素)
uint16_t charWidth; ///< 中文字符宽度(像素)
uint16_t charHeight; ///< 字符高度(像素)
};
/// 全局字体实例(定义在 font16cn_data.cpp 中)
extern const UTF8_Font Font16CN;
/**
* @brief 在墨水屏上绘制 UTF-8 中英文混合字符串。
*
* ASCII 部分使用英文字体(sFONT),中文部分查 UTF-8 字体表。
* 不在字体表中的中文字符会被跳过(不显示,不会乱码)。
*
* @param x 起始 X 坐标
* @param y 起始 Y 坐标
* @param str UTF-8 编码的字符串
* @param cnFont 中文字体(UTF8_Font)
* @param fg 前景色
* @param bg 背景色
*/
void Paint_DrawString_UTF8(uint16_t x, uint16_t y, const char *str,
const UTF8_Font &cnFont,
uint16_t fg, uint16_t bg);
#endif // CHINESE_FONT_H