Skip to main content

glifo/atlas/
region.rs

1// Copyright 2026 the Vello Authors
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4//! Atlas slot and rasterization data structures.
5
6use vello_common::paint::ImageId;
7
8/// Location and metrics of a cached glyph within an atlas page.
9///
10/// One slot is stored per distinct (font, glyph ID, size, subpixel offset)
11/// combination in [`GlyphAtlas`](super::GlyphAtlas).
12#[derive(Clone, Copy, Debug)]
13pub struct AtlasSlot {
14    /// The image ID for this glyph in the [`ImageCache`].
15    ///
16    /// Used for deallocation and for looking up the atlas page/offset.
17    ///
18    /// [`ImageCache`]: vello_common::image_cache::ImageCache
19    pub image_id: ImageId,
20    /// Which atlas page contains this glyph.
21    pub page_index: u32,
22    /// X position in atlas (pixels).
23    pub x: u16,
24    /// Y position in atlas (pixels).
25    pub y: u16,
26    /// Width of glyph bitmap (pixels).
27    pub width: u16,
28    /// Height of glyph bitmap (pixels).
29    pub height: u16,
30    /// Horizontal bearing (offset from glyph origin to left edge of bitmap).
31    pub bearing_x: i16,
32    /// Vertical bearing (offset from glyph origin to top edge of bitmap).
33    pub bearing_y: i16,
34}
35
36/// Metadata for a rasterized glyph (no pixel data).
37///
38/// Returned by rasterization to communicate bitmap dimensions and
39/// bearing offsets.
40#[derive(Clone, Copy, Debug)]
41pub struct RasterMetrics {
42    /// Width of the rasterized glyph (pixels).
43    pub width: u16,
44    /// Height of the rasterized glyph (pixels).
45    pub height: u16,
46    /// Horizontal bearing (offset from glyph origin to left edge of bitmap).
47    pub bearing_x: i16,
48    /// Vertical bearing (offset from glyph origin to top edge of bitmap).
49    pub bearing_y: i16,
50}