From fd7b9d9e1eb8eef60c20e65dfc946c4424f02c8f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 21 Nov 2022 14:09:30 +0100 Subject: [PATCH] Move destination property from text to link --- library/src/graphics/image.rs | 4 ++-- library/src/graphics/shape.rs | 4 ++-- library/src/text/link.rs | 6 +++++- library/src/text/mod.rs | 3 --- library/src/text/shaping.rs | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/library/src/graphics/image.rs b/library/src/graphics/image.rs index 5524e1c0..12121257 100644 --- a/library/src/graphics/image.rs +++ b/library/src/graphics/image.rs @@ -3,7 +3,7 @@ use std::ffi::OsStr; use typst::image::{Image, ImageFormat, RasterFormat, VectorFormat}; use crate::prelude::*; -use crate::text::TextNode; +use crate::text::LinkNode; /// Show a raster or vector graphic. #[derive(Debug, Hash)] @@ -90,7 +90,7 @@ impl LayoutInline for ImageNode { } // Apply link if it exists. - if let Some(url) = styles.get(TextNode::LINK) { + if let Some(url) = styles.get(LinkNode::DEST) { frame.link(url.clone()); } diff --git a/library/src/graphics/shape.rs b/library/src/graphics/shape.rs index e336c3a3..d484b993 100644 --- a/library/src/graphics/shape.rs +++ b/library/src/graphics/shape.rs @@ -1,7 +1,7 @@ use std::f64::consts::SQRT_2; use crate::prelude::*; -use crate::text::TextNode; +use crate::text::LinkNode; /// A sizable and fillable shape with optional content. #[derive(Debug, Hash)] @@ -161,7 +161,7 @@ impl LayoutInline for ShapeNode { } // Apply link if it exists. - if let Some(url) = styles.get(TextNode::LINK) { + if let Some(url) = styles.get(LinkNode::DEST) { frame.link(url.clone()); } diff --git a/library/src/text/link.rs b/library/src/text/link.rs index 45e7c7ec..fd7aec8a 100644 --- a/library/src/text/link.rs +++ b/library/src/text/link.rs @@ -25,6 +25,10 @@ impl LinkNode { #[node(Show, Finalize)] impl LinkNode { + /// A destination the text should be linked to. + #[property(skip, referenced)] + pub(crate) const DEST: Option = None; + fn construct(_: &mut Vm, args: &mut Args) -> SourceResult { let dest = args.expect::("destination")?; Ok(match dest { @@ -62,6 +66,6 @@ impl Finalize for LinkNode { _: StyleChain, realized: Content, ) -> SourceResult { - Ok(realized.styled(TextNode::LINK, Some(self.dest.clone()))) + Ok(realized.styled(Self::DEST, Some(self.dest.clone()))) } } diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs index a00510b6..c12a61cb 100644 --- a/library/src/text/mod.rs +++ b/library/src/text/mod.rs @@ -124,9 +124,6 @@ impl TextNode { /// Whether small capital glyphs should be used. ("smcp") #[property(skip)] const SMALLCAPS: bool = false; - /// A destination the text should be linked to. - #[property(skip, referenced)] - pub(crate) const LINK: Option = None; /// Decorative lines. #[property(skip, fold)] const DECO: Decoration = vec![]; diff --git a/library/src/text/shaping.rs b/library/src/text/shaping.rs index ac7218a0..6ce4d671 100644 --- a/library/src/text/shaping.rs +++ b/library/src/text/shaping.rs @@ -92,7 +92,7 @@ impl<'a> ShapedText<'a> { let lang = self.styles.get(TextNode::LANG); let decos = self.styles.get(TextNode::DECO); let fill = self.styles.get(TextNode::FILL); - let link = self.styles.get(TextNode::LINK); + let link = self.styles.get(LinkNode::DEST); for ((font, y_offset), group) in self.glyphs.as_ref().group_by_key(|g| (g.font.clone(), g.y_offset))