diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-27 14:33:00 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-27 14:34:27 +0200 |
| commit | f8009b5b59660b8252bd3ee2cedfd234a1c30cb1 (patch) | |
| tree | 1039e298423f017344e3c9369c2872c82168f6ba /src/frame.rs | |
| parent | 736289b064c53c215249aad70b3a6a96e79b6021 (diff) | |
Reuse location type
Diffstat (limited to 'src/frame.rs')
| -rw-r--r-- | src/frame.rs | 28 |
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()), } } } |
