summaryrefslogtreecommitdiff
path: root/crates/typst-layout/src/inline/finalize.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-10-27 19:04:55 +0100
committerGitHub <noreply@github.com>2024-10-27 18:04:55 +0000
commitbe7cfc85d08c545abfac08098b7b33b4bd71f37e (patch)
treef4137fa2aaa57babae1f7603a9b2ed7e688f43d8 /crates/typst-layout/src/inline/finalize.rs
parentb8034a343831e8609aec2ec81eb7eeda57aa5d81 (diff)
Split out four new crates (#5302)
Diffstat (limited to 'crates/typst-layout/src/inline/finalize.rs')
-rw-r--r--crates/typst-layout/src/inline/finalize.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/typst-layout/src/inline/finalize.rs b/crates/typst-layout/src/inline/finalize.rs
new file mode 100644
index 00000000..599ace9d
--- /dev/null
+++ b/crates/typst-layout/src/inline/finalize.rs
@@ -0,0 +1,36 @@
+use typst_library::introspection::SplitLocator;
+use typst_utils::Numeric;
+
+use super::*;
+
+/// Turns the selected lines into frames.
+#[typst_macros::time]
+pub fn finalize(
+ engine: &mut Engine,
+ p: &Preparation,
+ lines: &[Line],
+ styles: StyleChain,
+ region: Size,
+ expand: bool,
+ locator: &mut SplitLocator<'_>,
+) -> SourceResult<Fragment> {
+ // Determine the paragraph's width: Full width of the region if we should
+ // expand or there's fractional spacing, fit-to-width otherwise.
+ let width = if !region.x.is_finite()
+ || (!expand && lines.iter().all(|line| line.fr().is_zero()))
+ {
+ region
+ .x
+ .min(p.hang + lines.iter().map(|line| line.width).max().unwrap_or_default())
+ } else {
+ region.x
+ };
+
+ // Stack the lines into one frame per region.
+ let shrink = ParElem::shrink_in(styles);
+ lines
+ .iter()
+ .map(|line| commit(engine, p, line, width, region.y, shrink, locator, styles))
+ .collect::<SourceResult<_>>()
+ .map(Fragment::frames)
+}