artery_font/
structs.rs

1use bytemuck::{Pod, Zeroable};
2use crate::enums::*;
3use crate::header::Real;
4
5#[derive(Debug, Copy, Clone, Zeroable, Pod)]
6#[repr(C)]
7pub struct Advance {
8    pub horizontal: Real,
9    pub vertical: Real
10}
11
12#[derive(Debug, Copy, Clone, Zeroable, Pod)]
13#[repr(C)]
14pub struct Rect {
15    pub left: Real,
16    pub bottom: Real,
17    pub right: Real,
18    pub top: Real
19}
20
21impl Rect {
22    pub fn is_empty(self) -> bool{
23        self.top == self.bottom || self.left == self.right
24    }
25
26    pub fn scaled(self, x: Real, y: Real) -> Self {
27        Self {
28            left: self.left * x,
29            bottom: self.bottom * y,
30            right: self.right * x,
31            top: self.top * y
32        }
33    }
34}
35
36#[derive(Debug, Copy, Clone, Zeroable, Pod)]
37#[repr(C)]
38pub struct Glyph {
39    pub codepoint: u32,
40    pub image: u32,
41    pub plane_bounds: Rect,
42    pub image_bounds: Rect,
43    pub advance: Advance
44}
45
46impl Glyph {
47    pub fn is_drawable(self) -> bool{
48        !self.plane_bounds.is_empty() && !self.image_bounds.is_empty()
49    }
50}
51
52#[derive(Debug, Copy, Clone, Zeroable, Pod)]
53#[repr(C)]
54pub struct KernPair {
55    pub codepoint1: u32,
56    pub codepoint2: u32,
57    pub advance: Advance
58}
59
60#[derive(Debug, Copy, Clone, Zeroable, Pod)]
61#[repr(C)]
62pub struct FontMetric {
63    pub font_size: Real,
64    pub distance_range: Real,
65    pub em_size: Real,
66    pub ascender: Real,
67    pub descender: Real,
68    pub line_height: Real,
69    pub underline_y: Real,
70    pub underline_thickness: Real
71}
72
73#[derive(Debug, Clone)]
74pub struct FontVariant {
75    pub flags: u32,
76    pub weight: u32,
77    pub codepoint_type: CodepointType,
78    pub image_type: ImageType,
79    pub fallback_variant: u32,
80    pub fallback_glyph: u32,
81    pub metrics: FontMetric,
82    pub name: String,
83    pub metadata: String,
84    pub glyphs: Vec<Glyph>,
85    pub kern_pairs: Vec<KernPair>
86}
87
88#[derive(Debug, Clone)]
89pub struct Image {
90    pub flags: u32,
91    pub width: u32,
92    pub height: u32,
93    pub channels: u32,
94    pub pixel_format: PixelFormat,
95    pub image_type: ImageType,
96    pub child_images: u32,
97    pub texture_flags: u32,
98    pub metadata: String,
99    pub data: Vec<u8>
100}
101
102#[derive(Debug, Clone)]
103pub struct Appendix {
104    pub metadata: String,
105    pub data: Vec<u8>
106}
107
108#[derive(Debug, Clone)]
109pub struct ArteryFont {
110    pub metadata_format: MetadataFormat,
111    pub variants: Vec<FontVariant>,
112    pub images: Vec<Image>,
113    pub appendices: Vec<Appendix>
114}