mirror of
https://github.com/typst/typst
synced 2025-07-27 14:27:56 +08:00
feat: use local krilla version
This commit is contained in:
parent
ac6b9d6008
commit
8075f551e2
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1367,7 +1367,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "krilla"
|
name = "krilla"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/LaurenzV/krilla?rev=20c14fe#20c14fefee5002566b3d6668b338bbe2168784e7"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
@ -1395,7 +1394,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "krilla-svg"
|
name = "krilla-svg"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/LaurenzV/krilla?rev=20c14fe#20c14fefee5002566b3d6668b338bbe2168784e7"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flate2",
|
"flate2",
|
||||||
"fontdb",
|
"fontdb",
|
||||||
|
@ -73,8 +73,8 @@ image = { version = "0.25.5", default-features = false, features = ["png", "jpeg
|
|||||||
indexmap = { version = "2", features = ["serde"] }
|
indexmap = { version = "2", features = ["serde"] }
|
||||||
infer = { version = "0.19.0", default-features = false }
|
infer = { version = "0.19.0", default-features = false }
|
||||||
kamadak-exif = "0.6"
|
kamadak-exif = "0.6"
|
||||||
krilla = { git = "https://github.com/LaurenzV/krilla", rev = "20c14fe", default-features = false, features = ["raster-images", "comemo", "rayon"] }
|
krilla = { path = "../krilla/crates/krilla", default-features = false, features = ["raster-images", "comemo", "rayon"] }
|
||||||
krilla-svg = { git = "https://github.com/LaurenzV/krilla", rev = "20c14fe" }
|
krilla-svg = { path = "../krilla/crates/krilla-svg" }
|
||||||
kurbo = "0.11"
|
kurbo = "0.11"
|
||||||
libfuzzer-sys = "0.4"
|
libfuzzer-sys = "0.4"
|
||||||
lipsum = "0.9"
|
lipsum = "0.9"
|
||||||
|
@ -588,6 +588,16 @@ fn convert_error(
|
|||||||
"{prefix} missing document date";
|
"{prefix} missing document date";
|
||||||
hint: "set the date of the document"
|
hint: "set the date of the document"
|
||||||
),
|
),
|
||||||
|
ValidationError::DuplicateTagId(_id, loc) => {
|
||||||
|
// TODO: display the id and better error message
|
||||||
|
let span = to_span(*loc);
|
||||||
|
error!(span, "{prefix} duplicate tag id")
|
||||||
|
}
|
||||||
|
ValidationError::UnknownHeaderTagId(_id, loc) => {
|
||||||
|
// TODO: display the id and better error message
|
||||||
|
let span = to_span(*loc);
|
||||||
|
error!(span, "{prefix} unknown header tag id")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@ use std::collections::HashMap;
|
|||||||
use krilla::page::Page;
|
use krilla::page::Page;
|
||||||
use krilla::surface::Surface;
|
use krilla::surface::Surface;
|
||||||
use krilla::tagging::{
|
use krilla::tagging::{
|
||||||
ArtifactType, ContentTag, Identifier, Node, Tag, TagGroup, TagTree,
|
ArtifactType, ContentTag, Identifier, Node, Tag, TagBuilder, TagGroup, TagKind,
|
||||||
|
TagTree,
|
||||||
};
|
};
|
||||||
use typst_library::foundations::{Content, LinkMarker, StyleChain};
|
use typst_library::foundations::{Content, LinkMarker, StyleChain};
|
||||||
use typst_library::introspection::Location;
|
use typst_library::introspection::Location;
|
||||||
@ -100,25 +101,22 @@ impl Tags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn build_tree(&mut self) -> TagTree {
|
pub(crate) fn build_tree(&mut self) -> TagTree {
|
||||||
let mut tree = TagTree::new();
|
let children = std::mem::take(&mut self.tree)
|
||||||
let nodes = std::mem::take(&mut self.tree);
|
.into_iter()
|
||||||
// PERF: collect into vec and construct TagTree directly from tag nodes.
|
.map(|node| self.resolve_node(node))
|
||||||
for node in nodes.into_iter().map(|node| self.resolve_node(node)) {
|
.collect::<Vec<_>>();
|
||||||
tree.push(node);
|
TagTree::from(children)
|
||||||
}
|
|
||||||
tree
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves [`Placeholder`] nodes.
|
/// Resolves [`Placeholder`] nodes.
|
||||||
fn resolve_node(&mut self, node: TagNode) -> Node {
|
fn resolve_node(&mut self, node: TagNode) -> Node {
|
||||||
match node {
|
match node {
|
||||||
TagNode::Group(tag, nodes) => {
|
TagNode::Group(tag, nodes) => {
|
||||||
let mut group = TagGroup::new(tag);
|
let children = nodes
|
||||||
// PERF: collect into vec and construct TagTree directly from tag nodes.
|
.into_iter()
|
||||||
for node in nodes.into_iter().map(|node| self.resolve_node(node)) {
|
.map(|node| self.resolve_node(node))
|
||||||
group.push(node);
|
.collect::<Vec<_>>();
|
||||||
}
|
Node::Group(TagGroup::with_children(tag, children))
|
||||||
Node::Group(group)
|
|
||||||
}
|
}
|
||||||
TagNode::Leaf(identifier) => Node::Leaf(identifier),
|
TagNode::Leaf(identifier) => Node::Leaf(identifier),
|
||||||
TagNode::Placeholder(placeholder) => self.take_placeholder(placeholder),
|
TagNode::Placeholder(placeholder) => self.take_placeholder(placeholder),
|
||||||
@ -196,31 +194,31 @@ pub(crate) fn handle_start(
|
|||||||
|
|
||||||
let mut link_id = None;
|
let mut link_id = None;
|
||||||
let mut wrappers = Vec::new();
|
let mut wrappers = Vec::new();
|
||||||
let tag = if let Some(pdf_tag) = elem.to_packed::<PdfTagElem>() {
|
let tag: Tag = if let Some(pdf_tag) = elem.to_packed::<PdfTagElem>() {
|
||||||
let kind = pdf_tag.kind(StyleChain::default());
|
let kind = pdf_tag.kind(StyleChain::default());
|
||||||
match kind {
|
match kind {
|
||||||
PdfTagKind::Part => Tag::Part,
|
PdfTagKind::Part => TagKind::Part.into(),
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
}
|
}
|
||||||
} else if let Some(heading) = elem.to_packed::<HeadingElem>() {
|
} else if let Some(heading) = elem.to_packed::<HeadingElem>() {
|
||||||
let level = heading.level();
|
let level = heading.level();
|
||||||
let name = heading.body.plain_text().to_string();
|
let name = heading.body.plain_text().to_string();
|
||||||
match level.get() {
|
match level.get() {
|
||||||
1 => Tag::H1(Some(name)),
|
1 => TagKind::H1(Some(name)).into(),
|
||||||
2 => Tag::H2(Some(name)),
|
2 => TagKind::H2(Some(name)).into(),
|
||||||
3 => Tag::H3(Some(name)),
|
3 => TagKind::H3(Some(name)).into(),
|
||||||
4 => Tag::H4(Some(name)),
|
4 => TagKind::H4(Some(name)).into(),
|
||||||
5 => Tag::H5(Some(name)),
|
5 => TagKind::H5(Some(name)).into(),
|
||||||
// TODO: when targeting PDF 2.0 headings `> 6` are supported
|
// TODO: when targeting PDF 2.0 headings `> 6` are supported
|
||||||
_ => Tag::H6(Some(name)),
|
_ => TagKind::H6(Some(name)).into(),
|
||||||
}
|
}
|
||||||
} else if let Some(_) = elem.to_packed::<OutlineElem>() {
|
} else if let Some(_) = elem.to_packed::<OutlineElem>() {
|
||||||
Tag::TOC
|
TagKind::TOC.into()
|
||||||
} else if let Some(_) = elem.to_packed::<OutlineEntry>() {
|
} else if let Some(_) = elem.to_packed::<OutlineEntry>() {
|
||||||
Tag::TOCI
|
TagKind::TOCI.into()
|
||||||
} else if let Some(_) = elem.to_packed::<FigureElem>() {
|
} else if let Some(_) = elem.to_packed::<FigureElem>() {
|
||||||
let alt = None; // TODO
|
let alt = None; // TODO
|
||||||
Tag::Figure(alt)
|
TagKind::Figure.with_alt_text(alt)
|
||||||
} else if let Some(image) = elem.to_packed::<ImageElem>() {
|
} else if let Some(image) = elem.to_packed::<ImageElem>() {
|
||||||
let alt = image.alt(StyleChain::default()).map(|s| s.to_string());
|
let alt = image.alt(StyleChain::default()).map(|s| s.to_string());
|
||||||
|
|
||||||
@ -228,26 +226,26 @@ pub(crate) fn handle_start(
|
|||||||
let id = surface.start_tagged(ContentTag::Other);
|
let id = surface.start_tagged(ContentTag::Other);
|
||||||
let mut node = TagNode::Leaf(id);
|
let mut node = TagNode::Leaf(id);
|
||||||
|
|
||||||
if let Some(Tag::Figure(alt_text)) = gc.tags.parent().0 {
|
if let Some(parent) = gc.tags.parent().0 {
|
||||||
// HACK: set alt text of outer figure tag, if the contained image
|
if parent.kind == TagKind::Figure && parent.alt_text.is_none() {
|
||||||
// has alt text specified
|
// HACK: set alt text of outer figure tag, if the contained image
|
||||||
if alt_text.is_none() {
|
// has alt text specified
|
||||||
*alt_text = alt;
|
parent.alt_text = alt;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
node = TagNode::Group(Tag::Figure(alt), vec![node]);
|
node = TagNode::Group(TagKind::Figure.with_alt_text(alt), vec![node]);
|
||||||
}
|
}
|
||||||
gc.tags.push(node);
|
gc.tags.push(node);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if let Some(_) = elem.to_packed::<FigureCaption>() {
|
} else if let Some(_) = elem.to_packed::<FigureCaption>() {
|
||||||
Tag::Caption
|
TagKind::Caption.into()
|
||||||
} else if let Some(link) = elem.to_packed::<LinkMarker>() {
|
} else if let Some(link) = elem.to_packed::<LinkMarker>() {
|
||||||
link_id = Some(gc.tags.next_link_id());
|
link_id = Some(gc.tags.next_link_id());
|
||||||
if let Destination::Position(_) | Destination::Location(_) = link.dest {
|
if let Destination::Position(_) | Destination::Location(_) = link.dest {
|
||||||
wrappers.push(Tag::Reference);
|
wrappers.push(TagKind::Reference.into());
|
||||||
}
|
}
|
||||||
Tag::Link
|
TagKind::Link.into()
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user