diff --git a/examples/editor-libcosmic/src/main.rs b/examples/editor-libcosmic/src/main.rs index 6cdf91b..8f5a11a 100644 --- a/examples/editor-libcosmic/src/main.rs +++ b/examples/editor-libcosmic/src/main.rs @@ -42,9 +42,6 @@ lazy_static::lazy_static! { static ref FONT_SYSTEM: FontSystem = FontSystem::new(); } -//TODO: find out how to do this! -static mut FONT_MATCHES: Option> = None; - static FONT_SIZES: &'static [TextMetrics] = &[ TextMetrics::new(10, 14), // Caption TextMetrics::new(14, 20), // Body @@ -57,38 +54,6 @@ static FONT_SIZES: &'static [TextMetrics] = &[ fn main() -> cosmic::iced::Result { env_logger::init(); - let font_matches: FontMatches<'static> = FONT_SYSTEM.matches(|info| -> bool { - #[cfg(feature = "mono")] - let monospaced = true; - - #[cfg(not(feature = "mono"))] - let monospaced = false; - - let matched = { - info.style == fontdb::Style::Normal && - info.weight == fontdb::Weight::NORMAL && - info.stretch == fontdb::Stretch::Normal && - (info.monospaced == monospaced || info.post_script_name.contains("Emoji")) - }; - - if matched { - log::debug!( - "{:?}: family '{}' postscript name '{}' style {:?} weight {:?} stretch {:?} monospaced {:?}", - info.id, - info.family, - info.post_script_name, - info.style, - info.weight, - info.stretch, - info.monospaced - ); - } - - matched - }).unwrap(); - - unsafe { FONT_MATCHES = Some(font_matches); } - let mut settings = settings(); settings.window.min_size = Some((400, 100)); Window::run(settings) @@ -134,9 +99,39 @@ impl Application for Window { type Theme = Theme; fn new(_flags: ()) -> (Self, Command) { + let font_matches: FontMatches<'static> = FONT_SYSTEM.matches(|info| -> bool { + #[cfg(feature = "mono")] + let monospaced = true; + + #[cfg(not(feature = "mono"))] + let monospaced = false; + + let matched = { + info.style == fontdb::Style::Normal && + info.weight == fontdb::Weight::NORMAL && + info.stretch == fontdb::Stretch::Normal && + (info.monospaced == monospaced || info.post_script_name.contains("Emoji")) + }; + + if matched { + log::debug!( + "{:?}: family '{}' postscript name '{}' style {:?} weight {:?} stretch {:?} monospaced {:?}", + info.id, + info.family, + info.post_script_name, + info.style, + info.weight, + info.stretch, + info.monospaced + ); + } + + matched + }).unwrap(); + let font_size_i = 1; // Body let buffer = TextBuffer::new( - unsafe { FONT_MATCHES.as_ref().unwrap() }, + font_matches, FONT_SIZES[font_size_i], ); diff --git a/examples/editor-orbclient/src/main.rs b/examples/editor-orbclient/src/main.rs index 644bfb0..69909e3 100644 --- a/examples/editor-orbclient/src/main.rs +++ b/examples/editor-orbclient/src/main.rs @@ -85,7 +85,7 @@ fn main() { let line_x = 8 * display_scale; let mut buffer = TextBuffer::new( - &font_matches, + font_matches, font_sizes[font_size_i] ); buffer.set_size( diff --git a/examples/editor-test/src/main.rs b/examples/editor-test/src/main.rs index 2753b8d..bf07d68 100644 --- a/examples/editor-test/src/main.rs +++ b/examples/editor-test/src/main.rs @@ -86,7 +86,7 @@ fn main() { let font_size_default = 1; // Body let mut buffer = TextBuffer::new( - &font_matches, + font_matches, font_sizes[font_size_default] ); buffer.set_size( diff --git a/src/buffer.rs b/src/buffer.rs index 261aadc..ed13602 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -167,7 +167,7 @@ impl TextBufferLine { /// A buffer of text that is shaped and laid out pub struct TextBuffer<'a> { - font_matches: &'a FontMatches<'a>, + font_matches: FontMatches<'a>, lines: Vec, metrics: TextMetrics, width: i32, @@ -182,7 +182,7 @@ pub struct TextBuffer<'a> { impl<'a> TextBuffer<'a> { pub fn new( - font_matches: &'a FontMatches<'a>, + font_matches: FontMatches<'a>, metrics: TextMetrics, ) -> Self { let mut buffer = Self { @@ -217,7 +217,7 @@ impl<'a> TextBuffer<'a> { reshaped += 1; } let layout = line.layout( - self.font_matches, + &self.font_matches, self.metrics.font_size, self.width ); @@ -247,7 +247,7 @@ impl<'a> TextBuffer<'a> { reshaped += 1; } let layout = line.layout( - self.font_matches, + &self.font_matches, self.metrics.font_size, self.width ); @@ -309,7 +309,7 @@ impl<'a> TextBuffer<'a> { if line.shape_opt.is_some() { line.layout_opt = None; line.layout( - self.font_matches, + &self.font_matches, self.metrics.font_size, self.width ); @@ -368,7 +368,7 @@ impl<'a> TextBuffer<'a> { fn set_layout_cursor(&mut self, cursor: LayoutCursor) { let line = &mut self.lines[cursor.line.get()]; let layout = line.layout( - self.font_matches, + &self.font_matches, self.metrics.font_size, self.width ); @@ -547,7 +547,7 @@ impl<'a> TextBuffer<'a> { let layout_len = { let line = &mut self.lines[cursor.line.get()]; let layout = line.layout( - self.font_matches, + &self.font_matches, self.metrics.font_size, self.width ); @@ -984,7 +984,7 @@ impl<'a> TextBuffer<'a> { for glyph in layout_line.glyphs.iter() { let (cache_key, x_int, y_int) = (glyph.cache_key, glyph.x_int, glyph.y_int); - self.cache.with_pixels(self.font_matches, cache_key, color, |x, y, color| { + self.cache.with_pixels(&self.font_matches, cache_key, color, |x, y, color| { f(x_int + x, line_y + y_int + y, 1, 1, color) }); } diff --git a/src/font/system.rs b/src/font/system.rs index 40dee32..251c063 100644 --- a/src/font/system.rs +++ b/src/font/system.rs @@ -35,9 +35,7 @@ impl FontSystem { assert_eq!(db.len(), db.faces().len()); for i in 0..db.len() { let id = db.faces()[i].id; - unsafe { - db.make_shared_face_data(id); - } + unsafe { db.make_shared_face_data(id); } } Self { locale, db }