Skip to content

Commit

Permalink
make font lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
s3bk committed Jan 4, 2025
1 parent 0928caa commit 83e4a97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 16 additions & 0 deletions pdf/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,14 @@ impl<T> Clone for Lazy<T> {
}
}
}
impl<T: Object> DeepClone for Lazy<T> {
fn deep_clone(&self, cloner: &mut impl Cloner) -> Result<Self> {
Ok(Lazy {
primitive: self.primitive.deep_clone(cloner)?,
_marker: PhantomData
})
}
}
impl<T: Object> Lazy<T> {
pub fn load(&self, resolve: &impl Resolve) -> Result<T> {
T::from_primitive(self.primitive.clone(), resolve)
Expand All @@ -463,6 +471,14 @@ impl<T> Default for Lazy<T> {
Lazy { primitive: Primitive::Null, _marker: PhantomData }
}
}
impl<T: Object> From<RcRef<T>> for Lazy<T> {
fn from(value: RcRef<T>) -> Self {
Lazy {
primitive: Primitive::Reference(value.inner),
_marker: PhantomData
}
}
}

//////////////////////////////////////
// Object for Primitives & other types
Expand Down
7 changes: 1 addition & 6 deletions pdf/src/object/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,11 @@ pub struct Resources {
pub xobjects: HashMap<Name, Ref<XObject>>,
// /XObject is a dictionary that map arbitrary names to XObjects
#[pdf(key="Font")]
pub fonts: HashMap<Name, MaybeRef<Font>>,
pub fonts: HashMap<Name, Lazy<Font>>,

#[pdf(key="Properties")]
pub properties: HashMap<Name, MaybeRef<Dictionary>>,
}
impl Resources {
pub fn fonts(&self) -> impl Iterator<Item=(&str, &MaybeRef<Font>)> {
self.fonts.iter().map(|(k, v)| (k.as_str(), v))
}
}


#[derive(Debug, Object, ObjectWrite, DataSize, Clone, DeepClone)]
Expand Down

0 comments on commit 83e4a97

Please sign in to comment.