diff --git a/crates/benilla-app/src/ui_text/outline.rs b/crates/benilla-app/src/ui_text/outline.rs index 072e3ec0d..dcced3d24 100644 --- a/crates/benilla-app/src/ui_text/outline.rs +++ b/crates/benilla-app/src/ui_text/outline.rs @@ -57,7 +57,8 @@ fn fill_gray(coverage: u8) -> u8 { /// 4. Pack: the coverage as a 4-bit gray ([`fill_gray`]), so the pure ring is black and the fill /// ramps toward it. /// -/// Deviation: `r × round(dpi)` passes, so the ring keeps its logical weight on a high-DPI raster. +/// Deviation: `r × floor(dpi)` passes, so the ring keeps its logical weight on a whole-number +/// high-DPI raster; a fractional scale such as 1.5 rounds down to the reference's one texel a pass. /// /// It draws as one quad per glyph (`0x5ccbe0`) whose vertex colour tints the fill and leaves the /// ring black. Returns `(rgba, out_w, out_h, pad)`: the cell grows `pad` texels each side (the @@ -114,7 +115,7 @@ pub(super) fn outlined_cell( /// Dilation passes for ring reach `r` (logical px) on a `dpi` raster, also the cell's growth on /// every side. fn passes_of(r: u8, dpi: f32) -> u32 { - (u32::from(r) * (dpi.round().max(1.0) as u32)).max(1) + (u32::from(r) * (dpi.floor().max(1.0) as u32)).max(1) } /// The ink (`ink != 0`) of a `w × h` glyph marked 1 in a grid grown `passes` texels each side, then @@ -164,7 +165,7 @@ fn ringed(ink: &[u8], w: u32, h: u32, passes: u32) -> (Vec, u32, u32) { /// theirs a second black ring at alpha 7/15 (`0x7000`): no neighbour-count alpha, so a small /// glyph's ring follows its strokes and its counters stay open past the first ring. /// -/// Deviation: `r × round(dpi)` passes as in [`outlined_cell`], the first `round(dpi)` of them the +/// Deviation: `r × floor(dpi)` passes as in [`outlined_cell`], the first `floor(dpi)` of them the /// opaque ring. Same contract as [`outlined_cell`]: `(rgba, out_w, out_h, pad)`, `pad` 0 when plain. pub(super) fn mono_cell(bits: &[u8], w: u32, h: u32, r: u8, dpi: f32) -> (Vec, u32, u32, u32) { if r == 0 { @@ -325,4 +326,13 @@ mod mono_cell_tests { assert_eq!(px(&rgba, w, 0, 0), [0, 0, 0, 255]); assert_eq!(px(&rgba, w, 1, 1), [0, 0, 0, 255]); } + + #[test] + fn a_fractional_dpi_rings_one_texel_a_pass() { + // NORMAL at dpi 1.5: one pass, the reference's one-texel ring, not round(1.5) = 2. + let (_, w, h, pad) = mono_cell(&[1], 1, 1, 1, 1.5); + assert_eq!((w, h, pad), (3, 3, 1)); + let (_, w, h, pad) = outlined_cell(&[255], 1, 1, 1, 1.5); + assert_eq!((w, h, pad), (3, 3, 1)); + } } diff --git a/docs/DEVIATIONS.md b/docs/DEVIATIONS.md index f640e9185..d377b60bb 100644 --- a/docs/DEVIATIONS.md +++ b/docs/DEVIATIONS.md @@ -465,8 +465,8 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it - The reference evicts the least recently used glyph and repacks its hole (`0x5cad2b`, over `[CGxFont+0x64..0x6c]`); this drops every cell, because a shelf allocator cannot reclaim an interior cell and the sheet is far larger than the reference's 256×256 pages. ([`src/ui_text/engine/mod.rs:652`](../crates/benilla-app/src/ui_text/engine/mod.rs#L652)) - Every UI text block sits 1 device px below the reference's snapped row, because at that row UI text reads high. ([`src/ui_text/layout/mod.rs:119`](../crates/benilla-app/src/ui_text/layout/mod.rs#L119)) - The cap is 32 logical units, not 32 device px, because the reference's raster-memory ceiling draws all big text at the same 32 device px on a modern display; at the 768-tall design height the two agree. ([`src/ui_text/mod.rs:54`](../crates/benilla-app/src/ui_text/mod.rs#L54)) -- `r × round(dpi)` passes, so the ring keeps its logical weight on a high-DPI raster. ([`src/ui_text/outline.rs:60`](../crates/benilla-app/src/ui_text/outline.rs#L60)) -- `r × round(dpi)` passes as in `outlined_cell`, the first `round(dpi)` of them the opaque ring. ([`src/ui_text/outline.rs:167`](../crates/benilla-app/src/ui_text/outline.rs#L167)) +- `r × floor(dpi)` passes, so the ring keeps its logical weight on a whole-number high-DPI raster; a fractional scale such as 1.5 rounds down to the reference's one texel a pass. ([`src/ui_text/outline.rs:60`](../crates/benilla-app/src/ui_text/outline.rs#L60)) +- `r × floor(dpi)` passes as in `outlined_cell`, the first `floor(dpi)` of them the opaque ring. ([`src/ui_text/outline.rs:168`](../crates/benilla-app/src/ui_text/outline.rs#L168)) - One sheet, where the reference keeps up to 8 pages per font (`[CGxFont+0x18c]`), because a nameplate bakes its glyphs into one mesh with one material, which a page would split. ([`src/ui_text/pack.rs:11`](../crates/benilla-app/src/ui_text/pack.rs#L11)) #### ui_tooltip