xref: /DragonOS/kernel/src/libs/font/mod.rs (revision b5b571e02693d91eb6918d3b7561e088c3e7ee81)
1 use self::font_type::vga8x16::FONT_VGA_8X16;
2 
3 pub mod font_type;
4 
5 pub struct FontDesc {
6     pub index: usize,
7     pub name: &'static str,
8     pub width: u32,
9     pub height: u32,
10     pub char_count: u32,
11     pub data: &'static [u8],
12 }
13 
14 impl FontDesc {
15     pub fn get_default_font(_xres: u32, _yres: u32, _font_w: u32, _font_h: u32) -> &'static Self {
16         // todo: 目前先直接返回一个字体
17         &FONT_VGA_8X16
18     }
19 
20     pub const DOUBLE_WIDTH_RANGE: &'static [(u32, u32)] = &[
21         (0x1100, 0x115F),
22         (0x2329, 0x232A),
23         (0x2E80, 0x303E),
24         (0x3040, 0xA4CF),
25         (0xAC00, 0xD7A3),
26         (0xF900, 0xFAFF),
27         (0xFE10, 0xFE19),
28         (0xFE30, 0xFE6F),
29         (0xFF00, 0xFF60),
30         (0xFFE0, 0xFFE6),
31         (0x20000, 0x2FFFD),
32         (0x30000, 0x3FFFD),
33     ];
34     pub fn is_double_width(ch: u32) -> bool {
35         if ch < Self::DOUBLE_WIDTH_RANGE.first().unwrap().0
36             || ch > Self::DOUBLE_WIDTH_RANGE.last().unwrap().1
37         {
38             return false;
39         }
40 
41         for (first, last) in Self::DOUBLE_WIDTH_RANGE {
42             if ch > *first && ch < *last {
43                 return true;
44             }
45         }
46 
47         false
48     }
49 }
50