Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions fontique/src/collection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,24 @@ pub struct CollectionOptions {
///
/// The default value is `true`.
pub system_fonts: bool,
#[cfg(feature = "std")]
/// If true, the source cache will use a secondary shared cache
/// guaranteeing that all clones will use the same backing store.
///
/// This is useful for ensuring that only one copy of font data is
/// loaded into memory in multi-threaded scenarios.
///
/// The default value is `false`.
pub shared_source_cache: bool,
}

impl Default for CollectionOptions {
fn default() -> Self {
Self {
shared: false,
system_fonts: true,
#[cfg(feature = "std")]
shared_source_cache: false,
}
}
}
Expand All @@ -64,6 +75,7 @@ impl Default for CollectionOptions {
pub struct Collection {
inner: Inner,
query_state: query::QueryState,
source_cache: SourceCache,
}

impl Collection {
Expand All @@ -80,6 +92,9 @@ impl Collection {
Self {
inner: Inner::new(options),
query_state: Default::default(),
source_cache: SourceCache::new(crate::SourceCacheOptions {
shared: options.shared_source_cache,
}),
}
}

Expand Down Expand Up @@ -168,8 +183,8 @@ impl Collection {
}

/// Returns an object for selecting fonts from this collection.
pub fn query<'a>(&'a mut self, source_cache: &'a mut SourceCache) -> Query<'a> {
Query::new(self, source_cache)
pub fn query<'a>(&'a mut self) -> Query<'a> {
Query::new(self)
}

/// Registers all fonts that exist in the given data.
Expand Down
4 changes: 2 additions & 2 deletions fontique/src/collection/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ pub struct Query<'a> {
}

impl<'a> Query<'a> {
pub(super) fn new(collection: &'a mut Collection, source_cache: &'a mut SourceCache) -> Self {
pub(super) fn new(collection: &'a mut Collection) -> Self {
collection.query_state.clear();
Self {
collection: &mut collection.inner,
state: &mut collection.query_state,
source_cache,
source_cache: &mut collection.source_cache,
attributes: Attributes::default(),
fallbacks: None,
}
Expand Down
Loading