summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/typst-svg/src/lib.rs4
-rw-r--r--crates/typst/src/layout/container.rs11
-rw-r--r--crates/typst/src/layout/frame.rs9
3 files changed, 21 insertions, 3 deletions
diff --git a/crates/typst-svg/src/lib.rs b/crates/typst-svg/src/lib.rs
index 145e23f8..deb5fb00 100644
--- a/crates/typst-svg/src/lib.rs
+++ b/crates/typst-svg/src/lib.rs
@@ -240,6 +240,10 @@ impl SVGRenderer {
self.xml.start_element("g");
self.xml.write_attribute("class", "typst-group");
+ if let Some(label) = group.label {
+ self.xml.write_attribute("data-typst-label", label.as_str());
+ }
+
if let Some(clip_path) = &group.clip_path {
let hash = hash128(&group);
let id = self.clip_paths.insert_with(hash, || shape::convert_path(clip_path));
diff --git a/crates/typst/src/layout/container.rs b/crates/typst/src/layout/container.rs
index 443e660a..5f4a7cd2 100644
--- a/crates/typst/src/layout/container.rs
+++ b/crates/typst/src/layout/container.rs
@@ -196,6 +196,10 @@ impl Packed<BoxElem> {
frame.fill_and_stroke(fill, &stroke, &outset, &radius, self.span());
}
+ if let Some(label) = self.label() {
+ frame.group(|group| group.label = Some(label))
+ }
+
Ok(frame)
}
@@ -660,6 +664,13 @@ impl Packed<BlockElem> {
}
}
+ // Assign label to each frame in the fragment.
+ if let Some(label) = self.label() {
+ for frame in fragment.iter_mut() {
+ frame.group(|group| group.label = Some(label))
+ }
+ }
+
Ok(fragment)
}
diff --git a/crates/typst/src/layout/frame.rs b/crates/typst/src/layout/frame.rs
index 09a4362d..60b690dd 100644
--- a/crates/typst/src/layout/frame.rs
+++ b/crates/typst/src/layout/frame.rs
@@ -6,7 +6,7 @@ use std::sync::Arc;
use smallvec::SmallVec;
-use crate::foundations::{cast, dict, Dict, StyleChain, Value};
+use crate::foundations::{cast, dict, Dict, Label, StyleChain, Value};
use crate::introspection::Tag;
use crate::layout::{
Abs, Axes, Corners, FixedAlignment, HideElem, Length, Point, Rel, Sides, Size,
@@ -380,7 +380,7 @@ impl Frame {
styled_rect(size, radius, fill, stroke)
.into_iter()
.map(|x| (pos, FrameItem::Shape(x, span))),
- )
+ );
}
/// Arbitrarily transform the contents of the frame.
@@ -402,7 +402,7 @@ impl Frame {
}
/// Wrap the frame's contents in a group and modify that group with `f`.
- fn group<F>(&mut self, f: F)
+ pub fn group<F>(&mut self, f: F)
where
F: FnOnce(&mut GroupItem),
{
@@ -549,6 +549,8 @@ pub struct GroupItem {
pub transform: Transform,
/// Whether the frame should be a clipping boundary.
pub clip_path: Option<Path>,
+ /// The group's label.
+ pub label: Option<Label>,
}
impl GroupItem {
@@ -558,6 +560,7 @@ impl GroupItem {
frame,
transform: Transform::identity(),
clip_path: None,
+ label: None,
}
}
}