use crate::length::{Length, ScaleLength}; use crate::paper::{Paper, PaperClass}; use super::*; function! { /// `page`: Configure pages. #[derive(Debug, Clone, PartialEq)] pub struct PageFunc { paper: Option, width: Option, height: Option, margins: Option, left: Option, right: Option, top: Option, bottom: Option, flip: bool, } parse(header, body, state, f) { expect_no_body(body, f); Self { paper: header.args.pos.get::(), width: header.args.key.get::("width", f), height: header.args.key.get::("height", f), margins: header.args.key.get::("margins", f), left: header.args.key.get::("left", f), right: header.args.key.get::("right", f), top: header.args.key.get::("top", f), bottom: header.args.key.get::("bottom", f), flip: header.args.key.get::("flip", f).unwrap_or(false), } } layout(self, ctx, f) { let mut style = ctx.style.page; if let Some(paper) = self.paper { style.class = paper.class; style.size = paper.size(); } else if self.width.is_some() || self.height.is_some() { style.class = PaperClass::Custom; } self.width.with(|v| style.size.x = v.as_raw()); self.height.with(|v| style.size.y = v.as_raw()); self.margins.with(|v| style.margins.set_all(Some(v))); self.left.with(|v| style.margins.left = Some(v)); self.right.with(|v| style.margins.right = Some(v)); self.top.with(|v| style.margins.top = Some(v)); self.bottom.with(|v| style.margins.bottom = Some(v)); if self.flip { style.size.swap(); } vec![SetPageStyle(style)] } }