Run cargo fmt

This commit is contained in:
Jeremy Soller 2023-01-04 20:03:03 -07:00
parent 00bc4d1e88
commit 8cc988d374
25 changed files with 732 additions and 731 deletions

View file

@ -15,9 +15,7 @@ pub fn common_fallback() -> &'static [&'static str] {
// Fallbacks to never use
pub fn forbidden_fallback() -> &'static [&'static str] {
&[
".LastResort",
]
&[".LastResort"]
}
fn han_unification(locale: &str) -> &'static [&'static str] {

View file

@ -9,11 +9,7 @@ use crate::Font;
use self::platform::*;
#[cfg(not(any(
target_os = "linux",
target_os = "macos",
target_os = "windows",
)))]
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows",)))]
#[path = "other.rs"]
mod platform;
@ -46,7 +42,7 @@ impl<'a> FontFallbackIter<'a> {
fonts: &'a [Arc<Font<'a>>],
default_families: &'a [&'a str],
scripts: Vec<Script>,
locale: &'a str
locale: &'a str,
) -> Self {
Self {
fonts,
@ -78,7 +74,7 @@ impl<'a> FontFallbackIter<'a> {
font.info.family,
word
);
} else if ! self.scripts.is_empty() && self.common_i > 0 {
} else if !self.scripts.is_empty() && self.common_i > 0 {
let family = common_fallback()[self.common_i - 1];
log::debug!(
"Failed to find script fallback for {:?} locale '{}', used '{}': '{}'",
@ -117,7 +113,12 @@ impl<'a> Iterator for FontFallbackIter<'a> {
return Some(font);
}
}
log::warn!("failed to find family '{}' for script {:?} and locale '{}'", script_family, script, self.locale);
log::warn!(
"failed to find family '{}' for script {:?} and locale '{}'",
script_family,
script,
self.locale
);
}
self.script_i.0 += 1;
@ -142,7 +143,7 @@ impl<'a> Iterator for FontFallbackIter<'a> {
while self.other_i < self.fonts.len() {
let font = &self.fonts[self.other_i];
self.other_i += 1;
if ! forbidden_families.contains(&font.info.family.as_str()) {
if !forbidden_families.contains(&font.info.family.as_str()) {
return Some(font);
}
}

View file

@ -31,7 +31,7 @@ fn han_unification(locale: &str) -> &'static [&'static str] {
// Taiwan
"zh-TW" => &["Microsoft JhengHei UI"],
// Simplified Chinese is the default (also catches "zh-CN" for China)
_ => &["Microsoft YaHei UI"]
_ => &["Microsoft YaHei UI"],
}
}

View file

@ -2,10 +2,7 @@
use alloc::sync::Arc;
#[cfg(not(feature = "std"))]
use alloc::{
string::String,
vec::Vec,
};
use alloc::{string::String, vec::Vec};
use crate::Font;

View file

@ -9,7 +9,7 @@ use alloc::{
use crate::{Attrs, Font, FontMatches};
/// Access system fonts
pub struct FontSystem{
pub struct FontSystem {
locale: String,
db: fontdb::Database,
}
@ -25,16 +25,13 @@ impl FontSystem {
db.set_serif_family("DejaVu Serif");
}
Self {
locale,
db,
}
Self { locale, db }
}
pub fn new_with_locale_and_db(locale: &str, db: fontdb::Database) -> Self {
Self {
locale: locale.to_string(),
db
db,
}
}
@ -74,7 +71,7 @@ impl FontSystem {
Arc::new(FontMatches {
locale: &self.locale,
default_family: self.db.family_name(&attrs.family).to_string(),
fonts
fonts,
})
}
}

View file

@ -9,7 +9,7 @@ use alloc::{
use crate::{Attrs, Font, FontMatches};
/// Access system fonts
pub struct FontSystem{
pub struct FontSystem {
locale: String,
db: fontdb::Database,
}
@ -46,7 +46,9 @@ impl FontSystem {
//TODO only do this on demand!
for i in 0..db.faces().len() {
let id = db.faces()[i].id;
unsafe { db.make_shared_face_data(id); }
unsafe {
db.make_shared_face_data(id);
}
}
log::info!(
@ -56,10 +58,7 @@ impl FontSystem {
);
}
Self {
locale,
db,
}
Self { locale, db }
}
pub fn locale(&self) -> &str {
@ -98,7 +97,7 @@ impl FontSystem {
Arc::new(FontMatches {
locale: &self.locale,
default_family: self.db.family_name(&attrs.family).to_string(),
fonts
fonts,
})
}
}

View file

@ -59,7 +59,9 @@ impl FontSystem {
//TODO only do this on demand!
for i in 0..db.faces().len() {
let id = db.faces()[i].id;
unsafe { db.make_shared_face_data(id); }
unsafe {
db.make_shared_face_data(id);
}
}
log::info!(
@ -69,12 +71,15 @@ impl FontSystem {
);
}
Self(FontSystemInnerBuilder {
locale,
db,
font_cache_builder: |_| Mutex::new(HashMap::new()),
font_matches_cache_builder: |_, _| Mutex::new(HashMap::new())
}.build())
Self(
FontSystemInnerBuilder {
locale,
db,
font_cache_builder: |_| Mutex::new(HashMap::new()),
font_matches_cache_builder: |_, _| Mutex::new(HashMap::new()),
}
.build(),
)
}
pub fn locale(&self) -> &str {
@ -93,53 +98,66 @@ impl FontSystem {
// Clippy false positive
#[allow(clippy::needless_lifetimes)]
pub fn get_font<'a>(&'a self, id: fontdb::ID) -> Option<Arc<Font<'a>>> {
self.0.with(|fields| {
get_font(&fields, id)
})
self.0.with(|fields| get_font(&fields, id))
}
pub fn get_font_matches<'a>(&'a self, attrs: Attrs) -> Arc<FontMatches<'a>> {
self.0.with(|fields| {
let mut font_matches_cache = fields.font_matches_cache.lock().expect("failed to lock font matches cache");
let mut font_matches_cache = fields
.font_matches_cache
.lock()
.expect("failed to lock font matches cache");
//TODO: do not create AttrsOwned unless entry does not already exist
font_matches_cache.entry(AttrsOwned::new(attrs)).or_insert_with(|| {
let now = std::time::Instant::now();
font_matches_cache
.entry(AttrsOwned::new(attrs))
.or_insert_with(|| {
let now = std::time::Instant::now();
let mut fonts = Vec::new();
for face in fields.db.faces() {
if !attrs.matches(face) {
continue;
let mut fonts = Vec::new();
for face in fields.db.faces() {
if !attrs.matches(face) {
continue;
}
if let Some(font) = get_font(&fields, face.id) {
fonts.push(font);
}
}
if let Some(font) = get_font(&fields, face.id) {
fonts.push(font);
}
}
let font_matches = Arc::new(FontMatches {
locale: fields.locale,
default_family: fields.db.family_name(&attrs.family).to_string(),
fonts,
});
let font_matches = Arc::new(FontMatches {
locale: fields.locale,
default_family: fields.db.family_name(&attrs.family).to_string(),
fonts
});
let elapsed = now.elapsed();
log::debug!("font matches for {:?} in {:?}", attrs, elapsed);
let elapsed = now.elapsed();
log::debug!("font matches for {:?} in {:?}", attrs, elapsed);
font_matches
}).clone()
font_matches
})
.clone()
})
}
}
fn get_font<'b>(fields: &ouroboros_impl_font_system_inner::BorrowedFields<'_, 'b>, id: fontdb::ID) -> Option<Arc<Font<'b>>> {
fields.font_cache.lock().expect("failed to lock font cache").entry(id).or_insert_with(|| {
let face = fields.db.face(id)?;
match Font::new(face) {
Some(font) => Some(Arc::new(font)),
None => {
log::warn!("failed to load font '{}'", face.post_script_name);
None
fn get_font<'b>(
fields: &ouroboros_impl_font_system_inner::BorrowedFields<'_, 'b>,
id: fontdb::ID,
) -> Option<Arc<Font<'b>>> {
fields
.font_cache
.lock()
.expect("failed to lock font cache")
.entry(id)
.or_insert_with(|| {
let face = fields.db.face(id)?;
match Font::new(face) {
Some(font) => Some(Arc::new(font)),
None => {
log::warn!("failed to load font '{}'", face.post_script_name);
None
}
}
}
}).clone()
})
.clone()
}