From 2ee5810fecb96a8d4e0d078faecc8c91096d6881 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 6 Jan 2020 12:41:42 +0100 Subject: =?UTF-8?q?Asyncify=20font=20loading=20=F0=9F=AA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/text.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/layout/text.rs') diff --git a/src/layout/text.rs b/src/layout/text.rs index 96704f60..2fdb3f6d 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -20,8 +20,8 @@ pub struct TextContext<'a, 'p> { /// /// There is no complex layout involved. The text is simply laid out left- /// to-right using the correct font for each character. -pub fn layout_text(text: &str, ctx: TextContext) -> LayoutResult { - TextLayouter::new(text, ctx).layout() +pub async fn layout_text(text: &str, ctx: TextContext<'_, '_>) -> LayoutResult { + TextLayouter::new(text, ctx).layout().await } /// Layouts text into boxes. @@ -48,14 +48,14 @@ impl<'a, 'p> TextLayouter<'a, 'p> { } /// Layout the text - fn layout(mut self) -> LayoutResult { + async fn layout(mut self) -> LayoutResult { if self.ctx.axes.primary.is_positive() { for c in self.text.chars() { - self.layout_char(c)?; + self.layout_char(c).await?; } } else { for c in self.text.chars().rev() { - self.layout_char(c)?; + self.layout_char(c).await?; } } @@ -71,8 +71,8 @@ impl<'a, 'p> TextLayouter<'a, 'p> { } /// Layout an individual character. - fn layout_char(&mut self, c: char) -> LayoutResult<()> { - let (index, char_width) = self.select_font(c)?; + async fn layout_char(&mut self, c: char) -> LayoutResult<()> { + let (index, char_width) = self.select_font(c).await?; self.width += char_width; @@ -93,7 +93,7 @@ impl<'a, 'p> TextLayouter<'a, 'p> { /// Select the best font for a character and return its index along with /// the width of the char in the font. - fn select_font(&mut self, c: char) -> LayoutResult<(FontIndex, Size)> { + async fn select_font(&mut self, c: char) -> LayoutResult<(FontIndex, Size)> { let mut loader = self.ctx.loader.borrow_mut(); let query = FontQuery { @@ -102,7 +102,7 @@ impl<'a, 'p> TextLayouter<'a, 'p> { c, }; - if let Some((font, index)) = loader.get(query) { + if let Some((font, index)) = loader.get(query).await { let font_unit_ratio = 1.0 / (font.read_table::
()?.units_per_em as f32); let font_unit_to_size = |x| Size::pt(font_unit_ratio * x); -- cgit v1.2.3