mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Move destination property from text to link
This commit is contained in:
parent
36ea0b05c9
commit
fd7b9d9e1e
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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<const S: ShapeKind> LayoutInline for ShapeNode<S> {
|
||||
}
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
|
@ -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<Destination> = None;
|
||||
|
||||
fn construct(_: &mut Vm, args: &mut Args) -> SourceResult<Content> {
|
||||
let dest = args.expect::<Destination>("destination")?;
|
||||
Ok(match dest {
|
||||
@ -62,6 +66,6 @@ impl Finalize for LinkNode {
|
||||
_: StyleChain,
|
||||
realized: Content,
|
||||
) -> SourceResult<Content> {
|
||||
Ok(realized.styled(TextNode::LINK, Some(self.dest.clone())))
|
||||
Ok(realized.styled(Self::DEST, Some(self.dest.clone())))
|
||||
}
|
||||
}
|
||||
|
@ -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<Destination> = None;
|
||||
/// Decorative lines.
|
||||
#[property(skip, fold)]
|
||||
const DECO: Decoration = vec![];
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user