From be04cdb0291904ddcd8ea0774f9ca8dc42f30bc5 Mon Sep 17 00:00:00 2001 From: Tobias Schmitz Date: Mon, 28 Jul 2025 11:51:48 +0200 Subject: [PATCH] feat: update krilla --- Cargo.lock | 4 ++-- crates/typst-pdf/src/convert.rs | 4 +--- crates/typst-pdf/src/embed.rs | 2 +- crates/typst-pdf/src/image.rs | 2 +- crates/typst-pdf/src/shape.rs | 2 +- crates/typst-pdf/src/tags/mod.rs | 10 ++++++---- crates/typst-pdf/src/tags/table.rs | 8 ++++---- crates/typst-pdf/src/text.rs | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb7778ac1..8d8143bfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1430,7 +1430,7 @@ dependencies = [ [[package]] name = "krilla" version = "0.4.0" -source = "git+https://github.com/LaurenzV/krilla?branch=main#9e825532895036c7dfb440710d19271c6ad0473a" +source = "git+https://github.com/LaurenzV/krilla?branch=main#9bfd3adc167080017c6e90a5447b83b376c881ff" dependencies = [ "base64", "bumpalo", @@ -1460,7 +1460,7 @@ dependencies = [ [[package]] name = "krilla-svg" version = "0.1.0" -source = "git+https://github.com/LaurenzV/krilla?branch=main#9e825532895036c7dfb440710d19271c6ad0473a" +source = "git+https://github.com/LaurenzV/krilla?branch=main#9bfd3adc167080017c6e90a5447b83b376c881ff" dependencies = [ "flate2", "fontdb", diff --git a/crates/typst-pdf/src/convert.rs b/crates/typst-pdf/src/convert.rs index df45b7784..198b75359 100644 --- a/crates/typst-pdf/src/convert.rs +++ b/crates/typst-pdf/src/convert.rs @@ -1,5 +1,4 @@ use std::collections::{BTreeMap, HashMap, HashSet}; -use std::num::NonZeroU64; use ecow::{EcoVec, eco_format}; use krilla::configure::{Configuration, ValidationError, Validator}; @@ -667,8 +666,7 @@ fn convert_error( /// Convert a krilla location to a span. fn to_span(loc: Option) -> Span { - loc.map(|l| Span::from_raw(NonZeroU64::new(l).unwrap())) - .unwrap_or(Span::detached()) + loc.map(Span::from_raw).unwrap_or(Span::detached()) } fn collect_named_destinations( diff --git a/crates/typst-pdf/src/embed.rs b/crates/typst-pdf/src/embed.rs index b50f4a56d..203e39607 100644 --- a/crates/typst-pdf/src/embed.rs +++ b/crates/typst-pdf/src/embed.rs @@ -47,7 +47,7 @@ pub(crate) fn embed_files( association_kind, data: data.into(), compress, - location: Some(span.into_raw().get()), + location: Some(span.into_raw()), }; if document.embed_file(file).is_none() { diff --git a/crates/typst-pdf/src/image.rs b/crates/typst-pdf/src/image.rs index e0788dd92..89b11b118 100644 --- a/crates/typst-pdf/src/image.rs +++ b/crates/typst-pdf/src/image.rs @@ -29,7 +29,7 @@ pub(crate) fn handle_image( span: Span, ) -> SourceResult<()> { surface.push_transform(&fc.state().transform().to_krilla()); - surface.set_location(span.into_raw().get()); + surface.set_location(span.into_raw()); let interpolate = image.scaling() == Smart::Custom(ImageScaling::Smooth); diff --git a/crates/typst-pdf/src/shape.rs b/crates/typst-pdf/src/shape.rs index 95e9ada4d..854667844 100644 --- a/crates/typst-pdf/src/shape.rs +++ b/crates/typst-pdf/src/shape.rs @@ -22,7 +22,7 @@ pub(crate) fn handle_shape( let mut handle = tags::start_artifact(gc, surface, ArtifactKind::Other); let surface = handle.surface(); - surface.set_location(span.into_raw().get()); + surface.set_location(span.into_raw()); surface.push_transform(&fc.state().transform().to_krilla()); if let Some(path) = convert_geometry(&shape.geometry) { diff --git a/crates/typst-pdf/src/tags/mod.rs b/crates/typst-pdf/src/tags/mod.rs index d9bc06694..029a87b2c 100644 --- a/crates/typst-pdf/src/tags/mod.rs +++ b/crates/typst-pdf/src/tags/mod.rs @@ -113,8 +113,7 @@ pub(crate) fn handle_start( // Wrap the figure tag and the sibling caption in a container, if the // caption is contained within the figure like recommended for tables // screen readers might ignore it. - // TODO: maybe this could be a `NonStruct` tag? - Tag::P.into() + Tag::NonStruct.into() } else if let Some(_) = elem.to_packed::() { Tag::Caption.into() } else if let Some(image) = elem.to_packed::() { @@ -186,7 +185,7 @@ pub(crate) fn handle_start( return Ok(()); }; - tag.set_location(Some(elem.span().into_raw().get())); + tag.set_location(Some(elem.span().into_raw())); push_stack(gc, elem, StackEntryKind::Standard(tag))?; Ok(()) @@ -341,7 +340,7 @@ fn pop_stack(gc: &mut GlobalContext, loc: Location, entry: StackEntry) { // PDF/UA compliance of the structure hierarchy is checked // elsewhere. While this doesn't make a lot of sense, just // avoid crashing here. - let tag = Tag::TD.with_location(Some(cell.span().into_raw().get())); + let tag = Tag::TD.with_location(Some(cell.span().into_raw())); gc.tags.push(TagNode::Group(tag.into(), entry.nodes)); return; }; @@ -791,6 +790,7 @@ impl StackEntryKind { TagKind::Part(_) => !is_pdf_ua, TagKind::Article(_) => !is_pdf_ua, TagKind::Section(_) => !is_pdf_ua, + TagKind::Div(_) => !is_pdf_ua, TagKind::BlockQuote(_) => !is_pdf_ua, TagKind::Caption(_) => !is_pdf_ua, TagKind::TOC(_) => false, @@ -810,6 +810,7 @@ impl StackEntryKind { TagKind::THead(_) => false, TagKind::TBody(_) => false, TagKind::TFoot(_) => false, + TagKind::Span(_) => false, TagKind::InlineQuote(_) => !is_pdf_ua, TagKind::Note(_) => !is_pdf_ua, TagKind::Reference(_) => !is_pdf_ua, @@ -819,6 +820,7 @@ impl StackEntryKind { TagKind::Annot(_) => !is_pdf_ua, TagKind::Figure(_) => !is_pdf_ua, TagKind::Formula(_) => !is_pdf_ua, + TagKind::NonStruct(_) => !is_pdf_ua, TagKind::Datetime(_) => !is_pdf_ua, TagKind::Terms(_) => !is_pdf_ua, TagKind::Title(_) => !is_pdf_ua, diff --git a/crates/typst-pdf/src/tags/table.rs b/crates/typst-pdf/src/tags/table.rs index 96133b012..fc90eb4dc 100644 --- a/crates/typst-pdf/src/tags/table.rs +++ b/crates/typst-pdf/src/tags/table.rs @@ -182,14 +182,14 @@ impl TableCtx { .with_headers(cell.headers) .with_row_span(rowspan) .with_col_span(colspan) - .with_location(Some(cell.span.into_raw().get())) + .with_location(Some(cell.span.into_raw())) .into() } TableCellKind::Footer | TableCellKind::Data => Tag::TD .with_headers(cell.headers) .with_row_span(rowspan) .with_col_span(colspan) - .with_location(Some(cell.span.into_raw().get())) + .with_location(Some(cell.span.into_raw())) .into(), }; Some(TagNode::Group(tag, cell.nodes)) @@ -421,7 +421,7 @@ mod tests { Tag::TH(scope) .with_id(Some(id)) .with_headers(ids) - .with_location(Some(Span::detached().into_raw().get())) + .with_location(Some(Span::detached().into_raw())) .into(), Vec::new(), ) @@ -432,7 +432,7 @@ mod tests { TagNode::Group( Tag::TD .with_headers(ids) - .with_location(Some(Span::detached().into_raw().get())) + .with_location(Some(Span::detached().into_raw())) .into(), Vec::new(), ) diff --git a/crates/typst-pdf/src/text.rs b/crates/typst-pdf/src/text.rs index 466b6f430..293a6ff83 100644 --- a/crates/typst-pdf/src/text.rs +++ b/crates/typst-pdf/src/text.rs @@ -138,6 +138,6 @@ impl krilla::text::Glyph for PdfGlyph { } fn location(&self) -> Option { - Some(self.0.span.0.into_raw().get()) + Some(self.0.span.0.into_raw()) } }