From ec5384c97f24c3e6d8284926fd3e415f47fe2b04 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 25 Jul 2021 01:16:38 +0200 Subject: State-based monospace handling --- src/exec/context.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/exec/context.rs') diff --git a/src/exec/context.rs b/src/exec/context.rs index 925fd7de..13e53b09 100644 --- a/src/exec/context.rs +++ b/src/exec/context.rs @@ -1,7 +1,7 @@ use std::mem; use std::rc::Rc; -use super::{Exec, ExecWithMap, FontFamily, State}; +use super::{Exec, ExecWithMap, State}; use crate::diag::{Diag, DiagSet, Pass}; use crate::eco::EcoString; use crate::eval::{ExprMap, Template}; @@ -44,15 +44,6 @@ impl ExecContext { self.diags.insert(diag); } - /// Set the font to monospace. - pub fn set_monospace(&mut self) { - self.state - .font_mut() - .families_mut() - .list - .insert(0, FontFamily::Monospace); - } - /// Execute a template and return the result as a stack node. pub fn exec_template_stack(&mut self, template: &Template) -> StackNode { self.exec_stack(|ctx| template.exec(ctx)) @@ -83,6 +74,14 @@ impl ExecContext { self.stack.par.push(self.make_text_node(text)); } + /// Push text, but in monospace. + pub fn push_monospace_text(&mut self, text: impl Into) { + let prev = Rc::clone(&self.state.font); + self.state.font_mut().monospace = true; + self.push_text(text); + self.state.font = prev; + } + /// Push a word space into the active paragraph. pub fn push_word_space(&mut self) { self.stack.par.push_soft(self.make_text_node(" ")); -- cgit v1.2.3