From 010cc2effc2fd0e1c4e52d5c914cb4d74506bc0a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 9 Nov 2022 18:16:59 +0100 Subject: New block spacing model --- library/src/text/par.rs | 12 +++--------- library/src/text/raw.rs | 33 ++++----------------------------- 2 files changed, 7 insertions(+), 38 deletions(-) (limited to 'library/src/text') 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 = None; - /// The spacing above block-level raw. - #[property(resolve, shorthand(around))] - pub const ABOVE: Option = Some(Ratio::one().into()); - /// The spacing below block-level raw. - #[property(resolve, shorthand(around))] - pub const BELOW: Option = Some(Ratio::one().into()); fn construct(_: &mut Vm, args: &mut Args) -> SourceResult { 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, - styles: StyleChain, - mut realized: Content, - ) -> SourceResult { - 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); -- cgit v1.2.3