diff options
Diffstat (limited to 'library/src/layout')
| -rw-r--r-- | library/src/layout/measure.rs | 20 | ||||
| -rw-r--r-- | library/src/layout/mod.rs | 2 | ||||
| -rw-r--r-- | library/src/layout/page.rs | 21 |
3 files changed, 34 insertions, 9 deletions
diff --git a/library/src/layout/measure.rs b/library/src/layout/measure.rs new file mode 100644 index 00000000..b116cbf8 --- /dev/null +++ b/library/src/layout/measure.rs @@ -0,0 +1,20 @@ +use crate::prelude::*; + +/// Measure the size of content. +/// +/// Display: Measure +/// Category: layout +/// Returns: array +#[func] +pub fn measure( + /// The content whose size to measure. + content: Content, + /// The styles with which to layout the content. + styles: StyleMap, +) -> Value { + let pod = Regions::one(Axes::splat(Abs::inf()), Axes::splat(false)); + let styles = StyleChain::new(&styles); + let frame = content.measure(&mut vm.vt, styles, pod)?.into_frame(); + let Size { x, y } = frame.size(); + Value::Array(array![x, y]) +} diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index 0ce292aa..b6ecce51 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -10,6 +10,7 @@ mod fragment; mod grid; mod hide; mod list; +mod measure; mod pad; mod page; mod par; @@ -31,6 +32,7 @@ pub use self::fragment::*; pub use self::grid::*; pub use self::hide::*; pub use self::list::*; +pub use self::measure::*; pub use self::pad::*; pub use self::page::*; pub use self::par::*; diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs index eeb74a55..93ee08ce 100644 --- a/library/src/layout/page.rs +++ b/library/src/layout/page.rs @@ -2,7 +2,7 @@ use std::ptr; use std::str::FromStr; use super::{AlignNode, ColumnsNode}; -use crate::meta::{Counter, CounterAction, CounterKey, CounterNode, Numbering}; +use crate::meta::{Counter, CounterKey, Numbering}; use crate::prelude::*; /// Layouts its child onto one or multiple pages. @@ -214,8 +214,10 @@ pub struct PageNode { /// footer: [ /// #set align(right) /// #set text(8pt) - /// #counter(page).get("1") of - /// #counter(page).final("I") + /// #counter(page).display( + /// "1 of I", + /// both: true, + /// ) /// ] /// ) /// @@ -311,12 +313,13 @@ impl PageNode { let header_ascent = self.header_ascent(styles); let footer = self.footer(styles).or_else(|| { self.numbering(styles).map(|numbering| { - CounterNode::new( - Counter::new(CounterKey::Page), - CounterAction::Both(numbering), - ) - .pack() - .aligned(self.number_align(styles)) + let both = match &numbering { + Numbering::Pattern(pattern) => pattern.pieces() >= 2, + Numbering::Func(_) => true, + }; + Counter::new(CounterKey::Page) + .display(numbering, both) + .aligned(self.number_align(styles)) }) }); let footer_descent = self.footer_descent(styles); |
