92 lines
2.5 KiB
Rust
92 lines
2.5 KiB
Rust
//! Typed link nodes and the annotations produced when TeX ships their lists.
|
|
use super::catalog::CatalogAction;
|
|
use crate::execution::Token;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
|
pub enum LinkAction {
|
|
User(Vec<Token>),
|
|
GotoName(Vec<Token>),
|
|
Catalog(CatalogAction),
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
|
pub struct LinkStart {
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub object_number: Option<u32>,
|
|
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, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
|
|
)]
|
|
pub enum DestinationId<T> {
|
|
Name(T),
|
|
Number(i32),
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
|
pub enum LinkNode {
|
|
Start(LinkStart),
|
|
End,
|
|
Running(bool),
|
|
Destination {
|
|
destination: DestinationId<Vec<Token>>,
|
|
view: DestinationView,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
structure: Option<u32>,
|
|
},
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
pub enum AnnotationAction {
|
|
User(String),
|
|
GotoName(String),
|
|
Catalog(CatalogAction),
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
pub struct LinkAnnotation {
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub object_number: Option<u32>,
|
|
/// 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 destination: DestinationId<String>,
|
|
pub point: [i64; 2],
|
|
pub view: DestinationView,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub structure: Option<u32>,
|
|
}
|
|
|
|
#[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()
|
|
}
|
|
}
|