diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-02-13 21:58:49 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-02-13 21:58:49 +0100 |
| commit | 1658b00282b631fb5218f477ea7f45f925644cea (patch) | |
| tree | 13a0f51f335e687c363a5afb9cc73993a69489cc /src/layout | |
| parent | 60099aed50b89daef29543c4700470e566c48798 (diff) | |
New syntax features 👔
- Forced line breaks with backslash followed by whitespace
- (Multline) raw text in backticks
- Set font class fallbacks with [font.family] (e.g. [font.family: monospace=("CMU Typewriter Text")])
- More sophisticated procedure to find end of function, which accounts for comments, strings, raw text and nested functions (this is a mix of a feature and a bug fix)
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); |
