diff options
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/model.rs | 31 | ||||
| -rw-r--r-- | src/layout/text.rs | 20 |
2 files changed, 27 insertions, 24 deletions
diff --git a/src/layout/model.rs b/src/layout/model.rs index 7e899f2e..2800774a 100644 --- a/src/layout/model.rs +++ b/src/layout/model.rs @@ -164,7 +164,8 @@ impl<'a> ModelLayouter<'a> { match node { Space => self.layout_space(), - Newline => self.layout_paragraph(), + Parbreak => self.layout_paragraph(), + Linebreak => self.layouter.finish_line(), Text(text) => { if self.style.text.variant.style == FontStyle::Italic { @@ -175,10 +176,6 @@ impl<'a> ModelLayouter<'a> { decorate(self, Decoration::Bold); } - if self.style.text.monospace { - decorate(self, Decoration::Monospace); - } - self.layout_text(text).await; } @@ -192,12 +189,28 @@ impl<'a> ModelLayouter<'a> { decorate(self, Decoration::Bold); } - ToggleMonospace => { - self.style.text.monospace = !self.style.text.monospace; - decorate(self, Decoration::Monospace); + Raw(lines) => { + // TODO: Make this more efficient. + let fallback = self.style.text.fallback.clone(); + self.style.text.fallback.list.insert(0, "monospace".to_string()); + self.style.text.fallback.flatten(); + + // Layout the first line. + let mut iter = lines.iter(); + if let Some(line) = iter.next() { + self.layout_text(line).await; + } + + // Put a newline before each following line. + for line in iter { + self.layouter.finish_line(); + self.layout_text(line).await; + } + + self.style.text.fallback = fallback; } - Node::Model(model) => { + Model(model) => { self.layout(Spanned::new(model.as_ref(), *span)).await; } } diff --git a/src/layout/text.rs b/src/layout/text.rs index 614d59fd..286ccc68 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -118,23 +118,13 @@ impl<'a> TextLayouter<'a> { variant.weight.0 += 300; } - let queried = if self.ctx.style.monospace { - loader.get(FontQuery { - // FIXME: This is a hack. - fallback: std::iter::once("source code pro") - .chain(self.ctx.style.fallback.iter()), - variant, - c, - }).await - } else { - loader.get(FontQuery { - fallback: self.ctx.style.fallback.iter(), - variant, - c, - }).await + let query = FontQuery { + fallback: self.ctx.style.fallback.iter(), + variant, + c, }; - if let Some((font, index)) = queried { + if let Some((font, index)) = loader.get(query).await { // Determine the width of the char. let header = font.read_table::<Header>().ok()?; let font_unit_ratio = 1.0 / (header.units_per_em as f32); |
