Merge branch 'mut-font-system' of https://github.com/geieredgar/cosmic-text into geieredgar-mut-font-system

This commit is contained in:
Jeremy Soller 2023-03-17 18:15:45 -06:00
commit 9ebbc33792
23 changed files with 650 additions and 453 deletions

View file

@ -21,7 +21,7 @@ fn shape_fallback(
) -> (Vec<ShapeGlyph>, Vec<usize>) {
let run = &line[start_run..end_run];
let font_scale = font.rustybuzz.units_per_em() as f32;
let font_scale = font.rustybuzz().units_per_em() as f32;
let mut buffer = rustybuzz::UnicodeBuffer::new();
buffer.set_direction(if span_rtl {
@ -35,7 +35,7 @@ fn shape_fallback(
let rtl = matches!(buffer.direction(), rustybuzz::Direction::RightToLeft);
assert_eq!(rtl, span_rtl);
let glyph_buffer = rustybuzz::shape(&font.rustybuzz, &[], buffer);
let glyph_buffer = rustybuzz::shape(font.rustybuzz(), &[], buffer);
let glyph_infos = glyph_buffer.glyph_infos();
let glyph_positions = glyph_buffer.glyph_positions();
@ -61,7 +61,7 @@ fn shape_fallback(
y_advance,
x_offset,
y_offset,
font_id: font.info.id,
font_id: font.id(),
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,
@ -98,7 +98,7 @@ fn shape_fallback(
}
fn shape_run(
font_system: &FontSystem,
font_system: &mut FontSystem,
line: &str,
attrs_list: &AttrsList,
start_run: usize,
@ -122,24 +122,15 @@ fn shape_run(
let attrs = attrs_list.get_span(start_run);
let font_matches = font_system.get_font_matches(attrs);
let fonts = font_system.get_font_matches(attrs);
let default_families = [font_matches.default_family.as_str()];
let mut font_iter = FontFallbackIter::new(
&font_matches.fonts,
&default_families,
scripts,
font_matches.locale,
);
let default_families = [&attrs.family];
let mut font_iter = FontFallbackIter::new(font_system, &fonts, &default_families, scripts);
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() {
@ -148,9 +139,12 @@ fn shape_run(
None => break,
};
log::trace!("Evaluating fallback with font '{}'", font.name());
log::trace!(
"Evaluating fallback with font '{}'",
font_iter.face_name(font.id())
);
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;
@ -278,7 +272,7 @@ pub struct ShapeWord {
impl ShapeWord {
pub fn new(
font_system: &FontSystem,
font_system: &mut FontSystem,
line: &str,
attrs_list: &AttrsList,
word_range: Range<usize>,
@ -352,7 +346,7 @@ pub struct ShapeSpan {
impl ShapeSpan {
pub fn new(
font_system: &FontSystem,
font_system: &mut FontSystem,
line: &str,
attrs_list: &AttrsList,
span_range: Range<usize>,
@ -443,7 +437,7 @@ impl ShapeLine {
/// # Panics
///
/// Will panic if `line` contains more than one paragraph.
pub fn new(font_system: &FontSystem, line: &str, attrs_list: &AttrsList) -> Self {
pub fn new(font_system: &mut FontSystem, line: &str, attrs_list: &AttrsList) -> Self {
let mut spans = Vec::new();
let bidi = unicode_bidi::BidiInfo::new(line, None);