Make FontSystem not self-referencing

This commit is contained in:
Edgar Geier 2023-03-01 02:50:10 +01:00
parent 0548d7ae59
commit 506a4194be
No known key found for this signature in database
GPG key ID: 7A65B51FD6B75EF5
10 changed files with 206 additions and 175 deletions

View file

@ -9,7 +9,9 @@ use unicode_script::{Script, UnicodeScript};
use unicode_segmentation::UnicodeSegmentation;
use crate::fallback::FontFallbackIter;
use crate::{Align, AttrsList, CacheKey, Color, Font, FontSystem, LayoutGlyph, LayoutLine, Wrap};
use crate::{
Align, AttrsList, CacheKey, Color, Font, FontKey, FontSystem, LayoutGlyph, LayoutLine, Wrap,
};
fn shape_fallback(
font: &Font,
@ -62,7 +64,7 @@ fn shape_fallback(
y_advance,
x_offset,
y_offset,
font_id: font.info.id,
font_key: font.key(),
glyph_id: info.glyph_id.try_into().expect("failed to cast glyph ID"),
//TODO: color should not be related to shaping
color_opt: attrs.color_opt,
@ -125,22 +127,21 @@ fn shape_run(
let font_matches = font_system.get_font_matches(attrs);
let default_families = [font_matches.default_family.as_str()];
let db = font_system.db();
let default_families = [db.family_name(&attrs.family)];
let mut font_iter = FontFallbackIter::new(
&font_matches.fonts,
db,
&font_matches,
&default_families,
scripts,
font_matches.locale,
font_system.locale(),
);
let (mut glyphs, mut missing) = shape_fallback(
font_iter.next().expect("no default font found"),
line,
attrs_list,
start_run,
end_run,
span_rtl,
);
let font = font_iter.next().expect("no default font found");
let (mut glyphs, mut missing) =
shape_fallback(&font, line, attrs_list, start_run, end_run, span_rtl);
//TODO: improve performance!
while !missing.is_empty() {
@ -151,7 +152,7 @@ fn shape_run(
log::trace!("Evaluating fallback with font '{}'", font.info.family);
let (mut fb_glyphs, fb_missing) =
shape_fallback(font, line, attrs_list, start_run, end_run, span_rtl);
shape_fallback(&font, line, attrs_list, start_run, end_run, span_rtl);
// Insert all matching glyphs
let mut fb_i = 0;
@ -228,7 +229,7 @@ pub struct ShapeGlyph {
pub y_advance: f32,
pub x_offset: f32,
pub y_offset: f32,
pub font_id: fontdb::ID,
pub font_key: FontKey,
pub glyph_id: u16,
pub color_opt: Option<Color>,
pub metadata: usize,
@ -247,7 +248,7 @@ impl ShapeGlyph {
let y_offset = font_size * self.y_offset;
let (cache_key, x_int, y_int) = CacheKey::new(
self.font_id,
self.font_key,
self.glyph_id,
font_size,
(x + x_offset, y - y_offset),