WIP [no ci]

This commit is contained in:
Tobias Schmitz 2025-06-17 17:00:33 +02:00
parent 96e29d5773
commit 4a64a717e8
No known key found for this signature in database
3 changed files with 19 additions and 26 deletions

View File

@ -422,6 +422,7 @@ impl Show for Packed<OutlineEntry> {
let context = Context::new(None, Some(styles));
let context = context.track();
// TODO: prefix should be wrapped in a `Lbl` structure element
let prefix = self.prefix(engine, context, span)?;
let body = self.body().at(span)?;
let page = self.page(engine, context, span)?;

View File

@ -74,12 +74,12 @@ pub(crate) fn handle_link(
let placeholder = gc.tags.reserve_placeholder();
let mut node = TagNode::Placeholder(placeholder);
let (parent_tag, _) = gc.tags.parent_nodes();
if !matches!(parent_tag, Some(Tag::Link | Tag::Reference)) {
node = TagNode::Group(Link, )
let (parent_tag, _) = gc.tags.parent();
if !matches!(parent_tag, Some(Tag::Link)) {
node = TagNode::Group(Tag::Link, vec![node]);
}
// Prepend so the link annotation is the first child.
gc.tags.prepend();
gc.tags.prepend(node);
fc.push_annotation(
placeholder,

View File

@ -67,20 +67,22 @@ impl Tags {
.expect("initialized placeholder node")
}
pub(crate) fn push(&mut self, node: TagNode) {
if let Some((_, _, nodes)) = self.stack.last_mut() {
nodes.push(node);
/// Returns the current parent's list of children and the structure type ([Tag]).
/// In case of the document root the structure type will be `None`.
pub(crate) fn parent(&mut self) -> (Option<&mut Tag>, &mut Vec<TagNode>) {
if let Some((_, tag, parent_nodes)) = self.stack.last_mut() {
(Some(tag), parent_nodes)
} else {
self.tree.push(node);
(None, &mut self.tree)
}
}
pub(crate) fn prepend(&mut self, node: TagNode) {
if let Some((_, _, nodes)) = self.stack.last_mut() {
nodes.insert(0, node);
} else {
self.tree.insert(0, node);
pub(crate) fn push(&mut self, node: TagNode) {
self.parent().1.push(node);
}
pub(crate) fn prepend(&mut self, node: TagNode) {
self.parent().1.insert(0, node);
}
pub(crate) fn build_tree(&mut self) -> TagTree {
@ -109,15 +111,6 @@ impl Tags {
}
}
/// Returns the current parent's list of children and whether it is the tree root.
pub(crate) fn parent_nodes(&mut self) -> (Option<&mut Tag>, &mut Vec<TagNode>) {
if let Some((_, tag, parent_nodes)) = self.stack.last_mut() {
(Some(tag), parent_nodes)
} else {
(None, &mut self.tree)
}
}
fn context_supports(&self, _tag: &Tag) -> bool {
// TODO: generate using: https://pdfa.org/resource/iso-ts-32005-hierarchical-inclusion-rules/
true
@ -245,9 +238,9 @@ pub(crate) fn handle_end(gc: &mut GlobalContext, surface: &mut Surface, loc: &Lo
surface.end_tagged();
let (is_root, parent_nodes) = gc.tags.parent_nodes();
let (parent_tag, parent_nodes) = gc.tags.parent();
parent_nodes.push(TagNode::Group(tag, nodes));
if !is_root {
if parent_tag.is_some() {
// TODO: somehow avoid empty marked-content sequences
let id = surface.start_tagged(ContentTag::Other);
parent_nodes.push(TagNode::Leaf(id));
@ -258,8 +251,7 @@ fn start_artifact(gc: &mut GlobalContext, surface: &mut Surface, kind: ArtifactK
let ty = artifact_type(kind);
let id = surface.start_tagged(ContentTag::Artifact(ty));
let (_, parent_nodes) = gc.tags.parent_nodes();
parent_nodes.push(TagNode::Leaf(id));
gc.tags.push(TagNode::Leaf(id));
}
fn artifact_type(kind: ArtifactKind) -> ArtifactType {