pub struct LazyCMap { /* private fields */ }Expand description
Lazy-loaded ToUnicode CMap wrapper.
Defers parsing of ToUnicode CMap streams until first character lookup, improving performance during initial font loading. After first access, the parsed CMap is cached and reused for subsequent lookups.
§Two-Level Caching
- Local cache (
parsed): Caches result in this LazyCMap instance - Global cache: Deduplicates identical CMaps across fonts (Phase 5.2)
§Design
- raw_stream: Stores unparsed CMap stream bytes
- cache_key: Hash of stream bytes for global cache lookup
- parsed: Mutex-protected optional Arc of parsed CMap
- Arc: Thread-safe sharing of the parsed result
- Mutex: Thread-safe mutable access to the Option
- Option: Tracks whether parsing has occurred
§Thread Safety
Multiple threads can safely call get() concurrently:
- Parse happens once, even with concurrent access
- Cached result is shared via
Arc<CMap>globally - Mutex ensures atomic updates to cached state
§Performance Impact
- Font creation: 30-40% faster (skips CMap parsing)
- First lookup: Slightly slower (parse + store cost, amortized across fonts)
- Subsequent lookups: Same speed (cached result)
- Multi-font documents: Significant improvement (50-70% for repeated fonts)
- Global cache: Deduplicates identical CMaps across fonts
Implementations§
Source§impl LazyCMap
impl LazyCMap
Sourcepub fn raw_data(&self) -> &[u8] ⓘ
pub fn raw_data(&self) -> &[u8] ⓘ
Get a reference to the parsed CMap.
On first call, checks global cache, then parses if needed.
On subsequent calls, returns the cached Arc<CMap>.
§Caching Strategy
- Check local
parsedcache (fastest, no lock contention) - Check global
CMAP_CACHE(fast, shared across fonts) - Parse and populate both caches on miss
§Returns
Some(Arc<CMap>) if parsing succeeded, None if parsing failed or stream was empty
Get the raw CMap stream bytes.
Sourcepub fn code_width(&self) -> u8
pub fn code_width(&self) -> u8
Return the character code width (1 or 2) declared by begincodespacerange.
Parses and caches the CMap if not already done.
Returns 1 when the CMap is missing or unparseable (safe default for simple fonts).
Returns 2 when the codespace declares 2-byte codes, indicating a CJK composite font
whose content stream must be read two bytes at a time.
Sourcepub fn wmode(&self) -> u8
pub fn wmode(&self) -> u8
Return the writing mode declared by the underlying CMap stream.
Parses and caches the CMap if not already done.
Returns 0 (horizontal) when the CMap is missing, unparseable, or does
not contain an explicit /WMode directive — matching the spec default.
Returns 1 when the CMap declares /WMode 1 def (vertical writing).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LazyCMap
impl RefUnwindSafe for LazyCMap
impl Send for LazyCMap
impl Sync for LazyCMap
impl Unpin for LazyCMap
impl UnsafeUnpin for LazyCMap
impl UnwindSafe for LazyCMap
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.