1 //! Basic representation of an in-memory font resource. 2 3 pub use read_fonts::FontRef; 4 5 /// Identifier used as a key for internal caches. 6 /// 7 /// The representation of a font in this crate is designed to be flexible for 8 /// clients (any type that implements [`TableProvider`](read_fonts::TableProvider) 9 /// is supported) without imposing any strict constraints on ownership or data layout. 10 /// 11 /// The price for this flexibility is that an additional mechanism is necessary 12 /// to enable caching of state for performance sensitive operations. The chosen 13 /// design stores cached data in separate contexts (see [`scale::Context`][crate::scale::Context] 14 /// as an example) keyed by this type. 15 /// 16 /// Thus, to enable caching, a client may provide an instance of this type when 17 /// making use of a context. For example, [`ScalerBuilder::cache_key`][crate::scale::ScalerBuilder::cache_key] can 18 /// be used when configuring a glyph scaler. 19 /// 20 /// # Semantics 21 /// Currently, the parameters used to construct this type carry no actual semantics. 22 /// The `index` parameter, for example, is not required to match the index of a font 23 /// in a collection. Types and names were chosen to accommodate the common representation 24 /// of a pointer and index pair. 25 /// 26 /// The only requirement is that the 96 bits be unique for a given font. 27 /// 28 /// ## Uniqueness and safety 29 /// Users are responsible for ensuring that a unique identifier is not used for 30 /// different fonts within a single context. Violating this invariant is guaranteed 31 /// to be safe, but will very likely lead to incorrect results. 32 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] 33 pub struct UniqueId { 34 /// Unique identifier for the data blob containing the content of 35 /// a font file. 36 data_id: u64, 37 /// Index of a font in a font collection file. 38 index: u32, 39 } 40 41 impl UniqueId { 42 /// Creates a new unique identifier from the given data identifier and font 43 /// collection index. new(data_id: u64, index: u32) -> Self44 pub fn new(data_id: u64, index: u32) -> Self { 45 Self { data_id, index } 46 } 47 } 48