// K2231-K2235: raster.glyphs — Bitmap font ve UTF8 fallback // Invariant: Glyph erişimi font tablosunda sınırlıdır // Positive: Türkçe karakter ve bilinmeyen glyph // Counterexample: Bozuk font offset // Acceptance: Fallback kutu çizilir panik yok pub const RASTER_GLYPHS_SCHEMA: &str = "turkos.os.raster.glyphs.v1"; pub const RASTER_GLYPHS_INVARIANT: &str = "Glyph erişimi font tablosunda sınırlıdır"; pub const RASTER_GLYPHS_POSITIVE: &str = "Türkçe karakter ve bilinmeyen glyph"; pub const RASTER_GLYPHS_COUNTEREXAMPLE: &str = "Bozuk font offset"; pub const RASTER_GLYPHS_ACCEPTANCE: &str = "Fallback kutu çizilir panik yok"; pub const EXPECTED_FONT_TABLE_GLYPHS: u32 = 512; pub const EXPECTED_GLYPH_STRIDE_BYTES: u32 = 16; pub const EXPECTED_FONT_TABLE_BYTES: u32 = 8192; pub const EXPECTED_TURKISH_GLYPHS_RENDERED: u32 = 12; pub const EXPECTED_FALLBACK_BOXES_DRAWN: u32 = 2; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum GlyphsError { CorruptedFontOffsetOutOfBounds = 1, FontTableGlyphCountMismatch = 2, GlyphStrideBytesMismatch = 3, FontTableBytesMismatch = 4, GlyphEndByteExceedsFontTable = 5, TurkishGlyphCountMismatch = 6, UnknownGlyphFallbackBoxMissing = 7, PanicTriggeredOnUnknownUtf8 = 8, ZeroGlyphEpoch = 9, NonMonotonicGlyphEpoch = 10, ZeroGlyphRenderDigest = 11, UnboundGlyphsDigest = 12, AlreadyRendered = 13, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct GlyphRenderRequest { pub corrupted_font_offset: bool, pub font_table_glyphs: u32, pub glyph_stride_bytes: u32, pub font_table_bytes: u32, pub max_glyph_end_byte: u32, pub turkish_glyphs_rendered: u32, pub fallback_boxes_drawn: u32, pub panic_on_unknown_utf8: bool, pub glyph_epoch: u64, pub previous_glyph_epoch: u64, pub glyph_render_digest: u64, pub glyphs_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct GlyphRenderReceipt { pub font_table_glyphs: u32, pub glyph_stride_bytes: u32, pub font_table_bytes: u32, pub max_glyph_end_byte: u32, pub turkish_glyphs_rendered: u32, pub fallback_boxes_drawn: u32, pub fallback_without_panic: bool, pub glyph_epoch: u64, pub glyph_render_digest: u64, pub receipt_digest: u64, } pub const fn compute_glyphs_binding_digest( font_table_glyphs: u32, glyph_stride_bytes: u32, font_table_bytes: u32, max_glyph_end_byte: u32, turkish_glyphs_rendered: u32, fallback_boxes_drawn: u32, glyph_epoch: u64, glyph_render_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2235_474c_5950_4853).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (font_table_glyphs as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (glyph_stride_bytes as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (font_table_bytes as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (max_glyph_end_byte as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (turkish_glyphs_rendered as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (fallback_boxes_drawn as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ glyph_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ glyph_render_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct RasterGlyphsCoordinator { rendered: bool, rendered_total: u64, rejected_total: u64, offset_refusals: u64, fallback_refusals: u64, table_refusals: u64, committed_receipt: Option, } impl RasterGlyphsCoordinator { pub const fn new() -> Self { Self { rendered: false, rendered_total: 0, rejected_total: 0, offset_refusals: 0, fallback_refusals: 0, table_refusals: 0, committed_receipt: None, } } pub fn is_rendered(&self) -> bool { self.rendered } pub fn rendered_total(&self) -> u64 { self.rendered_total } pub fn rejected_total(&self) -> u64 { self.rejected_total } pub fn offset_refusals(&self) -> u64 { self.offset_refusals } pub fn fallback_refusals(&self) -> u64 { self.fallback_refusals } pub fn table_refusals(&self) -> u64 { self.table_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_glyph_render( &mut self, req: &GlyphRenderRequest, ) -> Result { if self.rendered { self.rejected_total += 1; return Err(GlyphsError::AlreadyRendered); } if req.corrupted_font_offset { self.rejected_total += 1; self.offset_refusals += 1; return Err(GlyphsError::CorruptedFontOffsetOutOfBounds); } if req.font_table_glyphs != EXPECTED_FONT_TABLE_GLYPHS { self.rejected_total += 1; self.table_refusals += 1; return Err(GlyphsError::FontTableGlyphCountMismatch); } if req.glyph_stride_bytes != EXPECTED_GLYPH_STRIDE_BYTES { self.rejected_total += 1; self.table_refusals += 1; return Err(GlyphsError::GlyphStrideBytesMismatch); } if req.font_table_bytes != EXPECTED_FONT_TABLE_BYTES { self.rejected_total += 1; self.table_refusals += 1; return Err(GlyphsError::FontTableBytesMismatch); } if req.max_glyph_end_byte > req.font_table_bytes { self.rejected_total += 1; self.offset_refusals += 1; return Err(GlyphsError::GlyphEndByteExceedsFontTable); } if req.turkish_glyphs_rendered != EXPECTED_TURKISH_GLYPHS_RENDERED { self.rejected_total += 1; self.fallback_refusals += 1; return Err(GlyphsError::TurkishGlyphCountMismatch); } if req.fallback_boxes_drawn != EXPECTED_FALLBACK_BOXES_DRAWN { self.rejected_total += 1; self.fallback_refusals += 1; return Err(GlyphsError::UnknownGlyphFallbackBoxMissing); } if req.panic_on_unknown_utf8 { self.rejected_total += 1; self.fallback_refusals += 1; return Err(GlyphsError::PanicTriggeredOnUnknownUtf8); } if req.glyph_epoch == 0 { self.rejected_total += 1; return Err(GlyphsError::ZeroGlyphEpoch); } if req.glyph_epoch <= req.previous_glyph_epoch { self.rejected_total += 1; return Err(GlyphsError::NonMonotonicGlyphEpoch); } if req.glyph_render_digest == 0 { self.rejected_total += 1; return Err(GlyphsError::ZeroGlyphRenderDigest); } let expected_binding = compute_glyphs_binding_digest( req.font_table_glyphs, req.glyph_stride_bytes, req.font_table_bytes, req.max_glyph_end_byte, req.turkish_glyphs_rendered, req.fallback_boxes_drawn, req.glyph_epoch, req.glyph_render_digest, ); if req.glyphs_binding_digest != expected_binding { self.rejected_total += 1; self.fallback_refusals += 1; return Err(GlyphsError::UnboundGlyphsDigest); } self.rendered = true; self.rendered_total += 1; let receipt = GlyphRenderReceipt { font_table_glyphs: req.font_table_glyphs, glyph_stride_bytes: req.glyph_stride_bytes, font_table_bytes: req.font_table_bytes, max_glyph_end_byte: req.max_glyph_end_byte, turkish_glyphs_rendered: req.turkish_glyphs_rendered, fallback_boxes_drawn: req.fallback_boxes_drawn, fallback_without_panic: true, glyph_epoch: req.glyph_epoch, glyph_render_digest: req.glyph_render_digest, receipt_digest: expected_binding ^ 0x2235_ACE0_474c_5950, }; self.committed_receipt = Some(receipt); Ok(receipt) } }