diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-02 21:55:25 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-03 13:55:58 +0200 |
| commit | 23d108c8e099798dc4d35ce9cbcd3e37fb50f3b2 (patch) | |
| tree | aa068b11b9ac0a4795fb6e86bb8283b1d4718e95 /src/library/text/raw.rs | |
| parent | beca01c826ee51c9ee6d5eadd7e5ef10f7fb9f58 (diff) | |
Font fallback
Diffstat (limited to 'src/library/text/raw.rs')
| -rw-r--r-- | src/library/text/raw.rs | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs index e225803f..5c2133c2 100644 --- a/src/library/text/raw.rs +++ b/src/library/text/raw.rs @@ -3,8 +3,8 @@ use syntect::easy::HighlightLines; use syntect::highlighting::{FontStyle, Highlighter, Style, Theme, ThemeSet}; use syntect::parsing::SyntaxSet; +use super::{FontFamily, TextNode}; use crate::library::prelude::*; -use crate::library::text::TextNode; use crate::source::SourceId; use crate::syntax::{self, RedNode}; @@ -26,6 +26,8 @@ pub struct RawNode { #[node(showable)] impl RawNode { + /// The raw text's font family. Just the normal text family if `none`. + pub const FAMILY: Smart<FontFamily> = Smart::Custom(FontFamily::new("IBM Plex Mono")); /// The language to syntax-highlight in. pub const LANG: Option<EcoString> = None; @@ -40,8 +42,14 @@ impl RawNode { impl Show for RawNode { fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { let lang = styles.get_ref(Self::LANG).as_ref(); + let foreground = THEME + .settings + .foreground + .map(Color::from) + .unwrap_or(Color::BLACK) + .into(); - if let Some(content) = styles.show(self, ctx, [ + let mut content = if let Some(content) = styles.show(self, ctx, [ Value::Str(self.text.clone()), match lang { Some(lang) => Value::Str(lang.clone()), @@ -49,17 +57,8 @@ impl Show for RawNode { }, Value::Bool(self.block), ])? { - return Ok(content); - } - - let foreground = THEME - .settings - .foreground - .map(Color::from) - .unwrap_or(Color::BLACK) - .into(); - - let mut content = if matches!( + content + } else if matches!( lang.map(|s| s.to_lowercase()).as_deref(), Some("typ" | "typst") ) { @@ -93,11 +92,18 @@ impl Show for RawNode { Content::Text(self.text.clone()) }; + let mut map = StyleMap::new(); + if let Smart::Custom(family) = styles.get_cloned(Self::FAMILY) { + map.set_family(family, styles); + } + + content = content.styled_with_map(map); + if self.block { content = Content::Block(content.pack()); } - Ok(content.monospaced()) + Ok(content) } } |
