#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
pub struct GlyphId(pub u32);
impl GlyphId {
#[inline]
pub const fn new(id: u32) -> Self {
Self(id)
}
pub const NOTDEF: Self = Self(0);
#[inline]
pub const fn is_valid(&self) -> bool {
self.0 != 0
}
}
impl From<u32> for GlyphId {
#[inline]
fn from(id: u32) -> Self {
Self(id)
}
}
impl From<GlyphId> for u32 {
#[inline]
fn from(id: GlyphId) -> Self {
id.0
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct GlyphMetrics {
pub width: f32,
pub height: f32,
pub bearing_x: f32,
pub bearing_y: f32,
pub advance_x: f32,
pub advance_y: f32,
}
impl GlyphMetrics {
#[inline]
pub const fn new(width: f32, height: f32, advance_x: f32) -> Self {
Self {
width,
height,
bearing_x: 0.0,
bearing_y: 0.0,
advance_x,
advance_y: 0.0,
}
}
pub const ZERO: Self = Self {
width: 0.0,
height: 0.0,
bearing_x: 0.0,
bearing_y: 0.0,
advance_x: 0.0,
advance_y: 0.0,
};
#[inline]
pub const fn monospace(cell_width: f32, cell_height: f32) -> Self {
Self {
width: cell_width,
height: cell_height,
bearing_x: 0.0,
bearing_y: cell_height,
advance_x: cell_width,
advance_y: 0.0,
}
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct GlyphPosition {
pub id: GlyphId,
pub x: f32,
pub y: f32,
pub x_offset: f32,
pub y_offset: f32,
}
impl GlyphPosition {
#[inline]
pub const fn new(id: GlyphId, x: f32, y: f32) -> Self {
Self {
id,
x,
y,
x_offset: 0.0,
y_offset: 0.0,
}
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct ClusterInfo {
pub text_start: u32,
pub text_len: u32,
pub glyph_start: u32,
pub glyph_len: u32,
}
impl ClusterInfo {
#[inline]
pub const fn simple(text_index: u32, glyph_index: u32) -> Self {
Self {
text_start: text_index,
text_len: 1,
glyph_start: glyph_index,
glyph_len: 1,
}
}
}