Implement native PDF links and vertical discard lists

This commit is contained in:
gloamxun committed 2026-11-18 23:39:45 +08:00
1 parent b6567f67e2
commit a53d9c9bf9
29 files changed
+980 -109

No files matched your search

@@ -0,0 +1,71 @@
//! Typed link nodes and the annotations produced when TeX ships their lists.
use crate::execution::Token;
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum LinkAction {
User(Vec<Token>),
GotoName(Vec<Token>),
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct LinkStart {
pub width: Option<i32>,
pub height: Option<i32>,
pub depth: Option<i32>,
pub attributes: Vec<Token>,
pub action: LinkAction,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum DestinationView {
Xyz(Option<i32>),
Fit,
FitH,
FitV,
FitB,
FitBH,
FitBV,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum LinkNode {
Start(LinkStart),
End,
Destination {
name: Vec<Token>,
view: DestinationView,
},
}
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum AnnotationAction {
User(String),
GotoName(String),
}
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct LinkAnnotation {
/// Left, top, right and bottom in TeX sp, with y measured down the page.
pub rect: [i64; 4],
pub attributes: String,
pub action: AnnotationAction,
}
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct PageDestination {
pub name: String,
pub point: [i64; 2],
pub view: DestinationView,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct PageLinks {
pub annotations: Vec<LinkAnnotation>,
pub destinations: Vec<PageDestination>,
}
impl PageLinks {
pub(crate) fn is_empty(&self) -> bool {
self.annotations.is_empty() && self.destinations.is_empty()
}
}