summaryrefslogtreecommitdiff
path: root/src/layout/text.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-01-06 12:41:42 +0100
committerLaurenz <laurmaedje@gmail.com>2020-01-06 12:41:42 +0100
commit2ee5810fecb96a8d4e0d078faecc8c91096d6881 (patch)
tree702c746a3021f5034e1b31cd07e8fadba0e4dd7a /src/layout/text.rs
parentbd384a2a633e21cd7deff7ed2a29a9c03a63a20e (diff)
Asyncify font loading 🪐
Diffstat (limited to 'src/layout/text.rs')
-rw-r--r--src/layout/text.rs18
1 files changed, 9 insertions, 9 deletions
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<Layout> {
- TextLayouter::new(text, ctx).layout()
+pub async fn layout_text(text: &str, ctx: TextContext<'_, '_>) -> LayoutResult<Layout> {
+ 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<Layout> {
+ async fn layout(mut self) -> LayoutResult<Layout> {
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::<Header>()?.units_per_em as f32);
let font_unit_to_size = |x| Size::pt(font_unit_ratio * x);