1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
3 | |
4 | use crate::slice::Slice; |
5 | |
6 | #[repr (C)] |
7 | #[derive (Debug)] |
8 | /// A pre-rendered glyph with the alpha map and associated metrics |
9 | pub struct BitmapGlyph { |
10 | /// The starting x-coordinate for the glyph, relative to the base line |
11 | /// This is a fixed point number that is shifted by 6 bits |
12 | pub x: i16, |
13 | /// The starting y-coordinate for the glyph, relative to the base line |
14 | /// This is a fixed point number that is shifted by 6 bits |
15 | pub y: i16, |
16 | /// The width of the glyph in pixels |
17 | pub width: i16, |
18 | /// The height of the glyph in pixels |
19 | pub height: i16, |
20 | /// The horizontal distance to the next glyph |
21 | /// This is a fixed point number that is shifted by 6 bits |
22 | pub x_advance: i16, |
23 | /// The 8-bit alpha map that's to be blended with the current text color |
24 | /// or 8-bit signed distance field depending on `BitmapFont::sdf` |
25 | pub data: Slice<'static, u8>, |
26 | } |
27 | |
28 | #[repr (C)] |
29 | #[derive (Debug)] |
30 | /// A set of pre-rendered bitmap glyphs at a fixed pixel size |
31 | pub struct BitmapGlyphs { |
32 | /// The font size in pixels at which the glyphs were pre-rendered. The boundaries of glyphs may exceed this |
33 | /// size, if the font designer has chosen so. This is only used for matching. |
34 | pub pixel_size: i16, |
35 | /// The data of the pre-rendered glyphs |
36 | pub glyph_data: Slice<'static, BitmapGlyph>, |
37 | } |
38 | |
39 | #[repr (C)] |
40 | #[derive (Debug)] |
41 | /// An entry in the character map of a [`BitmapFont`]. |
42 | pub struct CharacterMapEntry { |
43 | /// The unicode code point for a given glyph |
44 | pub code_point: char, |
45 | /// The corresponding index in the `glyph_data` of [`BitmapGlyphs`] |
46 | pub glyph_index: u16, |
47 | } |
48 | |
49 | #[repr (C)] |
50 | #[derive (Debug)] |
51 | /// A subset of an originally scalable font that's rendered ahead of time. |
52 | pub struct BitmapFont { |
53 | /// The family name of the font |
54 | pub family_name: Slice<'static, u8>, |
55 | /// A vector of code points and their corresponding glyph index, sorted by code point. |
56 | pub character_map: Slice<'static, CharacterMapEntry>, |
57 | /// The font supplied size of the em square. |
58 | pub units_per_em: f32, |
59 | /// The font ascent in design metrics (typically positive) |
60 | pub ascent: f32, |
61 | /// The font descent in design metrics (typically negative) |
62 | pub descent: f32, |
63 | /// The font's x-height. |
64 | pub x_height: f32, |
65 | /// The font's cap-height. |
66 | pub cap_height: f32, |
67 | /// A vector of pre-rendered glyph sets. Each glyph set must have the same number of glyphs, |
68 | /// which must be at least as big as the largest glyph index in the character map. |
69 | pub glyphs: Slice<'static, BitmapGlyphs>, |
70 | /// The weight of the font in CSS units (400 is normal). |
71 | pub weight: u16, |
72 | /// Whether the type-face is rendered italic. |
73 | pub italic: bool, |
74 | /// Whether the format of the font is a signed distance field |
75 | pub sdf: bool, |
76 | } |
77 | |