Skip to content

Commit

Permalink
fontique: Fix and un-allow clippy::partial_pub_fields lint (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys authored Dec 17, 2024
1 parent 4154537 commit 3a7ce13
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
12 changes: 6 additions & 6 deletions fontique/src/backend/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ const DEFAULT_GENERIC_FAMILIES: &[(GenericFamily, &[&str])] = &[
(GenericFamily::Math, &["Noto Sans Math", "Noto Sans"]),
];

pub struct SystemFonts {
pub name_map: Arc<FamilyNameMap>,
pub generic_families: Arc<GenericFamilyMap>,
pub(crate) struct SystemFonts {
pub(crate) name_map: Arc<FamilyNameMap>,
pub(crate) generic_families: Arc<GenericFamilyMap>,
family_map: HashMap<FamilyId, FamilyInfo>,
locale_fallback: Box<[(Box<str>, FamilyId)]>,
script_fallback: Box<[(Script, FamilyId)]>,
}

impl SystemFonts {
pub fn new() -> Self {
pub(crate) fn new() -> Self {
let android_root: String = std::env::var("ANDROID_ROOT").unwrap_or("/system".to_string());

let scan::ScannedCollection {
Expand Down Expand Up @@ -180,11 +180,11 @@ impl SystemFonts {
}
}

pub fn family(&self, id: FamilyId) -> Option<FamilyInfo> {
pub(crate) fn family(&self, id: FamilyId) -> Option<FamilyInfo> {
self.family_map.get(&id).cloned()
}

pub fn fallback(&self, key: impl Into<FallbackKey>) -> Option<FamilyId> {
pub(crate) fn fallback(&self, key: impl Into<FallbackKey>) -> Option<FamilyId> {
let key: FallbackKey = key.into();
let script = key.script();

Expand Down
12 changes: 6 additions & 6 deletions fontique/src/backend/coretext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const DEFAULT_GENERIC_FAMILIES: &[(GenericFamily, &[&str])] = &[
(GenericFamily::Math, &["STIX Two Math"]),
];

pub struct SystemFonts {
pub name_map: Arc<FamilyNameMap>,
pub generic_families: Arc<GenericFamilyMap>,
pub(crate) struct SystemFonts {
pub(crate) name_map: Arc<FamilyNameMap>,
pub(crate) generic_families: Arc<GenericFamilyMap>,
family_map: HashMap<FamilyId, FamilyInfo>,
}

impl SystemFonts {
pub fn new() -> Self {
pub(crate) fn new() -> Self {
let paths = unsafe {
NSSearchPathForDirectoriesInDomains(
NSSearchPathDirectory::NSLibraryDirectory,
Expand Down Expand Up @@ -70,11 +70,11 @@ impl SystemFonts {
}
}

pub fn family(&mut self, id: FamilyId) -> Option<FamilyInfo> {
pub(crate) fn family(&mut self, id: FamilyId) -> Option<FamilyInfo> {
self.family_map.get(&id).cloned()
}

pub fn fallback(&mut self, key: impl Into<FallbackKey>) -> Option<FamilyId> {
pub(crate) fn fallback(&mut self, key: impl Into<FallbackKey>) -> Option<FamilyId> {
let key = key.into();
let sample = key.script().sample()?;
self.fallback_for_text(sample, key.locale(), false)
Expand Down
12 changes: 6 additions & 6 deletions fontique/src/backend/dwrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ const DEFAULT_GENERIC_FAMILIES: &[(GenericFamily, &[&str])] = &[
];

/// Raw access to the collection of local system fonts.
pub struct SystemFonts {
pub name_map: Arc<FamilyNameMap>,
pub generic_families: Arc<GenericFamilyMap>,
pub(crate) struct SystemFonts {
pub(crate) name_map: Arc<FamilyNameMap>,
pub(crate) generic_families: Arc<GenericFamilyMap>,
source_cache: SourcePathMap,
family_map: HashMap<FamilyId, Option<FamilyInfo>>,
dwrite_fonts: DWriteSystemFonts,
}

impl SystemFonts {
pub fn new() -> Self {
pub(crate) fn new() -> Self {
let dwrite_fonts = DWriteSystemFonts::new(false).unwrap();
let mut name_map = FamilyNameMap::default();
for family in dwrite_fonts.families() {
Expand Down Expand Up @@ -80,7 +80,7 @@ impl SystemFonts {
}
}

pub fn family(&mut self, id: FamilyId) -> Option<FamilyInfo> {
pub(crate) fn family(&mut self, id: FamilyId) -> Option<FamilyInfo> {
match self.family_map.get(&id) {
Some(Some(family)) => return Some(family.clone()),
Some(None) => return None,
Expand Down Expand Up @@ -109,7 +109,7 @@ impl SystemFonts {
None
}

pub fn fallback(&mut self, key: impl Into<FallbackKey>) -> Option<FamilyId> {
pub(crate) fn fallback(&mut self, key: impl Into<FallbackKey>) -> Option<FamilyId> {
// DirectWrite does not have a function to get the default font for a script and locale pair
// so here we provide a sample of the intended script instead.
let key = key.into();
Expand Down
14 changes: 7 additions & 7 deletions fontique/src/backend/fontconfig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ mod cache;
mod config;

/// Raw access to the collection of local system fonts.
pub struct SystemFonts {
pub name_map: Arc<FamilyNameMap>,
pub generic_families: Arc<GenericFamilyMap>,
pub(crate) struct SystemFonts {
pub(crate) name_map: Arc<FamilyNameMap>,
pub(crate) generic_families: Arc<GenericFamilyMap>,
raw_families: HashMap<FamilyId, RawFamily>,
family_map: HashMap<FamilyId, Option<FamilyInfo>>,
fallback_map: HashMap<Script, FallbackFamilies>,
}

impl SystemFonts {
pub fn new() -> Self {
pub(crate) fn new() -> Self {
Self::try_new().unwrap_or_else(|| Self {
name_map: Default::default(),
generic_families: Default::default(),
Expand All @@ -34,7 +34,7 @@ impl SystemFonts {
})
}

pub fn family(&mut self, id: FamilyId) -> Option<FamilyInfo> {
pub(crate) fn family(&mut self, id: FamilyId) -> Option<FamilyInfo> {
match self.family_map.get(&id) {
Some(Some(family)) => return Some(family.clone()),
Some(None) => return None,
Expand Down Expand Up @@ -63,7 +63,7 @@ impl SystemFonts {
Some(family)
}

pub fn fallback(&mut self, key: impl Into<FallbackKey>) -> Option<FamilyId> {
pub(crate) fn fallback(&mut self, key: impl Into<FallbackKey>) -> Option<FamilyId> {
let key = key.into();
let script = key.script();
let locale = key.locale();
Expand All @@ -81,7 +81,7 @@ impl SystemFonts {
}

impl SystemFonts {
pub fn try_new() -> Option<Self> {
pub(crate) fn try_new() -> Option<Self> {
let mut name_map = FamilyNameMap::default();
let mut generic_families = GenericFamilyMap::default();
let mut source_map = SourcePathMap::default();
Expand Down
12 changes: 6 additions & 6 deletions fontique/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ use super::{
use super::source::SourcePathMap;

#[cfg(feature = "system")]
pub use system::SystemFonts;
pub(crate) use system::SystemFonts;

#[cfg(not(feature = "system"))]
pub use null_backend::SystemFonts;
pub(crate) use null_backend::SystemFonts;

#[cfg(not(feature = "system"))]
mod null_backend {
use super::{FamilyNameMap, GenericFamilyMap};
use alloc::sync::Arc;

#[derive(Default)]
pub struct SystemFonts {
pub name_map: Arc<FamilyNameMap>,
pub generic_families: Arc<GenericFamilyMap>,
pub(crate) struct SystemFonts {
pub(crate) name_map: Arc<FamilyNameMap>,
pub(crate) generic_families: Arc<GenericFamilyMap>,
}

impl SystemFonts {
pub fn new() -> Self {
pub(crate) fn new() -> Self {
Self::default()
}
}
Expand Down
1 change: 0 additions & 1 deletion fontique/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#![allow(unreachable_pub)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::exhaustive_enums)]
#![allow(clippy::partial_pub_fields)]
#![allow(clippy::shadow_unrelated)]

#[cfg(not(any(feature = "std", feature = "libm")))]
Expand Down

0 comments on commit 3a7ce13

Please sign in to comment.