/
embedded_resources.rs
104 lines (92 loc) · 2.54 KB
/
embedded_resources.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
#[cfg(feature = "software-renderer")]
pub use resvg::tiny_skia::IntRect as Rect;
#[derive(Debug, Clone, Copy, Default)]
pub struct Size {
pub width: u32,
pub height: u32,
}
#[derive(Clone, Copy, Debug, strum::Display)]
pub enum PixelFormat {
// 24 bit RGB
Rgb,
// 32 bit RGBA
Rgba,
// 32 bit RGBA, but the RGB values are pre-multiplied by the alpha
RgbaPremultiplied,
// 8bit alpha map with a given color
AlphaMap([u8; 3]),
}
#[cfg(feature = "software-renderer")]
#[derive(Debug, Clone)]
pub struct Texture {
pub total_size: Size,
pub original_size: Size,
pub rect: Rect,
pub data: Vec<u8>,
pub format: PixelFormat,
}
#[cfg(feature = "software-renderer")]
impl Texture {
pub fn new_empty() -> Self {
Self {
total_size: Size::default(),
original_size: Size::default(),
rect: Rect::from_xywh(0, 0, 1, 1).unwrap(),
data: vec![0, 0, 0, 0],
format: PixelFormat::Rgba,
}
}
}
#[cfg(feature = "software-renderer")]
#[derive(Debug, Clone, Default)]
pub struct BitmapGlyph {
pub x: i16,
pub y: i16,
pub width: i16,
pub height: i16,
pub x_advance: i16,
pub data: Vec<u8>, // 8bit alpha map
}
#[cfg(feature = "software-renderer")]
#[derive(Debug, Clone)]
pub struct BitmapGlyphs {
pub pixel_size: i16,
pub glyph_data: Vec<BitmapGlyph>,
}
#[cfg(feature = "software-renderer")]
#[derive(Debug, Clone)]
pub struct CharacterMapEntry {
pub code_point: char,
pub glyph_index: u16,
}
#[cfg(feature = "software-renderer")]
#[derive(Debug, Clone)]
pub struct BitmapFont {
pub family_name: String,
pub character_map: Vec<CharacterMapEntry>, // map of available glyphs, sorted by char
pub units_per_em: f32,
pub ascent: f32,
pub descent: f32,
pub glyphs: Vec<BitmapGlyphs>,
pub weight: u16,
pub italic: bool,
}
#[derive(Debug, Clone)]
pub enum EmbeddedResourcesKind {
/// Just put the file content as a resource
RawData,
/// The data has been processed in a texture
#[cfg(feature = "software-renderer")]
TextureData(Texture),
/// A set of pre-rendered glyphs of a TrueType font
#[cfg(feature = "software-renderer")]
BitmapFontData(BitmapFont),
}
#[derive(Debug, Clone)]
pub struct EmbeddedResources {
/// unique integer id, that can be used by the generator for symbol generation.
pub id: usize,
pub kind: EmbeddedResourcesKind,
}