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