summaryrefslogtreecommitdiff
path: root/src/library/page.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-11-18 15:10:11 +0100
committerLaurenz <laurmaedje@gmail.com>2019-11-18 15:10:11 +0100
commit1a6fb48bc5e95d0a9ef243ab62517557189c0eea (patch)
tree06f704fe638d5ae25f4976874500c5da75316348 /src/library/page.rs
parent1eb25f86dd6763c4f2d7e60b6d09af60ada50af6 (diff)
Page style modification functions 📜
- `page.size` - `page.margins`
Diffstat (limited to 'src/library/page.rs')
-rw-r--r--src/library/page.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/library/page.rs b/src/library/page.rs
new file mode 100644
index 00000000..4efcbea0
--- /dev/null
+++ b/src/library/page.rs
@@ -0,0 +1,79 @@
+use crate::func::prelude::*;
+
+/// `page.break`: Ends the current page.
+#[derive(Debug, PartialEq)]
+pub struct PageBreak;
+
+function! {
+ data: PageBreak,
+ parse: plain,
+ layout(_, _) { Ok(commands![FinishLayout]) }
+}
+
+/// `page.size`: Set the size of pages.
+#[derive(Debug, PartialEq)]
+pub struct PageSize {
+ width: Option<Size>,
+ height: Option<Size>,
+}
+
+function! {
+ data: PageSize,
+
+ parse(args, body, _ctx) {
+ parse!(forbidden: body);
+ Ok(PageSize {
+ width: args.get_key_opt::<ArgSize>("width")?.map(|a| a.val),
+ height: args.get_key_opt::<ArgSize>("height")?.map(|a| a.val),
+ })
+ }
+
+ layout(this, ctx) {
+ let mut style = ctx.page_style;
+
+ if let Some(width) = this.width { style.dimensions.x = width; }
+ if let Some(height) = this.height { style.dimensions.y = height; }
+
+ Ok(commands![SetPageStyle(style)])
+ }
+}
+
+/// `page.margins`: Set the margins of pages.
+#[derive(Debug, PartialEq)]
+pub struct PageMargins {
+ left: Option<Size>,
+ top: Option<Size>,
+ right: Option<Size>,
+ bottom: Option<Size>,
+}
+
+function! {
+ data: PageMargins,
+
+ parse(args, body, _ctx) {
+ parse!(forbidden: body);
+ let default = args.get_pos_opt::<ArgSize>()?;
+ let mut get = |which| {
+ args.get_key_opt::<ArgSize>(which)
+ .map(|size| size.or(default).map(|a| a.val))
+ };
+
+ Ok(PageMargins {
+ left: get("left")?,
+ top: get("top")?,
+ right: get("right")?,
+ bottom: get("bottom")?,
+ })
+ }
+
+ layout(this, ctx) {
+ let mut style = ctx.page_style;
+
+ if let Some(left) = this.left { style.margins.left = left; }
+ if let Some(top) = this.top { style.margins.top = top; }
+ if let Some(right) = this.right { style.margins.right = right; }
+ if let Some(bottom) = this.bottom { style.margins.bottom = bottom; }
+
+ Ok(commands![SetPageStyle(style)])
+ }
+}