1use crate::Text;
4
5#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum FontRaster {
9 #[default]
11 Legacy,
12 Natural,
14}
15
16impl FontRaster {
17 pub(crate) fn position(self, pen: i32) -> i32 {
18 match self {
19 Self::Legacy => pen,
20 Self::Natural => ((pen as i64 + if pen < 0 { 31 } else { 32 }) >> 6)
21 .saturating_mul(64).clamp(i32::MIN as i64, i32::MAX as i64) as i32,
22 }
23 }
24}
25
26impl Text {
27 pub fn font_raster(&self, font: u32) -> FontRaster {
29 self.slot_idx(font).map_or(FontRaster::Legacy, |i| self.slots[i].raster)
30 }
31
32 pub fn set_font_raster(&mut self, font: u32, raster: FontRaster) -> bool {
35 let Some(i) = self.slot_idx(font).filter(|i| *i == font as usize) else { return false; };
36 if self.slots[i].raster != raster {
37 self.slots[i].raster = raster;
38 self.gc_flush();
39 }
40 true
41 }
42}