summaryrefslogtreecommitdiff
path: root/src/frame.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/frame.rs')
-rw-r--r--src/frame.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/frame.rs b/src/frame.rs
index 289de6da..2ece5147 100644
--- a/src/frame.rs
+++ b/src/frame.rs
@@ -3,6 +3,7 @@
use std::fmt::{self, Debug, Formatter, Write};
use std::sync::Arc;
+use crate::eval::{Dict, Value};
use crate::font::FaceId;
use crate::geom::{
Align, Em, Length, Numeric, Paint, Point, Shape, Size, Spec, Transform,
@@ -313,21 +314,30 @@ pub struct Glyph {
}
/// A link destination.
-#[derive(Clone, Eq, PartialEq, Hash)]
+#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum Destination {
/// A link to a point on a page.
- Internal(usize, Point),
+ Internal(Location),
/// A link to a URL.
Url(EcoString),
}
-impl Debug for Destination {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- match self {
- Self::Internal(page, point) => {
- write!(f, "Internal(Page {}, {:?})", page, point)
- }
- Self::Url(url) => write!(f, "Url({})", url),
+/// A physical location in a document.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+pub struct Location {
+ /// The page, starting at 1.
+ pub page: usize,
+ /// The exact coordinates on the page (from the top left, as usual).
+ pub pos: Point,
+}
+
+impl Location {
+ /// Encode into a user-facing dictionary.
+ pub fn encode(&self) -> Dict {
+ dict! {
+ "page" => Value::Int(self.page as i64),
+ "x" => Value::Length(self.pos.x.into()),
+ "y" => Value::Length(self.pos.y.into()),
}
}
}