Revert "Make FontSystem not self-referencing and update fontdb and rustybuzz"
This commit is contained in:
parent
b6398a2d57
commit
eca804c732
11 changed files with 179 additions and 225 deletions
|
|
@ -1,10 +1,11 @@
|
|||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||
|
||||
use alloc::sync::Arc;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
use unicode_script::Script;
|
||||
|
||||
use crate::{Font, FontKey};
|
||||
use crate::Font;
|
||||
|
||||
use self::platform::*;
|
||||
|
||||
|
|
@ -25,8 +26,7 @@ mod platform;
|
|||
mod platform;
|
||||
|
||||
pub struct FontFallbackIter<'a> {
|
||||
db: &'a fontdb::Database,
|
||||
font_keys: &'a [FontKey],
|
||||
fonts: &'a [Arc<Font<'a>>],
|
||||
default_families: &'a [&'a str],
|
||||
default_i: usize,
|
||||
scripts: Vec<Script>,
|
||||
|
|
@ -39,15 +39,13 @@ pub struct FontFallbackIter<'a> {
|
|||
|
||||
impl<'a> FontFallbackIter<'a> {
|
||||
pub fn new(
|
||||
db: &'a fontdb::Database,
|
||||
font_keys: &'a [FontKey],
|
||||
fonts: &'a [Arc<Font<'a>>],
|
||||
default_families: &'a [&'a str],
|
||||
scripts: Vec<Script>,
|
||||
locale: &'a str,
|
||||
) -> Self {
|
||||
Self {
|
||||
db,
|
||||
font_keys,
|
||||
fonts,
|
||||
default_families,
|
||||
default_i: 0,
|
||||
scripts,
|
||||
|
|
@ -68,13 +66,12 @@ impl<'a> FontFallbackIter<'a> {
|
|||
word
|
||||
);
|
||||
} else if self.other_i > 0 {
|
||||
let font_key = self.font_keys[self.other_i - 1];
|
||||
let font = Font::from_key(self.db, font_key).expect("invalid font key");
|
||||
let font = &self.fonts[self.other_i - 1];
|
||||
log::debug!(
|
||||
"Failed to find preset fallback for {:?} locale '{}', used '{}': '{}'",
|
||||
self.scripts,
|
||||
self.locale,
|
||||
font.name(),
|
||||
font.info.family,
|
||||
word
|
||||
);
|
||||
} else if !self.scripts.is_empty() && self.common_i > 0 {
|
||||
|
|
@ -91,15 +88,14 @@ impl<'a> FontFallbackIter<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Iterator for FontFallbackIter<'a> {
|
||||
type Item = Font<'a>;
|
||||
type Item = &'a Arc<Font<'a>>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
while self.default_i < self.default_families.len() {
|
||||
let default_family = self.default_families[self.default_i];
|
||||
self.default_i += 1;
|
||||
|
||||
for font_key in self.font_keys.iter().copied() {
|
||||
let font = Font::from_key(self.db, font_key).expect("invalid font key");
|
||||
if font.contains_family(default_family) {
|
||||
for font in self.fonts.iter() {
|
||||
if font.info.family == default_family {
|
||||
return Some(font);
|
||||
}
|
||||
}
|
||||
|
|
@ -112,9 +108,8 @@ impl<'a> Iterator for FontFallbackIter<'a> {
|
|||
while self.script_i.1 < script_families.len() {
|
||||
let script_family = script_families[self.script_i.1];
|
||||
self.script_i.1 += 1;
|
||||
for font_key in self.font_keys.iter().copied() {
|
||||
let font = Font::from_key(self.db, font_key).expect("invalid font key");
|
||||
if font.contains_family(script_family) {
|
||||
for font in self.fonts.iter() {
|
||||
if font.info.family == script_family {
|
||||
return Some(font);
|
||||
}
|
||||
}
|
||||
|
|
@ -134,9 +129,8 @@ impl<'a> Iterator for FontFallbackIter<'a> {
|
|||
while self.common_i < common_families.len() {
|
||||
let common_family = common_families[self.common_i];
|
||||
self.common_i += 1;
|
||||
for font_key in self.font_keys.iter().copied() {
|
||||
let font = Font::from_key(self.db, font_key).expect("invalid font key");
|
||||
if font.contains_family(common_family) {
|
||||
for font in self.fonts.iter() {
|
||||
if font.info.family == common_family {
|
||||
return Some(font);
|
||||
}
|
||||
}
|
||||
|
|
@ -146,14 +140,10 @@ impl<'a> Iterator for FontFallbackIter<'a> {
|
|||
//TODO: do we need to do this?
|
||||
//TODO: do not evaluate fonts more than once!
|
||||
let forbidden_families = forbidden_fallback();
|
||||
while self.other_i < self.font_keys.len() {
|
||||
let font_key = self.font_keys[self.other_i];
|
||||
let font = Font::from_key(self.db, font_key).expect("invalid font key");
|
||||
while self.other_i < self.fonts.len() {
|
||||
let font = &self.fonts[self.other_i];
|
||||
self.other_i += 1;
|
||||
if forbidden_families
|
||||
.iter()
|
||||
.all(|family| !font.contains_family(family))
|
||||
{
|
||||
if !forbidden_families.contains(&font.info.family.as_str()) {
|
||||
return Some(font);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue