diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-07-25 01:16:38 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-07-25 01:16:38 +0200 |
| commit | ec5384c97f24c3e6d8284926fd3e415f47fe2b04 (patch) | |
| tree | ae95815628fd9ae9f765453a6a4b8729b26943ab /src/exec/context.rs | |
| parent | dcfbf95220300a7866b6d03953fb4d29511cd6fa (diff) | |
State-based monospace handling
Diffstat (limited to 'src/exec/context.rs')
| -rw-r--r-- | src/exec/context.rs | 19 |
1 files changed, 9 insertions, 10 deletions
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<EcoString>) { + 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(" ")); |
