diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-09 18:16:59 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-09 18:20:02 +0100 |
| commit | 010cc2effc2fd0e1c4e52d5c914cb4d74506bc0a (patch) | |
| tree | e50060d271f076b00945e5569e7f8ffef2c28e9f /library/src/text | |
| parent | 12a59963b08b68cc39dcded4d3d3e6a6631c2732 (diff) | |
New block spacing model
Diffstat (limited to 'library/src/text')
| -rw-r--r-- | library/src/text/par.rs | 12 | ||||
| -rw-r--r-- | library/src/text/raw.rs | 33 |
2 files changed, 7 insertions, 38 deletions
diff --git a/library/src/text/par.rs b/library/src/text/par.rs index de948a98..0c4ec7af 100644 --- a/library/src/text/par.rs +++ b/library/src/text/par.rs @@ -28,18 +28,12 @@ pub enum ParChild { #[node(LayoutBlock)] impl ParNode { - /// The spacing between lines. - #[property(resolve)] - pub const LEADING: Length = Em::new(0.65).into(); - /// The extra spacing between paragraphs. - #[property(resolve)] - pub const SPACING: Length = Em::new(1.2).into(); /// The indent the first line of a consecutive paragraph should have. #[property(resolve)] pub const INDENT: Length = Length::zero(); - /// Whether to allow paragraph spacing when there is paragraph indent. - pub const SPACING_AND_INDENT: bool = false; - + /// The spacing between lines. + #[property(resolve)] + pub const LEADING: Length = Em::new(0.65).into(); /// How to align text and inline objects in their line. #[property(resolve)] pub const ALIGN: HorizontalAlign = HorizontalAlign(GenAlign::Start); diff --git a/library/src/text/raw.rs b/library/src/text/raw.rs index 2041b25e..d7dae244 100644 --- a/library/src/text/raw.rs +++ b/library/src/text/raw.rs @@ -6,8 +6,8 @@ use syntect::highlighting::{ use syntect::parsing::SyntaxSet; use typst::syntax; -use super::{FallbackList, FontFamily, Hyphenate, LinebreakNode, TextNode}; -use crate::layout::{BlockNode, BlockSpacing}; +use super::{FontFamily, Hyphenate, LinebreakNode, TextNode}; +use crate::layout::BlockNode; use crate::prelude::*; /// Monospaced text with optional syntax highlighting. @@ -19,17 +19,11 @@ pub struct RawNode { pub block: bool, } -#[node(Show, Finalize)] +#[node(Show)] impl RawNode { /// The language to syntax-highlight in. #[property(referenced)] pub const LANG: Option<EcoString> = None; - /// The spacing above block-level raw. - #[property(resolve, shorthand(around))] - pub const ABOVE: Option<BlockSpacing> = Some(Ratio::one().into()); - /// The spacing below block-level raw. - #[property(resolve, shorthand(around))] - pub const BELOW: Option<BlockSpacing> = Some(Ratio::one().into()); fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> { Ok(Self { @@ -104,31 +98,12 @@ impl Show for RawNode { map.set(TextNode::OVERHANG, false); map.set(TextNode::HYPHENATE, Hyphenate(Smart::Custom(false))); map.set(TextNode::SMART_QUOTES, false); + map.set_family(FontFamily::new("IBM Plex Mono"), styles); Ok(realized.styled_with_map(map)) } } -impl Finalize for RawNode { - fn finalize( - &self, - _: Tracked<dyn World>, - styles: StyleChain, - mut realized: Content, - ) -> SourceResult<Content> { - realized = realized.styled( - TextNode::FAMILY, - FallbackList(vec![FontFamily::new("IBM Plex Mono")]), - ); - - if self.block { - realized = realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW)); - } - - Ok(realized) - } -} - /// Style a piece of text with a syntect style. fn styled(piece: &str, foreground: Paint, style: Style) -> Content { let mut body = TextNode::packed(piece); |
