From 92f2c56203c6528e35ec1feae14e5dd2c2425311 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 18 Nov 2022 11:25:36 +0100 Subject: [PATCH] Reorganize style module --- library/src/layout/columns.rs | 2 +- library/src/layout/container.rs | 4 +- library/src/layout/flow.rs | 4 +- library/src/layout/mod.rs | 10 +- library/src/text/mod.rs | 6 +- library/src/text/par.rs | 2 +- src/model/content.rs | 10 +- src/model/styles.rs | 732 ++++++++++++++++---------------- 8 files changed, 378 insertions(+), 392 deletions(-) diff --git a/library/src/layout/columns.rs b/library/src/layout/columns.rs index ec9510d8d..c5a340ee1 100644 --- a/library/src/layout/columns.rs +++ b/library/src/layout/columns.rs @@ -99,7 +99,7 @@ impl LayoutBlock for ColumnsNode { } /// A column break. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Hash)] pub struct ColbreakNode { pub weak: bool, } diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs index eb899d547..408f67207 100644 --- a/library/src/layout/container.rs +++ b/library/src/layout/container.rs @@ -2,7 +2,7 @@ use super::VNode; use crate::prelude::*; /// An inline-level container that sizes content. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Hash)] pub struct BoxNode { /// How to size the content horizontally and vertically. pub sizing: Axes>>, @@ -58,7 +58,7 @@ impl LayoutInline for BoxNode { } /// A block-level container that places content into a separate flow. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Hash)] pub struct BlockNode(pub Content); #[node(LayoutBlock)] diff --git a/library/src/layout/flow.rs b/library/src/layout/flow.rs index f47a8f42f..b69f4f4e9 100644 --- a/library/src/layout/flow.rs +++ b/library/src/layout/flow.rs @@ -1,4 +1,4 @@ -use typst::model::{Property, StyleEntry}; +use typst::model::{Property, Style}; use super::{AlignNode, ColbreakNode, PlaceNode, Spacing, VNode}; use crate::prelude::*; @@ -161,7 +161,7 @@ impl FlowLayouter { let mut chained = styles; if !self.last_block_was_par && is_par && !styles.get(ParNode::INDENT).is_zero() { let property = Property::new(ParNode::INDENT, Length::zero()); - reset = StyleEntry::Property(property); + reset = Style::Property(property); chained = reset.chain(&styles); } diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index 5812115aa..bcc5bf6dd 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -32,8 +32,8 @@ use typst::diag::SourceResult; use typst::frame::Frame; use typst::geom::*; use typst::model::{ - capability, Content, Node, SequenceNode, Show, StyleChain, StyleEntry, - StyleVecBuilder, StyledNode, + capability, Content, Node, SequenceNode, Show, Style, StyleChain, StyleVecBuilder, + StyledNode, }; use typst::World; @@ -89,7 +89,7 @@ impl LayoutBlock for Content { ) -> SourceResult> { if !self.has::() || !styles.applicable(self) { if let Some(node) = self.to::() { - let barrier = StyleEntry::Barrier(self.id()); + let barrier = Style::Barrier(self.id()); let styles = barrier.chain(&styles); return node.layout_block(world, regions, styles); } @@ -128,13 +128,13 @@ impl LayoutInline for Content { if !self.has::() || !styles.applicable(self) { if let Some(node) = self.to::() { - let barrier = StyleEntry::Barrier(self.id()); + let barrier = Style::Barrier(self.id()); let styles = barrier.chain(&styles); return node.layout_inline(world, regions, styles); } if let Some(node) = self.to::() { - let barrier = StyleEntry::Barrier(self.id()); + let barrier = Style::Barrier(self.id()); let styles = barrier.chain(&styles); return Ok(node.layout_block(world, regions, styles)?.remove(0)); } diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs index 8484ff576..1ab1c37d8 100644 --- a/library/src/text/mod.rs +++ b/library/src/text/mod.rs @@ -407,7 +407,7 @@ impl Fold for FontFeatures { } /// A text space. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Hash)] pub struct SpaceNode; #[node(Behave)] @@ -424,7 +424,7 @@ impl Behave for SpaceNode { } /// A line break. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Hash)] pub struct LinebreakNode { pub justify: bool, } @@ -444,7 +444,7 @@ impl Behave for LinebreakNode { } /// A smart quote. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Hash)] pub struct SmartQuoteNode { pub double: bool, } diff --git a/library/src/text/par.rs b/library/src/text/par.rs index 1d01071da..6551ae9c4 100644 --- a/library/src/text/par.rs +++ b/library/src/text/par.rs @@ -114,7 +114,7 @@ castable! { } /// A paragraph break. -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Hash)] pub struct ParbreakNode; #[node] diff --git a/src/model/content.rs b/src/model/content.rs index 3851d38d2..3cae99b2d 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -9,7 +9,7 @@ use comemo::Tracked; use siphasher::sip128::{Hasher128, SipHasher}; use typst_macros::node; -use super::{Args, Key, Property, Recipe, RecipeId, StyleEntry, StyleMap, Value, Vm}; +use super::{Args, Key, Property, Recipe, RecipeId, Style, StyleMap, Value, Vm}; use crate::diag::{SourceResult, StrResult}; use crate::util::ReadableTypeId; use crate::World; @@ -95,7 +95,7 @@ impl Content { /// Style this content with a single style property. pub fn styled<'k, K: Key<'k>>(self, key: K, value: K::Value) -> Self { - self.styled_with_entry(StyleEntry::Property(Property::new(key, value))) + self.styled_with_entry(Style::Property(Property::new(key, value))) } /// Style this content with a recipe, eagerly applying it if possible. @@ -107,12 +107,12 @@ impl Content { if recipe.selector.is_none() { recipe.transform.apply(world, recipe.span, || Value::Content(self)) } else { - Ok(self.styled_with_entry(StyleEntry::Recipe(recipe))) + Ok(self.styled_with_entry(Style::Recipe(recipe))) } } /// Style this content with a style entry. - pub fn styled_with_entry(mut self, entry: StyleEntry) -> Self { + pub fn styled_with_entry(mut self, entry: Style) -> Self { if let Some(styled) = self.try_downcast_mut::() { styled.map.apply(entry); self @@ -141,7 +141,7 @@ impl Content { /// Reenable a specific show rule recipe. pub fn unguard(&self, id: RecipeId) -> Self { - self.clone().styled_with_entry(StyleEntry::Unguard(id)) + self.clone().styled_with_entry(Style::Unguard(id)) } } diff --git a/src/model/styles.rs b/src/model/styles.rs index 7aa041c7a..16c1eab4f 100644 --- a/src/model/styles.rs +++ b/src/model/styles.rs @@ -18,7 +18,7 @@ use crate::World; /// A map of style properties. #[derive(Default, Clone, PartialEq, Hash)] -pub struct StyleMap(Vec); +pub struct StyleMap(Vec