Files
Deshab-OS/CODE/font
xyou efa626ed17 feat: Phase 1 网络端到端打通 + FirstInit/Login/DevMode 完善
- 用户态共享网络协议栈 CODE/tools/net_stack.h(eth/ARP/IPv4/ICMP/UDP-DNS/TCP static inline,轮询模型)
- shell 内建 ping/curl/run 命令;ping.elf/curl.elf 对齐 net_stack.h 真实协议栈
- shell dev_mode 串口镜像(g_serial_mirror)便于自动化验证
- DSK 启动流程:firstInit.txt 双行格式(firstInit + dev_mode),dev_mode=1 触发 shell 自动回归测试
- FirstInit 完成→持久化 USER.CONF + 翻转 firstInit 0->1(保留 dev_mode)
- firstInit=1 时 DSK 加载 login.elf 进行用户选择 + 密码校验后再进 desktop
- 新增 CODE/login/ 登录应用、CODE/DKM/dkm_shared.h、Logo.png
- ahci/e1000/virtio_net/fat32/console_fb 驱动更新;utsm serial/block/dsk_loader 调整
- build.ps1 打包 ping.elf/curl.elf 进 SATA FAT32 根目录
- 移除 CODE/tools/bash(与 shell.elf 重复)
2026-07-26 21:07:36 +08:00
..

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.
# Deshab Bitmap Font (.dbf)

`CODE/font` 包含 Deshab 自研位图字体工具和规范。

## 文件格式

```text
Offset  Size   Field
0       4      magic "DBF\x10" (version 16)
4       4      u32 glyph_count
8       2      u16 default_width
10      2      u16 default_height
12      2      u16 bits_per_pixel (8=grayscale)
14      N×12   index table (N entries)
...     ...    glyph bitmap data
```

每条索引:
```text
[0..1]  u16  codepoint (Unicode BMP)
[2..3]  u16  actual_width (pixels)
[4..7]  u32  data_offset
[8..11] u32  data_size
```

索引按 codepoint 升序排列,可用二分查找。

## 字体文件

| 文件 | 大小 | 字形数 | 精度 |
|------|------|--------|------|
| [simhei_16.dbf](file:///d:/Code/Deshab/SYSTEM/system/font/simhei_16.dbf) | 1.8MB | 6858 | 16×16 8bpp |
| [simhei_24.dbf](file:///d:/Code/Deshab/SYSTEM/system/font/simhei_24.dbf) | 3.9MB | 6858 | 24×24 8bpp |
| [simhei_32.dbf](file:///d:/Code/Deshab/SYSTEM/system/font/simhei_32.dbf) | 6.9MB | 6858 | 32×32 8bpp |

字形覆盖:GB2312 全部 6763 个简体汉字 + ASCII 32–126 可打印字符。

## 生成工具

```bash
python CODE/font/mkfont.py <ttf_path> <pixel_size> <output.dbf>
```

依赖:Python 3 + Pillow (`pip install Pillow`)

## C 头文件

[dbf.h](file:///d:/Code/Deshab/CODE/font/dbf.h) 定义数据结构和二分查找函数:

```c
#include "dbf.h"
const u8 *font = ...; // 加载 .dbf 到内存
dbf_header *hdr = (dbf_header *)font;
dbf_index_entry *idx = (dbf_index_entry *)(font + 14);
int entry = dbf_lookup(idx, hdr->count, codepoint);
if (entry >= 0) {
    u8 *glyph = font + idx[entry].offset;
    u16 w = idx[entry].width;
    u16 h = hdr->height;
    // 逐行渲染 8bpp 灰度位图
}
```

## 使用方式

1. 启动时将 `.dbf` 文件通过 boot module 或 FAT32 加载到内存
2. GBK/GB2312 双字节序列转为 Unicode codepoint 后查表
3. 8bpp 灰度可直接 alpha-blend 到 framebuffer