use super::*;
impl GlyphKey {
#[inline(always)]
#[must_use]
pub const fn pack_u64(&self) -> u64 {
let Self {
codepoint,
size_tenths,
bold,
monospace,
italic,
} = *self;
((codepoint as u64) << 19)
| ((size_tenths as u64) << 3)
| ((bold as u64) << 2)
| ((monospace as u64) << 1)
| (italic as u64)
}
#[must_use]
pub fn from_style(codepoint: char, physical_size: f32, weight: FontWeight) -> Self {
let clamped: f32 = physical_size.clamp(6.0, 256.0);
let size_tenths: u16 = (clamped * 10.0 + 0.5) as u16;
Self::new(codepoint, size_tenths, weight.is_bold())
}
#[must_use]
pub fn from_text_style(codepoint: char, physical_size: f32, style: TextStyle) -> Self {
let clamped: f32 = physical_size.clamp(6.0, 256.0);
let size_tenths: u16 = (clamped * 10.0 + 0.5) as u16;
Self {
codepoint,
size_tenths,
bold: style.get_weight().is_bold(),
monospace: style.get_family() == FontFamily::Monospace,
italic: style.get_italic(),
}
}
}
impl PartialEq for GlyphKey {
#[inline(always)]
fn eq(&self, other: &Self) -> bool {
self.pack_u64() == other.pack_u64()
}
}
impl PartialOrd for GlyphKey {
#[inline(always)]
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for GlyphKey {
#[inline(always)]
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.pack_u64().cmp(&other.pack_u64())
}
}
impl Hash for GlyphKey {
#[inline(always)]
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
state.write_u64(self.pack_u64());
}
}