summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Schmitz <tobiasschmitz2001@gmail.com>2025-06-20 15:59:43 +0200
committerTobias Schmitz <tobiasschmitz2001@gmail.com>2025-07-03 18:42:23 +0200
commit00c3b62f1d01ffe2e7d827114ec866ca862a52cd (patch)
tree22b49cc614ff0572d31b97cbb64aa7494c933535
parent6c686bd460d9db388edaeaf014e61621d6ebf661 (diff)
feat: write tags for more elements
-rw-r--r--crates/typst-library/src/layout/repeat.rs1
-rw-r--r--crates/typst-library/src/model/outline.rs1
-rw-r--r--crates/typst-library/src/pdf/accessibility.rs2
-rw-r--r--crates/typst-pdf/src/tags.rs28
4 files changed, 30 insertions, 2 deletions
diff --git a/crates/typst-library/src/layout/repeat.rs b/crates/typst-library/src/layout/repeat.rs
index ab042ceb..ffc149bb 100644
--- a/crates/typst-library/src/layout/repeat.rs
+++ b/crates/typst-library/src/layout/repeat.rs
@@ -25,6 +25,7 @@ use crate::layout::{BlockElem, Length};
/// Berlin, the 22nd of December, 2022
/// ]
/// ```
+// TODO: should this be a PDF artifact by deafult?
#[elem(Locatable, Show)]
pub struct RepeatElem {
/// The content to repeat.
diff --git a/crates/typst-library/src/model/outline.rs b/crates/typst-library/src/model/outline.rs
index e2c8650c..9db263be 100644
--- a/crates/typst-library/src/model/outline.rs
+++ b/crates/typst-library/src/model/outline.rs
@@ -418,6 +418,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)?;
diff --git a/crates/typst-library/src/pdf/accessibility.rs b/crates/typst-library/src/pdf/accessibility.rs
index 586e2cbb..a0a0bb95 100644
--- a/crates/typst-library/src/pdf/accessibility.rs
+++ b/crates/typst-library/src/pdf/accessibility.rs
@@ -47,7 +47,7 @@ cast! {
}
impl Show for Packed<ArtifactElem> {
- #[typst_macros::time(name = "underline", span = self.span())]
+ #[typst_macros::time(name = "pdf.artifact", span = self.span())]
fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
Ok(self.body.clone())
}
diff --git a/crates/typst-pdf/src/tags.rs b/crates/typst-pdf/src/tags.rs
index 92d3bfe7..28dc9dde 100644
--- a/crates/typst-pdf/src/tags.rs
+++ b/crates/typst-pdf/src/tags.rs
@@ -9,9 +9,11 @@ use krilla::tagging::{
use typst_library::foundations::{Content, LinkMarker, StyleChain};
use typst_library::introspection::Location;
use typst_library::model::{
- Destination, HeadingElem, Outlinable, OutlineElem, OutlineEntry,
+ Destination, FigureCaption, FigureElem, HeadingElem, Outlinable, OutlineElem,
+ OutlineEntry,
};
use typst_library::pdf::{ArtifactElem, ArtifactKind};
+use typst_library::visualize::ImageElem;
use crate::convert::GlobalContext;
use crate::link::LinkAnnotation;
@@ -210,6 +212,30 @@ pub(crate) fn handle_start(
Tag::TOC
} else if let Some(_) = elem.to_packed::<OutlineEntry>() {
Tag::TOCI
+ } else if let Some(_) = elem.to_packed::<FigureElem>() {
+ let alt = None; // TODO
+ Tag::Figure(alt)
+ } else if let Some(image) = elem.to_packed::<ImageElem>() {
+ let alt = image.alt(StyleChain::default()).map(|s| s.to_string());
+
+ end_open(gc, surface);
+ let id = surface.start_tagged(ContentTag::Other);
+ let mut node = TagNode::Leaf(id);
+
+ if let Some(Tag::Figure(alt_text)) = gc.tags.parent().0 {
+ // HACK: set alt text of outer figure tag, if the contained image
+ // has alt text specified
+ if alt_text.is_none() {
+ *alt_text = alt;
+ }
+ } else {
+ node = TagNode::Group(Tag::Figure(alt), vec![node]);
+ }
+ gc.tags.push(node);
+
+ return;
+ } else if let Some(_) = elem.to_packed::<FigureCaption>() {
+ Tag::Caption
} else if let Some(link) = elem.to_packed::<LinkMarker>() {
link_id = Some(gc.tags.next_link_id());
if let Destination::Position(_) | Destination::Location(_) = link.dest {