From 1658b00282b631fb5218f477ea7f45f925644cea Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 13 Feb 2020 21:58:49 +0100 Subject: =?UTF-8?q?New=20syntax=20features=20=F0=9F=91=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- src/layout/model.rs | 31 ++++++++++++++++++++++--------- src/layout/text.rs | 20 +++++--------------- 2 files changed, 27 insertions(+), 24 deletions(-) (limited to 'src/layout') 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::
().ok()?; let font_unit_ratio = 1.0 / (header.units_per_em as f32); -- cgit v1.2.3