From 9bdc4a7de0fb685fa2b8d02280e70aa0b5d92bf9 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 17 Apr 2023 13:25:31 +0200 Subject: Write PDF outline --- library/src/lib.rs | 1 + library/src/meta/figure.rs | 12 ++++++------ library/src/prelude.rs | 6 +++--- library/src/text/misc.rs | 8 +++++++- library/src/text/mod.rs | 8 +++++++- 5 files changed, 24 insertions(+), 11 deletions(-) (limited to 'library') diff --git a/library/src/lib.rs b/library/src/lib.rs index caf76ded..ccdf448c 100644 --- a/library/src/lib.rs +++ b/library/src/lib.rs @@ -211,6 +211,7 @@ fn items() -> LangItems { }, bibliography_keys: meta::BibliographyElem::keys, heading: |level, title| meta::HeadingElem::new(title).with_level(level).pack(), + heading_func: meta::HeadingElem::func(), list_item: |body| layout::ListItem::new(body).pack(), enum_item: |number, body| { let mut elem = layout::EnumItem::new(body); diff --git a/library/src/meta/figure.rs b/library/src/meta/figure.rs index 42b32c9d..1f1499fc 100644 --- a/library/src/meta/figure.rs +++ b/library/src/meta/figure.rs @@ -173,14 +173,14 @@ impl Synthesize for FigureElem { // Determine the figure's kind. let kind = match self.kind(styles) { Smart::Auto => self - .find_figurable(vt, styles) + .find_figurable(styles) .map(|elem| FigureKind::Elem(elem.func())) .unwrap_or_else(|| FigureKind::Elem(ImageElem::func())), Smart::Custom(kind) => kind, }; let content = match &kind { - FigureKind::Elem(func) => self.find_of_elem(vt, *func), + FigureKind::Elem(func) => self.find_of_elem(*func), FigureKind::Name(_) => None, } .unwrap_or_else(|| self.body()); @@ -303,9 +303,9 @@ impl Refable for FigureElem { impl FigureElem { /// Determines the type of the figure by looking at the content, finding all /// [`Figurable`] elements and sorting them by priority then returning the highest. - pub fn find_figurable(&self, vt: &Vt, styles: StyleChain) -> Option { + pub fn find_figurable(&self, styles: StyleChain) -> Option { self.body() - .query(vt.introspector, Selector::can::()) + .query(Selector::can::()) .into_iter() .max_by_key(|elem| elem.with::().unwrap().priority(styles)) .cloned() @@ -313,9 +313,9 @@ impl FigureElem { /// Finds the element with the given function in the figure's content. /// Returns `None` if no element with the given function is found. - pub fn find_of_elem(&self, vt: &Vt, func: ElemFunc) -> Option { + pub fn find_of_elem(&self, func: ElemFunc) -> Option { self.body() - .query(vt.introspector, Selector::Elem(func, None)) + .query(Selector::Elem(func, None)) .into_iter() .next() .cloned() diff --git a/library/src/prelude.rs b/library/src/prelude.rs index fc71e2c2..cb21a732 100644 --- a/library/src/prelude.rs +++ b/library/src/prelude.rs @@ -23,9 +23,9 @@ pub use typst::geom::*; #[doc(no_inline)] pub use typst::model::{ element, Behave, Behaviour, Construct, Content, ElemFunc, Element, Finalize, Fold, - Introspector, Label, Locatable, LocatableSelector, Location, MetaElem, Resolve, - Selector, Set, Show, StabilityProvider, StyleChain, StyleVec, Styles, Synthesize, - Unlabellable, Vt, + Introspector, Label, Locatable, LocatableSelector, Location, MetaElem, PlainText, + Resolve, Selector, Set, Show, StabilityProvider, StyleChain, StyleVec, Styles, + Synthesize, Unlabellable, Vt, }; #[doc(no_inline)] pub use typst::syntax::{Span, Spanned}; diff --git a/library/src/text/misc.rs b/library/src/text/misc.rs index e1d9c0f2..a707d130 100644 --- a/library/src/text/misc.rs +++ b/library/src/text/misc.rs @@ -5,7 +5,7 @@ use crate::prelude::*; /// /// Display: Space /// Category: text -#[element(Unlabellable, Behave)] +#[element(Behave, Unlabellable, PlainText)] pub struct SpaceElem {} impl Behave for SpaceElem { @@ -16,6 +16,12 @@ impl Behave for SpaceElem { impl Unlabellable for SpaceElem {} +impl PlainText for SpaceElem { + fn plain_text(&self, text: &mut EcoString) { + text.push(' '); + } +} + /// Inserts a line break. /// /// Advances the paragraph to the next line. A single trailing line break at the diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs index 16268aad..f4b3c0de 100644 --- a/library/src/text/mod.rs +++ b/library/src/text/mod.rs @@ -40,7 +40,7 @@ use crate::prelude::*; /// /// Display: Text /// Category: text -#[element(Construct)] +#[element(Construct, PlainText)] pub struct TextElem { /// A prioritized sequence of font families. /// @@ -497,6 +497,12 @@ impl Construct for TextElem { } } +impl PlainText for TextElem { + fn plain_text(&self, text: &mut EcoString) { + text.push_str(&self.text()); + } +} + /// A lowercased font family like "arial". #[derive(Clone, Eq, PartialEq, Hash)] pub struct FontFamily(EcoString); -- cgit v1.2.3