summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-19 13:32:12 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-19 13:32:12 +0100
commitca3df70e2a5069832d7d2135967674c34a155442 (patch)
tree9a92594d73ce060f30296df5c3bc3e230d9d8459 /src/library
parent54a9ccb1a5e9f1f1e5d2538d2f4ce3d4f7afc4ae (diff)
Add basic paragraph function 📑
Allows to change: - (paragraph) spacing - leading - word-spacing
Diffstat (limited to 'src/library')
-rw-r--r--src/library/mod.rs3
-rw-r--r--src/library/par.rs41
2 files changed, 44 insertions, 0 deletions
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 453eab26..e813a138 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -9,6 +9,7 @@ mod font;
mod image;
mod pad;
mod page;
+mod par;
mod shapes;
mod spacing;
@@ -18,6 +19,7 @@ pub use base::*;
pub use font::*;
pub use pad::*;
pub use page::*;
+pub use par::*;
pub use shapes::*;
pub use spacing::*;
@@ -50,6 +52,7 @@ pub fn new() -> Scope {
set!(func: "pad", pad);
set!(func: "page", page);
set!(func: "pagebreak", pagebreak);
+ set!(func: "paragraph", paragraph);
set!(func: "rect", rect);
set!(func: "repr", repr);
set!(func: "rgb", rgb);
diff --git a/src/library/par.rs b/src/library/par.rs
new file mode 100644
index 00000000..8242bfdc
--- /dev/null
+++ b/src/library/par.rs
@@ -0,0 +1,41 @@
+use super::*;
+
+/// `paragraph`: Configure paragraphs.
+///
+/// # Named parameters
+/// - Paragraph spacing: `spacing`, of type `linear` relative to current font size.
+/// - Line leading: `leading`, of type `linear` relative to current font size.
+/// - Word spacing: `word-spacing`, of type `linear` relative to current font size.
+///
+/// # Return value
+/// A template that configures paragraph properties. The effect is scoped to the
+/// body if present.
+pub fn paragraph(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value {
+ let spacing = args.get(ctx, "spacing");
+ let leading = args.get(ctx, "leading");
+ let word_spacing = args.get(ctx, "word-spacing");
+ let body = args.find::<ValueTemplate>(ctx);
+
+ Value::template("paragraph", move |ctx| {
+ let snapshot = ctx.state.clone();
+
+ if let Some(spacing) = spacing {
+ ctx.state.par.spacing = spacing;
+ }
+
+ if let Some(leading) = leading {
+ ctx.state.par.leading = leading;
+ }
+
+ if let Some(word_spacing) = word_spacing {
+ ctx.state.par.word_spacing = word_spacing;
+ }
+
+ ctx.push_parbreak();
+
+ if let Some(body) = &body {
+ body.exec(ctx);
+ ctx.state = snapshot;
+ }
+ })
+}