mirror of
https://github.com/typst/typst
synced 2025-05-19 03:25:27 +08:00
Animation-friendly export (#4822)
This commit is contained in:
parent
cfde809feb
commit
4fda03abdc
@ -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));
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user